65 Commits

Author SHA1 Message Date
ea7e693759 Merge pull request 'liquidation pour une parcelle' (#208) from features/fiche_refonte into develop
Reviewed-on: #208
2026-04-30 16:04:27 +00:00
ae2f5bd188 liquidation pour une parcelle
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 29s
2026-04-30 17:03:51 +01:00
6b954c7467 Merge pull request 'liquidation pour une parcelle' (#206) from features/fiche_refonte into develop
Reviewed-on: #206
2026-04-30 10:32:29 +00:00
71e566da25 liquidation pour une parcelle
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 34s
2026-04-30 11:31:58 +01:00
2b2805a125 Merge pull request 'liquidation pour une parcelle' (#204) from features/fiche_refonte into develop
Reviewed-on: #204
2026-04-24 15:46:11 +00:00
fc82e6b1df liquidation pour une parcelle
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 28s
2026-04-24 16:45:38 +01:00
49aea6e50a Merge pull request 'liquidation pour une parcelle' (#202) from features/fiche_refonte into develop
Reviewed-on: #202
2026-04-24 13:53:38 +00:00
ec991b7df9 liquidation pour une parcelle
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 37s
2026-04-24 14:51:28 +01:00
3e105855f0 Merge pull request 'centre assignation et parcelle de contact' (#200) from features/fiche_refonte into develop
Reviewed-on: #200
2026-04-10 14:08:13 +00:00
03f38dfe1c centre assignation et parcelle de contact
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 37s
2026-04-10 15:06:22 +01:00
5b73474192 Merge pull request 'centre assignation' (#198) from features/fiche_refonte into develop
Reviewed-on: #198
2026-04-01 20:03:57 +00:00
9a91961484 centre assignation
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 28s
2026-04-01 21:03:26 +01:00
13ce1f31e2 Merge pull request 'version finale avec imposition TFU, IRF et SRTB' (#196) from features/fiche_refonte into develop
Reviewed-on: #196
2026-03-24 21:17:26 +00:00
ff5a659190 version finale avec imposition TFU, IRF et SRTB
Some checks failed
CI - Build & Test (develop) / build-and-test (pull_request) Has been cancelled
2026-03-24 22:14:44 +01:00
d8dd0ed95e Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#194) from features/fiche_refonte into develop
Reviewed-on: #194
2026-03-23 19:54:16 +00:00
5f2686ed7b fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 35s
2026-03-23 20:53:45 +01:00
ada442ffa4 Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#192) from features/fiche_refonte into develop
Reviewed-on: #192
2026-03-22 18:43:38 +00:00
77671bfb90 fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 34s
2026-03-22 19:41:19 +01:00
5d519855a7 Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#190) from features/fiche_refonte into develop
Reviewed-on: #190
2026-03-21 20:27:23 +00:00
44827030be fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 33s
2026-03-21 21:26:15 +01:00
8bcae0751a Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#188) from features/fiche_refonte into develop
Reviewed-on: #188
2026-03-21 14:59:29 +00:00
14ca79d49e fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 27s
2026-03-21 15:58:37 +01:00
34d1502334 Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#186) from features/fiche_refonte into develop
Reviewed-on: #186
2026-03-21 14:16:31 +00:00
aec566935c fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 28s
2026-03-21 15:15:36 +01:00
e2468328fd Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#184) from features/fiche_refonte into develop
Reviewed-on: #184
2026-03-21 10:13:37 +00:00
d06d6336de fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 29s
2026-03-21 11:11:28 +01:00
41e55da1df Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#182) from features/fiche_refonte into develop
Reviewed-on: #182
2026-03-20 13:39:59 +00:00
16dd68c72c fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 30s
2026-03-20 14:39:31 +01:00
705af14b4e Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#181) from features/fiche_refonte into develop
Reviewed-on: #181
2026-03-20 13:39:00 +00:00
bfe7b319c2 fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 34s
2026-03-20 14:38:30 +01:00
9063162c33 Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#179) from features/fiche_refonte into develop
Reviewed-on: #179
2026-03-19 18:45:31 +00:00
4997fd32c1 fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 34s
2026-03-19 19:44:52 +01:00
3f9cdcdad3 Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#177) from features/fiche_refonte into develop
Reviewed-on: #177
2026-03-19 18:00:14 +00:00
d85b622acf fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 28s
2026-03-19 18:59:38 +01:00
e58e338123 Merge pull request 'features/fiche_refonte' (#175) from features/fiche_refonte into develop
Reviewed-on: #175
2026-03-19 16:15:42 +00:00
db8b38b1c0 fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 33s
2026-03-19 17:14:37 +01:00
afc44b95fb fusion maj parcelle,batiment,ulo et leur enquete 2026-03-19 17:13:54 +01:00
253332bbd3 Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#173) from features/fiche_refonte into develop
Reviewed-on: #173
2026-03-19 10:24:32 +00:00
faf2ccdb8f fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 34s
2026-03-19 11:23:47 +01:00
6dcd549889 Merge pull request 'features/fiche_refonte' (#171) from features/fiche_refonte into develop
Reviewed-on: #171
2026-03-18 17:18:14 +00:00
04ca166db4 fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 2m33s
2026-03-18 18:14:21 +01:00
6ba1365148 fusion maj parcelle,batiment,ulo et leur enquete 2026-03-18 17:49:01 +01:00
0d27aaebac Merge pull request 'fusion maj parcelle,batiment,ulo et leur enquete' (#169) from features/fiche_refonte into develop
Reviewed-on: #169
2026-03-16 13:27:34 +00:00
0d5f7bba1c fusion maj parcelle,batiment,ulo et leur enquete
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 1m32s
2026-03-16 14:17:45 +01:00
afbf525af5 Merge pull request 'Generation tfu batie et non batie avec ressource de liste de données imposition' (#167) from features/crud_entites into develop
Reviewed-on: #167
2026-03-14 14:47:18 +00:00
81bd7d9034 Generation tfu batie et non batie avec ressource de liste de données imposition
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 33s
2026-03-14 15:40:32 +01:00
8ee2f7c9b0 Merge pull request 'Generation tfu batie et non batie avec ressource de liste de données imposition' (#165) from features/crud_entites into develop
Reviewed-on: #165
2026-03-12 20:01:27 +00:00
cec02e24ae Generation tfu batie et non batie avec ressource de liste de données imposition
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 29s
2026-03-12 21:00:21 +01:00
6bdfa3ad1e Merge pull request 'Generation tfu batie et non batie avec ressource de liste de données imposition' (#163) from features/crud_entites into develop
Reviewed-on: #163
2026-03-12 19:34:04 +00:00
dae64dc079 Generation tfu batie et non batie avec ressource de liste de données imposition
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 32s
2026-03-12 20:33:32 +01:00
b8ba15c6fb Merge pull request 'Generation tfu batie et non batie' (#161) from features/crud_entites into develop
Reviewed-on: #161
2026-03-12 11:27:12 +00:00
9de2564108 Generation tfu batie et non batie
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 28s
2026-03-12 12:26:45 +01:00
698b7e7c99 Merge pull request 'Generation tfu batie et non batie' (#158) from features/crud_entites into develop
Reviewed-on: #158
2026-03-12 11:06:47 +00:00
b3e3e7109f Generation tfu batie et non batie
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 28s
2026-03-12 12:05:36 +01:00
9e597386f8 Merge pull request 'Generation tfu batie et non batie' (#156) from features/crud_entites into develop
Reviewed-on: #156
2026-03-12 00:03:12 +00:00
b22b6c8288 Generation tfu batie et non batie
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 27s
2026-03-12 01:00:03 +01:00
cb2faeea32 Merge pull request 'Generation tfu batie et non batie' (#154) from features/crud_entites into develop
Reviewed-on: #154
2026-03-11 00:10:38 +00:00
d326e227c4 Generation tfu batie et non batie
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 26s
2026-03-11 01:09:42 +01:00
6b3ab8fc43 Merge pull request 'Gestion des barem' (#152) from features/crud_entites into develop
Reviewed-on: #152
2026-03-10 21:37:55 +00:00
85be8a2e24 Gestion des barem
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 33s
2026-03-10 22:36:38 +01:00
906a74571f Merge pull request 'features/crud_entites' (#150) from features/crud_entites into develop
Reviewed-on: #150
2026-03-09 20:13:24 +00:00
fcc81e0607 Gestion des barem
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 28s
2026-03-09 21:12:09 +01:00
862b917689 Gestion des barem 2026-03-09 21:11:24 +01:00
6494fe235e Merge pull request 'Gestion des barem' (#148) from features/crud_entites into develop
Reviewed-on: #148
2026-03-09 20:00:03 +00:00
9b4edcdcea Gestion des barem
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 30s
2026-03-09 20:59:23 +01:00
125 changed files with 15491 additions and 490 deletions

View File

@@ -1,6 +1,7 @@
package io.gmss.fiscad.controllers.decoupage;
import io.gmss.fiscad.entities.decoupage.SecteurDecoupage;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.interfaces.decoupage.SecteurDecoupageService;
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
@@ -248,4 +249,221 @@ public class SecteurDecoupageController {
}
@GetMapping("/arbre/enquete-en-cours/user-id/{userId}")
public ResponseEntity<?> getArborescenceEnqueteEncoursByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, secteurDecoupageService.getStatEnqueteDecoupageByUserId(userId, StatutEnquete.EN_COURS.toString()), "SecteurDecoupage trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/arbre/enquete-valide/user-id/{userId}")
public ResponseEntity<?> getArborescenceEnqueteValideByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, secteurDecoupageService.getStatEnqueteDecoupageByUserId(userId, StatutEnquete.VALIDE.toString()), "SecteurDecoupage trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/arbre/enquete-cloture/user-id/{userId}")
public ResponseEntity<?> getArborescenceEnqueteClotureByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, secteurDecoupageService.getStatEnqueteDecoupageByUserId(userId, StatutEnquete.CLOTURE.toString()), "SecteurDecoupage trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/arbre/enquete-batiment-en-cours/user-id/{userId}")
public ResponseEntity<?> getArborescenceEnqueteBatimentEncoursByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, secteurDecoupageService.getStatEnqueteBatimentDecoupageByUserId(userId, StatutEnquete.EN_COURS.toString()), "SecteurDecoupage trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/arbre/enquete-batiment-valide/user-id/{userId}")
public ResponseEntity<?> getArborescenceEnqueteBatimentValideByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, secteurDecoupageService.getStatEnqueteBatimentDecoupageByUserId(userId, StatutEnquete.VALIDE.toString()), "SecteurDecoupage trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/arbre/enquete-batiment-cloture/user-id/{userId}")
public ResponseEntity<?> getArborescenceEnqueteBatimentClotureByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, secteurDecoupageService.getStatEnqueteBatimentDecoupageByUserId(userId, StatutEnquete.CLOTURE.toString()), "SecteurDecoupage trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/arbre/enquete-unitlog-en-cours/user-id/{userId}")
public ResponseEntity<?> getArborescenceEnqueteUniteLogEncoursByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, secteurDecoupageService.getStatEnqueteUniteLogementDecoupageByUserId(userId, StatutEnquete.EN_COURS.toString()), "SecteurDecoupage trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/arbre/enquete-unitlog-valide/user-id/{userId}")
public ResponseEntity<?> getArborescenceEnqueteUniteLogValideByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, secteurDecoupageService.getStatEnqueteUniteLogementDecoupageByUserId(userId, StatutEnquete.VALIDE.toString()), "SecteurDecoupage trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/arbre/enquete-unitlog-cloture/user-id/{userId}")
public ResponseEntity<?> getArborescenceEnqueteUniteLigClotureByUserId(@PathVariable Long userId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, secteurDecoupageService.getStatEnqueteUniteLogementDecoupageByUserId(userId, StatutEnquete.CLOTURE.toString()), "SecteurDecoupage trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
}

View File

@@ -3,6 +3,7 @@ package io.gmss.fiscad.controllers.infocad.metier;
import io.gmss.fiscad.entities.infocad.metier.Enquete;
import io.gmss.fiscad.entities.rfu.metier.EnqueteBatiment;
import io.gmss.fiscad.entities.user.User;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.interfaces.infocad.metier.EnqueteService;
import io.gmss.fiscad.paylaods.ApiResponse;
@@ -67,7 +68,8 @@ public class EnqueteController {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
e.printStackTrace();
// logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
@@ -122,6 +124,7 @@ public class EnqueteController {
@PutMapping("/rejet")
public ResponseEntity<?> rejeterEnquete(@RequestBody EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteService.rejeterEnquete(enqueteTraitementPayLoad), "Rejet effectuée avec succès."),
HttpStatus.OK
@@ -483,8 +486,65 @@ public class EnqueteController {
@GetMapping("/all-paged/en-cours/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllEnqueteEncoursByQuartierPaged(@CurrentUser UserPrincipal currentUser,@PathVariable Long quartierId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
if(currentUser==null)
return new ResponseEntity<>(
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
HttpStatus.OK
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteService.getEnqueteListByQuartierByStatutPageableToDto(userId,quartierId, StatutEnquete.EN_COURS, pageable), "Liste des enquetes en cours chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged/cloture/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllEnqueteClotureByQuartierPaged(@CurrentUser UserPrincipal currentUser,@PathVariable Long quartierId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
if(currentUser==null)
return new ResponseEntity<>(
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
HttpStatus.OK
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteService.getEnqueteListByQuartierByStatutPageableToDto(userId,quartierId, StatutEnquete.CLOTURE, pageable), "Liste des enquetes en cours chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
}

View File

@@ -154,7 +154,7 @@ public class ParcelleController {
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, parcelleService.getParcelleByIdToDto(userId,id), "enquete trouvé avec succès."),
new ApiResponse<>(true, parcelleService.getParcelleByIdToDto(userId,id), "parcelle trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {

View File

@@ -223,4 +223,52 @@ public class BatimentController {
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllBatimentByQuartierPaged(@PathVariable Long quartierId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, batimentService.getBatimentListByquartierPageable(quartierId,pageable), "Liste des batiments chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllBatimentByQuartier(@PathVariable Long quartierId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, batimentService.getBatimentListByquartier(quartierId), "Liste des batiments chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
}

View File

@@ -0,0 +1,314 @@
package io.gmss.fiscad.controllers.rfu.metier;
import io.gmss.fiscad.entities.user.User;
import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.implementations.infocad.metier.PersonneServiceImpl;
import io.gmss.fiscad.interfaces.rfu.metier.CommuneCentreAssignationService;
import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb;
import io.gmss.fiscad.security.CurrentUser;
import io.gmss.fiscad.security.UserPrincipal;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException;
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/commune-centre-assignation", produces = MediaType.APPLICATION_JSON_VALUE)
@SecurityRequirement(name = "bearer")
@Tag(name = "CommuneCentreAssignation")
@CrossOrigin(origins = "*")
public class CommuneCentreAssignationController {
private final CommuneCentreAssignationService communeCentreAssignationService;
private final PersonneServiceImpl personneService;
private static final Logger logger = LoggerFactory.getLogger(CommuneCentreAssignationController.class);
// public CommuneCentreAssignationController(CommuneCentreAssignationService communeCentreAssignationService) {
// this.communeCentreAssignationService = communeCentreAssignationService;
// }
@PostMapping("/assigne-centre")
public ResponseEntity<?> AssigneCommuneCentre(@CurrentUser UserPrincipal userPrincipal, @RequestBody CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) {
try {
if(userPrincipal==null){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "vous ne pouvez pas faire cette action."),
HttpStatus.OK
);
}
User user = userPrincipal.getUser();
communeCentreAssignationPaylaodWeb = communeCentreAssignationService.createCommuneCentreAssignation(user,communeCentreAssignationPaylaodWeb);
return new ResponseEntity<>(
new ApiResponse<>(true, communeCentreAssignationPaylaodWeb, "CommuneCentreAssignation créé avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PostMapping("/detache-centre")
public ResponseEntity<?> detacheCommuneCentre(@CurrentUser UserPrincipal userPrincipal, @RequestBody CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) {
try {
if(userPrincipal==null){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "vous ne pouvez pas faire cette action."),
HttpStatus.OK
);
}
User user = userPrincipal.getUser();
communeCentreAssignationPaylaodWeb = communeCentreAssignationService.detacherCommuneCentreAssignation(user,communeCentreAssignationPaylaodWeb);
return new ResponseEntity<>(
new ApiResponse<>(true, communeCentreAssignationPaylaodWeb, "CommuneCentreAssignation créé avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PutMapping("/update/{id}")
public ResponseEntity<?> updateCommuneCentreAssignation(@PathVariable Long id, @RequestBody CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, communeCentreAssignationService.updateCommuneCentreAssignation(id,communeCentreAssignationPaylaodWeb), "CommuneCentreAssignation mise à jour avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@DeleteMapping("/delete/{id}")
public ResponseEntity<?> deleteCommuneCentreAssignation(@PathVariable Long id) {
try {
communeCentreAssignationService.deleteCommuneCentreAssignation(id);
return new ResponseEntity<>(
new ApiResponse<>(true, "CommuneCentreAssignation supprimée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged")
public ResponseEntity<?> getAllCommuneCentreAssignationPaged(@RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationList(pageable), "Liste des caractéristiques chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged/by-commune-id/{communeId}")
public ResponseEntity<?> getAllCommuneCentreAssignationByCommuneList(@PathVariable Long communeId,@RequestParam int pageNo, @RequestParam int pageSize ) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationListByCommunePageable(communeId,pageable), "Liste des assignation de centre chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/id/{id}")
public ResponseEntity<?> getCommuneCentreAssignationById(@PathVariable Long id) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationById(id), "CommuneCentreAssignation trouvée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@Operation(summary = "Liste des contribuables ayant un centre d'assignation")
@GetMapping("/all-paged/by-structure-id/{structureId}")
public ResponseEntity<?> getAllCommuneCentreAssignationByStrucutrePaged(@PathVariable Long structureId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationListByCentrePageable(structureId, pageable), "Liste des communeCentreAssignations chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@Operation(summary = "Liste des contribuables sans centre d'assignation")
@GetMapping("/all-paged/sans-centre-assignation")
public ResponseEntity<?> getAllPersonneSansCentreAssignationPaged(@RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, personneService.getPersonneListNonAssigneePage(pageable), "Liste des contribuables sans centre d'assignation chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@Operation(summary = "Vérifier l'assignation d'un contribuable",description = "permet de vérifier si un contribuable a déjà un centre d'assignation dans la commune de l'utilisateur connecté")
@GetMapping("/contribuable/{personneId}")
public ResponseEntity<?> getAssignationPersonne(@CurrentUser UserPrincipal currentUser, @PathVariable Long personneId) {
try {
if(currentUser==null){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "vous ne pouvez pas faire cette action."),
HttpStatus.OK
);
}
User user = currentUser.getUser();
return new ResponseEntity<>(
new ApiResponse<>(true, communeCentreAssignationService.getCommuneCentreAssignationByPersonneIdCommune(user,personneId).orElse(null), "Assignation chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
}

View File

@@ -36,7 +36,7 @@ public class DeclarationNcController {
@PostMapping("/create")
public ResponseEntity<?> createDeclarationNc(@RequestBody @Valid @Validated DeclarationNcPayloadWeb declarationNcPayloadWeb) {
public ResponseEntity<?> createDeclarationNc(@RequestBody DeclarationNcPayloadWeb declarationNcPayloadWeb) {
try {
declarationNcPayloadWeb = declarationNcService.createDeclarationNc(declarationNcPayloadWeb);
return new ResponseEntity<>(

View File

@@ -9,6 +9,8 @@ import io.gmss.fiscad.interfaces.rfu.metier.DonneesImpositionTfuService;
import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.paylaods.request.crudweb.ImpositionsTfuPaylaodWeb;
import io.gmss.fiscad.persistence.repositories.rfu.metier.ImpositionsTfuRepository;
import io.gmss.fiscad.security.CurrentUser;
import io.gmss.fiscad.security.UserPrincipal;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -114,11 +116,60 @@ public class DonneesImpositionTfuController {
}
}
@GetMapping("/all")
public ResponseEntity<?> getAllDonneesImpositionTfuList() {
// @GetMapping("/all")
// public ResponseEntity<?> getAllDonneesImpositionTfuList() {
// try {
// return new ResponseEntity<>(
// new ApiResponse<>(true, donneesImpositionTfuService.getDonneesImpositionTfuList(), "Liste des impositions chargée avec succès."),
// HttpStatus.OK
// );
// } catch (HttpClientErrorException.MethodNotAllowed e) {
// logger.error(e.getLocalizedMessage());
// return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
// } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
// FileStorageException e) {
// logger.error(e.getLocalizedMessage());
// return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
// } catch (NullPointerException e) {
// logger.error(e.getLocalizedMessage());
// return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
// } catch (Exception e) {
// logger.error(e.getLocalizedMessage());
// return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
// }
// }
// @GetMapping("/all-paged")
// public ResponseEntity<?> getAllDonneesImpositionTfuPaged(@RequestParam int pageNo, @RequestParam int pageSize) {
// try {
// Pageable pageable = PageRequest.of(pageNo, pageSize);
// return new ResponseEntity<>(
// new ApiResponse<>(true, donneesImpositionTfuService.getDonneesImpositionTfuList(pageable), "Liste des impositions chargée avec succès."),
// HttpStatus.OK
// );
// } catch (HttpClientErrorException.MethodNotAllowed e) {
// logger.error(e.getLocalizedMessage());
// return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
// } catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
// FileStorageException e) {
// logger.error(e.getLocalizedMessage());
// return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
// } catch (NullPointerException e) {
// logger.error(e.getLocalizedMessage());
// return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
// } catch (Exception e) {
// logger.error(e.getLocalizedMessage());
// return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
// }
// }
@GetMapping("/all-page/by-imposition-id/{impositionId}")
public ResponseEntity<?> getAllDonneesImpositionTfuByImpositionIdPaged(@PathVariable Long impositionId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesImpositionTfuList(), "Liste des caractéristiques chargée avec succès."),
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdPageable(impositionId, pageable), "Liste des impositions chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
@@ -137,12 +188,61 @@ public class DonneesImpositionTfuController {
}
}
@GetMapping("/all-paged")
public ResponseEntity<?> getAllDonneesImpositionTfuPaged(@RequestParam int pageNo, @RequestParam int pageSize) {
@GetMapping("/all-page/by-imposition-id/non-batie/{impositionId}")
public ResponseEntity<?> getAllDonneesImpositionTfuByImpositionIdNonBatiePaged(@PathVariable Long impositionId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesImpositionTfuList(pageable), "Liste des caractéristiques chargée avec succès."),
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdNonBatiePageable(impositionId, pageable), "Liste des impositions chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-page/by-imposition-id/batie-batiment/{impositionId}")
public ResponseEntity<?> getAllDonneesImpositionTfuByImpositionIdBatieBatimentPaged(@PathVariable Long impositionId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdBatieBatimentPageable(impositionId, pageable), "Liste des impositions chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-page/by-imposition-id/batie-unite-logement/{impositionId}")
public ResponseEntity<?> getAllDonneesImpositionTfuByImpositionIdBatieUniteLogPaged(@PathVariable Long impositionId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdBatieUniteLogPageable(impositionId, pageable), "Liste des impositions chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
@@ -183,9 +283,114 @@ public class DonneesImpositionTfuController {
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@Operation(summary = "Générer les données fiscales TFU")
@PostMapping("/generer")
public ResponseEntity<?> genererDonneesFiscale(@RequestBody ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb) {
@Operation(summary = "Générer les données fiscales TFU des parcelle baties")
@PostMapping("/generer-batie")
public ResponseEntity<?> genererDonneesFiscaleBatie(@CurrentUser UserPrincipal userPrincipal, @RequestBody ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb) {
try {
Optional<ImpositionsTfu> optionalImpositionsTfu =impositionsTfuRepository.findById(impositionsTfuPaylaodWeb.getId());
if(optionalImpositionsTfu.isEmpty()){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "L'instance d'imposition n'est pas trouvée."),
HttpStatus.OK
);
}
if(!optionalImpositionsTfu.get().getStatusAvis().equals(StatusAvis.TFU_FNB_GENERE)){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "l'état actuel : "+optionalImpositionsTfu.get().getStatusAvis()+" ne permet pas cette opération."),
HttpStatus.OK
);
}
if(userPrincipal==null){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "Vous n'êtes pas autorisé à accéder à cette ressource"),
HttpStatus.OK
);
}
impositionsTfuPaylaodWeb=donneesImpositionTfuService.genererDonneesFiscalesParcelleBatie(impositionsTfuPaylaodWeb,userPrincipal.getUser().getId());
return new ResponseEntity<>(
new ApiResponse<>(true,impositionsTfuPaylaodWeb, "Données d'imposition des fonciers batis Générées avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@Operation(
summary = "Générer les données fiscales TFU pour une seule parcelle",
description = "Génère les impositions TFU pour une parcelle bâtie donnée"
)
@PostMapping("/generer-batie/{parcelleId}")
public ResponseEntity<?> genererDonneesFiscaleBatieUneParcelle(@CurrentUser UserPrincipal userPrincipal, @RequestBody ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb,@PathVariable Long parcelleId) {
try {
Optional<ImpositionsTfu> optionalImpositionsTfu =impositionsTfuRepository.findById(impositionsTfuPaylaodWeb.getId());
if(optionalImpositionsTfu.isEmpty()){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "L'instance d'imposition n'est pas trouvée."),
HttpStatus.OK
);
}
// if(!optionalImpositionsTfu.get().getStatusAvis().equals(StatusAvis.TFU_FNB_GENERE)){
// return new ResponseEntity<>(
// new ApiResponse<>(false, null, "l'état actuel : "+optionalImpositionsTfu.get().getStatusAvis()+" ne permet pas cette opération."),
// HttpStatus.OK
// );
// }
if(userPrincipal==null){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "Vous n'êtes pas autorisé à accéder à cette ressource"),
HttpStatus.OK
);
}
impositionsTfuPaylaodWeb=donneesImpositionTfuService.genererDonneesFiscalesParcelleBatieUneParcelle(impositionsTfuPaylaodWeb,userPrincipal.getUser().getId(),parcelleId);
return new ResponseEntity<>(
new ApiResponse<>(true,impositionsTfuPaylaodWeb, "Données d'imposition des fonciers batis Générées avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@Operation(summary = "Générer les données fiscales TFU des parcelle baties")
@PostMapping("/generer-non-batie")
public ResponseEntity<?> genererDonneesImpositionNonBaties(@CurrentUser UserPrincipal userPrincipal, @RequestBody ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb) {
try {
Optional<ImpositionsTfu> optionalImpositionsTfu =impositionsTfuRepository.findById(impositionsTfuPaylaodWeb.getId());
@@ -203,12 +408,69 @@ public class DonneesImpositionTfuController {
);
}
optionalImpositionsTfu.get().setStatusAvis(StatusAvis.GENERE);
impositionsTfuPaylaodWeb=donneesImpositionTfuService.genererDonneesFiscales(impositionsTfuPaylaodWeb);
if(userPrincipal==null){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "Vous n'êtes pas autorisé à accéder à cette ressource"),
HttpStatus.OK
);
}
impositionsTfuPaylaodWeb=donneesImpositionTfuService.genererDonneesFiscalesParcelleNonBatie(impositionsTfuPaylaodWeb,userPrincipal.getUser().getId());
return new ResponseEntity<>(
new ApiResponse<>(true,impositionsTfuPaylaodWeb, "Données d'imposition Générées avec succès."),
new ApiResponse<>(true,impositionsTfuPaylaodWeb, "Données d'imposition pour les fonciers non batis Générées avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@Operation(
summary = "Générer les données fiscales TFU pour une seule parcelle",
description = "Génère les impositions TFU pour une parcelle non bâtie donnée"
)
@PostMapping("/generer-non-batie/{parcelleId}")
public ResponseEntity<?> genererDonneesImpositionNonBatiesUneParcelle(@CurrentUser UserPrincipal userPrincipal, @RequestBody ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, @PathVariable Long parcelleId) {
try {
Optional<ImpositionsTfu> optionalImpositionsTfu =impositionsTfuRepository.findById(impositionsTfuPaylaodWeb.getId());
if(optionalImpositionsTfu.isEmpty()){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "L'instance d'imposition n'est pas trouvée."),
HttpStatus.OK
);
}
// if(!optionalImpositionsTfu.get().getStatusAvis().equals(StatusAvis.GENERATION_AUTORISE)){
// return new ResponseEntity<>(
// new ApiResponse<>(false, null, "l'état actuel : "+optionalImpositionsTfu.get().getStatusAvis()+" ne permet pas cette opération."),
// HttpStatus.OK
// );
// }
if(userPrincipal==null){
return new ResponseEntity<>(
new ApiResponse<>(false, null, "Vous n'êtes pas autorisé à accéder à cette ressource"),
HttpStatus.OK
);
}
impositionsTfuPaylaodWeb=donneesImpositionTfuService.genererDonneesFiscalesParcelleNonBatieUneParcelle(impositionsTfuPaylaodWeb,userPrincipal.getUser().getId(),parcelleId);
return new ResponseEntity<>(
new ApiResponse<>(true,impositionsTfuPaylaodWeb, "Données d'imposition pour les fonciers non batis Générées avec succès."),
HttpStatus.OK
);
@@ -278,4 +540,79 @@ public class DonneesImpositionTfuController {
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-page/by-exercice-id/by-structure-id/{exerciceId}/{structureId}")
public ResponseEntity<?> getAllDonneesImpositionTfuByExerciceIdAndStructureIdPaged(@PathVariable Long exerciceId, @PathVariable Long structureId,@RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
System.out.println("NOUS SOMMES ICI");
return new ResponseEntity<>(
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByExerciceAndStructureIdPageable(exerciceId,structureId, pageable), "Liste des impositions chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all/by-exercice-id/by-structure-id/by-quartier-id/{exerciceId}/{structureId}/{quartierId}")
public ResponseEntity<?> getAllDonneesImpositionTfuByExerciceIdAndStructureId(@PathVariable Long exerciceId, @PathVariable Long structureId, @PathVariable Long quartierId) {
try {
System.out.println("NOUS SOMMES ICI");
return new ResponseEntity<>(
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByExerciceAndStructureId(exerciceId,structureId,quartierId), "Liste des imposition chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all/by-personne-id/{personneId}")
public ResponseEntity<?> getAllDonneesImpositionTfuByPersonneId(@PathVariable Long personneId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByPersonneId(personneId), "Liste des impositions chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
}

View File

@@ -2,10 +2,14 @@ package io.gmss.fiscad.controllers.rfu.metier;
import io.gmss.fiscad.entities.rfu.metier.EnqueteBatiment;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.interfaces.rfu.metier.EnqueteBatimentService;
import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.EnqueteBatimentPayloadWeb;
import io.gmss.fiscad.security.CurrentUser;
import io.gmss.fiscad.security.UserPrincipal;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -20,6 +24,8 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException;
import java.util.List;
@RestController
@RequestMapping(value = "api/enquete-batiment", produces = MediaType.APPLICATION_JSON_VALUE)
@@ -51,6 +57,7 @@ public class EnqueteBatimentController {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
e.printStackTrace();
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
@@ -223,4 +230,159 @@ public class EnqueteBatimentController {
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged/en-cours/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllEnqueteBatimentEnCoursByQuartierPaged(@CurrentUser UserPrincipal currentUser, @PathVariable Long quartierId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
if(currentUser==null)
return new ResponseEntity<>(
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
HttpStatus.OK
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteBatimentService.getEnqueteBatimentListByQuartierByStatutPageableToDto(userId,quartierId, StatutEnquete.EN_COURS, pageable), "Liste des enquetes en cours chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged/cloture/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllEnqueteBatimentClotureByQuartierPaged(@CurrentUser UserPrincipal currentUser, @PathVariable Long quartierId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
if(currentUser==null)
return new ResponseEntity<>(
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
HttpStatus.OK
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteBatimentService.getEnqueteBatimentListByQuartierByStatutPageableToDto(userId,quartierId, StatutEnquete.CLOTURE, pageable), "Liste des enquetes en cours chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PutMapping("/validation")
public ResponseEntity<?> validerEnquete(@RequestBody EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteBatimentService.validerEnquete(enqueteTraitementPayLoad), "Validation effectuée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PutMapping("/rejet")
public ResponseEntity<?> rejeterEnquete(@RequestBody EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteBatimentService.rejeterEnquete(enqueteTraitementPayLoad), "Rejet effectuée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PutMapping("/validation-lot")
public ResponseEntity<?> validerEnqueteParLot(@RequestBody List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteBatimentService.validerEnquete(enqueteTraitementPayLoads), "Validation effectuée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PutMapping("/rejet-lot")
public ResponseEntity<?> rejeterEnqueteParLot(@RequestBody List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteBatimentService.rejeterEnquete(enqueteTraitementPayLoads), "Rejet effectuée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
}

View File

@@ -2,10 +2,14 @@ package io.gmss.fiscad.controllers.rfu.metier;
import io.gmss.fiscad.entities.rfu.metier.EnqueteUniteLogement;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.interfaces.rfu.metier.EnqueteUniteLogementService;
import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.EnqueteUniteLogementPayloadWeb;
import io.gmss.fiscad.security.CurrentUser;
import io.gmss.fiscad.security.UserPrincipal;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
@@ -20,6 +24,8 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException;
import java.util.List;
@RestController
@RequestMapping(value = "api/enquete-unite-logement", produces = MediaType.APPLICATION_JSON_VALUE)
@@ -223,4 +229,160 @@ public class EnqueteUniteLogementController {
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged/en-cours/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllEnqueteUniteLogementEncoursByQuartierPaged(@CurrentUser UserPrincipal currentUser, @PathVariable Long quartierId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
if(currentUser==null)
return new ResponseEntity<>(
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
HttpStatus.OK
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.getEnqueteUniteLogementListByQuartierByStatutPageableToDto(userId,quartierId, StatutEnquete.EN_COURS, pageable), "Liste des enquetes en cours chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged/cloture/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllEnqueteUniteLogementClotureByQuartierPaged(@CurrentUser UserPrincipal currentUser, @PathVariable Long quartierId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
if(currentUser==null)
return new ResponseEntity<>(
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
HttpStatus.OK
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.getEnqueteUniteLogementListByQuartierByStatutPageableToDto(userId,quartierId, StatutEnquete.CLOTURE, pageable), "Liste des enquetes en cours chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PutMapping("/validation")
public ResponseEntity<?> validerEnquete(@RequestBody EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.validerEnquete(enqueteTraitementPayLoad), "Validation effectuée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PutMapping("/rejet")
public ResponseEntity<?> rejeterEnquete(@RequestBody EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.rejeterEnquete(enqueteTraitementPayLoad), "Rejet effectuée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PutMapping("/validation-lot")
public ResponseEntity<?> validerEnqueteParLot(@RequestBody List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.validerEnquete(enqueteTraitementPayLoads), "Validation effectuée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@PutMapping("/rejet-lot")
public ResponseEntity<?> rejeterEnqueteParLot(@RequestBody List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.rejeterEnquete(enqueteTraitementPayLoads), "Rejet effectuée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
}

View File

@@ -247,4 +247,54 @@ public class UniteLogementController {
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all-paged/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllUniteLogementByQuartierPaged(@PathVariable Long quartierId, @RequestParam int pageNo, @RequestParam int pageSize) {
try {
Pageable pageable = PageRequest.of(pageNo, pageSize);
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementListByQuartierPageable(quartierId,pageable), "Liste des unites de logements chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@GetMapping("/all/by-quartier-id/{quartierId}")
public ResponseEntity<?> getAllUniteLogementByQuartier(@PathVariable Long quartierId) {
try {
return new ResponseEntity<>(
new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementListByQuartier(quartierId), "Liste des unites de logements chargée avec succès."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
}

View File

@@ -35,7 +35,7 @@ public class BaremRfuNonBatiController {
@PostMapping("/create")
public ResponseEntity<?> createBaremRfuNonBati(@RequestBody @Valid @Validated BaremRfuNonBatiPayloadWeb baremRfuNonBatiPayloadWeb) {
public ResponseEntity<?> createBaremRfuNonBati(@RequestBody BaremRfuNonBatiPayloadWeb baremRfuNonBatiPayloadWeb) {
try {
baremRfuNonBatiPayloadWeb = baremRfuNonBatiService.createBaremRfuNonBati(baremRfuNonBatiPayloadWeb);
return new ResponseEntity<>(

View File

@@ -1,9 +1,12 @@
package io.gmss.fiscad.controllers.statistique;
import io.gmss.fiscad.enums.NiveauDecoupage;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.interfaces.statistique.StatistiquesService;
import io.gmss.fiscad.paylaods.ApiResponse;
import io.gmss.fiscad.security.CurrentUser;
import io.gmss.fiscad.security.UserPrincipal;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -174,4 +177,77 @@ public class StatistiqueController {
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@Operation(
summary = "Statistique des enquetes en cours par object ",
description = "Donnes le nombre d'enquetes en coures par objet"
)
@GetMapping(path = "/nombre-enquete/par-objet/en-cours")
public ResponseEntity<?> getStatistiquesEnqueteEnCoursParObjet(@CurrentUser UserPrincipal currentUser) {
try {
if(currentUser==null)
return new ResponseEntity<>(
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
HttpStatus.OK
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, statistiquesService.getStatNombreEnqueteParObjetUserConnect(userId,StatutEnquete.EN_COURS.toString()), "Statistique des personne par type."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
@Operation(
summary = "Statistique des enquetes en cours par object ",
description = "Donnes le nombre d'enquetes en coures par objet"
)
@GetMapping(path = "/nombre-enquete/par-objet/cloture")
public ResponseEntity<?> getStatistiquesEnqueteClotureParObjet(@CurrentUser UserPrincipal currentUser) {
try {
if(currentUser==null)
return new ResponseEntity<>(
new ApiResponse<>(true,null, "Vous ne pouvez pas accéder à cette ressource"),
HttpStatus.OK
);
Long userId = currentUser.getUser().getId();
return new ResponseEntity<>(
new ApiResponse<>(true, statistiquesService.getStatNombreEnqueteParObjetUserConnect(userId, StatutEnquete.CLOTURE.toString()), "Statistique des personne par type."),
HttpStatus.OK
);
} catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
FileStorageException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
} catch (NullPointerException e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
}
}
}

View File

@@ -29,6 +29,8 @@ public class Quartier extends BaseEntity implements Serializable {
@ManyToOne
private Arrondissement arrondissement;
private String longitude;
private String latitude;
// @JsonIgnore
// @OneToOne(mappedBy = "quartier")
// private Bloc bloc;

View File

@@ -99,9 +99,9 @@ public class Enquete extends BaseEntity implements Serializable {
@ManyToOne
private Campagne campagne;
@JsonIgnore
@ManyToOne
private Equipe equipe;
// @JsonIgnore
// @ManyToOne
// private Equipe equipe;
// @JsonIgnore
@ManyToOne

View File

@@ -61,7 +61,7 @@ public class Parcelle extends BaseEntity implements Serializable {
@ManyToOne
private Tpe terminal;
private String autreNumeroTitreFoncier;
private Long numeroProvisoire;
private String numeroProvisoire;
private Long blocId;
@ColumnDefault("false")
private boolean synchronise;

View File

@@ -97,6 +97,7 @@ public class ParcelleGeom extends BaseEntity implements Serializable {
@Enumerated(EnumType.STRING)
private SourceDonnee sourceDonnees;
private String observations;
@Enumerated(EnumType.STRING)
private StatutParcelle statutParcelle;
private Long uploadId;
@@ -118,7 +119,7 @@ public class ParcelleGeom extends BaseEntity implements Serializable {
private Quartier quartier ;
@ColumnDefault("0")
private int geomSrid;
private Integer geomSrid;
@JsonSerialize(using = GeometrySerializer.class)
@JsonDeserialize(contentUsing = GeometryDeserializer.class)
@Column(name = "geometry",columnDefinition = "geometry(Polygon,32631)")

View File

@@ -24,6 +24,7 @@ import org.hibernate.annotations.Where;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
@EqualsAndHashCode(callSuper = true)
@@ -88,7 +89,7 @@ public class Piece extends BaseEntity implements Serializable {
@OneToMany(mappedBy = "piece")
private List<Upload> uploads;
private List<Upload> uploads=new ArrayList<>();
@JsonIgnore
@ManyToOne
@@ -103,4 +104,9 @@ public class Piece extends BaseEntity implements Serializable {
private boolean synchronise;
private String observation;
private Long nombreFichier;
public Long getNombreFichier() {
return uploads==null? 0l:uploads.size() ;
}
}

View File

@@ -41,6 +41,7 @@ public class Personne extends BaseEntity implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String ifu;
private String nc;
private String nom;
private String prenom;
private String raisonSociale;

View File

@@ -0,0 +1,62 @@
package io.gmss.fiscad.entities.interface_sigibe;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.decoupage.Quartier;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDate;
@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeclarationSpontaneBien extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long idImposition ;
private String rImposition ;
private String ifu ;
private String rCommune ;
private String rQuartier ;
private String qipQuartier;
private String qipIlot;
private String qipParcelle;
private String nup;
private String gpsLatitude;
private String gpsLongitude;
private String commentaire;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateValidation;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateInformation;
private Long valeurBatiment;
private Long nub;
private Long nul;
private Long montantLocatifAnnuel ;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateConstruction;
private Float superficieSolBat;
private Float superficieSolUlot;
private Float superficieParcelle;
private String usage;
private Boolean bati;
@ManyToOne
private Personne personne;
@ManyToOne
private Quartier quartier;
}

View File

@@ -0,0 +1,58 @@
package io.gmss.fiscad.entities.interface_sigibe;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.infocad.parametre.PositionRepresentation;
import io.gmss.fiscad.entities.infocad.parametre.TypeContestation;
import io.gmss.fiscad.entities.infocad.parametre.TypeRepresentation;
import io.gmss.fiscad.enums.SourceDonnee;
import io.gmss.fiscad.enums.TypeDroit;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDate;
@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EpaiementAcompte extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long idPaiementAcompte;
private Long idPaiementImpot;
private String rDoc;
private String rImpot;
private String idImpotType;
private String idImpotNature;
private String ifu;
private String rCommune;
private String rQuartier;
private String qipQuartier;
private String qipIlot;
private String qipParcelle;
private String nup;
private Long exercice;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateValidation;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateAvisCredit;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateRapprochement;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateInformation;
private Long montantPayer;
}

View File

@@ -0,0 +1,55 @@
package io.gmss.fiscad.entities.interface_sigibe;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.enums.SourceDonnee;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDate;
@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EpaiementRetenu extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long idPaiementRetenue;
private Long idEdiGenerique;
private Long idPaiementImpot;
private String rDoc;
private String rImpot;
private String idImpotType;
private String idImpotNature;
private String ifuPayeur;
private String ifuRetenue;
private String rCommune;
private String rQuartier;
private String qipQuartier;
private String qipIlot;
private String qipParcelle;
private String nup;
private Long exercice;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateValidation;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateAvisCredit;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateRapprochement;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateInformation;
private Long montantPayer;
}

View File

@@ -0,0 +1,50 @@
package io.gmss.fiscad.entities.interface_sigibe;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.enums.SourceDonnee;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDate;
@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PaiementAvis extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long idPaiementImpot;
private Long idAvis;
private Long idUniteFoncier;
private Long idContribuableFoncier;
private String rDoc;
private String rImpot;
private String idImpotType;
private String idImpotNature;
private String ifu;
private String rCommune;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateValidation;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateAvisCredit;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateRapprochement;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateInformation;
private Long montantPayer;
}

View File

@@ -0,0 +1,67 @@
package io.gmss.fiscad.entities.rfu.metier;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.decoupage.Commune;
import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.entities.infocad.metier.Tpe;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.infocad.parametre.Structure;
import io.gmss.fiscad.enums.StatutEnregistrement;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDate;
@Entity
@Table(
uniqueConstraints = {
@UniqueConstraint(
name = "uk_structure_commune_personne",
columnNames = {"structure_id", "commune_id", "personne_id"}
)
}
)
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class CommuneCentreAssignation extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JsonIgnore
@ManyToOne
@JoinColumn(name = "structure_id", nullable = false)
private Structure structure;
@JsonIgnore
@ManyToOne
@JoinColumn(name = "commune_id", nullable = false)
private Commune commune;
@JsonIgnore
@ManyToOne
@JoinColumn(name = "personne_id")
private Personne personne;
@JsonIgnore
@ManyToOne
@JoinColumn(name = "parcelle_id")
private Parcelle parcelle;
private String nc;
private String ifu;
private String adresseContact ;
}

View File

@@ -36,19 +36,22 @@ public class DeclarationNc extends BaseEntity implements Serializable {
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateDerniereDeclaration;
@JsonFormat(pattern = "yyyy-MM-dd")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateDeclarationNc;
private String nc;
private String q;
private String i;
private String p;
private String numeroTitreFoncier;
private String nup;
private String observation;
@JsonIgnore
@ManyToOne
private Structure structure;
private Long enqueteExternalKey;
@JsonIgnore

View File

@@ -8,6 +8,10 @@ import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.infocad.metier.Enquete;
import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.entities.infocad.metier.Tpe;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.infocad.parametre.Structure;
import io.gmss.fiscad.entities.rfu.parametre.ZoneRfu;
import io.gmss.fiscad.enums.NatureImpot;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -70,16 +74,22 @@ public class DonneesImpositionTfu extends BaseEntity implements Serializable {
private String latitude;
private int superficieParc;
private Long superficieAuSolBat;
private Long superficieAuSolLoue;
private Long superficieAuSolUlog;
private String batieOuiNon;
private String exhonereOuiNon;
private String batimentExhonereOuiNon;
private String uniteLogementExhonereOuiNon;
private Boolean batie;
private Boolean exonere;
private Boolean batimentExonere;
private Boolean uniteLogementExonere;
private Long valeurLocativeAdm;
private Long valeurLocativeAdmTauxPropParc;
private Long valeurLocativeAdmSupReel;
private Long superficieAuSolTauxPropParc;
private Long valeurLocativeAdmMetreCarre;
private Long montantLoyerAnnuel;
private Long tfuMetreCarre;
private Long tfuMinimum;
private String standingBat;
private String categorieUsage;
private String categorieBat;
private Long nombrePiscine;
private Long nombreUlog;
@@ -88,14 +98,59 @@ public class DonneesImpositionTfu extends BaseEntity implements Serializable {
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateEnquete;
private Long enqueteId;
private Long structureId;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "structure_id")
private Structure structure ;
private Long secteurId;
private Long zoneRfuId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "zone_rfu_id")
private ZoneRfu zoneRfu ;
@ColumnDefault("0")
private float tauxParcelleNonBati;
private Long valeurAdministrativeParcelleNonBati;
private Long valeurAdminParcelleNb;
private Float tauxTfu;
private Long tfuPiscine;
private Float montantTaxe;
private Float penalite;
private Float retenuIrf ;
private Float acompte ;
private Float montantRestant ;
private Float montantTaxeBrut; //montant de la taxe calculée sans comparaisons avec TFU MINI
private Float tfuCalculeTauxPropParc;
private Float tfuSuperficieAuSolReel;
private Long valeurAdminParcelleNbMetreCarre;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "impositions_tfu_id", nullable = false)
private ImpositionsTfu impositionsTfu ;
@Enumerated(EnumType.STRING)
private NatureImpot natureImpot;
private Long valeurBatiment;
private Long valeurParcelle;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parcelle_id")
private Parcelle parcelleImposee ;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "batiment_id")
private Batiment batimentImpose ;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "unite_logement_id")
private UniteLogement uniteLogementImposee ;
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
private Personne personne ;
private Boolean parcelleContact;
}

View File

@@ -83,6 +83,14 @@ public class EnqueteBatiment extends BaseEntity implements Serializable {
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateEnquete;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateValidation;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateRejet;
private String descriptionMotifRejet;
@ManyToOne
private Exercice exercice;

View File

@@ -73,6 +73,15 @@ public class EnqueteUniteLogement extends BaseEntity implements Serializable {
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateEnquete;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateValidation;
@JsonFormat(pattern = "dd-MM-yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate dateRejet;
private String descriptionMotifRejet;
private String observation;
private Long uniteLogementExternalKey;

View File

@@ -55,7 +55,10 @@ public class ImpositionsTfu extends BaseEntity implements Serializable {
@Enumerated(EnumType.STRING)
private StatusAvis statusAvis;
private Long nombreAvis;
private Integer nombreAvis;
private Integer nombreAvisFnb;
private Integer nombreAvisBatiment;
private Integer nombreAvisUniteLog;
@Column(columnDefinition = "TEXT")
private String motif;
@@ -65,7 +68,5 @@ public class ImpositionsTfu extends BaseEntity implements Serializable {
@JoinColumn(name = "impositions_tfu_id")
private List<DonneesImpositionTfu> donneesImpositionTfus;
public Long getNombreAvis(){
return donneesImpositionTfus==null?0l:donneesImpositionTfus.size();
}
}

View File

@@ -51,6 +51,7 @@ public class UniteLogement extends BaseEntity implements Serializable {
private Long montantLocatifAnnuelDeclare;
private Long montantLocatifAnnuelCalcule;
private Long valeurUniteLogementEstime;
private Long montantLocatifAnnuelEstime;
private Long valeurUniteLogementReel;
private Long valeurUniteLogementCalcule;
private Integer nombrePiscine;

View File

@@ -23,6 +23,8 @@ public class BaremRfuNonBati extends BaseEntity implements Serializable {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long valeurAdministrative;
private Long valeurAdministrativeMetreCarre;
private Boolean auMetreCarre;
private Float taux;
@ManyToOne
private Commune commune;

View File

@@ -0,0 +1,8 @@
package io.gmss.fiscad.enums;
public enum NatureImpot {
FB,
FNB,
IRF,
SRTB
}

View File

@@ -12,5 +12,11 @@ public enum ParametersType {
CORPS_RESET_PASSWORD,
OBJET_CREATE_ACCOUNT,
CORPS_CREATE_ACCOUNT,
TOKEN_IFU_EN_LIGNE ;
TOKEN_IFU_EN_LIGNE,
TAUX_TFU,
TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE,
TAUX_DEFAUT_SUPERFICIE_AU_SOL,
TAUX_IRF,
TAXE_SRTB,
TFU_PAR_PISCINE;
}

View File

@@ -2,9 +2,12 @@ package io.gmss.fiscad.enums;
public enum StatusAvis {
EN_COURS,
CLOTURE,
GENERATION_AUTORISE,
REJETE,
TFU_FNB_GENERE,
GENERE
}

View File

@@ -2,7 +2,6 @@ package io.gmss.fiscad.enums;
public enum StatutEnquete {
EN_COURS,
// DECLARATION,
FINALISE,
REJETE,
VALIDE,

View File

@@ -1,7 +1,7 @@
package io.gmss.fiscad.enums;
public enum StatutParcelle {
NON_ENQUETER,
NON_ENQUETE,
AJOUR,
NON_AJOUR;
}

View File

@@ -3,7 +3,11 @@ package io.gmss.fiscad.enums;
public enum UserProfile {
INSPECTEUR_GESTIONNAIRE,
ADMIN_FONCTIONNEL,
ADMIN_TECHNIQUE,
INSPECTEUR_GESTIONNAIRE_CHEF_SERVICE,
AGENT_CONSTATATION_ASSIETTE,
CONSULTATION,
ENQUETEUR,
INSPECTEUR_GESTIONNAIRE_CHEF_SECTEUR,
INSPECTEUR_GESTIONNAIRE_CHEF_SECTION,
INSPECTEUR_GESTIONNAIRE_CHEF_CENTRE
}

View File

@@ -2,15 +2,18 @@ package io.gmss.fiscad.implementations.decoupage;
import io.gmss.fiscad.entities.decoupage.Secteur;
import io.gmss.fiscad.entities.decoupage.SecteurDecoupage;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.decoupage.SecteurDecoupageService;
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
import io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb;
import io.gmss.fiscad.paylaods.request.crudweb.SecteurPaylaodWeb;
import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur;
import io.gmss.fiscad.paylaods.response.statistique.ParcelleStatsProjectionUnSecteur;
import io.gmss.fiscad.persistence.repositories.decoupage.SecteurDecoupageRepository;
import io.gmss.fiscad.persistence.repositories.infocad.metier.EnqueteRepository;
import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.EnqueteBatimentRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.EnqueteUniteLogementRepository;
import io.gmss.fiscad.service.EntityFromPayLoadService;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
@@ -26,6 +29,9 @@ public class SecteurDecoupageServiceImpl implements SecteurDecoupageService {
private final SecteurDecoupageRepository secteurDecoupageRepository;
private final SecteurService secteurService;
private final ParcelleRepository parcelleRepository;
private final EnqueteRepository enqueteRepository;
private final EnqueteBatimentRepository enqueteBatimentRepository;
private final EnqueteUniteLogementRepository enqueteUniteLogementRepository;
private final EntityFromPayLoadService entityFromPayLoadService;
@@ -112,4 +118,36 @@ public class SecteurDecoupageServiceImpl implements SecteurDecoupageService {
return parcelleStatsProjectionUnSecteurs ;
}
@Override
public List<ParcelleStatsProjectionUnSecteur> getStatEnqueteDecoupageByUserId(Long userId, String statutEnquete) {
List<Secteur> secteurs= secteurService.getListSecteurUserId(userId);
List<Long> secteurIds = secteurs.stream()
.map(Secteur::getId)
.toList();
System.out.println(statutEnquete);
return enqueteRepository.findStatsEnqueteBySecteurs(secteurIds,statutEnquete);
}
@Override
public List<ParcelleStatsProjectionUnSecteur> getStatEnqueteBatimentDecoupageByUserId(Long userId, String statutEnquete) {
List<Secteur> secteurs= secteurService.getListSecteurUserId(userId);
List<Long> secteurIds = secteurs.stream()
.map(Secteur::getId)
.toList();
System.out.println(statutEnquete);
System.out.println(secteurIds);
return enqueteBatimentRepository.findStatsEnqueteBatimentBySecteurs(secteurIds,statutEnquete);
}
@Override
public List<ParcelleStatsProjectionUnSecteur> getStatEnqueteUniteLogementDecoupageByUserId(Long userId, String statutEnquete) {
List<Secteur> secteurs= secteurService.getListSecteurUserId(userId);
List<Long> secteurIds = secteurs.stream()
.map(Secteur::getId)
.toList();
return enqueteUniteLogementRepository.findStatsEnqueteBatimentBySecteurs(secteurIds,statutEnquete);
}
}

View File

@@ -1,5 +1,6 @@
package io.gmss.fiscad.implementations.infocad.metier;
import io.gmss.fiscad.entities.decoupage.Secteur;
import io.gmss.fiscad.entities.infocad.metier.*;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.rfu.metier.CaracteristiqueParcelle;
@@ -13,7 +14,9 @@ import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.ApplicationException;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
import io.gmss.fiscad.interfaces.infocad.metier.EnqueteService;
import io.gmss.fiscad.interfaces.infocad.metier.ParcelleService;
import io.gmss.fiscad.interfaces.infocad.metier.PieceService;
import io.gmss.fiscad.interfaces.rfu.metier.CaracteristiqueParcelleService;
import io.gmss.fiscad.interfaces.rfu.metier.DeclarationNcService;
@@ -23,6 +26,7 @@ import io.gmss.fiscad.interfaces.user.UserService;
import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad;
import io.gmss.fiscad.paylaods.request.FiltreEnquetePayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.EnquetePayLoadWeb;
import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb;
import io.gmss.fiscad.paylaods.response.* ;
import io.gmss.fiscad.paylaods.response.FicheResponse.* ;
import io.gmss.fiscad.paylaods.response.synchronisation.EnqueteNonSyncResponse;
@@ -44,6 +48,7 @@ import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.Query;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.NotAcceptableException;
import lombok.RequiredArgsConstructor;
import org.modelmapper.ModelMapper;
import org.springframework.data.domain.Page;
@@ -78,13 +83,9 @@ public class EnqueteServiceImpl implements EnqueteService {
private final ParcelleServiceImpl parcelleService;
private final PersonneRepository personneRepository;
private final ZoneRfuRepository zoneRfuRepository ;
private final EquipeRepository equipeRepository ;
private final RueRepository rueRepository ;
private final CaracteristiqueParcelleService caracteristiqueParcelleService ;
private final PieceService pieceService ;
private final UploadRepository uploadRepository ;
private final DeclarationNcService declarationNcService ;
private final EntityFromPayLoadService entityFromPayLoadService ;
private final SecteurService secteurService ;
;
@PersistenceContext
private final EntityManager em;
@@ -92,69 +93,75 @@ public class EnqueteServiceImpl implements EnqueteService {
@Override
@Transactional
public EnquetePayLoadWeb createEnquete(EnquetePayLoadWeb enquetePayLoadWeb) throws BadRequestException {
Optional<User> optionalUser = userRepository.findById(enquetePayLoadWeb.getEnqueteurId());
if (!optionalUser.isPresent()) {
throw new BadRequestException("Echec de l'enregistrement : Enquêteur inexistant");
}
Optional<Personne> optionalPersonne = personneRepository.findById(enquetePayLoadWeb.getPersonneId());
if (!optionalPersonne.isPresent()) {
throw new BadRequestException("Echec de l'enregistrement : Propriétaire inexistant");
}
if(enquetePayLoadWeb.getParcelleId()!=null) {
Optional<Parcelle> optionalParcelle = parcelleRepository.findById(enquetePayLoadWeb.getParcelleId());
if (!optionalParcelle.isPresent()) {
throw new BadRequestException("Echec de l'enregistrement : Parcelle inexistante");
}
}
Optional<ZoneRfu> optionalZoneRfu = zoneRfuRepository.findById(enquetePayLoadWeb.getZoneRfuId());
if (!optionalZoneRfu.isPresent()) {
throw new BadRequestException("Echec de l'enregistrement : zone inexistante");
}
if (enquetePayLoadWeb.getParcelleId() == null) {
throw new ApplicationException("Echec de l'enregistrement : La parcelle non renseignée.");
ParcellePayLoadWeb parcellePayLoadWeb= getParcellePayloadFromEnquetePl(enquetePayLoadWeb);
if(parcellePayLoadWeb.getId()==null){
parcellePayLoadWeb=parcelleService.createParcelle(parcellePayLoadWeb);
}else{
parcellePayLoadWeb=parcelleService.updateParcelle(parcellePayLoadWeb.getId(),parcellePayLoadWeb);
}
enquetePayLoadWeb.setParcelleId(parcellePayLoadWeb.getId());
Enquete enquete = entityFromPayLoadService.getEnqueteFromPayLoadWeb(enquetePayLoadWeb);
////enregistrement de l'enquete
enquete=enqueteRepository.save(enquete);
//////Enregistrement des caractéristiques parcelle
// enquetePayLoadWeb.getCaracteristiqueParcellePayloadWebs().forEach(caracteristiqueParcellePayloadWeb -> {
// caracteristiqueParcellePayloadWeb.setEnqueteId(finalEnquete.getId());
// CaracteristiqueParcelle caracteristiqueParcelle=entityFromPayLoadService.getCaracteristiqueParcelleFromPayLoadWeb(caracteristiqueParcellePayloadWeb);
// caracteristiqueParcelleService.createCaracteristiqueParcelle(caracteristiqueParcelle);
// });
/////Enregistrement des pièce de parcelles
// enquetePayLoadWeb.getPiecePayLoadWebs().forEach(piecePayLoadWeb -> {
// piecePayLoadWeb.setEnqueteId(finalEnquete.getId());
// //Piece piece=entityFromPayLoadService.getPieceFromPayLoadWeb(piecePayLoadWeb);
// Piece piecefinal = pieceService.createPiece(entityFromPayLoadService.getPieceFromPayLoadWeb(piecePayLoadWeb));
// piecePayLoadWeb.getUploadPayLoadWebs().forEach(uploadPayLoadWeb -> {
// uploadPayLoadWeb.setEnqueteId(finalEnquete.getId());
// Upload upload=entityFromPayLoadService.getUploadFromPayLoadWeb(uploadPayLoadWeb);
// upload.setPiece(piecefinal);
// uploadRepository.save(upload);
// });
// });
/////Enregistrement des pièce de parcelles
// enquetePayLoadWeb.getDeclarationNcPayloadWebs().forEach(declarationNcPayloadWeb -> {
// declarationNcPayloadWeb.setEnqueteId(finalEnquete.getId());
// DeclarationNc declarationNcfinal=declarationNcService.createDeclarationNc(entityFromPayLoadService.getDeclarationNcFromPayLoadWeb(declarationNcPayloadWeb));
// declarationNcPayloadWeb.getUploadPayLoadWebs().forEach(uploadPayLoadWeb -> {
// uploadPayLoadWeb.setEnqueteId(finalEnquete.getId());
// Upload upload=entityFromPayLoadService.getUploadFromPayLoadWeb(uploadPayLoadWeb);
// upload.setDeclarationNc(declarationNcfinal);
// uploadRepository.save(upload);
// });
// });
return enqueteRepository.findEnqueteToDto(enquete.getId()).orElse(null);
}
private ParcellePayLoadWeb getParcellePayloadFromEnquetePl(EnquetePayLoadWeb enquetePayLoadWeb) {
ParcellePayLoadWeb parcellePayLoadWeb=new ParcellePayLoadWeb();
parcellePayLoadWeb.setId(enquetePayLoadWeb.getParcelleId());
parcellePayLoadWeb.setQ(enquetePayLoadWeb.getParcelleQ());
parcellePayLoadWeb.setI(enquetePayLoadWeb.getParcelleI());
parcellePayLoadWeb.setP(enquetePayLoadWeb.getParcelleP());
parcellePayLoadWeb.setNup(enquetePayLoadWeb.getParcelleNup());
parcellePayLoadWeb.setNupProvisoire(enquetePayLoadWeb.getNupProvisoire());
parcellePayLoadWeb.setNumTitreFoncier(enquetePayLoadWeb.getNumeroTitreFoncier());
parcellePayLoadWeb.setLongitude(enquetePayLoadWeb.getLongitude());
parcellePayLoadWeb.setLatitude(enquetePayLoadWeb.getLatitude());
parcellePayLoadWeb.setAltitude(enquetePayLoadWeb.getAltitude());
parcellePayLoadWeb.setSuperficie(enquetePayLoadWeb.getSuperficie());
parcellePayLoadWeb.setObservation(enquetePayLoadWeb.getObservation());
parcellePayLoadWeb.setSituationGeographique(enquetePayLoadWeb.getSituationGeographique());
parcellePayLoadWeb.setNumEntreeParcelle(enquetePayLoadWeb.getNumEntreeParcelle());
parcellePayLoadWeb.setQuartierId(enquetePayLoadWeb.getQuartierId());
parcellePayLoadWeb.setNatureDomaineId(enquetePayLoadWeb.getNatureDomaineId());
parcellePayLoadWeb.setTypeDomaineId(enquetePayLoadWeb.getTypeDomaineId());
parcellePayLoadWeb.setRueId(enquetePayLoadWeb.getRueId());
parcellePayLoadWeb.setProprietaireId(enquetePayLoadWeb.getPersonneId());
parcellePayLoadWeb.setNatureDomaineId(enquetePayLoadWeb.getNatureDomaineId());
parcellePayLoadWeb.setNatureDomaineId(enquetePayLoadWeb.getNatureDomaineId());
return parcellePayLoadWeb;
}
@Override
public EnquetePayLoadWeb updateEnquete(Long id,EnquetePayLoadWeb enquetePayLoadWeb) throws NotFoundException {
if (enquetePayLoadWeb.getId() == null) {
@@ -168,8 +175,6 @@ public class EnqueteServiceImpl implements EnqueteService {
throw new BadRequestException("Impossible d'enregistrer une enquête avec une parcelle inexistante");
}
Optional<Parcelle> optionalParcelle=Optional.empty();
Long rueId;
Optional<User> optionalUser = userRepository.findById(enquetePayLoadWeb.getEnqueteurId());
if (!optionalUser.isPresent()) {
throw new BadRequestException("Echec de l'enregistrement : Enquêteur inexistant");
@@ -183,12 +188,25 @@ public class EnqueteServiceImpl implements EnqueteService {
if (!optionalZoneRfu.isPresent()) {
throw new BadRequestException("Echec de l'enregistrement : zone inexistante");
}
///enregistrement de la pacelle
if (enquetePayLoadWeb.getParcelleId() == null) {
throw new ApplicationException("Echec de l'enregistrement : La parcelle non renseignée.");
} else {
optionalParcelle = parcelleService.getParcelleById(enquetePayLoadWeb.getParcelleId());
if(enquetePayLoadWeb.getParcelleId()!=null) {
Optional<Parcelle> optionalParcelle = parcelleRepository.findById(enquetePayLoadWeb.getParcelleId());
if (!optionalParcelle.isPresent()) {
throw new BadRequestException("Echec de l'enregistrement : Parcelle inexistante");
}
}
ParcellePayLoadWeb parcellePayLoadWeb= getParcellePayloadFromEnquetePl(enquetePayLoadWeb);
if(parcellePayLoadWeb.getId()==null){
parcellePayLoadWeb=parcelleService.createParcelle(parcellePayLoadWeb);
}else{
parcellePayLoadWeb=parcelleService.updateParcelle(parcellePayLoadWeb.getId(),parcellePayLoadWeb);
}
enquetePayLoadWeb.setParcelleId(parcellePayLoadWeb.getId());
Enquete enquete = entityFromPayLoadService.getEnqueteFromPayLoadWeb(enquetePayLoadWeb);
enquete=enqueteRepository.save(enquete);
@@ -338,7 +356,7 @@ public class EnqueteServiceImpl implements EnqueteService {
}
@Override
public Enquete validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
public EnquetePayLoadWeb validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
if (enqueteTraitementPayLoad == null) {
throw new BadRequestException("Impossible de valider une enquête ayant un id null.");
}
@@ -346,15 +364,22 @@ public class EnqueteServiceImpl implements EnqueteService {
if (!optionalEnquete.isPresent()) {
throw new NotFoundException("Impossible de trouver l'enquête que vous désirez valider.");
}
if(optionalEnquete.get().getStatutEnquete()==StatutEnquete.CLOTURE ||
optionalEnquete.get().getStatutEnquete()==StatutEnquete.REJETE ){
throw new NotAcceptableException("Impossible de valider : Le statut actuel "+optionalEnquete.get().getStatutEnquete()+" ne le permet pas.");
}
Enquete enquete = optionalEnquete.get();
enquete.setDateValidation(LocalDate.now());
enquete.setStatutEnquete(StatutEnquete.VALIDE);
enquete.setSynchronise(true);
return enqueteRepository.save(enquete);
enquete= enqueteRepository.save(enquete);
return enqueteRepository.findEnqueteToDto(enquete.getId()).orElse(null);
}
@Override
public Enquete rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
public EnquetePayLoadWeb rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
if (enqueteTraitementPayLoad.getIdBackend() == null) {
throw new BadRequestException("Impossible de rejeter une enquête ayant un id null.");
}
@@ -362,38 +387,43 @@ public class EnqueteServiceImpl implements EnqueteService {
if (!optionalEnquete.isPresent()) {
throw new NotFoundException("Impossible de trouver l'enquête que vous désirez rejeter.");
}
if(optionalEnquete.get().getStatutEnquete()==StatutEnquete.CLOTURE ||
optionalEnquete.get().getStatutEnquete()==StatutEnquete.VALIDE ){
throw new NotAcceptableException("Impossible de rejeter : Le statut actuel "+optionalEnquete.get().getStatutEnquete()+" ne le permet pas.");
}
Enquete enquete = optionalEnquete.get();
enquete.setDateRejet(LocalDate.now());
enquete.setDescriptionMotifRejet(enqueteTraitementPayLoad.getMotifRejet());
enquete.setStatutEnquete(StatutEnquete.REJETE);
enquete.setSynchronise(false);
return enqueteRepository.save(enquete);
enquete= enqueteRepository.save(enquete);
return enqueteRepository.findEnqueteToDto(enquete.getId()).orElse(null);
}
@Override
public List<Enquete> validerEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
List<Enquete> enquetes = new ArrayList<>();
public List<EnquetePayLoadWeb> validerEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
List<EnquetePayLoadWeb> enquetePayLoadWebs = new ArrayList<>();
try {
for (EnqueteTraitementPayLoad enqueteTraitementPayLoad : enqueteTraitementPayLoads) {
enquetes.add(validerEnquete(enqueteTraitementPayLoad));
enquetePayLoadWebs.add(validerEnquete(enqueteTraitementPayLoad));
}
} catch (Exception e) {
enquetes.add(null);
enquetePayLoadWebs.add(null);
}
return enquetes;
return enquetePayLoadWebs;
}
@Override
public List<Enquete> rejeterEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
List<Enquete> enquetes = new ArrayList<>();
public List<EnquetePayLoadWeb> rejeterEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
List<EnquetePayLoadWeb> enquetePayLoadWebs = new ArrayList<>();
try {
for (EnqueteTraitementPayLoad enqueteTraitementPayLoad : enqueteTraitementPayLoads) {
enquetes.add(rejeterEnquete(enqueteTraitementPayLoad));
enquetePayLoadWebs.add(rejeterEnquete(enqueteTraitementPayLoad));
}
} catch (Exception e) {
enquetes.add(null);
enquetePayLoadWebs.add(null);
}
return enquetes;
return enquetePayLoadWebs;
}
@Override
@@ -554,6 +584,16 @@ public class EnqueteServiceImpl implements EnqueteService {
return nbreEnquete;
}
@Override
public Page<EnquetePayLoadWeb> getEnqueteListByQuartierByStatutPageableToDto(Long userId, Long quartierId, StatutEnquete statutEnquete, Pageable pageable) {
List<Secteur> secteurs= secteurService.getListSecteurUserId(userId);
List<Long> secteurIds = secteurs.stream()
.map(Secteur::getId)
.toList();
return enqueteRepository.findAllEnqueteByQuartierByStatutToDtoPageable(quartierId,secteurIds,statutEnquete,pageable);
}
@Override
@Transactional
public int cloturerEnqueteParcelleBatimentUniteLogementByStructureIdAndExerciceId(Long structureId,Long exerciceId) {

View File

@@ -2,10 +2,12 @@ package io.gmss.fiscad.implementations.infocad.metier;
import io.gmss.fiscad.entities.decoupage.Quartier;
import io.gmss.fiscad.entities.decoupage.Secteur;
import io.gmss.fiscad.entities.infocad.metier.Enquete;
import io.gmss.fiscad.entities.infocad.metier.EnqueteFiltreResponse;
import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.entities.infocad.metier.Rue;
import io.gmss.fiscad.entities.infocad.parametre.NatureDomaine;
import io.gmss.fiscad.entities.infocad.parametre.TypeDomaine;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
@@ -19,7 +21,9 @@ import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository
import io.gmss.fiscad.persistence.repositories.infocad.metier.RueRepository;
import io.gmss.fiscad.persistence.repositories.infocad.parametre.NatureDomaineRepository;
import io.gmss.fiscad.persistence.repositories.infocad.parametre.SituationGeographiqueRepository;
import io.gmss.fiscad.persistence.repositories.infocad.parametre.TypeDomaineRepository;
import io.gmss.fiscad.persistence.specification.ParcelleSpecification;
import io.gmss.fiscad.service.EntityFromPayLoadService;
import io.gmss.fiscad.service.GeometryService;
import jakarta.persistence.Query;
import jakarta.transaction.Transactional;
@@ -39,6 +43,8 @@ public class ParcelleServiceImpl implements ParcelleService {
private final RueRepository rueRepository;
private final GeometryService geometryService;
private final SecteurService secteurService;
private final TypeDomaineRepository typeDomaineRepository;
private final EntityFromPayLoadService entityFromPayLoadService;
// @Value("${infocad.geom.srid}")
// private String defaultSrid32631;
@@ -58,36 +64,29 @@ public class ParcelleServiceImpl implements ParcelleService {
if (!optionalQuartier.isPresent()) {
throw new BadRequestException("Impossible d'enregistrer une parcelle avec un quartier/village inexistant");
}
Optional<TypeDomaine> optionalTypeDomaine = typeDomaineRepository.findById(parcellePayLoadWeb.getTypeDomaineId());
if (!optionalTypeDomaine.isPresent()) {
throw new BadRequestException("Veuillez préciser le type de domaine");
}
Parcelle parcelle = new Parcelle();
parcelle.setNatureDomaine(optionalNatureDomaine.orElse(null));
parcelle.setQuartier(optionalQuartier.orElse(null));
parcelle = getParcelleFromPayload(parcelle, parcellePayLoadWeb);
parcelle = entityFromPayLoadService.getParcelleFromPayload(parcellePayLoadWeb);
parcelle= parcelleRepository.save(parcelle);
return parcelleRepository.findParcelleToDtoById(parcelle.getId()).orElse(null);
}
@Override
public ParcellePayLoadWeb updateParcelle(Long id, ParcellePayLoadWeb parcellePayLoadWeb) throws NotFoundException {
if(parcellePayLoadWeb.getId()!=null) {
Optional<Parcelle> optionalParcelle = parcelleRepository.findById(parcellePayLoadWeb.getId());
if (!optionalParcelle.isPresent()) {
throw new NotFoundException("Impossible de trouver la parcelle que vous désirer modifier");
}
Optional<NatureDomaine> optionalNatureDomaine = natureDomaineRepository.findById(parcellePayLoadWeb.getNatureDomaineId());
if (!optionalNatureDomaine.isPresent()) {
throw new BadRequestException("Impossible d'enregistrer une parcelle avec une nature de domaine inexistante");
}
Optional<Quartier> optionalQuartier = quartierRepository.findById(parcellePayLoadWeb.getQuartierId());
if (!optionalQuartier.isPresent()) {
throw new BadRequestException("Impossible d'enregistrer une parcelle avec un quartier/village inexistant");
}
// Optional<SituationGeographique> optionalSituationGeographique = situationGeographiqueRepository.findById(parcellePayLoadWeb.getSituationGeographiqueId());
// if (!optionalSituationGeographique.isPresent()) {
// throw new BadRequestException("Impossible d'enregistrer une parcelle avec une situation géographique inexistant");
// }
Parcelle parcelle=optionalParcelle.get();
parcelle.setNatureDomaine(optionalNatureDomaine.orElse(null));
parcelle.setQuartier(optionalQuartier.orElse(null));
parcelle = getParcelleFromPayload(optionalParcelle.get(), parcellePayLoadWeb);
Parcelle parcelle = new Parcelle();
parcelle = entityFromPayLoadService.getParcelleFromPayload(parcellePayLoadWeb);
parcelle= parcelleRepository.save(parcelle);
return parcelleRepository.findParcelleToDtoById(parcelle.getId()).orElse(null);
}
@@ -210,28 +209,6 @@ public class ParcelleServiceImpl implements ParcelleService {
}
private Parcelle getParcelleFromPayload(Parcelle parcelle, ParcellePayLoadWeb parcellePayLoadWeb) {
if(parcellePayLoadWeb.getRueId()!=null) {
Optional<Rue> optionalRue = rueRepository.findById(parcellePayLoadWeb.getRueId());
parcelle.setRue(optionalRue.orElse(null));
}
parcelle.setP(parcellePayLoadWeb.getP());
parcelle.setI(parcellePayLoadWeb.getI());
parcelle.setQ(parcellePayLoadWeb.getQ());
parcelle.setNup(parcellePayLoadWeb.getNup());
parcelle.setLatitude(parcellePayLoadWeb.getLatitude());
parcelle.setLongitude(parcellePayLoadWeb.getLongitude());
parcelle.setAltitude(parcellePayLoadWeb.getAltitude());
parcelle.setSituationGeographique(parcellePayLoadWeb.getSituationGeographique());
parcelle.setNupProvisoire(parcellePayLoadWeb.getNupProvisoire());
parcelle.setAutreNumeroTitreFoncier(parcellePayLoadWeb.getNumTitreFoncier());
parcelle.setObservation(parcellePayLoadWeb.getObservation());
parcelle.setSuperficie(parcellePayLoadWeb.getSuperficie());
return parcelle;
}
// private Parcelle getParcelle(Parcelle parcelle, ParcellePayLoadWeb parcellePayLoadWeb, Optional<SituationGeographique> optionalSituationGeographique, Optional<NatureDomaine> optionalNatureDomaine) {
// StringBuilder coordonnees = new StringBuilder();
// parcelle.setP(parcellePayLoadWeb.getP());

View File

@@ -86,6 +86,11 @@ public class PersonneServiceImpl implements PersonneService {
return null;
}
@Override
public Page<PersonnePayLoadWeb> getPersonneListNonAssigneePage(Pageable pageable) {
return personneRepository.findAllPersonneNonAssigneCentreToDto(pageable);
}
@Override
public List<PersonnePayLoadWeb> getPersonneList() {
return null;
@@ -253,12 +258,28 @@ public class PersonneServiceImpl implements PersonneService {
@Override
public List<PersonnePayLoadWeb> recherchePersonne(RecherchePersonneResquestBody request) {
List<PersonnePayLoadWeb> result = new ArrayList<>(
recherchePersonneLocal(request)
);
try {
if(request.getIfu()!=null && !request.getIfu().equals("")){
List<PersonnePayLoadWeb> personnePayLoadWebs =personneRepository.findAllPersonneByIfuToDto(request.getIfu());
if(!personnePayLoadWebs.isEmpty())
return personnePayLoadWebs;
}
if(request.getNpi()!=null && !request.getNpi().equals("")){
List<PersonnePayLoadWeb> personnePayLoadWebs = personneRepository.findAllPersonneByNpiToDto(request.getNpi());
if(!personnePayLoadWebs.isEmpty())
return personnePayLoadWebs;
}
List<PersonnePayLoadWeb> result=new ArrayList<>();
result = recherchePersonneLocal(request);
if (result != null && !result.isEmpty()) {
return result;
}
// Conversion date en String format yyyy-MM-dd
String dateNaissance = Optional.ofNullable(request.getDateNaissance())
.map(d -> d.format(DateTimeFormatter.ISO_LOCAL_DATE))
@@ -301,29 +322,48 @@ public class PersonneServiceImpl implements PersonneService {
personne.setEtatIdentificationPersonne(EtatIdentificationPersonne.IFU);
result.add(personne);
}
} catch (Exception e) {
// logger.error("Erreur appel IFU EN LIGNE", e);
}
return result;
} catch (Exception e) {
return new ArrayList<>();
}
}
private List<PersonnePayLoadWeb> recherchePersonneLocal(RecherchePersonneResquestBody recherchePersonneResquestBody) {
// private List<PersonnePayLoadWeb> recherchePersonneLocal(RecherchePersonneResquestBody recherchePersonneResquestBody) {
// System.out.println("NOUS SOMMES DANS RECHERCHE NOM ET PRENOM :"+recherchePersonneResquestBody.getNom()+" "+recherchePersonneResquestBody.getPrenom());
// List<PersonnePayLoadWeb> personnePayLoadWebs=
// personneRepository.findByFiltersInBaseIfuNpiCorrecte(
// recherchePersonneResquestBody.getNom()==null?null: "%"+recherchePersonneResquestBody.getNom().trim().toUpperCase()+"%",
// recherchePersonneResquestBody.getPrenom()==null?null: "%"+recherchePersonneResquestBody.getPrenom().trim().toUpperCase()+"%",
// recherchePersonneResquestBody.getRaisonSociale()==null?null: "%"+recherchePersonneResquestBody.getRaisonSociale().trim().toUpperCase()+"%",
// recherchePersonneResquestBody.getNomMere()==null?null: "%"+recherchePersonneResquestBody.getNomMere().trim().toUpperCase()+"%"
// );
// return personnePayLoadWebs ;
// }
List<PersonnePayLoadWeb> personnePayLoadWebs=
personneRepository.findByFiltersInBaseIfuNpiCorrecte(
recherchePersonneResquestBody.getIfu()==null?null:recherchePersonneResquestBody.getIfu().trim().toLowerCase(),
recherchePersonneResquestBody.getNpi()==null?null:recherchePersonneResquestBody.getNpi().trim().toLowerCase(),
recherchePersonneResquestBody.getNom()==null?null:recherchePersonneResquestBody.getNom().trim().toLowerCase(),
recherchePersonneResquestBody.getPrenom()==null?null:recherchePersonneResquestBody.getPrenom().trim().toLowerCase(),
recherchePersonneResquestBody.getRaisonSociale()==null?null:recherchePersonneResquestBody.getRaisonSociale().trim().toLowerCase(),
recherchePersonneResquestBody.getNomMere()==null?null:recherchePersonneResquestBody.getNomMere().trim().toLowerCase(),
recherchePersonneResquestBody.getDateNaissance()
private List<PersonnePayLoadWeb> recherchePersonneLocal(RecherchePersonneResquestBody request) {
String nom = normalizeLikeParam(request.getNom());
String prenom = normalizeLikeParam(request.getPrenom());
String raisonSociale = normalizeLikeParam(request.getRaisonSociale());
String nomMere = normalizeLikeParam(request.getNomMere());
return personneRepository.findByFiltersInBaseIfuNpiCorrecte(
nom,
prenom,
raisonSociale,
nomMere
);
return personnePayLoadWebs ;
}
private String normalizeLikeParam(String value) {
if (value == null) return null;
String cleaned = value.trim();
if (cleaned.isEmpty()) return null;
return "%" + cleaned.toUpperCase() + "%";
}
private List<PersonnePayLoadWeb> recherchePersonneSigibe(RecherchePersonneResquestBody recherchePersonneResquestBody) {
// callAPIService.callGetIfuEnLigneToken();

View File

@@ -1,11 +1,15 @@
package io.gmss.fiscad.implementations.rfu.metier;
import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.entities.rfu.metier.Batiment;
import io.gmss.fiscad.entities.rfu.parametre.CategorieBatiment;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.rfu.metier.BatimentService;
import io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb;
import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.BatimentRepository;
import io.gmss.fiscad.persistence.repositories.rfu.parametre.CategorieBatimentRepository;
import io.gmss.fiscad.service.EntityFromPayLoadService;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
@@ -19,6 +23,8 @@ import java.util.Optional;
public class BatimentServiceImpl implements BatimentService {
private final BatimentRepository batimentRepository;
private final ParcelleRepository parcelleRepository;
private final CategorieBatimentRepository categorieBatimentRepository;
private final EntityFromPayLoadService entityFromPayLoadService;
@@ -27,8 +33,22 @@ public class BatimentServiceImpl implements BatimentService {
if (batimentPaylaodWeb.getId() != null) {
throw new BadRequestException("Impossible de créer un nouveau batiment ayant un id non null.");
}
if (batimentPaylaodWeb.getParcelleId() == null) {
throw new BadRequestException("Impossible de créer un nouveau batiment: La parcelle doit être précisée.");
}else {
if(!parcelleRepository.existsById(batimentPaylaodWeb.getParcelleId()))
throw new BadRequestException("Impossible de créer un nouveau batiment: La parcelle doit être précisée.");
}
if (batimentPaylaodWeb.getCategorieBatimentId() == null) {
throw new BadRequestException("Impossible de créer un nouveau batiment: La catégorie doit être précisée.");
}else {
if(!categorieBatimentRepository.existsById(batimentPaylaodWeb.getCategorieBatimentId()))
throw new BadRequestException("Impossible de créer un nouveau batiment: La catégorie doit être précisée.");
}
Batiment batiment= entityFromPayLoadService.getBatimentFromPayLoadWeb(batimentPaylaodWeb);
batiment= batimentRepository.save(batiment);
System.out.println(batiment.getId());
return batimentRepository.findBatimentAvecOccupantCourantToDto(batiment.getId()).orElse(null);
}
@@ -40,6 +60,19 @@ public class BatimentServiceImpl implements BatimentService {
if (!batimentRepository.existsById(batimentPaylaodWeb.getId())) {
throw new NotFoundException("Impossible de trouver le batiment spécifié dans notre base de données.");
}
if (batimentPaylaodWeb.getParcelleId() == null) {
throw new BadRequestException("Impossible de créer un nouveau batiment: La parcelle doit être précisée.");
}else {
if(!parcelleRepository.existsById(batimentPaylaodWeb.getParcelleId()))
throw new BadRequestException("Impossible de créer un nouveau batiment: La parcelle doit être précisée.");
}
if (batimentPaylaodWeb.getCategorieBatimentId() == null) {
throw new BadRequestException("Impossible de créer un nouveau batiment: La catégorie doit être précisée.");
}else {
if(!categorieBatimentRepository.existsById(batimentPaylaodWeb.getCategorieBatimentId()))
throw new BadRequestException("Impossible de créer un nouveau batiment: La catégorie doit être précisée.");
}
Batiment batiment= entityFromPayLoadService.getBatimentFromPayLoadWeb(batimentPaylaodWeb);
batiment= batimentRepository.save(batiment);
return batimentRepository.findBatimentAvecOccupantCourantToDto(batiment.getId()).orElse(null);
@@ -85,4 +118,14 @@ public class BatimentServiceImpl implements BatimentService {
}
}
@Override
public Page<BatimentPaylaodWeb> getBatimentListByquartierPageable(Long quartierId, Pageable pageable) {
return batimentRepository.findAllBatimentsAvecOccupantCourantByQuartierToDtoPageble(quartierId,pageable);
}
@Override
public List<BatimentPaylaodWeb> getBatimentListByquartier(Long quartierId) {
return batimentRepository.findAllBatimentsAvecOccupantCourantByQuartierToDto(quartierId);
}
}

View File

@@ -0,0 +1,187 @@
package io.gmss.fiscad.implementations.rfu.metier;
import io.gmss.fiscad.entities.rfu.metier.CommuneCentreAssignation;
import io.gmss.fiscad.entities.user.User;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.rfu.metier.CommuneCentreAssignationService;
import io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb;
import io.gmss.fiscad.persistence.repositories.decoupage.CommuneRepository;
import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository;
import io.gmss.fiscad.persistence.repositories.infocad.parametre.PersonneRepository;
import io.gmss.fiscad.persistence.repositories.infocad.parametre.StructureRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.CommuneCentreAssignationRepository;
import io.gmss.fiscad.service.EntityFromPayLoadService;
import jakarta.ws.rs.NotAcceptableException;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@AllArgsConstructor
@Service
public class CommuneCentreAssignationServiceImpl implements CommuneCentreAssignationService {
private final EntityFromPayLoadService entityFromPayLoadService;
private final CommuneRepository communeRepository;
private final StructureRepository structureRepository ;
private final PersonneRepository personneRepository ;
private final ParcelleRepository parcelleRepository ;
private final CommuneCentreAssignationRepository communeCentreAssignationRepository;
@Override
public CommuneCentreAssignationPaylaodWeb createCommuneCentreAssignation(User user, CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws BadRequestException {
if (user.getStructure() == null) {
throw new BadRequestException("Impossible de créer l'assignation: Votre centre doit être précisé.");
}
if (user.getStructure().getCommune() == null) {
throw new BadRequestException("Impossible de créer un nouveau communeCentreAssignation: votre commune doit être précisée.");
}
if (communeCentreAssignationPaylaodWeb.getPersonneId() == null) {
throw new BadRequestException("Impossible de créer un nouveau communeCentreAssignation: Le contribuable doit être précisée.");
}else {
if(!personneRepository.existsById(communeCentreAssignationPaylaodWeb.getPersonneId()))
throw new BadRequestException("Impossible de créer un nouveau communeCentreAssignation: Le contribuable doit être précisée.");
}
if (communeCentreAssignationPaylaodWeb.getParcelleContactId() == null) {
throw new BadRequestException("Impossible de créer une nouvelle assignation de centre : La parcelle de contact doit être précisée.");
}else {
if(!parcelleRepository.existsById(communeCentreAssignationPaylaodWeb.getParcelleContactId()))
throw new BadRequestException("Impossible de créer une nouvelle assignation de centre: La parcelle précisée n'existe pas.");
}
Optional<CommuneCentreAssignationPaylaodWeb> communeCentreAssignationPaylaodWebOptional=communeCentreAssignationRepository.findbyCommuneAndPersonne(user.getStructure().getCommune().getId(),communeCentreAssignationPaylaodWeb.getPersonneId());
if(communeCentreAssignationPaylaodWeb.getId()==null && communeCentreAssignationPaylaodWebOptional.isPresent()){
throw new NotAcceptableException("Impossible de créer une nouvelle assignation de centre: Le contribuable est déjà assigné au centre : "+communeCentreAssignationPaylaodWebOptional.get().getStructureNom());
}
CommuneCentreAssignation communeCentreAssignation= entityFromPayLoadService.getCommuneCentreAssignationFromPayLoadWeb(communeCentreAssignationPaylaodWeb);
communeCentreAssignation.setStructure(user.getStructure());
communeCentreAssignation.setCommune(user.getStructure().getCommune());
communeCentreAssignation= communeCentreAssignationRepository.save(communeCentreAssignation);
return communeCentreAssignationRepository.findUnique(communeCentreAssignation.getId()).orElse(null);
}
@Override
public CommuneCentreAssignationPaylaodWeb updateCommuneCentreAssignation(Long id,CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws NotFoundException {
if (communeCentreAssignationPaylaodWeb.getId() == null) {
throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation ayant un id null.");
}
if (communeCentreAssignationPaylaodWeb.getCommuneId() == null) {
throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: La commune doit être précisée.");
}else {
if(!communeRepository.existsById(communeCentreAssignationPaylaodWeb.getCommuneId()))
throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: La commune doit être précisée.");
}
if (communeCentreAssignationPaylaodWeb.getStructureId() == null) {
throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: Le centre doit être précisée.");
}else {
if(!structureRepository.existsById(communeCentreAssignationPaylaodWeb.getStructureId()))
throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: Le centre doit être précisée.");
}
if (communeCentreAssignationPaylaodWeb.getPersonneId() == null) {
throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: Le contribuable doit être précisée.");
}else {
if(!personneRepository.existsById(communeCentreAssignationPaylaodWeb.getPersonneId()))
throw new BadRequestException("Impossible de modifier un nouveau communeCentreAssignation: Le contribuable doit être précisée.");
}
CommuneCentreAssignation communeCentreAssignation= entityFromPayLoadService.getCommuneCentreAssignationFromPayLoadWeb(communeCentreAssignationPaylaodWeb);
communeCentreAssignation= communeCentreAssignationRepository.save(communeCentreAssignation);
return communeCentreAssignationRepository.findUnique(communeCentreAssignation.getId()).orElse(null);
}
@Override
public CommuneCentreAssignationPaylaodWeb detacherCommuneCentreAssignation(User user, CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws NotFoundException {
if (communeCentreAssignationPaylaodWeb.getId() != null) {
throw new BadRequestException("Impossible de fait de detachement. L'assignation n'est pas précisée");
}
Optional<CommuneCentreAssignation> communeCentreAssignationOptional= communeCentreAssignationRepository.findById(communeCentreAssignationPaylaodWeb.getId());
if (communeCentreAssignationOptional.isEmpty()) {
throw new BadRequestException("Impossible de fait de detachement. L'assignation n'est pas précisée");
}
if(communeCentreAssignationOptional.get().getStructure() != user.getStructure()){
throw new BadRequestException("Impossible de fait de detachement. Le contribuable n'est pas rattaché à votre centre. Veuillez contracter : "+user.getStructure().getNom());
}
communeCentreAssignationOptional.get().setStructure(null);
CommuneCentreAssignation communeCentreAssignation = communeCentreAssignationRepository.save(communeCentreAssignationOptional.get());
return communeCentreAssignationRepository.findUnique(communeCentreAssignation.getId()).orElse(null);
}
@Override
public void deleteCommuneCentreAssignation(Long id) throws NotFoundException {
Optional<CommuneCentreAssignation> communeCentreAssignationOptional = communeCentreAssignationRepository.findById(id);
if (communeCentreAssignationOptional.isPresent()) {
communeCentreAssignationRepository.deleteById(communeCentreAssignationOptional.get().getId());
} else {
throw new NotFoundException("Impossible de trouver le communeCentreAssignation spécifié dans notre base de données.");
}
}
@Override
public Page<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationList(Pageable pageable) {
return communeCentreAssignationRepository.findAllPayload(pageable);
}
@Override
public Page<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationListByCommunePageable(Long communeId, Pageable pageable) {
return communeCentreAssignationRepository.findByCommuneId(communeId,pageable);
}
@Override
public Optional<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationById(Long id) {
if (communeCentreAssignationRepository.existsById(id)) {
return communeCentreAssignationRepository.findUnique(id);
} else {
throw new NotFoundException("Impossible de trouver le centre d'assignation spécifiée dans la base de données.");
}
}
@Override
public Optional<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationByPersonneIdCommune(User user,Long personneId) {
if (user.getStructure() == null) {
throw new BadRequestException("Impossible de récuperer l'assignation: Votre centre doit être précisé.");
}
if (user.getStructure().getCommune() == null) {
throw new BadRequestException("Impossible de récuperer une assignation: votre commune doit être précisée.");
}
if (personneId == null) {
throw new BadRequestException("Impossible de récuperer l'assignation: Le contribuable doit être précisée.");
}else {
if(!personneRepository.existsById(personneId))
throw new BadRequestException("Impossible de récuperer l'assignation: Le contribuable précisée n'existe pas.");
}
Optional<CommuneCentreAssignationPaylaodWeb> communeCentreAssignationPaylaodWebOptional=communeCentreAssignationRepository.findbyCommuneAndPersonne(user.getStructure().getCommune().getId(),personneId);
return communeCentreAssignationPaylaodWebOptional;
}
@Override
public Page<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationListByCentrePageable(Long centreId, Pageable pageable) {
return communeCentreAssignationRepository.findByStructureId(centreId,pageable);
}
}

View File

@@ -38,6 +38,11 @@ public class DeclarationNcServiceImpl implements DeclarationNcService {
if (!structureRepository.existsById(declarationNcPayloadWeb.getStructureId())) {
throw new BadRequestException("Veuillez préciser le centre.");
}
List<DeclarationNcPayloadWeb> declarationNcPayloadWebs= declarationNcRepository.findAllDeclarationNcByNcNotPersonneToDto(declarationNcPayloadWeb.getNc(),declarationNcPayloadWeb.getPersonneId());
if (!declarationNcPayloadWebs.isEmpty()) {
throw new BadRequestException("Ce numéro Contribuable est déjà rattaché à un autre IFU");
}
DeclarationNc declarationNc= entityFromPayLoadService.getDeclarationNcFromPayLoadWeb(declarationNcPayloadWeb);
declarationNc =declarationNcRepository.save(declarationNc);

View File

@@ -8,6 +8,7 @@ import io.gmss.fiscad.enums.StatusAvis;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.rfu.metier.DonneesImpositionTfuService;
import io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb;
import io.gmss.fiscad.paylaods.request.crudweb.ImpositionsTfuPaylaodWeb;
import io.gmss.fiscad.paylaods.response.DonneesImpositionTfuResponse;
import io.gmss.fiscad.persistence.repositories.decoupage.ArrondissementRepository;
@@ -95,100 +96,96 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ
@Override
@Transactional
public ImpositionsTfuPaylaodWeb genererDonneesFiscales(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb) {
public ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleNonBatie(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, Long userId) {
Integer nb= donneesImpositionTfuRepository.genererDonneesTfuNonBatie(impositionsTfuPaylaodWeb.getId(),userId);
// List<DonneesImpositionTfuResponse> donneesImpositionTfuResponses= donneesImpositionTfuRepository.findAllDonneesImpositionTfu(impositionsTfu.getCommune().getId(),impositionsTfu.getExercice().getAnnee());
Long n=0l;
// for (DonneesImpositionTfuResponse donneesImpositionTfuResponse: donneesImpositionTfuResponses){
// DonneesImpositionTfu donneesImpositionTfu=new DonneesImpositionTfu();
// donneesImpositionTfu.setImpositionsTfu(impositionsTfu);
// donneesImpositionTfu.setZoneRfuId(donneesImpositionTfuResponse.getZoneRfuId());
// donneesImpositionTfu.setCodeQuartierVillage(donneesImpositionTfuResponse.getCodeQuartierVillage());
// donneesImpositionTfu.setNomQuartierVillage(donneesImpositionTfuResponse.getNomQuartierVillage());
// donneesImpositionTfu.setCodeArrondissement(donneesImpositionTfuResponse.getCodeArrondissement());
// donneesImpositionTfu.setNomArrondissement(donneesImpositionTfuResponse.getNomArrondissement());
// donneesImpositionTfu.setCodeCommune(donneesImpositionTfuResponse.getCodeCommune());
// donneesImpositionTfu.setNomCommune(donneesImpositionTfuResponse.getNomCommune());
// donneesImpositionTfu.setCodeDepartement(donneesImpositionTfuResponse.getCodeDepartement());
// donneesImpositionTfu.setNomDepartement(donneesImpositionTfuResponse.getNomDepartement());
// donneesImpositionTfu.setQ(donneesImpositionTfuResponse.getQ());
// donneesImpositionTfu.setIlot(donneesImpositionTfuResponse.getIlot());
// donneesImpositionTfu.setParcelle(donneesImpositionTfuResponse.getParcelle());
// donneesImpositionTfu.setLatitude(donneesImpositionTfuResponse.getLatitude());
// donneesImpositionTfu.setLongitude(donneesImpositionTfuResponse.getLongitude());
// donneesImpositionTfu.setNup(donneesImpositionTfuResponse.getNup());
// donneesImpositionTfu.setNupProvisoire(donneesImpositionTfuResponse.getNupProvisoire());
// donneesImpositionTfu.setSuperficieParc(donneesImpositionTfuResponse.getSuperficieParc());
// donneesImpositionTfu.setAdresseProp(donneesImpositionTfuResponse.getAdresseProp());
// donneesImpositionTfu.setAnnee(donneesImpositionTfuResponse.getAnnee());
// donneesImpositionTfu.setAdresseSc(donneesImpositionTfuResponse.getAdresseSc());
// donneesImpositionTfu.setBatieOuiNon(donneesImpositionTfuResponse.getBatieOuiNon());
// donneesImpositionTfu.setTfuMinimum(donneesImpositionTfuResponse.getTfuMinimum());
// donneesImpositionTfu.setCategorieBat(donneesImpositionTfuResponse.getCategorieBat());
// donneesImpositionTfu.setDateEnquete(donneesImpositionTfuResponse.getDateEnquete());
// donneesImpositionTfu.setEmailProp(donneesImpositionTfuResponse.getEmailProp());
// donneesImpositionTfu.setEmailSc(donneesImpositionTfuResponse.getEmailSc());
// donneesImpositionTfu.setMontantLoyerAnnuel(donneesImpositionTfuResponse.getMontantLoyerAnnuel());
// donneesImpositionTfu.setEnqueteId(donneesImpositionTfuResponse.getEnqueteId());
// donneesImpositionTfu.setExhonereOuiNon(donneesImpositionTfuResponse.getExhonereOuiNon());
// donneesImpositionTfu.setIfu(donneesImpositionTfuResponse.getIfu());
// donneesImpositionTfu.setNombreBat(donneesImpositionTfuResponse.getNombreBat());
// donneesImpositionTfu.setNombrePiscine(donneesImpositionTfuResponse.getNombrePiscine());
// donneesImpositionTfu.setNombreUlog(donneesImpositionTfuResponse.getNombreUlog());
// donneesImpositionTfu.setNomProp(donneesImpositionTfuResponse.getNomProp());
// donneesImpositionTfu.setNomSc(donneesImpositionTfuResponse.getNomSc());
// donneesImpositionTfu.setNpi(donneesImpositionTfuResponse.getNpi());
// donneesImpositionTfu.setNumBatiment(donneesImpositionTfuResponse.getNumBatiment()==null?"":donneesImpositionTfuResponse.getNumBatiment());
// donneesImpositionTfu.setNumUniteLogement(donneesImpositionTfuResponse.getNumUniteLogement()==null?"":donneesImpositionTfuResponse.getNumUniteLogement());
// donneesImpositionTfu.setPrenomProp(donneesImpositionTfuResponse.getPrenomProp());
// donneesImpositionTfu.setPrenomSc(donneesImpositionTfuResponse.getPrenomSc());
// donneesImpositionTfu.setRaisonSociale(donneesImpositionTfuResponse.getRaisonSociale());
// donneesImpositionTfu.setSecteurId(donneesImpositionTfuResponse.getSecteurId());
// donneesImpositionTfu.setStandingBat(donneesImpositionTfuResponse.getStandingBat());
// donneesImpositionTfu.setStructureId(donneesImpositionTfuResponse.getStructureId());
// donneesImpositionTfu.setSuperficieAuSolBat(donneesImpositionTfuResponse.getSuperficieAuSolBat());
// donneesImpositionTfu.setSuperficieAuSolUlog(donneesImpositionTfuResponse.getSuperficieAuSolUlog());
// donneesImpositionTfu.setTelProp(donneesImpositionTfuResponse.getTelProp());
// donneesImpositionTfu.setTelSc(donneesImpositionTfuResponse.getTelSc());
// donneesImpositionTfu.setTfuMetreCarre(donneesImpositionTfuResponse.getTfuMetreCarre());
// donneesImpositionTfu.setTitreFoncier(donneesImpositionTfuResponse.getTitreFoncier());
// donneesImpositionTfu.setValeurLocativeAdm(donneesImpositionTfuResponse.getValeurLocativeAdm());
// donneesImpositionTfu.setBatimentExhonereOuiNon(donneesImpositionTfuResponse.getBatimentExhonereOuiNon());
// donneesImpositionTfu.setUniteLogementExhonereOuiNon(donneesImpositionTfuResponse.getUniteLogementExhonereOuiNon());
// try {
// Optional<BaremRfuNonBati> baremRfuNonBatiOptional=baremRfuNonBatiRepository.findAllByCommune_IdAndZoneRfu_Id(impositionsTfu.getCommune().getId(),donneesImpositionTfu.getZoneRfuId());
// if(baremRfuNonBatiOptional.isPresent()){
// donneesImpositionTfu.setValeurAdministrativeParcelleNonBati(baremRfuNonBatiOptional.get().getValeurAdministrative());
// donneesImpositionTfu.setTauxParcelleNonBati(baremRfuNonBatiOptional.get().getTaux());
// }
//
//
// donneesImpositionTfuRepository.save(donneesImpositionTfu);
// n++;
// }catch (DataIntegrityViolationException e) {
// if (e.getCause() instanceof org.hibernate.exception.ConstraintViolationException constraintEx &&
// constraintEx.getSQLException().getSQLState().equals("23505")) {
// System.out.println("Doublon détecté (clé unique) !");
// } else {
// throw e;
// }
// }
// }
ImpositionsTfu impositionsTfu = entityFromPayLoadService.getImpositionsTfuFromPayLoadWeb(impositionsTfuPaylaodWeb);
impositionsTfu.setStatusAvis(StatusAvis.GENERE);
impositionsTfu.setStatusAvis(StatusAvis.TFU_FNB_GENERE);
impositionsTfu.setNombreAvisFnb(nb);
impositionsTfuRepository.save(impositionsTfu);
return impositionsTfuPaylaodWeb;
return impositionsTfuRepository.findByIdToDto(impositionsTfu.getId()).orElse(null);
}
@Override
public List<DonneesImpositionTfu> getDonneesFiscalesByImposition(Long impositionsId) {
return donneesImpositionTfuRepository.findAllByImpositionsTfu_Id(impositionsId);
@Transactional
public ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleNonBatieUneParcelle(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, Long userId,Long parcelleId) {
Integer nb= donneesImpositionTfuRepository.genererDonneesTfuNonBatie(impositionsTfuPaylaodWeb.getId(),userId,parcelleId);
ImpositionsTfu impositionsTfu = entityFromPayLoadService.getImpositionsTfuFromPayLoadWeb(impositionsTfuPaylaodWeb);
impositionsTfu.setStatusAvis(StatusAvis.TFU_FNB_GENERE);
impositionsTfu.setNombreAvisFnb(nb);
impositionsTfuRepository.save(impositionsTfu);
return impositionsTfuRepository.findByIdToDto(impositionsTfu.getId()).orElse(null);
}
@Override
@Transactional
public ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleBatie(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, Long userId) {
Integer nbb= donneesImpositionTfuRepository.genererDonneesTfuBatie(impositionsTfuPaylaodWeb.getId(),userId);
Integer nbirfbtPlusieursBati = donneesImpositionTfuRepository.majDonneesTfuBatiePlusieursBatiment(impositionsTfuPaylaodWeb.getId());
Integer nbulo= donneesImpositionTfuRepository.genererDonneesTfuBatieUniteLogement(impositionsTfuPaylaodWeb.getId(),userId);
Integer nbirfbt= donneesImpositionTfuRepository.genererDonneesIrfBatie(impositionsTfuPaylaodWeb.getId(),userId);
Integer nbirfulo= donneesImpositionTfuRepository.genererDonneesIrfBatieUniteLogement(impositionsTfuPaylaodWeb.getId(),userId);
Integer nbsrtbbt= donneesImpositionTfuRepository.genererDonneesSrtbBatie(impositionsTfuPaylaodWeb.getId(),userId);
ImpositionsTfu impositionsTfu = entityFromPayLoadService.getImpositionsTfuFromPayLoadWeb(impositionsTfuPaylaodWeb);
impositionsTfu.setStatusAvis(StatusAvis.GENERE);
impositionsTfu.setNombreAvis(nbb+nbulo+ (impositionsTfu.getNombreAvisFnb()==null?0:impositionsTfu.getNombreAvisFnb()));
impositionsTfu.setNombreAvisBatiment(nbb);
impositionsTfu.setNombreAvisUniteLog(nbulo);
impositionsTfuRepository.save(impositionsTfu);
return impositionsTfuRepository.findByIdToDto(impositionsTfu.getId()).orElse(null);
}
@Override
@Transactional
public ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleBatieUneParcelle(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, Long userId, Long parcelleId) {
Integer nbb= donneesImpositionTfuRepository.genererDonneesTfuBatie(impositionsTfuPaylaodWeb.getId(),userId,parcelleId);
Integer nbirfbtPlusieursBati = donneesImpositionTfuRepository.majDonneesTfuBatiePlusieursBatiment(impositionsTfuPaylaodWeb.getId(),parcelleId);
Integer nbulo= donneesImpositionTfuRepository.genererDonneesTfuBatieUniteLogement(impositionsTfuPaylaodWeb.getId(),userId,parcelleId);
Integer nbirfbt= donneesImpositionTfuRepository.genererDonneesIrfBatie(impositionsTfuPaylaodWeb.getId(),userId,parcelleId);
Integer nbirfulo= donneesImpositionTfuRepository.genererDonneesIrfBatieUniteLogement(impositionsTfuPaylaodWeb.getId(),userId,parcelleId);
Integer nbsrtbbt= donneesImpositionTfuRepository.genererDonneesSrtbBatie(impositionsTfuPaylaodWeb.getId(),userId,parcelleId);
ImpositionsTfu impositionsTfu = entityFromPayLoadService.getImpositionsTfuFromPayLoadWeb(impositionsTfuPaylaodWeb);
impositionsTfu.setStatusAvis(StatusAvis.GENERE);
impositionsTfu.setNombreAvis(nbb+nbulo+ (impositionsTfu.getNombreAvisFnb()==null?0:impositionsTfu.getNombreAvisFnb()));
impositionsTfu.setNombreAvisBatiment(nbb);
impositionsTfu.setNombreAvisUniteLog(nbulo);
impositionsTfuRepository.save(impositionsTfu);
return impositionsTfuRepository.findByIdToDto(impositionsTfu.getId()).orElse(null);
}
@Override
public List<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImposition(Long impositionsId) {
return donneesImpositionTfuRepository.findAllByImpositionTfuId(impositionsId);
}
@Override
@@ -200,4 +197,59 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ
return null;
}
}
@Override
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdPageable(Long impositionsTfuId, Pageable pageable) {
return donneesImpositionTfuRepository.findAllByImpositionTfuIdPageable(impositionsTfuId,pageable);
}
@Override
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdNonBatiePageable(Long impositionsTfuId, Pageable pageable) {
return donneesImpositionTfuRepository.findAllByImpositionTfuIdNonBatiePageable(impositionsTfuId,pageable);
}
@Override
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable) {
return donneesImpositionTfuRepository.findAllByImpositionTfuIdBatieBatimentPageable(impositionsTfuId,pageable);
}
@Override
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable) {
return donneesImpositionTfuRepository.findAllByImpositionTfuIdBatieUniteLogPageable(impositionsTfuId,pageable);
}
@Override
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionIrfIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable) {
return null;
}
@Override
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionIrfIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable) {
return null;
}
@Override
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionSrtbIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable) {
return null;
}
@Override
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionSrtbIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable) {
return null;
}
@Override
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByExerciceAndStructureIdPageable(Long exerciceId, Long structureId, Pageable pageable) {
return donneesImpositionTfuRepository.findAllByExericeIdStructureIdPageable(exerciceId,structureId,pageable);
}
@Override
public List<DonneesImpositionPaylaodWeb> getDonneesFiscalesByExerciceAndStructureId(Long exerciceId, Long structureId,Long quartierId) {
return donneesImpositionTfuRepository.findAllByExericeIdStructureId(exerciceId,structureId,quartierId);
}
@Override
public List<DonneesImpositionPaylaodWeb> getDonneesFiscalesByPersonneId(Long personneId) {
return donneesImpositionTfuRepository.findAllByPersonneId(personneId);
}
}

View File

@@ -1,59 +1,103 @@
package io.gmss.fiscad.implementations.rfu.metier;
import io.gmss.fiscad.entities.decoupage.Secteur;
import io.gmss.fiscad.entities.infocad.metier.Enquete;
import io.gmss.fiscad.entities.infocad.metier.Upload;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.rfu.metier.Batiment;
import io.gmss.fiscad.entities.rfu.metier.CaracteristiqueBatiment;
import io.gmss.fiscad.entities.rfu.metier.EnqueteBatiment;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
import io.gmss.fiscad.interfaces.rfu.metier.BatimentService;
import io.gmss.fiscad.interfaces.rfu.metier.CaracteristiqueBatimentService;
import io.gmss.fiscad.interfaces.rfu.metier.EnqueteBatimentService;
import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.BaremRfuNonBatiPayloadWeb;
import io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb;
import io.gmss.fiscad.paylaods.request.crudweb.EnqueteBatimentPayloadWeb;
import io.gmss.fiscad.paylaods.request.crudweb.EnquetePayLoadWeb;
import io.gmss.fiscad.persistence.repositories.infocad.metier.EnqueteRepository;
import io.gmss.fiscad.persistence.repositories.infocad.metier.UploadRepository;
import io.gmss.fiscad.persistence.repositories.infocad.parametre.PersonneRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.BatimentRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.EnqueteBatimentRepository;
import io.gmss.fiscad.service.EntityFromPayLoadService;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.NotAcceptableException;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@AllArgsConstructor
@Service
public class EnqueteBatimentServiceImpl implements EnqueteBatimentService {
private final EnqueteBatimentRepository enqueteBatimentRepository;
private final BatimentService batimentService;
private final EnqueteRepository enqueteRepository;
private final PersonneRepository personneRepository;
private final EntityFromPayLoadService entityFromPayLoadService;
private final CaracteristiqueBatimentService caracteristiqueBatimentService;
private final UploadRepository uploadRepository;
private final BatimentRepository batimentRepository;
private final BatimentService batimentService;
private final SecteurService secteurService;
@Override
@Transactional
public EnqueteBatimentPayloadWeb createEnqueteBatiment(EnqueteBatimentPayloadWeb enqueteBatimentPayloadWeb) throws BadRequestException {
EnqueteBatiment enqueteBatiment=new EnqueteBatiment();
if(enqueteBatimentPayloadWeb.getBatimentId()!=null) {
if (!batimentRepository.existsById(enqueteBatimentPayloadWeb.getBatimentId())) {
throw new NotFoundException("Impossible d'enregistrer sans le batiment.");
}
}
BatimentPaylaodWeb batimentPaylaodWeb= getBatimentPayloadFromEnqueteBat(enqueteBatimentPayloadWeb);
if(batimentPaylaodWeb.getId()==null){
batimentPaylaodWeb=batimentService.createBatiment(batimentPaylaodWeb);
}else{
batimentPaylaodWeb=batimentService.updateBatiment(batimentPaylaodWeb.getId(),batimentPaylaodWeb);
}
enqueteBatimentPayloadWeb.setBatimentId(batimentPaylaodWeb.getId());
enqueteBatiment = entityFromPayLoadService.getEnqueteBatimentFromPayLoadWeb(enqueteBatimentPayloadWeb);
enqueteBatiment= enqueteBatimentRepository.save(enqueteBatiment);
enqueteBatimentPayloadWeb= enqueteBatimentRepository.findEnqueteBatimentByIdToDto(enqueteBatiment.getId()).orElse(null);
return enqueteBatimentPayloadWeb ;
}
private BatimentPaylaodWeb getBatimentPayloadFromEnqueteBat(EnqueteBatimentPayloadWeb enqueteBatimentPayloadWeb) {
BatimentPaylaodWeb batimentPaylaodWeb= new BatimentPaylaodWeb();
batimentPaylaodWeb.setId(enqueteBatimentPayloadWeb.getBatimentId());
batimentPaylaodWeb.setNub(enqueteBatimentPayloadWeb.getNub());
batimentPaylaodWeb.setCode(enqueteBatimentPayloadWeb.getCode());
batimentPaylaodWeb.setDateConstruction(enqueteBatimentPayloadWeb.getDateConstruction());
batimentPaylaodWeb.setParcelleId(enqueteBatimentPayloadWeb.getParcelleId());
batimentPaylaodWeb.setPersonneId(enqueteBatimentPayloadWeb.getPersonneId());
batimentPaylaodWeb.setSuperficieAuSol(enqueteBatimentPayloadWeb.getSuperficieAuSol());
batimentPaylaodWeb.setSuperficieLouee(enqueteBatimentPayloadWeb.getSuperficieLouee());
batimentPaylaodWeb.setCategorieBatimentId(enqueteBatimentPayloadWeb.getCategorieBatimentId());
batimentPaylaodWeb.setNombrePiscine(enqueteBatimentPayloadWeb.getNombrePiscine());
batimentPaylaodWeb.setMontantLocatifAnnuelDeclare(enqueteBatimentPayloadWeb.getMontantLocatifAnnuelDeclare());
batimentPaylaodWeb.setMontantLocatifAnnuelEstime(enqueteBatimentPayloadWeb.getMontantLocatifAnnuelEstime());
batimentPaylaodWeb.setValeurBatimentEstime(enqueteBatimentPayloadWeb.getValeurBatimentEstime());
batimentPaylaodWeb.setValeurBatimentReel(enqueteBatimentPayloadWeb.getValeurBatimentReel());
batimentPaylaodWeb.setMontantMensuelLocation(enqueteBatimentPayloadWeb.getMontantMensuelLocation());
batimentPaylaodWeb.setUsageId(enqueteBatimentPayloadWeb.getUsageId());
batimentPaylaodWeb.setNbreUniteLogement(enqueteBatimentPayloadWeb.getNbreUniteLogement());
return batimentPaylaodWeb;
}
@Override
@Transactional
public EnqueteBatimentPayloadWeb updateEnqueteBatiment(Long id, EnqueteBatimentPayloadWeb enqueteBatimentPayloadWeb) throws NotFoundException {
if (enqueteBatimentPayloadWeb.getId() == null) {
throw new BadRequestException("Impossible de mettre à jour une nouvelle enquete de batiment ayant un id null.");
@@ -64,6 +108,18 @@ public class EnqueteBatimentServiceImpl implements EnqueteBatimentService {
if (!batimentRepository.existsById(enqueteBatimentPayloadWeb.getBatimentId())) {
throw new NotFoundException("Impossible d'enregistrer sans le batiment.");
}
BatimentPaylaodWeb batimentPaylaodWeb= getBatimentPayloadFromEnqueteBat(enqueteBatimentPayloadWeb);
if(batimentPaylaodWeb.getId()==null){
batimentPaylaodWeb=batimentService.createBatiment(batimentPaylaodWeb);
}else{
batimentPaylaodWeb=batimentService.updateBatiment(batimentPaylaodWeb.getId(),batimentPaylaodWeb);
}
enqueteBatimentPayloadWeb.setBatimentId(batimentPaylaodWeb.getId());
EnqueteBatiment enqueteBatiment = entityFromPayLoadService.getEnqueteBatimentFromPayLoadWeb(enqueteBatimentPayloadWeb);
enqueteBatiment= enqueteBatimentRepository.save(enqueteBatiment);
enqueteBatimentPayloadWeb= enqueteBatimentRepository.findEnqueteBatimentByIdToDto(enqueteBatiment.getId()).orElse(null);
@@ -110,4 +166,84 @@ public class EnqueteBatimentServiceImpl implements EnqueteBatimentService {
public List<EnqueteBatimentPayloadWeb> getEnqueteBatimentByBatimentList(Long batimentId) {
return enqueteBatimentRepository.findAllByBatimentToDto(batimentId);
}
@Override
public Page<EnqueteBatimentPayloadWeb> getEnqueteBatimentListByQuartierByStatutPageableToDto(Long userId, Long quartierId, StatutEnquete statutEnquete, Pageable pageable) {
List<Secteur> secteurs= secteurService.getListSecteurUserId(userId);
List<Long> secteurIds = secteurs.stream()
.map(Secteur::getId)
.toList();
return enqueteBatimentRepository.findAllEnqueteBatimentByQuartierByStatutToDtoPageable(quartierId,secteurIds,statutEnquete,pageable);
}
@Override
public EnqueteBatimentPayloadWeb validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
if (enqueteTraitementPayLoad == null || enqueteTraitementPayLoad.getIdBackend()==null) {
throw new BadRequestException("Impossible de valider une enquête ayant un id null.");
}
Optional<EnqueteBatiment> optionalEnqueteBatiment = enqueteBatimentRepository.findById(enqueteTraitementPayLoad.getIdBackend());
if (!optionalEnqueteBatiment.isPresent()) {
throw new NotFoundException("Impossible de trouver l'enquête que vous désirez valider.");
}
if(optionalEnqueteBatiment.get().getStatutEnquete()==StatutEnquete.CLOTURE ||
optionalEnqueteBatiment.get().getStatutEnquete()==StatutEnquete.REJETE ){
throw new NotAcceptableException("Impossible de valider : Le statut actuel "+optionalEnqueteBatiment.get().getStatutEnquete()+" ne le permet pas.");
}
EnqueteBatiment enqueteBatiment = optionalEnqueteBatiment.get();
enqueteBatiment.setDateValidation(LocalDate.now());
enqueteBatiment.setStatutEnquete(StatutEnquete.VALIDE);
enqueteBatiment= enqueteBatimentRepository.save(enqueteBatiment);
return enqueteBatimentRepository.findEnqueteBatimentByIdToDto(enqueteBatiment.getId()).orElse(null);
}
@Override
public EnqueteBatimentPayloadWeb rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
if (enqueteTraitementPayLoad == null || enqueteTraitementPayLoad.getIdBackend()==null) {
throw new BadRequestException("Impossible de rejeter une enquête ayant un id null.");
}
Optional<EnqueteBatiment> optionalEnqueteBatiment = enqueteBatimentRepository.findById(enqueteTraitementPayLoad.getIdBackend());
if (!optionalEnqueteBatiment.isPresent()) {
throw new NotFoundException("Impossible de trouver l'enquête que vous désirez rejeter.");
}
if(optionalEnqueteBatiment.get().getStatutEnquete()==StatutEnquete.CLOTURE ||
optionalEnqueteBatiment.get().getStatutEnquete()==StatutEnquete.VALIDE ){
throw new NotAcceptableException("Impossible de rejeter : Le statut actuel "+optionalEnqueteBatiment.get().getStatutEnquete()+" ne le permet pas.");
}
EnqueteBatiment enqueteBatiment = optionalEnqueteBatiment.get();
enqueteBatiment.setDateRejet(LocalDate.now());
enqueteBatiment.setDescriptionMotifRejet(enqueteTraitementPayLoad.getMotifRejet());
enqueteBatiment.setStatutEnquete(StatutEnquete.REJETE);
enqueteBatiment= enqueteBatimentRepository.save(enqueteBatiment);
return enqueteBatimentRepository.findEnqueteBatimentByIdToDto(enqueteBatiment.getId()).orElse(null);
}
@Override
public List<EnqueteBatimentPayloadWeb> validerEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
List<EnqueteBatimentPayloadWeb> enqueteBatimentPayloadWebs = new ArrayList<>();
try {
for (EnqueteTraitementPayLoad enqueteTraitementPayLoad : enqueteTraitementPayLoads) {
enqueteBatimentPayloadWebs.add(validerEnquete(enqueteTraitementPayLoad));
}
} catch (Exception e) {
enqueteBatimentPayloadWebs.add(null);
}
return enqueteBatimentPayloadWebs;
}
@Override
public List<EnqueteBatimentPayloadWeb> rejeterEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
List<EnqueteBatimentPayloadWeb> enqueteBatimentPayloadWebs = new ArrayList<>();
try {
for (EnqueteTraitementPayLoad enqueteTraitementPayLoad : enqueteTraitementPayLoads) {
enqueteBatimentPayloadWebs.add(rejeterEnquete(enqueteTraitementPayLoad));
}
} catch (Exception e) {
enqueteBatimentPayloadWebs.add(null);
}
return enqueteBatimentPayloadWebs;
}
}

View File

@@ -1,26 +1,36 @@
package io.gmss.fiscad.implementations.rfu.metier;
import io.gmss.fiscad.entities.decoupage.Secteur;
import io.gmss.fiscad.entities.infocad.metier.Enquete;
import io.gmss.fiscad.entities.infocad.metier.Upload;
import io.gmss.fiscad.entities.infocad.parametre.Personne;
import io.gmss.fiscad.entities.rfu.metier.*;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
import io.gmss.fiscad.interfaces.rfu.metier.CaracteristiqueUniteLogementService;
import io.gmss.fiscad.interfaces.rfu.metier.EnqueteUniteLogementService;
import io.gmss.fiscad.interfaces.rfu.metier.UniteLogementService;
import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.EnqueteBatimentPayloadWeb;
import io.gmss.fiscad.paylaods.request.crudweb.EnqueteUniteLogementPayloadWeb;
import io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb;
import io.gmss.fiscad.persistence.repositories.infocad.metier.EnqueteRepository;
import io.gmss.fiscad.persistence.repositories.infocad.metier.UploadRepository;
import io.gmss.fiscad.persistence.repositories.infocad.parametre.PersonneRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.EnqueteUniteLogementRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.UniteLogementRepository;
import io.gmss.fiscad.service.EntityFromPayLoadService;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.NotAcceptableException;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@AllArgsConstructor
@@ -28,31 +38,65 @@ import java.util.Optional;
public class EnqueteUniteLogementServiceImpl implements EnqueteUniteLogementService {
private final EnqueteUniteLogementRepository enqueteUniteLogementRepository;
private final UniteLogementService uniteLogementService;
private final EntityFromPayLoadService entityFromPayLoadService ;
private final PersonneRepository personneRepository ;
private final EnqueteRepository enqueteRepository ;
private final UploadRepository uploadRepository ;
private final UniteLogementRepository uniteLogementRepository ;
private final CaracteristiqueUniteLogementService caracteristiqueUniteLogementService ;
private final UniteLogementService uniteLogementService ;
private final SecteurService secteurService ;
@Transactional
@Override
public EnqueteUniteLogementPayloadWeb createEnqueteUniteLogement(EnqueteUniteLogementPayloadWeb enqueteUniteLogementPayloadWeb) throws BadRequestException {
EnqueteUniteLogement enqueteUniteLogement=new EnqueteUniteLogement();
Optional<UniteLogement> optionalUniteLogement= Optional.empty();
if (enqueteUniteLogementPayloadWeb.getUniteLogementId() == null) {
throw new BadRequestException("Impossible d'enregistrer une nouvelle enquete d'unité de logement sans l'unité de logement.");
if(enqueteUniteLogementPayloadWeb.getUniteLogementId()!=null) {
if (!uniteLogementRepository.existsById(enqueteUniteLogementPayloadWeb.getUniteLogementId())) {
throw new NotFoundException("Unité de logement inexistant.");
}
}
UniteLogementPaylaodWeb uniteLogementPaylaodWeb=getUniteLogementPayloadFromEnqueteUl(enqueteUniteLogementPayloadWeb);
if(uniteLogementPaylaodWeb.getId()==null){
uniteLogementPaylaodWeb= uniteLogementService.createUniteLogement(uniteLogementPaylaodWeb);
}else{
uniteLogementPaylaodWeb= uniteLogementService.updateUniteLogement(uniteLogementPaylaodWeb.getId(),uniteLogementPaylaodWeb);
}
enqueteUniteLogementPayloadWeb.setUniteLogementId(uniteLogementPaylaodWeb.getId());
enqueteUniteLogement = entityFromPayLoadService.getEnqueteUniteLogementFromPayLoadWeb(enqueteUniteLogementPayloadWeb);
enqueteUniteLogement= enqueteUniteLogementRepository.save(enqueteUniteLogement);
enqueteUniteLogementPayloadWeb = enqueteUniteLogementRepository.findEnqueteUniteLogementToDto(enqueteUniteLogement.getId()).orElse(null);
return enqueteUniteLogementPayloadWeb ;
}
private UniteLogementPaylaodWeb getUniteLogementPayloadFromEnqueteUl(EnqueteUniteLogementPayloadWeb enqueteUniteLogementPayloadWeb) {
UniteLogementPaylaodWeb uniteLogementPaylaodWeb=new UniteLogementPaylaodWeb();
uniteLogementPaylaodWeb.setId(enqueteUniteLogementPayloadWeb.getUniteLogementId());
uniteLogementPaylaodWeb.setNul(enqueteUniteLogementPayloadWeb.getNul());
uniteLogementPaylaodWeb.setNumeroEtage(enqueteUniteLogementPayloadWeb.getNumeroEtage());
uniteLogementPaylaodWeb.setCode(enqueteUniteLogementPayloadWeb.getCode());
uniteLogementPaylaodWeb.setBatimentId(enqueteUniteLogementPayloadWeb.getBatimentId());
uniteLogementPaylaodWeb.setSuperficieAuSol(enqueteUniteLogementPayloadWeb.getSuperficieAuSol());
uniteLogementPaylaodWeb.setSuperficieLouee(enqueteUniteLogementPayloadWeb.getSuperficieLouee());
uniteLogementPaylaodWeb.setObservation(enqueteUniteLogementPayloadWeb.getObservation());
uniteLogementPaylaodWeb.setDateConstruction(enqueteUniteLogementPayloadWeb.getDateConstruction());
uniteLogementPaylaodWeb.setPersonneId(enqueteUniteLogementPayloadWeb.getPersonneId());
uniteLogementPaylaodWeb.setCategorieBatimentId(enqueteUniteLogementPayloadWeb.getCategorieBatimentId());
uniteLogementPaylaodWeb.setMontantLocatifAnnuelDeclare(enqueteUniteLogementPayloadWeb.getMontantLocatifAnnuelDeclare());
uniteLogementPaylaodWeb.setMontantLocatifAnnuelEstime(enqueteUniteLogementPayloadWeb.getMontantLocatifAnnuelEstime());
uniteLogementPaylaodWeb.setMontantMensuelLocation(enqueteUniteLogementPayloadWeb.getMontantMensuelLocation());
uniteLogementPaylaodWeb.setValeurUniteLogementReel(enqueteUniteLogementPayloadWeb.getValeurUniteLogementReel());
uniteLogementPaylaodWeb.setValeurUniteLogementEstime(enqueteUniteLogementPayloadWeb.getValeurUniteLogementEstime());
uniteLogementPaylaodWeb.setNombrePiscine(enqueteUniteLogementPayloadWeb.getNombrePiscine());
uniteLogementPaylaodWeb.setUsageId(enqueteUniteLogementPayloadWeb.getUsageId());
return uniteLogementPaylaodWeb;
}
@Override
@Transactional
public EnqueteUniteLogementPayloadWeb updateEnqueteUniteLogement(Long id, EnqueteUniteLogementPayloadWeb enqueteUniteLogementPayloadWeb) throws NotFoundException {
if (enqueteUniteLogementPayloadWeb.getId() == null) {
throw new BadRequestException("Impossible de mettre à jour une nouvelle enquete d'unité de logement ayant un id null.");
@@ -68,6 +112,16 @@ public class EnqueteUniteLogementServiceImpl implements EnqueteUniteLogementServ
EnqueteUniteLogement enqueteUniteLogement= new EnqueteUniteLogement();
UniteLogementPaylaodWeb uniteLogementPaylaodWeb=getUniteLogementPayloadFromEnqueteUl(enqueteUniteLogementPayloadWeb);
if(uniteLogementPaylaodWeb.getId()==null){
uniteLogementPaylaodWeb= uniteLogementService.createUniteLogement(uniteLogementPaylaodWeb);
}else{
uniteLogementPaylaodWeb= uniteLogementService.updateUniteLogement(uniteLogementPaylaodWeb.getId(),uniteLogementPaylaodWeb);
}
enqueteUniteLogementPayloadWeb.setUniteLogementId(uniteLogementPaylaodWeb.getId());
enqueteUniteLogement = entityFromPayLoadService.getEnqueteUniteLogementFromPayLoadWeb(enqueteUniteLogementPayloadWeb);
enqueteUniteLogement= enqueteUniteLogementRepository.save(enqueteUniteLogement);
enqueteUniteLogementPayloadWeb = enqueteUniteLogementRepository.findEnqueteUniteLogementToDto(enqueteUniteLogement.getId()).orElse(null);
@@ -114,4 +168,84 @@ public class EnqueteUniteLogementServiceImpl implements EnqueteUniteLogementServ
}
}
@Override
public Page<EnqueteUniteLogementPayloadWeb> getEnqueteUniteLogementListByQuartierByStatutPageableToDto(Long userId, Long quartierId, StatutEnquete statutEnquete, Pageable pageable) {
List<Secteur> secteurs= secteurService.getListSecteurUserId(userId);
List<Long> secteurIds = secteurs.stream()
.map(Secteur::getId)
.toList();
return enqueteUniteLogementRepository.findAllEnqueteUniteLogementByQuartierByStatutToDtoPageable(quartierId,secteurIds,statutEnquete,pageable);
}
@Override
public EnqueteUniteLogementPayloadWeb validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
if (enqueteTraitementPayLoad == null || enqueteTraitementPayLoad.getIdBackend()==null) {
throw new BadRequestException("Impossible de valider une enquête ayant un id null.");
}
Optional<EnqueteUniteLogement> optionalEnqueteUniteLogement = enqueteUniteLogementRepository.findById(enqueteTraitementPayLoad.getIdBackend());
if (!optionalEnqueteUniteLogement.isPresent()) {
throw new NotFoundException("Impossible de trouver l'enquête que vous désirez valider.");
}
if(optionalEnqueteUniteLogement.get().getStatutEnquete()==StatutEnquete.CLOTURE ||
optionalEnqueteUniteLogement.get().getStatutEnquete()==StatutEnquete.REJETE ){
throw new NotAcceptableException("Impossible de valider : Le statut actuel "+optionalEnqueteUniteLogement.get().getStatutEnquete()+" ne le permet pas.");
}
EnqueteUniteLogement enqueteUniteLogement = optionalEnqueteUniteLogement.get();
enqueteUniteLogement.setDateValidation(LocalDate.now());
enqueteUniteLogement.setStatutEnquete(StatutEnquete.VALIDE);
enqueteUniteLogement= enqueteUniteLogementRepository.save(enqueteUniteLogement);
return enqueteUniteLogementRepository.findEnqueteUniteLogementToDto(enqueteUniteLogement.getId()).orElse(null);
}
@Override
public EnqueteUniteLogementPayloadWeb rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad) {
if (enqueteTraitementPayLoad == null || enqueteTraitementPayLoad.getIdBackend()==null) {
throw new BadRequestException("Impossible de rejeter une enquête ayant un id null.");
}
Optional<EnqueteUniteLogement> optionalEnqueteUniteLogement = enqueteUniteLogementRepository.findById(enqueteTraitementPayLoad.getIdBackend());
if (!optionalEnqueteUniteLogement.isPresent()) {
throw new NotFoundException("Impossible de trouver l'enquête que vous désirez rejeter.");
}
if(optionalEnqueteUniteLogement.get().getStatutEnquete()==StatutEnquete.CLOTURE ||
optionalEnqueteUniteLogement.get().getStatutEnquete()==StatutEnquete.VALIDE ){
throw new NotAcceptableException("Impossible de rejeter : Le statut actuel "+optionalEnqueteUniteLogement.get().getStatutEnquete()+" ne le permet pas.");
}
EnqueteUniteLogement enqueteUniteLogement = optionalEnqueteUniteLogement.get();
enqueteUniteLogement.setDateRejet(LocalDate.now());
enqueteUniteLogement.setDescriptionMotifRejet(enqueteTraitementPayLoad.getMotifRejet());
enqueteUniteLogement.setStatutEnquete(StatutEnquete.REJETE);
enqueteUniteLogement= enqueteUniteLogementRepository.save(enqueteUniteLogement);
return enqueteUniteLogementRepository.findEnqueteUniteLogementToDto(enqueteUniteLogement.getId()).orElse(null);
}
@Override
public List<EnqueteUniteLogementPayloadWeb> validerEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
List<EnqueteUniteLogementPayloadWeb> enqueteUniteLogementPayloadWebs = new ArrayList<>();
try {
for (EnqueteTraitementPayLoad enqueteTraitementPayLoad : enqueteTraitementPayLoads) {
enqueteUniteLogementPayloadWebs.add(validerEnquete(enqueteTraitementPayLoad));
}
} catch (Exception e) {
enqueteUniteLogementPayloadWebs.add(null);
}
return enqueteUniteLogementPayloadWebs;
}
@Override
public List<EnqueteUniteLogementPayloadWeb> rejeterEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads) {
List<EnqueteUniteLogementPayloadWeb> enqueteUniteLogementPayloadWebs = new ArrayList<>();
try {
for (EnqueteTraitementPayLoad enqueteTraitementPayLoad : enqueteTraitementPayLoads) {
enqueteUniteLogementPayloadWebs.add(rejeterEnquete(enqueteTraitementPayLoad));
}
} catch (Exception e) {
enqueteUniteLogementPayloadWebs.add(null);
}
return enqueteUniteLogementPayloadWebs;
}
}

View File

@@ -19,6 +19,7 @@ import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@AllArgsConstructor
@@ -46,7 +47,17 @@ public class ImpositionsTfuServiceImpl implements ImpositionsTfuService {
}
List<ImpositionsTfu> impositionsTfus=impositionsTfuRepository.getImpositionsTfuByStructureAndExercice(impositionsTfuPaylaodWeb.getStructureId(), impositionsTfuPaylaodWeb.getExerciceId());
if (!impositionsTfus.isEmpty()) {
throw new BadRequestException("Une Imposition non annulée existe déjà");
throw new BadRequestException("Une Imposition non annulée existe déjà ce centre et le même exercice ");
}
List<StatusAvis> statusAvis= new ArrayList<>();
statusAvis.add(StatusAvis.EN_COURS);
statusAvis.add(StatusAvis.CLOTURE);
statusAvis.add(StatusAvis.GENERATION_AUTORISE);
Optional<ImpositionsTfu> optionalImpositionsTfu= impositionsTfuRepository.findDistinctByStructure_IdAndExercice_IdAndStatusAvisIn(impositionsTfuPaylaodWeb.getStructureId(),impositionsTfuPaylaodWeb.getExerciceId(),statusAvis);
if(optionalImpositionsTfu.isPresent()){
throw new BadRequestException("Une Imposition est déjà dans le workflow");
}
ImpositionsTfu impositionsTfu=entityFromPayLoadService.getImpositionsTfuFromPayLoadWeb(impositionsTfuPaylaodWeb);
@@ -133,12 +144,15 @@ public class ImpositionsTfuServiceImpl implements ImpositionsTfuService {
@Override
public void deleteImpositionsTfu(Long id) throws NotFoundException {
// Optional<ImpositionsTfu> impositionsTfuOptional = impositionsTfuRepository.findById(id);
// if (impositionsTfuOptional.isPresent()) {
// impositionsTfuRepository.deleteById(impositionsTfuOptional.get().getId());
// } else {
// throw new NotFoundException("Impossible de trouver la nouvelle unité de logement spécifiée dans notre base de données.");
// }
Optional<ImpositionsTfu> impositionsTfuOptional = impositionsTfuRepository.findById(id);
if (impositionsTfuOptional.isPresent()) {
if(!impositionsTfuOptional.get().getStatusAvis().equals(StatusAvis.EN_COURS)){
throw new NotFoundException("L'état actuel : "+impositionsTfuOptional.get().getStatusAvis()+ " ne permet pas de supprimer");
}
impositionsTfuRepository.deleteById(impositionsTfuOptional.get().getId());
} else {
throw new NotFoundException("Impossible de trouver la nouvelle unité de logement spécifiée dans notre base de données.");
}
}
@Override
@@ -153,9 +167,9 @@ public class ImpositionsTfuServiceImpl implements ImpositionsTfuService {
@Override
public Optional<ImpositionsTfu> getImpositionsTfuById(Long id) {
public Optional<ImpositionsTfuPaylaodWeb> getImpositionsTfuById(Long id) {
if (impositionsTfuRepository.existsById(id)) {
return impositionsTfuRepository.findById(id);
return impositionsTfuRepository.findByIdToDto(id);
} else {
throw new NotFoundException("Impossible de trouver la nouvelle unité de logement spécifiée dans la base de données.");
}
@@ -163,11 +177,12 @@ public class ImpositionsTfuServiceImpl implements ImpositionsTfuService {
@Override
public List<ImpositionsTfuPaylaodWeb> getImpositionsTfuByUserIdIds(Long userId) {
System.out.println(userId);
List<Structure> structures = structureService.getListStructureUserId(userId);
List<Long> structureIds = structures.stream()
.map(Structure::getId)
.toList();
System.out.println(structureIds.get(0));
return impositionsTfuRepository.findByStructureIdsToDto(structureIds);
}
}

View File

@@ -5,7 +5,10 @@ import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.rfu.metier.UniteLogementService;
import io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb;
import io.gmss.fiscad.persistence.repositories.rfu.metier.BatimentRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.UniteLogementRepository;
import io.gmss.fiscad.persistence.repositories.rfu.parametre.BaremRfuNonBatiRepository;
import io.gmss.fiscad.persistence.repositories.rfu.parametre.CategorieBatimentRepository;
import io.gmss.fiscad.service.EntityFromPayLoadService;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
@@ -20,6 +23,8 @@ public class UniteLogementServiceImpl implements UniteLogementService {
private final UniteLogementRepository uniteLogementRepository;
private final EntityFromPayLoadService entityFromPayLoadService;
private final BatimentRepository batimentRepository;
private final CategorieBatimentRepository categorieBatimentRepository;
@@ -28,6 +33,21 @@ public class UniteLogementServiceImpl implements UniteLogementService {
if (uniteLogementPaylaodWeb.getId() != null) {
throw new BadRequestException("Impossible de créer une nouvelle unité de logement ayant un id non null.");
}
if (uniteLogementPaylaodWeb.getBatimentId() == null) {
throw new BadRequestException("Impossible de créer l'unité de logement: Le batiment doit être précisé.");
}else {
if(!batimentRepository.existsById(uniteLogementPaylaodWeb.getBatimentId()))
throw new BadRequestException("Impossible de créer l'unite de logement: L'unité de logement doit être précisée.");
}
if (uniteLogementPaylaodWeb.getCategorieBatimentId() == null) {
throw new BadRequestException("Impossible de créer l'unite de logement: La catégorie doit être précisée.");
}else {
if(!categorieBatimentRepository.existsById(uniteLogementPaylaodWeb.getCategorieBatimentId()))
throw new BadRequestException("Impossible de créer l'unite de logement: La catégorie doit être précisée.");
}
UniteLogement uniteLogement = entityFromPayLoadService.getUniteLogementFromPayLoadWeb(uniteLogementPaylaodWeb);
uniteLogement = uniteLogementRepository.save(uniteLogement);
return uniteLogementRepository.findUniteLogementAvecOccupantCourantToDto(uniteLogement.getId()).orElse(null);
@@ -91,4 +111,14 @@ public class UniteLogementServiceImpl implements UniteLogementService {
public List<UniteLogementPaylaodWeb> getUniteLogementListByParcelle(Long parcelleId) {
return uniteLogementRepository.findAllUnitesLogementAvecOccupantCourantByParcelleToDto(parcelleId);
}
@Override
public Page<UniteLogementPaylaodWeb> getUniteLogementListByQuartierPageable(Long quartierId, Pageable pageable) {
return uniteLogementRepository.findUnitesLogementAvecOccupantCourantByQuartierToDtoPageable(quartierId,pageable);
}
@Override
public List<UniteLogementPaylaodWeb> getUniteLogementListByQuartier(Long quartierId) {
return uniteLogementRepository.findUnitesLogementAvecOccupantCourantByQuartierToDto(quartierId);
}
}

View File

@@ -1,14 +1,23 @@
package io.gmss.fiscad.implementations.statistiques;
import io.gmss.fiscad.entities.decoupage.Secteur;
import io.gmss.fiscad.entities.user.User;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
import io.gmss.fiscad.interfaces.statistique.StatistiquesService;
import io.gmss.fiscad.interfaces.user.UserService;
import io.gmss.fiscad.paylaods.request.crudweb.EnquetePayLoadWeb;
import io.gmss.fiscad.paylaods.response.statistique.*;
import io.gmss.fiscad.persistence.repositories.infocad.metier.EnqueteRepository;
import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository;
import io.gmss.fiscad.persistence.repositories.infocad.parametre.PersonneRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.BatimentRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.EnqueteBatimentRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.EnqueteUniteLogementRepository;
import io.gmss.fiscad.persistence.repositories.rfu.metier.UniteLogementRepository;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
@@ -25,14 +34,20 @@ public class StatistiquesServiceImpl implements StatistiquesService {
private final BatimentRepository batimentRepository;
private final UniteLogementRepository uniteLogementRepository;
private final PersonneRepository personneRepository;
private final SecteurService secteurService;
private final EnqueteBatimentRepository enqueteBatimentRepository;
private final EnqueteUniteLogementRepository enqueteUniteLogementRepository;
public StatistiquesServiceImpl(UserService userService, EnqueteRepository enqueteRepository, ParcelleRepository parcelleRepository, BatimentRepository batimentRepository, UniteLogementRepository uniteLogementRepository, PersonneRepository personneRepository) {
public StatistiquesServiceImpl(UserService userService, EnqueteRepository enqueteRepository, ParcelleRepository parcelleRepository, BatimentRepository batimentRepository, UniteLogementRepository uniteLogementRepository, PersonneRepository personneRepository, SecteurService secteurService, EnqueteBatimentRepository enqueteBatimentRepository, EnqueteUniteLogementRepository enqueteUniteLogementRepository) {
this.userService = userService;
this.enqueteRepository = enqueteRepository;
this.parcelleRepository = parcelleRepository;
this.batimentRepository = batimentRepository;
this.uniteLogementRepository = uniteLogementRepository;
this.personneRepository = personneRepository;
this.secteurService = secteurService;
this.enqueteBatimentRepository = enqueteBatimentRepository;
this.enqueteUniteLogementRepository = enqueteUniteLogementRepository;
}
@@ -98,4 +113,20 @@ public class StatistiquesServiceImpl implements StatistiquesService {
public List<StatistiqueTypeNombreResponse> getStatNombrePersonneParCategorie() {
return personneRepository.getNombrePersonnesResponse();
}
@Override
public NombreEnquetesParObjet getStatNombreEnqueteParObjetUserConnect(Long userId, String statutEnquete) {
NombreEnquetesParObjet nombreEnquetesParObjet= new NombreEnquetesParObjet();
List<Secteur> secteurs= secteurService.getListSecteurUserId(userId);
List<Long> secteurIds = secteurs.stream()
.map(Secteur::getId)
.toList();
nombreEnquetesParObjet.setNombreEnqueteUniteLogement(enqueteUniteLogementRepository.getNombreEnqueteUniteLogementByUserConnecte(secteurIds,statutEnquete));
nombreEnquetesParObjet.setNombreEnqueteParcelle(enqueteRepository.getNombreEnqueteByUserConnecte(secteurIds,statutEnquete));
nombreEnquetesParObjet.setNombreEnqueteBatiment(enqueteBatimentRepository.getNombreEnqueteBatimentByUserConnecte(secteurIds,statutEnquete));
return nombreEnquetesParObjet;
}
}

View File

@@ -1,11 +1,11 @@
package io.gmss.fiscad.interfaces.decoupage;
import io.gmss.fiscad.entities.decoupage.SecteurDecoupage;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.crudweb.SecteurDecoupagePaylaodWeb;
import io.gmss.fiscad.paylaods.request.crudweb.SecteurPaylaodWeb;
import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur;
import io.gmss.fiscad.paylaods.response.statistique.ParcelleStatsProjectionUnSecteur;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -33,4 +33,7 @@ public interface SecteurDecoupageService {
List<ParcelleStatsProjectionUnSecteur> getStatParcelleDecoupageUnSecteur(Long secteurId) ;
List<ParcelleStatsProjectionUnSecteur> getStatParcelleDecoupageByUserId(Long userId) ;
List<ParcelleStatsProjectionUnSecteur> getStatEnqueteDecoupageByUserId(Long userId, String statutEnquete) ;
List<ParcelleStatsProjectionUnSecteur> getStatEnqueteBatimentDecoupageByUserId(Long userId, String statutEnquete) ;
List<ParcelleStatsProjectionUnSecteur> getStatEnqueteUniteLogementDecoupageByUserId(Long userId, String statutEnquete) ;
}

View File

@@ -4,8 +4,6 @@ import io.gmss.fiscad.entities.decoupage.Secteur;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.crudweb.SecteurPaylaodWeb;
import io.gmss.fiscad.paylaods.request.synchronisation.SecteurPayload;
import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

View File

@@ -2,11 +2,13 @@ package io.gmss.fiscad.interfaces.infocad.metier;
import io.gmss.fiscad.entities.infocad.metier.Enquete;
import io.gmss.fiscad.entities.infocad.metier.EnqueteFiltreResponse;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad;
import io.gmss.fiscad.paylaods.request.FiltreEnquetePayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.EnquetePayLoadWeb;
import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb;
import io.gmss.fiscad.paylaods.response.synchronisation.EnqueteNonSyncResponse;
import io.gmss.fiscad.paylaods.response.EnqueteResponse;
import io.gmss.fiscad.paylaods.response.FicheResponse.FicheEnqueteResponse;
@@ -38,13 +40,13 @@ public interface EnqueteService {
Optional<EnquetePayLoadWeb> getEnqueteById(Long id);
Enquete validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad);
EnquetePayLoadWeb validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad);
Enquete rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad);
EnquetePayLoadWeb rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad);
List<Enquete> validerEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads);
List<EnquetePayLoadWeb> validerEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads);
List<Enquete> rejeterEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads);
List<EnquetePayLoadWeb> rejeterEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads);
Enquete finaliserEnquete(Long enqueteId);
@@ -60,4 +62,8 @@ public interface EnqueteService {
int cloturerEnqueteParcelleBatimentUniteLogementByStructureIdAndExerciceId(Long strucutreId,Long exerciceId);
int cloturerEnqueteParcelleBatimentUniteLogementByUserIdAndExerciceId(Long userId,Long exerciceId);
Page<EnquetePayLoadWeb> getEnqueteListByQuartierByStatutPageableToDto(Long userId, Long quartierId, StatutEnquete statutEnquete, Pageable pageable);
}

View File

@@ -4,10 +4,7 @@ import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.FiltreParcelle;
import io.gmss.fiscad.paylaods.request.FiltreParcellePayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb;
import io.gmss.fiscad.paylaods.response.dataTableResponse.ParcelleDataTableResponse;
import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

View File

@@ -21,6 +21,7 @@ public interface PersonneService {
void deletePersonne(Long id) throws NotFoundException;
Page<PersonnePayLoadWeb> getPersonneList(Pageable pageable);
Page<PersonnePayLoadWeb> getPersonneListNonAssigneePage(Pageable pageable);
List<PersonnePayLoadWeb> getPersonneList();

View File

@@ -27,4 +27,10 @@ public interface BatimentService {
List<BatimentPaylaodWeb> getBatimentListByParcelle(Long parcelleId);
Optional<BatimentPaylaodWeb> getBatimentById(Long id);
Page<BatimentPaylaodWeb> getBatimentListByquartierPageable(Long quartierId, Pageable pageable);
List<BatimentPaylaodWeb> getBatimentListByquartier(Long quartierId);
}

View File

@@ -0,0 +1,38 @@
package io.gmss.fiscad.interfaces.rfu.metier;
import io.gmss.fiscad.entities.user.User;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Optional;
public interface CommuneCentreAssignationService {
CommuneCentreAssignationPaylaodWeb createCommuneCentreAssignation(User user, CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws BadRequestException;
CommuneCentreAssignationPaylaodWeb updateCommuneCentreAssignation(Long id,CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws NotFoundException;
CommuneCentreAssignationPaylaodWeb detacherCommuneCentreAssignation(User user,CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) throws NotFoundException;
void deleteCommuneCentreAssignation(Long id) throws NotFoundException;
Page<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationList(Pageable pageable);
Page<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationListByCommunePageable(Long communeId, Pageable pageable);
Optional<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationById(Long id);
Optional<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationByPersonneIdCommune(User user,Long personneId);
Page<CommuneCentreAssignationPaylaodWeb> getCommuneCentreAssignationListByCentrePageable(Long centreId, Pageable pageable);
// public CommuneCentreAssignationPaylaodWeb getCommuneCentreAssignationPersonneCommune(User user, Long personneId);
}

View File

@@ -4,6 +4,7 @@ import io.gmss.fiscad.entities.rfu.metier.DonneesImpositionTfu;
import io.gmss.fiscad.entities.rfu.metier.ImpositionsTfu;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb;
import io.gmss.fiscad.paylaods.request.crudweb.ImpositionsTfuPaylaodWeb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -12,8 +13,6 @@ import java.util.List;
import java.util.Optional;
public interface DonneesImpositionTfuService {
DonneesImpositionTfu createDonneesImpositionTfu(DonneesImpositionTfu donneesImpositionTfu) throws BadRequestException;
DonneesImpositionTfu updateDonneesImpositionTfu(Long id, DonneesImpositionTfu donneesImpositionTfu) throws NotFoundException;
@@ -26,7 +25,30 @@ public interface DonneesImpositionTfuService {
Optional<DonneesImpositionTfu> getDonneesImpositionTfuById(Long id);
ImpositionsTfuPaylaodWeb genererDonneesFiscales(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb);
List<DonneesImpositionTfu> getDonneesFiscalesByImposition(Long impositionsId);
ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleBatie(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb,Long userId);
ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleNonBatie(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb,Long userId);
public ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleNonBatieUneParcelle(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, Long userId,Long parcelleId);
List<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImposition(Long impositionsId);
List<DonneesImpositionTfu> getDonneesFiscalesByImpositionArrondissement(Long impositionsId,Long arrondissementId);
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdPageable(Long impositionsTfuId, Pageable pageable);
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdNonBatiePageable(Long impositionsTfuId, Pageable pageable);
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable);
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable);
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionIrfIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable);
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionIrfIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable);
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionSrtbIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable);
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionSrtbIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable);
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByExerciceAndStructureIdPageable(Long exerciceId, Long structureId, Pageable pageable);
List<DonneesImpositionPaylaodWeb> getDonneesFiscalesByExerciceAndStructureId(Long exerciceId, Long structureId,Long quartierId);
List<DonneesImpositionPaylaodWeb> getDonneesFiscalesByPersonneId(Long personneId);
public ImpositionsTfuPaylaodWeb genererDonneesFiscalesParcelleBatieUneParcelle(ImpositionsTfuPaylaodWeb impositionsTfuPaylaodWeb, Long userId, Long parcelleId);
}

View File

@@ -1,9 +1,12 @@
package io.gmss.fiscad.interfaces.rfu.metier;
import io.gmss.fiscad.entities.rfu.metier.EnqueteBatiment;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.EnqueteBatimentPayloadWeb;
import io.gmss.fiscad.paylaods.request.crudweb.EnquetePayLoadWeb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -26,4 +29,15 @@ public interface EnqueteBatimentService {
Page<EnqueteBatimentPayloadWeb> getEnqueteBatimentByBatimentListPageable(Long batimentId, Pageable pageable);
List<EnqueteBatimentPayloadWeb> getEnqueteBatimentByBatimentList(Long batimentId);
Page<EnqueteBatimentPayloadWeb> getEnqueteBatimentListByQuartierByStatutPageableToDto(Long userId, Long quartierId, StatutEnquete statutEnquete, Pageable pageable);
EnqueteBatimentPayloadWeb validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad);
EnqueteBatimentPayloadWeb rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad);
List<EnqueteBatimentPayloadWeb> validerEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads);
List<EnqueteBatimentPayloadWeb> rejeterEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads);
}

View File

@@ -1,8 +1,11 @@
package io.gmss.fiscad.interfaces.rfu.metier;
import io.gmss.fiscad.entities.rfu.metier.EnqueteUniteLogement;
import io.gmss.fiscad.enums.StatutEnquete;
import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad;
import io.gmss.fiscad.paylaods.request.crudweb.EnqueteBatimentPayloadWeb;
import io.gmss.fiscad.paylaods.request.crudweb.EnqueteUniteLogementPayloadWeb;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -27,4 +30,14 @@ public interface EnqueteUniteLogementService {
List<EnqueteUniteLogementPayloadWeb> getEnqueteUniteLogementUniteLogementList(Long uniteLogementId);
Optional<EnqueteUniteLogementPayloadWeb> getEnqueteUniteLogementById(Long enqueteUniteLogement);
Page<EnqueteUniteLogementPayloadWeb> getEnqueteUniteLogementListByQuartierByStatutPageableToDto(Long userId, Long quartierId, StatutEnquete statutEnquete, Pageable pageable);
EnqueteUniteLogementPayloadWeb validerEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad);
EnqueteUniteLogementPayloadWeb rejeterEnquete(EnqueteTraitementPayLoad enqueteTraitementPayLoad);
List<EnqueteUniteLogementPayloadWeb> validerEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads);
List<EnqueteUniteLogementPayloadWeb> rejeterEnquete(List<EnqueteTraitementPayLoad> enqueteTraitementPayLoads);
}

View File

@@ -25,6 +25,6 @@ public interface ImpositionsTfuService {
List<ImpositionsTfu> getImpositionsTfuList();
Optional<ImpositionsTfu> getImpositionsTfuById(Long id);
Optional<ImpositionsTfuPaylaodWeb> getImpositionsTfuById(Long id);
List<ImpositionsTfuPaylaodWeb> getImpositionsTfuByUserIdIds(Long userId);
}

View File

@@ -30,4 +30,9 @@ public interface UniteLogementService {
List<UniteLogementPaylaodWeb> getUniteLogementListByBatiment(Long batimentId);
List<UniteLogementPaylaodWeb> getUniteLogementListByParcelle(Long parcelleId);
Page<UniteLogementPaylaodWeb> getUniteLogementListByQuartierPageable(Long quartierId, Pageable pageable);
List<UniteLogementPaylaodWeb> getUniteLogementListByQuartier(Long quartierId);
}

View File

@@ -11,4 +11,5 @@ public interface StatistiquesService {
List<StatEnqueteParBlocResponse> getStatBloc();
StatNombreTotalObjet getStatNombreTotalObjet(String codeDecoupageAdmin);
List<StatistiqueTypeNombreResponse> getStatNombrePersonneParCategorie();
NombreEnquetesParObjet getStatNombreEnqueteParObjetUserConnect(Long userId, String statutEnquete);
}

View File

@@ -18,8 +18,20 @@ public class BaremRfuNonBatiPayloadWeb {
private Long zoneRfuId;
private String zoneRfuCode;
private String zoneRfuNom;
private Long valeurAdministrativeMetreCarre;
private Boolean auMetreCarre;
public BaremRfuNonBatiPayloadWeb(Long id, Long valeurAdministrative, float taux, Long communeId, String communeCode, String communeNom, Long zoneRfuId, String zoneRfuCode, String zoneRfuNom) {
public BaremRfuNonBatiPayloadWeb(Long id,
Long valeurAdministrative,
Float taux,
Long communeId,
String communeCode,
String communeNom,
Long zoneRfuId,
String zoneRfuCode,
String zoneRfuNom,
Long valeurAdministrativeMetreCarre,
Boolean auMetreCarre) {
this.id = id;
this.valeurAdministrative = valeurAdministrative;
this.taux = taux;
@@ -29,5 +41,7 @@ public class BaremRfuNonBatiPayloadWeb {
this.zoneRfuId = zoneRfuId;
this.zoneRfuCode = zoneRfuCode;
this.zoneRfuNom = zoneRfuNom;
this.valeurAdministrativeMetreCarre = valeurAdministrativeMetreCarre;
this.auMetreCarre = auMetreCarre;
}
}

View File

@@ -0,0 +1,55 @@
package io.gmss.fiscad.paylaods.request.crudweb;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@Data
public class CommuneCentreAssignationPaylaodWeb {
private Long id;
private String code;
private String nom;
private Long communeId;
private String communeCode;
private String communeNom;
private Long structureId;
private String structureCode;
private String structureNom;
private Long personneId;
private String personneNom;
private String personnePrenom;
private String personneRaisonSociale;
private String personneIfu;
private String personneNc;
private String personneNpi;
private Long parcelleContactId;
private String parcelleContactQuartierCode;
private String parcelleContactQ;
private String parcelleContactI;
private String parcelleContactP;
private String adresseContact;
public CommuneCentreAssignationPaylaodWeb(Long id, Long communeId, String communeCode, String communeNom, Long structureId, String structureCode, String structureNom, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, String personneIfu, String personneNc, String personneNpi, Long parcelleContactId, String parcelleContactQuartierCode, String parcelleContactQ, String parcelleContactI, String parcelleContactP,
String adresseContact) {
this.id = id;
this.communeId = communeId;
this.communeCode = communeCode;
this.communeNom = communeNom;
this.structureId = structureId;
this.structureCode = structureCode;
this.structureNom = structureNom;
this.personneId = personneId;
this.personneNom = personneNom;
this.personnePrenom = personnePrenom;
this.personneRaisonSociale = personneRaisonSociale;
this.personneIfu = personneIfu;
this.personneNc = personneNc;
this.personneNpi = personneNpi;
this.parcelleContactId = parcelleContactId;
this.parcelleContactQuartierCode = parcelleContactQuartierCode;
this.parcelleContactQ = parcelleContactQ;
this.parcelleContactI = parcelleContactI;
this.parcelleContactP = parcelleContactP;
this.adresseContact=adresseContact;
}
}

View File

@@ -15,6 +15,11 @@ public class DeclarationNcPayloadWeb {
private LocalDate dateDerniereDeclaration;
private LocalDate dateDeclarationNc;
private String nc;
private String q;
private String i;
private String p;
private String numeroTitreFoncier;
private String nup;
private Long structureId;
private String structureCode;
private String structureNom;
@@ -24,7 +29,14 @@ public class DeclarationNcPayloadWeb {
private String personneRaisonSociale;
private String observation;
public DeclarationNcPayloadWeb(Long id, LocalDate dateDerniereDeclaration, LocalDate dateDeclarationNc, String nc, Long structureId, String structureCode, String structureNom, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, String observation) {
public DeclarationNcPayloadWeb(Long id, LocalDate dateDerniereDeclaration, LocalDate dateDeclarationNc, String nc, Long structureId, String structureCode, String structureNom, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale,
String observation,
String q,
String i,
String p,
String numeroTitreFoncier,
String nup
) {
this.id = id;
this.dateDerniereDeclaration = dateDerniereDeclaration;
this.dateDeclarationNc = dateDeclarationNc;
@@ -36,6 +48,11 @@ public class DeclarationNcPayloadWeb {
this.personneNom = personneNom;
this.personnePrenom = personnePrenom;
this.personneRaisonSociale = personneRaisonSociale;
this.q = q;
this.i = i;
this.p = p;
this.numeroTitreFoncier = numeroTitreFoncier;
this.observation = observation;
this.nup = nup;
}
}

View File

@@ -1,6 +1,9 @@
package io.gmss.fiscad.paylaods.request.crudweb;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.gmss.fiscad.enums.NatureImpot;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -20,68 +23,120 @@ public class DonneesImpositionPaylaodWeb {
private String nomArrondissement;
private String codeQuartierVillage;
private String nomQuartierVillage;
private String q;
private String ilot;
private String parcelle;
private String nup;
private String titreFoncier;
private String numBatiment;
private String numUniteLogement;
private String ifu;
private String npi;
private String telProp;
private String emailProp;
private String nomProp;
private String prenomProp;
private String raisonSociale;
private String adresseProp;
private String telSc;
private String telRep;
private String emailRep;
private String nomRep;
private String prenomRep;
private String adresseRep;
private String longitude;
private String latitude;
private Integer superficieParc;
private Long superficieAuSolBat;
private Long superficieAuSolUlog;
private String batieOuiNon;
private String exhonereOuiNon;
private String batimentExhonereOuiNon;
private String uniteLogementExhonereOuiNon;
private Boolean batie;
private Boolean exonere;
private Boolean batimentExonere;
private Boolean uniteLogementExonere;
private Long valeurLocativeAdm;
private Long valeurBatiment;
private Long valeurParcelle;
private Long montantLoyerAnnuel;
private Long tfuMetreCarre;
private Long tfuMinimum;
private String standingBat;
private String categorieBat;
private Long nombrePiscine;
private Long nombreUlog;
private Long nombreBat;
@JsonFormat(pattern = "yyyy-MM-dd")
private LocalDate dateEnquete;
private Long serviceId;
private Long zoneRfu;
private String serviceCode;
private Long zoneRfuId;
private String zoneRfuNom;
private Float tauxTfu;
private Long valeurAdminParcelleNb;
@Enumerated(EnumType.STRING)
private NatureImpot natureImpot;
private Long valeurLocativeAdmMetreCarre;
private Long valeurAdminParcelleNbMetreCarre;
private Float montantTaxe;
private Float tauxParcelleNonBati;
private Long valeurAdministrativeParcelleNonBati;
public DonneesImpositionPaylaodWeb(Long id, Long annee, String codeDepartement, String nomDepartement, String codeCommune, String nomCommune, String codeArrondissement, String nomArrondissement, String codeQuartierVillage, String nomQuartierVillage, String q, String ilot, String parcelle, String nup, String titreFoncier, String numBatiment, String numUniteLogement, String ifu, String npi, String telProp, String emailProp, String nomProp, String prenomProp, String raisonSociale, String adresseProp, String telSc, String emailRep, String nomRep, String prenomRep, String adresseRep, String longitude, String latitude, Integer superficieParc, Long superficieAuSolBat, Long superficieAuSolUlog, String batieOuiNon, String exhonereOuiNon, String batimentExhonereOuiNon, String uniteLogementExhonereOuiNon, Long valeurLocativeAdm, Long montantLoyerAnnuel, Long tfuMetreCarre, Long tfuMinimum, String standingBat, String categorieBat, Long nombrePiscine, Long nombreUlog, Long nombreBat, LocalDate dateEnquete, Long serviceId, Long zoneRfu, Float tauxParcelleNonBati, Long valeurAdministrativeParcelleNonBati) {
public DonneesImpositionPaylaodWeb(Long id,
Long annee,
String codeDepartement,
String nomDepartement,
String codeCommune,
String nomCommune,
String codeArrondissement,
String nomArrondissement,
String codeQuartierVillage,
String nomQuartierVillage,
String q, String ilot,
String parcelle,
String nup,
String titreFoncier,
String numBatiment,
String numUniteLogement,
String ifu,
String npi,
String telProp,
String emailProp,
String nomProp,
String prenomProp,
String raisonSociale,
String adresseProp,
String telRep,
String emailRep,
String nomRep,
String prenomRep,
String adresseRep,
String longitude,
String latitude,
Integer superficieParc,
Long superficieAuSolBat,
Long superficieAuSolUlog,
Boolean batie,
Boolean exonere,
Boolean batimentExonere,
Boolean uniteLogementExonere,
Long valeurLocativeAdm,
Long montantLoyerAnnuel,
Long tfuMetreCarre,
Long tfuMinimum,
String standingBat,
String categorieBat,
Long nombrePiscine,
Long nombreUlog,
Long nombreBat,
LocalDate dateEnquete,
Long serviceId,
Long zoneRfuId,
Long valeurAdministrativeParcelleNonBati,
NatureImpot natureImpot,
String serviceCode,
String zoneRfuNom,
Long valeurBatiment,
Long valeurParcelle,
Long valeurLocativeAdmMetreCarre,
Long valeurAdministrativeParcelleNonBatiAuMetreCarre,
Float montantTaxe
) {
this.id = id;
this.annee = annee;
this.codeDepartement = codeDepartement;
@@ -107,7 +162,7 @@ public class DonneesImpositionPaylaodWeb {
this.prenomProp = prenomProp;
this.raisonSociale = raisonSociale;
this.adresseProp = adresseProp;
this.telSc = telSc;
this.telRep = telRep;
this.emailRep = emailRep;
this.nomRep = nomRep;
this.prenomRep = prenomRep;
@@ -117,10 +172,10 @@ public class DonneesImpositionPaylaodWeb {
this.superficieParc = superficieParc;
this.superficieAuSolBat = superficieAuSolBat;
this.superficieAuSolUlog = superficieAuSolUlog;
this.batieOuiNon = batieOuiNon;
this.exhonereOuiNon = exhonereOuiNon;
this.batimentExhonereOuiNon = batimentExhonereOuiNon;
this.uniteLogementExhonereOuiNon = uniteLogementExhonereOuiNon;
this.batie = batie;
this.exonere = exonere;
this.batimentExonere = batimentExonere;
this.uniteLogementExonere = uniteLogementExonere;
this.valeurLocativeAdm = valeurLocativeAdm;
this.montantLoyerAnnuel = montantLoyerAnnuel;
this.tfuMetreCarre = tfuMetreCarre;
@@ -132,8 +187,15 @@ public class DonneesImpositionPaylaodWeb {
this.nombreBat = nombreBat;
this.dateEnquete = dateEnquete;
this.serviceId = serviceId;
this.zoneRfu = zoneRfu;
this.tauxParcelleNonBati = tauxParcelleNonBati;
this.valeurAdministrativeParcelleNonBati = valeurAdministrativeParcelleNonBati;
this.zoneRfuId = zoneRfuId;
this.valeurAdminParcelleNb = valeurAdministrativeParcelleNonBati;
this.natureImpot = natureImpot;
this.serviceCode = serviceCode;
this.zoneRfuNom = zoneRfuNom;
this.valeurBatiment = valeurBatiment;
this.valeurParcelle = valeurParcelle;
this.valeurLocativeAdmMetreCarre = valeurLocativeAdmMetreCarre;
this.valeurAdminParcelleNbMetreCarre = valeurAdministrativeParcelleNonBatiAuMetreCarre;
this.montantTaxe = montantTaxe;
}
}

View File

@@ -15,9 +15,6 @@ import java.util.List;
@Data
public class EnqueteBatimentPayloadWeb {
private Long id;
// private BatimentPaylaodWeb batimentPaylaodWeb ;
// private List<CaracteristiqueBatimentPayloadWeb> caracteristiqueBatimentPayloadWebs;
// private List<UploadPayLoadWeb> uploadPayLoadWebs;
private String observation;
private String autreMenuisierie;
private String autreMur;
@@ -52,7 +49,6 @@ public class EnqueteBatimentPayloadWeb {
private String enqueteurNom;
private String enqueteurPrenom;
@Enumerated(EnumType.STRING)
// @JsonIgnore
private StatutEnquete statutEnquete;
private Long exerciceId;
private Integer exerciceAnnee;
@@ -68,6 +64,18 @@ public class EnqueteBatimentPayloadWeb {
private Long usageId;
private String usageNom;
private String nub;
private String code;
private LocalDate dateConstruction;
private Long parcelleId;
private String parcelleNup;
private String parcelleQ;
private String parcelleI;
private String parcelleP;
private Long montantLocatifAnnuelEstime;
private Long valeurBatimentCalcule;
private Integer nbreUniteLogement;
public EnqueteBatimentPayloadWeb(Long id, String observation, String autreMenuisierie, String autreMur, boolean sbee, String numCompteurSbee, boolean soneb, String numCompteurSoneb, int nbreLotUnite, int nbreUniteLocation, Float superficieLouee, Float superficieAuSol, LocalDate dateEnquete, int nbreMenage, int nbreHabitant, Long montantMensuelLocation, Long montantLocatifAnnuelDeclare, Long nbreEtage, Long valeurBatimentEstime, Long valeurBatimentReel, int nbreMoisLocation, String autreCaracteristiquePhysique, LocalDate dateDebutExcemption, LocalDate dateFinExcemption, Long batimentId, String batimentNub, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, Long enqueteurId, String enqueteurNom, String enqueteurPrenom,
StatutEnquete statutEnquete,
Long exerciceId,
@@ -82,7 +90,18 @@ public class EnqueteBatimentPayloadWeb {
Integer nombrePiscine,
Long montantLocatifAnnuelCalcule,
Long usageId,
String usageNom
String usageNom,
String nub,
String code,
LocalDate dateConstruction,
Long parcelleId,
String parcelleNup,
String parcelleQ,
String parcelleI,
String parcelleP,
Long montantLocatifAnnuelEstime,
Long valeurBatimentCalcule,
Integer nbreUniteLogement
) {
this.id = id;
this.observation = observation;
@@ -131,5 +150,16 @@ public class EnqueteBatimentPayloadWeb {
this.montantLocatifAnnuelCalcule = montantLocatifAnnuelCalcule;
this.usageId = usageId ;
this.usageNom = usageNom ;
this.nub=nub;
this.code=code;
this.dateConstruction=dateConstruction;
this.parcelleId=parcelleId;
this.parcelleNup=parcelleNup;
this.parcelleQ=parcelleQ;
this.parcelleI=parcelleI;
this.parcelleP=parcelleP;
this.montantLocatifAnnuelEstime=montantLocatifAnnuelEstime;
this.valeurBatimentCalcule=valeurBatimentCalcule;
this.nbreUniteLogement=nbreUniteLogement;
}
}

View File

@@ -15,19 +15,10 @@ public class EnquetePayLoadWeb {
private LocalDate dateEnquete;
private LocalDate dateFinalisation;
private Boolean litige;
// private ParcellePayLoadWeb parcellePayLoadWeb;
// private List<CaracteristiqueParcellePayloadWeb> caracteristiqueParcellePayloadWebs;
// private List<DeclarationNcPayloadWeb> declarationNcPayloadWebs;
// private List<PiecePayLoadWeb> piecePayLoadWebs;
@Enumerated(EnumType.STRING)
private StatutEnquete statutEnquete;
private String descriptionMotifRejet;
private String observation;
private String numeroTitreFoncier;
private LocalDate dateTitreFoncier;
private String numEntreeParcelle;
private String numRue;
private String nomRue;
private Float precision;
private Integer nbreCoProprietaire;
private Integer nbreIndivisiaire;
@@ -51,11 +42,6 @@ public class EnquetePayLoadWeb {
private Long enqueteurId;
private String enqueteurNom;
private String enqueteurPrenom;
private Long parcelleId;
private String parcelleNup;
private String parcelleQ;
private String parcelleI;
private String parcelleP;
private Long exerciceId;
private Integer exerciceAnnee;
private Long modeAcquisitionId;
@@ -65,12 +51,54 @@ public class EnquetePayLoadWeb {
private String representantTel;
private String representantNpi;
private Long parcelleId;
private String parcelleNup;
private String parcelleQ;
private String parcelleI;
private String parcelleP;
private String numeroTitreFoncier;
private LocalDate dateTitreFoncier;
private String numEntreeParcelle;
private String numRue;
private String nomRue;
private String nupProvisoire;
private String longitude;
private String latitude;
private String altitude;
private String situationGeographique;
private Long quartierId;
private String quartierCode;
private String quartierNom;
private Long natureDomaineId;
private String natureDomaineLibelle;
private Long typeDomaineId;
private String typeDomaineLibelle;
private Long rueId;
public EnquetePayLoadWeb(Long id, LocalDate dateEnquete, LocalDate dateFinalisation, Boolean litige, StatutEnquete statutEnquete, String descriptionMotifRejet, String observation, String numeroTitreFoncier, LocalDate dateTitreFoncier, String numEntreeParcelle, String numRue, String nomRue, Float precision, Integer nbreCoProprietaire, Integer nbreIndivisiaire, String autreAdresse, Float superficie, Integer nbreBatiment, Integer nbrePiscine, LocalDate dateDebutExemption, LocalDate dateFinExemption, String autreNumeroTitreFoncier, Long montantMensuelleLocation, Long montantAnnuelleLocation, Long valeurParcelleEstime, Long valeurParcelleReel, Long zoneRfuId, String zoneRfuNom, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, Long enqueteurId, String enqueteurNom, String enqueteurPrenom,Long parcelleId, String parcelleNup, String parcelleQ, String parcelleI, String parcelleP, Long exerciceId, Integer exerciceAnnee,
Long modeAcquisitionId,String modeAcquisitionLibelle,
Long modeAcquisitionId,
String modeAcquisitionLibelle,
String representantNom,
String representantPrenom,
String representantTel,
String representantNpi) {
String representantNpi,
String nupProvisoire,
String longitude,
String latitude,
String altitude,
String situationGeographique,
Long quartierId,
String quartierCode,
String quartierNom,
Long natureDomaineId,
String natureDomaineLibelle,
Long typeDomaineId,
String typeDomaineLibelle,
Long rueId
) {
this.id = id;
this.dateEnquete = dateEnquete;
this.dateFinalisation = dateFinalisation;
@@ -119,5 +147,18 @@ public class EnquetePayLoadWeb {
this.representantTel = representantTel;
this.representantPrenom = representantPrenom;
this.representantNpi = representantNpi;
this.nupProvisoire=nupProvisoire;
this.longitude=longitude;
this.latitude=latitude;
this.altitude=altitude;
this.situationGeographique=situationGeographique;
this.quartierId=quartierId;
this.quartierCode=quartierCode;
this.quartierNom=quartierNom;
this.natureDomaineId=natureDomaineId;
this.natureDomaineLibelle=natureDomaineLibelle;
this.typeDomaineId=typeDomaineId;
this.typeDomaineLibelle=typeDomaineLibelle;
this.rueId=rueId;
}
}

View File

@@ -56,6 +56,17 @@ public class EnqueteUniteLogementPayloadWeb {
private Integer nombrePiscine;
private Long usageId;
private String usageNom;
private String nul;
private String numeroEtage;
private String code;
private Long batimentId;
private String batimentNub;
private LocalDate dateConstruction;
private Long enqueteUniteLogementCourantId;
private Long montantLocatifAnnuelEstime;
private Long valeurUniteLogementCalcule;
public EnqueteUniteLogementPayloadWeb(Long id, String observation, Integer nbrePiece, Integer nbreHabitant, Integer nbreMenage, Boolean enLocation, Integer nbreMoisLocation, Long montantMensuelLocation, Long montantLocatifAnnuelDeclare, Long valeurUniteLogementEstime, Long valeurUniteLogementReel, Float superficieLouee, Float superficieAuSol, LocalDate dateEnquete, Boolean sbee, Boolean soneb, String numCompteurSbee, String numCompteurSoneb, LocalDate dateDebutExemption, LocalDate dateFinExemption, Long uniteLogementId, String uniteLogementNumeroEtage, String uniteLogementNul, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, Long enqueteurId, String enqueteurNom, String enqueteurPrenom, Long exerciceId, Integer exerciceAnnee,
StatutEnquete statutEnquete,
String representantNom,
@@ -68,7 +79,15 @@ public class EnqueteUniteLogementPayloadWeb {
Integer nombrePiscine,
Long montantLocatifAnnuelCalcule,
Long usageId,
String usageNom
String usageNom,
String nul,
String numeroEtage,
String code,
Long batimentId,
String batimentNub,
LocalDate dateConstruction,
Long montantLocatifAnnuelEstime,
Long valeurUniteLogementCalcule
) {
this.id = id;
this.observation = observation;
@@ -114,5 +133,14 @@ public class EnqueteUniteLogementPayloadWeb {
this.montantLocatifAnnuelCalcule = montantLocatifAnnuelCalcule;
this.usageId = usageId ;
this.usageNom = usageNom ;
this.nul=nul;
this.numeroEtage=numeroEtage;
this.code=code;
this.batimentId=batimentId;
this.batimentNub=batimentNub;
this.dateConstruction=dateConstruction;
this.montantLocatifAnnuelEstime=montantLocatifAnnuelEstime;
this.valeurUniteLogementCalcule=valeurUniteLogementCalcule;
}
}

View File

@@ -6,6 +6,7 @@ import io.gmss.fiscad.deserializer.LocalDateDeserializer;
import io.gmss.fiscad.entities.decoupage.Commune;
import io.gmss.fiscad.entities.infocad.parametre.Structure;
import io.gmss.fiscad.entities.rfu.parametre.Exercice;
import io.gmss.fiscad.enums.NatureImpot;
import io.gmss.fiscad.enums.StatusAvis;
import jakarta.persistence.*;
import lombok.Data;
@@ -23,7 +24,10 @@ public class ImpositionsTfuPaylaodWeb {
private String datePieceAdmin;
@Enumerated(EnumType.STRING)
private StatusAvis statusAvis;
private Long nombreAvis;
private Integer nombreAvis;
private Integer nombreAvisFnb;
private Integer nombreAvisBatiment;
private Integer nombreAvisUniteLog;
@Column(columnDefinition = "TEXT")
private String motif;
private Long exerciceId;
@@ -33,8 +37,11 @@ public class ImpositionsTfuPaylaodWeb {
private String communeNom;
private Long structureId ;
private String structureNom ;
public ImpositionsTfuPaylaodWeb(Long id, LocalDate dateGeneration, LocalDate dateCloture, String referencePieceAdmin, String datePieceAdmin, StatusAvis statusAvis, Long nombreAvis, String motif, Long exerciceId, Integer exerciceAnnee, Long communeId, String communeCode, String communeNom, Long structureId, String structureNom) {
public ImpositionsTfuPaylaodWeb(Long id, LocalDate dateGeneration, LocalDate dateCloture, String referencePieceAdmin, String datePieceAdmin, StatusAvis statusAvis, Integer nombreAvis, String motif, Long exerciceId, Integer exerciceAnnee, Long communeId, String communeCode, String communeNom, Long structureId, String structureNom,
Integer nombreAvisFnb,
Integer nombreAvisBatiment,
Integer nombreAvisUniteLog
) {
this.id = id;
this.dateGeneration = dateGeneration;
this.dateCloture = dateCloture;
@@ -50,5 +57,8 @@ public class ImpositionsTfuPaylaodWeb {
this.communeNom = communeNom;
this.structureId = structureId;
this.structureNom = structureNom;
this.nombreAvisFnb = nombreAvisFnb;
this.nombreAvisBatiment = nombreAvisBatiment;
this.nombreAvisUniteLog = nombreAvisUniteLog;
}
}

View File

@@ -90,7 +90,7 @@ public class ParcelleGeomPaylaodWeb {
private String quartierCode ;
private String quartierNom ;
private int geomSrid;
private Integer geomSrid;
@JsonSerialize(using = GeometrySerializer.class)
@JsonDeserialize(contentUsing = GeometryDeserializer.class)
//@Column(name = "geometry",columnDefinition = "geometry(Polygon,32631)")
@@ -100,7 +100,7 @@ public class ParcelleGeomPaylaodWeb {
private Long parcelleId;
public ParcelleGeomPaylaodWeb(Long id, String nup, String nupProvisoire, String longitude, String latitude, String numeroRue, String numeroEntreePorte, String codeInstad, String numeroEtatLieux, String numeroTitreFoncier, LocalDate dateTitreFoncier, Boolean batie, String npi, String ifu, String nom, String prenom, String raisonSociale, String nomEtPrenoms, String telephone, String adresse, String nomRepresentant, String prenomRepresentant, String raisonSocialeRepresentant, String nomEtPrenomsRepresentant, String telephoneRepresentant, String adresseRepresentant, String q, String zone, String ilot, String p, String qLotissement, String ilotLotissement, String pLotissement, String pointsPolygone, Integer superficie, String dateCollecte, SourceDonnee sourceDonnees, String observations, StatutParcelle statutParcelle, Long departementId, String departementCode, String departementNom, Long communeId, String communeCode, String communeNom, Long arrondissementId, String arrondissementCode, String arrondissementNom, Long quartierId, String quartierCode, String quartierNom, int geomSrid, Polygon geometry, String geometryString, Long parcelleId) {
public ParcelleGeomPaylaodWeb(Long id, String nup, String nupProvisoire, String longitude, String latitude, String numeroRue, String numeroEntreePorte, String codeInstad, String numeroEtatLieux, String numeroTitreFoncier, LocalDate dateTitreFoncier, Boolean batie, String npi, String ifu, String nom, String prenom, String raisonSociale, String nomEtPrenoms, String telephone, String adresse, String nomRepresentant, String prenomRepresentant, String raisonSocialeRepresentant, String nomEtPrenomsRepresentant, String telephoneRepresentant, String adresseRepresentant, String q, String zone, String ilot, String p, String qLotissement, String ilotLotissement, String pLotissement, String pointsPolygone, Integer superficie, String dateCollecte, SourceDonnee sourceDonnees, String observations, StatutParcelle statutParcelle, Long departementId, String departementCode, String departementNom, Long communeId, String communeCode, String communeNom, Long arrondissementId, String arrondissementCode, String arrondissementNom, Long quartierId, String quartierCode, String quartierNom, Integer geomSrid, Polygon geometry, String geometryString, Long parcelleId) {
this.id = id;
this.nup = nup;
this.nupProvisoire = nupProvisoire;

View File

@@ -27,10 +27,11 @@ public class PiecePayLoadWeb {
private Long enqueteId;
private Long enqueteBatimentId;
private Long enqueteUniteLogementId;
//private List<UploadPayLoadWeb> uploadPayLoadWebs;
private Long nombreFichier;
public PiecePayLoadWeb(Long id, LocalDate dateExpiration, LocalDate dateEtablissement, String numeroPiece, String url, Long typePieceId, String typePieceLibelle, Long personneId, String personneNom, String personnePrenom, String personneRaisonSociale, Long sourceDroitId, String sourceDroitLibelle, Long modeAcquisitionId, String modeAcquisitionLibelle, String observation, Long enqueteId,
Long enqueteBatimentId,Long enqueteUniteLogementId) {
Long enqueteBatimentId,Long enqueteUniteLogementId,
Long nombreFichier) {
this.id = id;
this.dateExpiration = dateExpiration;
this.dateEtablissement = dateEtablissement;
@@ -50,6 +51,7 @@ public class PiecePayLoadWeb {
this.enqueteId = enqueteId;
this.enqueteBatimentId = enqueteBatimentId;
this.enqueteUniteLogementId = enqueteUniteLogementId;
this.nombreFichier = nombreFichier;
}
}

View File

@@ -25,7 +25,7 @@ public class ParcellePayLoad {
/////////////////////////////////
private Long typeDomaineId;
private Long numeroProvisoire;
private String numeroProvisoire;
private Long blocId;
private String situationGeographique;
private String autreNumeroTitreFoncier;

View File

@@ -0,0 +1,10 @@
package io.gmss.fiscad.paylaods.response.statistique;
import lombok.Data;
@Data
public class NombreEnquetesParObjet {
Integer nombreEnqueteParcelle;
Integer nombreEnqueteBatiment;
Integer nombreEnqueteUniteLogement;
}

View File

@@ -1,4 +1,4 @@
package io.gmss.fiscad.paylaods.response.restoration;
package io.gmss.fiscad.paylaods.response.statistique;
public interface ParcelleStatsProjectionUnSecteur {
// ================== Département ==================

View File

@@ -0,0 +1,497 @@
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS
$$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_montant_srtb NUMERIC;
BEGIN
-- récupération de l'année
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
join exercice ex on ex.id =it.exercice_id
WHERE it.id = p_impositions_tfu_id;
select value
into STRICT v_montant_srtb
from parameters
where name ='TAXE_SRTB';
INSERT INTO donnees_imposition_tfu(
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at ,
created_by ,
"source",
updated_at ,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, ----tfu correspondant au 70%
valeur_locative_adm_sup_reel,
valeur_locative_adm, ----------valeur locative administrative
tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle
tfu_piscine,
montant_taxe, ----tfu finale
taux_tfu, ----taux tfu batie
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
TRUE,
(
CURRENT_DATE >= ep.date_debut_exemption
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
),
(
CURRENT_DATE >= eb.date_debut_excemption
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
),
cb.standing,
cb.nom,
eb.nombre_piscine,
eb.date_enquete,
st.id,
ep.zone_rfu_id,
'SRTB',
p.superficie,
eb.superficie_au_sol,
case -------valeur_batiment
WHEN eb.valeur_batiment_reel IS NOT NULL AND eb.valeur_batiment_reel <> 0 THEN eb.valeur_batiment_reel
WHEN eb.valeur_batiment_calcule IS NOT NULL AND eb.valeur_batiment_calcule <> 0 THEN eb.valeur_batiment_calcule
WHEN eb.valeur_batiment_estime IS NOT NULL AND eb.valeur_batiment_estime <> 0 THEN eb.valeur_batiment_estime
ELSE 0
END,
brb.valeur_locative,
case ----- montant_loyer_annuel
WHEN eb.montant_locatif_annuel_declare IS NOT NULL AND eb.montant_locatif_annuel_declare <> 0 THEN eb.montant_locatif_annuel_declare
WHEN eb.montant_locatif_annuel_calcule IS NOT NULL AND eb.montant_locatif_annuel_calcule <> 0 THEN eb.montant_locatif_annuel_calcule
WHEN eb.montant_locatif_annuel_estime IS NOT NULL AND eb.montant_locatif_annuel_estime <> 0 THEN eb.montant_locatif_annuel_estime
ELSE 0
END,
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
false,
current_date ,
p_user_id ,
'FISCAD',
current_date ,
p_user_id,
eb.categorie_usage,
0,---superficie_au_sol_70pour100
0,
0,
eb.superficie_au_sol * brb.valeur_locative,
0, ------ valeur_locative_adm : en attente de update
0,
0,
v_montant_srtb,
0,
p.id,
b.id,
null,
eb.superficie_louee
FROM parcelle p
LEFT JOIN (
SELECT DISTINCT ON (parcelle_id)
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
ORDER BY parcelle_id, date_enquete DESC, id DESC
) ep ON ep.parcelle_id = p.id
LEFT JOIN personne pers
ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
--JOIN secteur_decoupage sd ON sd.quartier_id = q.id
JOIN (
SELECT DISTINCT ON (quartier_id)
quartier_id,
secteur_id
FROM secteur_decoupage
ORDER BY quartier_id
) sd ON sd.quartier_id = q.id
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
JOIN (
SELECT DISTINCT ON (batiment_id)
batiment_id,
superficie_au_sol,
nombre_piscine,
categorie_batiment_id,
date_enquete,
montant_locatif_annuel_declare,
montant_locatif_annuel_calcule,
montant_locatif_annuel_estime,
date_debut_excemption,
date_fin_excemption,
valeur_batiment_reel,
valeur_batiment_calcule,
valeur_batiment_estime,
u.categorie_usage,
superficie_louee
FROM enquete_batiment eb
join usage u on u.id=eb.usage_id
ORDER BY batiment_id, date_enquete DESC, eb.id DESC
) eb ON eb.batiment_id = b.id
JOIN categorie_batiment cb
ON cb.id = eb.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND NOT EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = b.id
)
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$; */
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_montant_srtb NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- 1. année + structure
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- 2. paramètre (une seule requête)
SELECT value
INTO STRICT v_montant_srtb
FROM parameters
WHERE name = 'TAXE_SRTB';
-- 3. INSERT optimisé (SANS DISTINCT ON, SANS UPDATE)
INSERT INTO donnees_imposition_tfu (
annee,
code_departement, nom_departement,
code_commune, nom_commune,
code_arrondissement, nom_arrondissement,
code_quartier_village, nom_quartier_village,
q, ilot, parcelle, nup,
titre_foncier,
num_batiment,
ifu, npi, tel_prop, email_prop,
nom_prop, prenom_prop, raison_sociale, adresse_prop,
tel_sc, nom_sc, prenom_sc,
longitude, latitude,
batie,
exonere,
batiment_exonere,
standing_bat, categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
source,
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc,
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc,
valeur_locative_adm_sup_reel,
valeur_locative_adm,
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe,
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue,
personne_id
)
SELECT
v_annee,
d.code, d.nom,
c.code, c.nom,
a.code, a.nom,
q.code, q.nom,
p.q, p.i, p.p, p.nup,
ep.numero_titre_foncier,
b.nub,
pers.ifu, pers.npi, pers.tel1, pers.email,
pers.nom, pers.prenom, pers.raison_sociale, pers.adresse,
ep.representant_tel, ep.representant_nom, ep.representant_prenom,
p.longitude, p.latitude,
TRUE,
(v_today BETWEEN ep.date_debut_exemption AND COALESCE(ep.date_fin_exemption, v_today)),
(v_today BETWEEN eb.date_debut_excemption AND COALESCE(eb.date_fin_excemption, v_today)),
cb.standing,
cb.nom,
COALESCE(eb.nombre_piscine, 0),
eb.date_enquete,
st.id,
ep.zone_rfu_id,
'SRTB',
p.superficie,
eb.superficie_au_sol,
-- valeur bâtiment optimisée
COALESCE(
NULLIF(eb.valeur_batiment_reel,0),
NULLIF(eb.valeur_batiment_calcule,0),
NULLIF(eb.valeur_batiment_estime,0),
0
),
brb.valeur_locative,
-- loyer optimisé
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare,0),
NULLIF(eb.montant_locatif_annuel_calcule,0),
NULLIF(eb.montant_locatif_annuel_estime,0),
0
),
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
FALSE,
v_today, p_user_id, 'FISCAD',
v_today, p_user_id,
eb.categorie_usage,
0, 0, 0,
eb.superficie_au_sol * brb.valeur_locative,
0,
0,
0,
-- 🔥 SRTB = valeur directe (pas de calcul)
v_montant_srtb,
0,
p.id,
b.id,
NULL,
eb.superficie_louee,
ep.personne_id
FROM parcelle p
-- dernière enquête parcelle
LEFT JOIN LATERAL (
SELECT *
FROM enquete e
WHERE e.parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- structure via secteur
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN structure st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
-- 🔥 remplace DISTINCT ON
JOIN LATERAL (
SELECT eb2.*,u.categorie_usage
FROM enquete_batiment eb2
LEFT JOIN usage u ON u.id = eb2.usage_id
WHERE eb2.batiment_id = b.id
ORDER BY eb2.date_enquete DESC, eb2.id DESC
LIMIT 1
) eb ON TRUE
JOIN categorie_batiment cb ON cb.id = eb.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND NOT EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = b.id
)
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,547 @@
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie_unite_logement(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS
$$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_montant_srtb NUMERIC;
BEGIN
-- récupération de l'année
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
join exercice ex on ex.id =it.exercice_id
WHERE it.id = p_impositions_tfu_id;
select value
into STRICT v_montant_srtb
from parameters
where name ='TAXE_SRTB';
INSERT INTO donnees_imposition_tfu(
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
num_unite_logement,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
unite_logement_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
superficie_au_sol_ulog,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at ,
created_by ,
"source",
updated_at ,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, ----tfu correspondant au 70%
valeur_locative_adm_sup_reel,
valeur_locative_adm, ----------valeur locative administrative
tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle
tfu_piscine,
montant_taxe, ----tfu finale
taux_tfu, ----taux tfu batie
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
ul.nul,
eul.ifu,
eul.npi,
eul.tel1,
eul.email,
eul.nom,
eul.prenom,
eul.raison_sociale,
eul.adresse,
eul.representant_tel,
eul.representant_nom,
eul.representant_prenom,
p.longitude,
p.latitude,
TRUE,
(
CURRENT_DATE >= ep.date_debut_exemption
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
),
(
CURRENT_DATE >= eb.date_debut_excemption
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
),
(
CURRENT_DATE >= eul.date_debut_exemption
AND CURRENT_DATE <= COALESCE(eul.date_fin_exemption, CURRENT_DATE)
),
cb.standing,
cb.nom,
CASE
WHEN eul.nombre_piscine is null then 0
else eul.nombre_piscine
END,
eul.date_enquete,
st.id,
ep.zone_rfu_id,
'IRF',
p.superficie,
eb.superficie_au_sol,
eul.superficie_au_sol,
CASE -------valeur_batiment
WHEN eul.valeur_unite_logement_reel IS NOT NULL AND eul.valeur_unite_logement_reel <> 0 THEN eul.valeur_unite_logement_reel
WHEN eul.valeur_unite_logement_calcule IS NOT NULL AND eul.valeur_unite_logement_calcule <> 0 THEN eul.valeur_unite_logement_calcule
WHEN eul.valeur_unite_logement_estime IS NOT NULL AND eul.valeur_unite_logement_estime <> 0 THEN eul.valeur_unite_logement_estime
ELSE 0
END,
brb.valeur_locative,
CASE ----- montant_loyer_annuel
WHEN eul.montant_locatif_annuel_declare IS NOT NULL AND eul.montant_locatif_annuel_declare <> 0 THEN eul.montant_locatif_annuel_declare
WHEN eul.montant_locatif_annuel_calcule IS NOT NULL AND eul.montant_locatif_annuel_calcule <> 0 THEN eul.montant_locatif_annuel_calcule
WHEN eul.montant_locatif_annuel_estime IS NOT NULL AND eul.montant_locatif_annuel_estime <> 0 THEN eul.montant_locatif_annuel_estime
ELSE 0
END,
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
false,
current_date,
p_user_id,
'FISCAD',
current_date,
p_user_id,
eul.categorie_usage,
0,---superficie_au_sol_70pour100
0,
0,
eul.superficie_au_sol * brb.valeur_locative,
0, ------ valeur_locative_adm : en attente de update
0,
0,
v_montant_srtb,
0,
p.id,
b.id,
ul.id,
eul.superficie_louee
FROM parcelle p
LEFT JOIN (
SELECT DISTINCT ON (parcelle_id)
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
ORDER BY parcelle_id, date_enquete DESC, id DESC
) ep ON ep.parcelle_id = p.id
LEFT JOIN personne pers
ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
--JOIN secteur_decoupage sd ON sd.quartier_id = q.id
JOIN (
SELECT DISTINCT ON (quartier_id)
quartier_id,
secteur_id
FROM secteur_decoupage
ORDER BY quartier_id
) sd ON sd.quartier_id = q.id
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
JOIN (
SELECT DISTINCT ON (batiment_id)
batiment_id,
superficie_au_sol,
nombre_piscine,
categorie_batiment_id,
date_enquete,
montant_locatif_annuel_declare,
montant_locatif_annuel_calcule,
montant_locatif_annuel_estime,
date_debut_excemption,
date_fin_excemption,
valeur_batiment_reel,
valeur_batiment_calcule,
valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb
join usage u on u.id=eb.usage_id
ORDER BY batiment_id, date_enquete DESC, eb.id DESC
) eb ON eb.batiment_id = b.id
JOIN unite_logement ul on ul.batiment_id = b.id
JOIN (
SELECT DISTINCT ON (eult.unite_logement_id)
eult.unite_logement_id,
pers1.id,
pers1.ifu,
pers1.npi,
pers1.tel1,
pers1.email,
pers1.nom,
pers1.prenom,
pers1.raison_sociale,
pers1.adresse,
eult.nombre_piscine,
eult.categorie_batiment_id,
eult.superficie_au_sol,
eult.superficie_louee,
eult.nbre_piece,
eult.date_enquete,
eult.montant_locatif_annuel_calcule,
eult.montant_locatif_annuel_declare,
eult.montant_locatif_annuel_estime,
eult.date_debut_exemption,
eult.date_fin_exemption,
eult.representant_nom,
eult.representant_prenom,
eult.representant_tel,
eult.valeur_unite_logement_reel,
eult.valeur_unite_logement_calcule,
eult.valeur_unite_logement_estime,
u.categorie_usage
FROM enquete_unite_logement eult
join usage u on u.id=eult.usage_id
left join personne pers1 on pers1.id = eult.personne_id
ORDER BY unite_logement_id, date_enquete DESC, eult.id DESC
) eul ON eul.unite_logement_id = ul.id
JOIN categorie_batiment cb
ON cb.id = eul.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = b.id
)
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;
*/
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie_unite_logement(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_montant_srtb NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- 1. année + structure
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- 2. paramètre
SELECT value
INTO STRICT v_montant_srtb
FROM parameters
WHERE name = 'TAXE_SRTB';
-- 3. INSERT optimisé
INSERT INTO donnees_imposition_tfu (
annee,
code_departement, nom_departement,
code_commune, nom_commune,
code_arrondissement, nom_arrondissement,
code_quartier_village, nom_quartier_village,
q, ilot, parcelle, nup,
titre_foncier,
num_batiment, num_unite_logement,
ifu, npi, tel_prop, email_prop,
nom_prop, prenom_prop, raison_sociale, adresse_prop,
tel_sc, nom_sc, prenom_sc,
longitude, latitude,
batie,
exonere, batiment_exonere, unite_logement_exonere,
standing_bat, categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
superficie_au_sol_ulog,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
source,
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc,
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc,
valeur_locative_adm_sup_reel,
valeur_locative_adm,
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe,
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue
)
SELECT
v_annee,
d.code, d.nom,
c.code, c.nom,
a.code, a.nom,
q.code, q.nom,
p.q, p.i, p.p, p.nup,
ep.numero_titre_foncier,
b.nub,
ul.nul,
eul.ifu, eul.npi, eul.tel1, eul.email,
eul.nom, eul.prenom, eul.raison_sociale, eul.adresse,
eul.representant_tel, eul.representant_nom, eul.representant_prenom,
p.longitude, p.latitude,
TRUE,
(v_today BETWEEN ep.date_debut_exemption AND COALESCE(ep.date_fin_exemption, v_today)),
(v_today BETWEEN eb.date_debut_excemption AND COALESCE(eb.date_fin_excemption, v_today)),
(v_today BETWEEN eul.date_debut_exemption AND COALESCE(eul.date_fin_exemption, v_today)),
cb.standing,
cb.nom,
COALESCE(eul.nombre_piscine, 0),
eul.date_enquete,
st.id,
ep.zone_rfu_id,
'SRTB',
p.superficie,
eb.superficie_au_sol,
eul.superficie_au_sol,
-- valeur logement optimisée
COALESCE(
NULLIF(eul.valeur_unite_logement_reel,0),
NULLIF(eul.valeur_unite_logement_calcule,0),
NULLIF(eul.valeur_unite_logement_estime,0),
0
),
brb.valeur_locative,
-- loyer optimisé
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare,0),
NULLIF(eul.montant_locatif_annuel_calcule,0),
NULLIF(eul.montant_locatif_annuel_estime,0),
0
),
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
FALSE,
v_today, p_user_id, 'FISCAD',
v_today, p_user_id,
eul.categorie_usage,
0, 0, 0,
eul.superficie_au_sol * brb.valeur_locative,
0,
0,
0,
-- 🔥 SRTB direct
v_montant_srtb,
0,
p.id,
b.id,
ul.id,
eul.superficie_louee
FROM parcelle p
LEFT JOIN LATERAL (
SELECT *
FROM enquete e
WHERE e.parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN structure st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
JOIN unite_logement ul ON ul.batiment_id = b.id
-- 🔥 remplace DISTINCT ON
JOIN LATERAL (
SELECT eult.*, pers1.*,u.categorie_usage
FROM enquete_unite_logement eult
LEFT JOIN usage u on eult.usage_id = u.id
LEFT JOIN personne pers1 ON pers1.id = eult.personne_id
WHERE eult.unite_logement_id = ul.id
ORDER BY date_enquete DESC, eult.id DESC
LIMIT 1
) eul ON TRUE
JOIN LATERAL (
SELECT eb2.*
FROM enquete_batiment eb2
WHERE eb2.batiment_id = b.id
ORDER BY date_enquete DESC
LIMIT 1
)eb ON TRUE
JOIN categorie_batiment cb ON cb.id = eb.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,754 @@
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS
$$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_tfu NUMERIC;
v_taux_valeur_locat_prof NUMERIC;
v_tfu_piscine_unitaire NUMERIC;
BEGIN
-- récupération de l'année
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
join exercice ex on ex.id =it.exercice_id
WHERE it.id = p_impositions_tfu_id;
select value
into strict v_taux_defaut_sup_sol
from parameters
where name ='TAUX_DEFAUT_SUPERFICIE_AU_SOL';
select value
into STRICT v_taux_tfu
from parameters
where name ='TAUX_TFU';
select value
into STRICT v_taux_valeur_locat_prof
from parameters
where name ='TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE';
select value
into STRICT v_tfu_piscine_unitaire
from parameters
where name ='TFU_PAR_PISCINE';
INSERT INTO donnees_imposition_tfu(
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at ,
created_by ,
"source",
updated_at ,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, ----tfu correspondant au 70%
valeur_locative_adm_sup_reel,
valeur_locative_adm, ----------valeur locative administrative
tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle
tfu_piscine,
montant_taxe, ----tfu finale
taux_tfu, ----taux tfu batie
parcelle_id,
batiment_id,
unite_logement_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
TRUE,
(
CURRENT_DATE >= ep.date_debut_exemption
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
),
(
CURRENT_DATE >= eb.date_debut_excemption
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
),
cb.standing,
cb.nom,
eb.nombre_piscine,
eb.date_enquete,
st.id,
ep.zone_rfu_id,
'TFU',
p.superficie,
eb.superficie_au_sol,
COALESCE(
NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0),
0
),
brb.valeur_locative,
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
),
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
false,
current_date ,
p_user_id ,
'FISCAD',
current_date ,
p_user_id,
eb.categorie_usage,
p.superficie*v_taux_defaut_sup_sol/100,---superficie_au_sol_70pour100
case ----valeur_locative_adm70pour100
when eb.categorie_usage = 'HABITATION' then (p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative
else 0
end,
case ----tfu calcule 70 pour 100 superficie parcelle
when eb.categorie_usage= 'HABITATION' then (p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative * v_taux_tfu/100
else 0
end,
case -----valeur_locative_adm_sup_reel
when eb.categorie_usage='HABITATION' then eb.superficie_au_sol * brb.valeur_locative
else 0
end,
0, ------ valeur_locative_adm : en attente de update
case -----tfu_superficie_au_sol_reel
when eb.categorie_usage='HABITATION' then eb.superficie_au_sol * brb.valeur_locative * v_taux_tfu/100 +eb.nombre_piscine * v_tfu_piscine_unitaire
else 0
end,
eb.nombre_piscine * v_tfu_piscine_unitaire,
0,
v_taux_tfu,
p.id,
b.id,
null
FROM parcelle p
LEFT JOIN (
SELECT DISTINCT ON (parcelle_id)
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
ORDER BY parcelle_id, date_enquete DESC, id DESC
) ep ON ep.parcelle_id = p.id
LEFT JOIN personne pers
ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
--JOIN secteur_decoupage sd ON sd.quartier_id = q.id
JOIN (
SELECT DISTINCT ON (quartier_id)
quartier_id,
secteur_id
FROM secteur_decoupage
ORDER BY quartier_id
) sd ON sd.quartier_id = q.id
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
JOIN (
SELECT DISTINCT ON (batiment_id)
batiment_id,
superficie_au_sol,
nombre_piscine,
categorie_batiment_id,
date_enquete,
montant_locatif_annuel_declare,
montant_locatif_annuel_calcule,
montant_locatif_annuel_estime,
date_debut_excemption,
date_fin_excemption,
valeur_batiment_reel,
valeur_batiment_calcule,
valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb
join usage u on u.id=eb.usage_id
ORDER BY batiment_id, date_enquete DESC, eb.id DESC
) eb ON eb.batiment_id = b.id
JOIN categorie_batiment cb
ON cb.id = eb.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND NOT EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = b.id
)
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
UPDATE donnees_imposition_tfu dtfu
SET
valeur_locative_adm =
CASE
WHEN categorie_usage = 'HABITATION' AND superficie_au_sol_bat <> 0
THEN valeur_locative_adm_sup_reel
WHEN categorie_usage = 'HABITATION' AND superficie_au_sol_bat = 0
THEN valeur_locative_adm_taux_prop_parc
WHEN categorie_usage IN ('PROFESSIONNELLE','MIXTE') AND valeur_batiment <> 0
THEN valeur_batiment * (v_taux_valeur_locat_prof/100)
WHEN categorie_usage IN ('PROFESSIONNELLE','MIXTE') AND valeur_batiment = 0
THEN montant_loyer_annuel
END,
montant_taxe =
CASE
WHEN categorie_usage = 'HABITATION' AND superficie_au_sol_bat <> 0 THEN
CASE
WHEN tfu_minimum < valeur_locative_adm_sup_reel * (v_taux_tfu/100) + tfu_piscine
THEN valeur_locative_adm_sup_reel * (v_taux_tfu/100) + tfu_piscine
ELSE tfu_minimum
END
WHEN categorie_usage = 'HABITATION' AND superficie_au_sol_bat = 0 THEN
CASE
WHEN tfu_minimum < valeur_locative_adm_taux_prop_parc * (v_taux_tfu/100) + tfu_piscine
THEN valeur_locative_adm_taux_prop_parc * (v_taux_tfu/100) + tfu_piscine
ELSE tfu_minimum
END
WHEN categorie_usage IN ('PROFESSIONNELLE','MIXTE') AND valeur_batiment <> 0 THEN
CASE
WHEN tfu_minimum < valeur_batiment * (v_taux_valeur_locat_prof/100) * (v_taux_tfu/100)
THEN valeur_batiment * (v_taux_valeur_locat_prof/100) * (v_taux_tfu/100)
ELSE tfu_minimum
END
WHEN categorie_usage IN ('PROFESSIONNELLE','MIXTE') AND valeur_batiment = 0 THEN
CASE
WHEN tfu_minimum < montant_loyer_annuel * (v_taux_tfu/100)
THEN montant_loyer_annuel * (v_taux_tfu/100)
ELSE tfu_minimum
END
END
WHERE impositions_tfu_id = p_impositions_tfu_id
AND batie = TRUE
AND NOT EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = dtfu.batiment_id
);
RETURN v_rows_inserted;
END;
$$;*/
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_tfu NUMERIC;
v_taux_tfu_ratio NUMERIC; -- v_taux_tfu / 100 (pré-calculé)
v_taux_valeur_locat_prof NUMERIC;
v_taux_vlp_ratio NUMERIC; -- v_taux_valeur_locat_prof / 100 (pré-calculé)
v_tfu_piscine_unitaire NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- -------------------------------------------------------------------------
-- 2. Récupération des 4 paramètres en UNE seule requête
-- (évite 4 accès séquentiels à la table parameters)
-- -------------------------------------------------------------------------
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_TFU'),
MAX(value) FILTER (WHERE name = 'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'),
MAX(value) FILTER (WHERE name = 'TFU_PAR_PISCINE')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_tfu,
v_taux_valeur_locat_prof,
v_tfu_piscine_unitaire
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_TFU',
'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE',
'TFU_PAR_PISCINE'
);
-- Ratios pré-calculés pour éviter la division répétée dans le SELECT
v_taux_tfu_ratio := v_taux_tfu / 100.0;
v_taux_vlp_ratio := v_taux_valeur_locat_prof / 100.0;
-- -------------------------------------------------------------------------
-- 3. INSERT avec calcul complet de valeur_locative_adm et montant_taxe
-- → supprime l'UPDATE post-INSERT (économie d'un second scan de table)
-- -------------------------------------------------------------------------
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- TFU à 70 %
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- valeur locative administrative finale
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe, -- TFU finale
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id,
personne_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
TRUE,
-- exonere parcelle
(v_today BETWEEN ep.date_debut_exemption
AND COALESCE(ep.date_fin_exemption, v_today)),
-- exonere batiment
(v_today BETWEEN eb.date_debut_excemption
AND COALESCE(eb.date_fin_excemption, v_today)),
cb.standing,
cb.nom,
eb.nombre_piscine,
eb.date_enquete,
st.id,
ep.zone_rfu_id,
'TFU',
p.superficie,
eb.superficie_au_sol,
-- valeur_batiment : première valeur non nulle non zéro
COALESCE(
NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0),
0
),
brb.valeur_locative,
-- montant_loyer_annuel
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
),
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
eb.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
p.superficie * v_taux_defaut_sup_sol / 100.0,
-- valeur_locative_adm_taux_prop_parc
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
ELSE 0
END,
-- tfu_calcule_taux_prop_parc
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative * v_taux_tfu_ratio
ELSE 0
END,
-- valeur_locative_adm_sup_reel
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN eb.superficie_au_sol * brb.valeur_locative
ELSE 0
END,
-- ---------------------------------------------------------------
-- 🔧 CORRECTION : valeur_locative_adm avec tests explicites
-- ---------------------------------------------------------------
CASE
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol <> 0
THEN eb.superficie_au_sol * brb.valeur_locative
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol = 0
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
-- ✅ Test explicite : valeur_batiment <> 0
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) <> 0
THEN COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0)
* v_taux_vlp_ratio
-- ✅ Test explicite : valeur_batiment = 0
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) = 0
THEN COALESCE(NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0), 0)
ELSE 0
END,
-- tfu_superficie_au_sol_reel
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN eb.superficie_au_sol * brb.valeur_locative * v_taux_tfu_ratio * eb.nombre_piscine * v_tfu_piscine_unitaire
ELSE 0
END,
-- tfu_piscine
eb.nombre_piscine * v_tfu_piscine_unitaire,
-- ---------------------------------------------------------------
-- montant_taxe ← calculé directement (plus d'UPDATE)
-- Utilise des CTE inline via expression pour éviter la redondance
-- ---------------------------------------------------------------
(
-- On matérialise valeur_batiment et valeur_locative une seule fois
WITH calc AS (
SELECT
COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) AS vb,
COALESCE(NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0), 0) AS loyer,
eb.superficie_au_sol * brb.valeur_locative AS vla_reel,
(p.superficie * v_taux_defaut_sup_sol / 100.0)
* brb.valeur_locative AS vla_70
)
SELECT
CASE
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol <> 0
THEN GREATEST(brb.tfu_minimum,
calc.vla_reel * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire)
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol = 0
THEN GREATEST(brb.tfu_minimum,
calc.vla_70 * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire)
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb <> 0
THEN GREATEST(brb.tfu_minimum,
calc.vb * v_taux_vlp_ratio * v_taux_tfu_ratio)
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb = 0
THEN GREATEST(brb.tfu_minimum,
calc.loyer * v_taux_tfu_ratio)
ELSE brb.tfu_minimum
END
FROM calc
),
v_taux_tfu,
p.id,
b.id,
NULL,
ep.personne_id
FROM parcelle p
-- Dernière enquête parcelle
LEFT JOIN LATERAL (
SELECT
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
WHERE parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- Rattachement structure via secteur (DISTINCT ON → LATERAL plus lisible)
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
ORDER BY quartier_id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
-- Bâtiments sans unités logement (anti-join via LEFT JOIN … IS NULL)
JOIN batiment b ON b.parcelle_id = p.id
LEFT JOIN unite_logement ul_filter ON ul_filter.batiment_id = b.id
-- Dernière enquête bâtiment
JOIN LATERAL (
SELECT
eb2.batiment_id,
eb2.superficie_au_sol,
eb2.nombre_piscine,
eb2.categorie_batiment_id,
eb2.date_enquete,
eb2.montant_locatif_annuel_declare,
eb2.montant_locatif_annuel_calcule,
eb2.montant_locatif_annuel_estime,
eb2.date_debut_excemption,
eb2.date_fin_excemption,
eb2.valeur_batiment_reel,
eb2.valeur_batiment_calcule,
eb2.valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb2
JOIN usage u ON u.id = eb2.usage_id
WHERE eb2.batiment_id = b.id
ORDER BY eb2.date_enquete DESC, eb2.id DESC
LIMIT 1
) eb ON TRUE
JOIN categorie_batiment cb ON cb.id = eb.categorie_batiment_id
-- Barème RFU bâti (inchangé)
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND ul_filter.batiment_id IS NULL -- anti-join : pas d'unité logement
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,855 @@
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_batie_unite_logement(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS
$$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_tfu NUMERIC;
v_taux_valeur_locat_prof NUMERIC;
v_tfu_piscine_unitaire NUMERIC;
BEGIN
-- récupération de l'année
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
join exercice ex on ex.id =it.exercice_id
WHERE it.id = p_impositions_tfu_id;
select value
into strict v_taux_defaut_sup_sol
from parameters
where name ='TAUX_DEFAUT_SUPERFICIE_AU_SOL';
select value
into STRICT v_taux_tfu
from parameters
where name ='TAUX_TFU';
RAISE NOTICE 'v_taux_tfu = %', v_taux_tfu;
select value
into STRICT v_taux_valeur_locat_prof
from parameters
where name ='TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE';
select value
into STRICT v_tfu_piscine_unitaire
from parameters
where name ='TFU_PAR_PISCINE';
INSERT INTO donnees_imposition_tfu(
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
num_unite_logement,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
unite_logement_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
superficie_au_sol_ulog,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at ,
created_by ,
"source",
updated_at ,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, ----tfu correspondant au 70%
valeur_locative_adm_sup_reel,
valeur_locative_adm, ----------valeur locative administrative
tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle
tfu_piscine,
montant_taxe, ----tfu finale
taux_tfu, ----taux tfu batie
parcelle_id,
batiment_id,
unite_logement_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
ul.nul,
eul.ifu,
eul.npi,
eul.tel1,
eul.email,
eul.nom,
eul.prenom,
eul.raison_sociale,
eul.adresse,
eul.representant_tel,
eul.representant_nom,
eul.representant_prenom,
p.longitude,
p.latitude,
TRUE,
(
CURRENT_DATE >= ep.date_debut_exemption
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
),
(
CURRENT_DATE >= eb.date_debut_excemption
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
),
(
CURRENT_DATE >= eul.date_debut_exemption
AND CURRENT_DATE <= COALESCE(eul.date_fin_exemption, CURRENT_DATE)
),
cb.standing,
cb.nom,
CASE
WHEN eul.nombre_piscine is null then 0
else eul.nombre_piscine
END,
eul.date_enquete,
st.id,
ep.zone_rfu_id,
'TFU',
p.superficie,
eb.superficie_au_sol,
eul.superficie_au_sol,
CASE -------valeur_batiment
WHEN eul.valeur_unite_logement_reel IS NOT NULL AND eul.valeur_unite_logement_reel <> 0 THEN eul.valeur_unite_logement_reel
WHEN eul.valeur_unite_logement_calcule IS NOT NULL AND eul.valeur_unite_logement_calcule <> 0 THEN eul.valeur_unite_logement_calcule
WHEN eul.valeur_unite_logement_estime IS NOT NULL AND eul.valeur_unite_logement_estime <> 0 THEN eul.valeur_unite_logement_estime
ELSE 0
END,
brb.valeur_locative,
CASE ----- montant_loyer_annuel
WHEN eul.montant_locatif_annuel_declare IS NOT NULL AND eul.montant_locatif_annuel_declare <> 0 THEN eul.montant_locatif_annuel_declare
WHEN eul.montant_locatif_annuel_calcule IS NOT NULL AND eul.montant_locatif_annuel_calcule <> 0 THEN eul.montant_locatif_annuel_calcule
WHEN eul.montant_locatif_annuel_estime IS NOT NULL AND eul.montant_locatif_annuel_estime <> 0 THEN eul.montant_locatif_annuel_estime
ELSE 0
END,
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
false,
current_date,
p_user_id,
'FISCAD',
current_date,
p_user_id,
eul.categorie_usage,
p.superficie * v_taux_defaut_sup_sol/100,---superficie_au_sol_70pour100
case ----valeur_locative_adm70pour100
when eul.categorie_usage = 'HABITATION' then (p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative
else 0
end,
case ----tfu calcule 70 pour 100 superficie parcelle
when eul.categorie_usage= 'HABITATION' then (p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative * v_taux_tfu/100
else 0
end,
case -----valeur_locative_adm_sup_reel
when eul.categorie_usage='HABITATION' then eul.superficie_au_sol * brb.valeur_locative
else 0
end,
0, ------ valeur_locative_adm : en attente de update
case -----tfu_superficie_au_sol_reel
when eul.categorie_usage='HABITATION' then eul.superficie_au_sol * brb.valeur_locative * 6/100
else 0
end,
CASE
WHEN eul.nombre_piscine is null then 0
else eul.nombre_piscine * v_tfu_piscine_unitaire
END,
0,
v_taux_tfu,
p.id,
b.id,
ul.id
FROM parcelle p
LEFT JOIN (
SELECT DISTINCT ON (parcelle_id)
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
ORDER BY parcelle_id, date_enquete DESC, id DESC
) ep ON ep.parcelle_id = p.id
LEFT JOIN personne pers
ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
--JOIN secteur_decoupage sd ON sd.quartier_id = q.id
JOIN (
SELECT DISTINCT ON (quartier_id)
quartier_id,
secteur_id
FROM secteur_decoupage
ORDER BY quartier_id
) sd ON sd.quartier_id = q.id
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
JOIN (
SELECT DISTINCT ON (batiment_id)
batiment_id,
superficie_au_sol,
nombre_piscine,
categorie_batiment_id,
date_enquete,
montant_locatif_annuel_declare,
montant_locatif_annuel_calcule,
montant_locatif_annuel_estime,
date_debut_excemption,
date_fin_excemption,
valeur_batiment_reel,
valeur_batiment_calcule,
valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb
join usage u on u.id=eb.usage_id
ORDER BY batiment_id, date_enquete DESC, eb.id DESC
) eb ON eb.batiment_id = b.id
JOIN unite_logement ul on ul.batiment_id = b.id
JOIN (
SELECT DISTINCT ON (eult.unite_logement_id)
eult.unite_logement_id,
pers1.id,
pers1.ifu,
pers1.npi,
pers1.tel1,
pers1.email,
pers1.nom,
pers1.prenom,
pers1.raison_sociale,
pers1.adresse,
eult.nombre_piscine,
eult.categorie_batiment_id,
eult.superficie_au_sol,
eult.superficie_louee,
eult.nbre_piece,
eult.date_enquete,
eult.montant_locatif_annuel_calcule,
eult.montant_locatif_annuel_declare,
eult.montant_locatif_annuel_estime,
eult.date_debut_exemption,
eult.date_fin_exemption,
eult.representant_nom,
eult.representant_prenom,
eult.representant_tel,
eult.valeur_unite_logement_reel,
eult.valeur_unite_logement_calcule,
eult.valeur_unite_logement_estime,
u.categorie_usage
FROM enquete_unite_logement eult
join usage u on u.id=eult.usage_id
left join personne pers1 on pers1.id = eult.personne_id
ORDER BY unite_logement_id, date_enquete DESC, eult.id DESC
) eul ON eul.unite_logement_id = ul.id
JOIN categorie_batiment cb
ON cb.id = eul.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = b.id
)
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
UPDATE donnees_imposition_tfu dtfu
SET
valeur_locative_adm =
CASE
WHEN categorie_usage = 'HABITATION' AND superficie_au_sol_ulog <> 0
THEN valeur_locative_adm_sup_reel
WHEN categorie_usage = 'HABITATION' AND superficie_au_sol_ulog = 0
THEN valeur_locative_adm_taux_prop_parc
WHEN categorie_usage IN ('PROFESSIONNELLE','MIXTE') AND valeur_batiment <> 0
THEN valeur_batiment * (v_taux_valeur_locat_prof/100)
WHEN categorie_usage IN ('PROFESSIONNELLE','MIXTE') AND valeur_batiment = 0
THEN montant_loyer_annuel
END,
montant_taxe =
CASE
WHEN categorie_usage = 'HABITATION' AND superficie_au_sol_ulog <> 0 THEN
CASE
WHEN tfu_minimum < valeur_locative_adm_sup_reel * (v_taux_tfu/100) + tfu_piscine
THEN valeur_locative_adm_sup_reel * (v_taux_tfu/100) + tfu_piscine
ELSE tfu_minimum
END
WHEN categorie_usage = 'HABITATION' AND superficie_au_sol_ulog = 0 THEN
CASE
WHEN tfu_minimum < valeur_locative_adm_taux_prop_parc * (v_taux_tfu/100) + tfu_piscine
THEN valeur_locative_adm_taux_prop_parc * (v_taux_tfu/100) + tfu_piscine
ELSE tfu_minimum
END
WHEN categorie_usage IN ('PROFESSIONNELLE','MIXTE') AND valeur_batiment <> 0 THEN
CASE
WHEN tfu_minimum < valeur_batiment * (v_taux_valeur_locat_prof/100) * (v_taux_tfu/100)
THEN valeur_batiment * (v_taux_valeur_locat_prof/100) * (v_taux_tfu/100)
ELSE tfu_minimum
END
WHEN categorie_usage IN ('PROFESSIONNELLE','MIXTE') AND valeur_batiment = 0 THEN
CASE
WHEN tfu_minimum < montant_loyer_annuel * (v_taux_tfu/100)
THEN montant_loyer_annuel * (v_taux_tfu/100)
ELSE tfu_minimum
END
END
WHERE impositions_tfu_id = p_impositions_tfu_id
AND batie = TRUE
AND EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = dtfu.batiment_id
);
RETURN v_rows_inserted;
END;
$$;*/
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_batie_unite_logement(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_tfu NUMERIC;
v_taux_tfu_ratio NUMERIC; -- v_taux_tfu / 100 (pré-calculé)
v_taux_valeur_locat_prof NUMERIC;
v_taux_vlp_ratio NUMERIC; -- v_taux_valeur_locat_prof / 100 (pré-calculé)
v_tfu_piscine_unitaire NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- -------------------------------------------------------------------------
-- 2. Récupération des 4 paramètres en UNE seule requête
-- (évite 4 accès séquentiels à la table parameters)
-- -------------------------------------------------------------------------
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_TFU'),
MAX(value) FILTER (WHERE name = 'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'),
MAX(value) FILTER (WHERE name = 'TFU_PAR_PISCINE')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_tfu,
v_taux_valeur_locat_prof,
v_tfu_piscine_unitaire
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_TFU',
'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE',
'TFU_PAR_PISCINE'
);
-- Ratios pré-calculés pour éviter la division répétée dans le SELECT
v_taux_tfu_ratio := v_taux_tfu / 100.0;
v_taux_vlp_ratio := v_taux_valeur_locat_prof / 100.0;
-- -------------------------------------------------------------------------
-- 3. INSERT avec calcul complet de valeur_locative_adm et montant_taxe
-- → supprime l'UPDATE post-INSERT (économie d'un second scan de table)
-- -------------------------------------------------------------------------
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
num_unite_logement,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
unite_logement_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
superficie_au_sol_ulog,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- TFU à 70 %
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- valeur locative administrative finale
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe, -- TFU finale
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
ul.nul,
eul.ifu,
eul.npi,
eul.tel1,
eul.email,
eul.nom,
eul.prenom,
eul.raison_sociale,
eul.adresse,
eul.representant_tel,
eul.representant_nom,
eul.representant_prenom,
p.longitude,
p.latitude,
TRUE,
-- exonere parcelle
(v_today BETWEEN ep.date_debut_exemption
AND COALESCE(ep.date_fin_exemption, v_today)),
-- exonere batiment
(v_today BETWEEN eb.date_debut_excemption
AND COALESCE(eb.date_fin_excemption, v_today)),
-- exonere unite logement
(v_today BETWEEN eul.date_debut_exemption
AND COALESCE(eul.date_fin_exemption, v_today)),
cb.standing,
cb.nom,
COALESCE(eul.nombre_piscine, 0),
eul.date_enquete,
st.id,
ep.zone_rfu_id,
'TFU',
p.superficie,
eb.superficie_au_sol,
eul.superficie_au_sol,
-- valeur_batiment (unité logement) : première valeur non nulle non zéro
COALESCE(
NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0),
0
),
brb.valeur_locative,
-- montant_loyer_annuel
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare, 0),
NULLIF(eul.montant_locatif_annuel_calcule, 0),
NULLIF(eul.montant_locatif_annuel_estime, 0),
0
),
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
eul.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
p.superficie * v_taux_defaut_sup_sol / 100.0,
-- valeur_locative_adm_taux_prop_parc
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
ELSE 0
END,
-- tfu_calcule_taux_prop_parc
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative * v_taux_tfu_ratio
ELSE 0
END,
-- valeur_locative_adm_sup_reel
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN eul.superficie_au_sol * brb.valeur_locative
ELSE 0
END,
-- ---------------------------------------------------------------
-- valeur_locative_adm avec tests explicites (corrigée)
-- ---------------------------------------------------------------
CASE
WHEN eul.categorie_usage = 'HABITATION'
AND eul.superficie_au_sol <> 0
THEN eul.superficie_au_sol * brb.valeur_locative
WHEN eul.categorie_usage = 'HABITATION'
AND eul.superficie_au_sol = 0
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
-- ✅ Test explicite : valeur_unite_logement <> 0
WHEN eul.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0) <> 0
THEN COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0)
* v_taux_vlp_ratio
-- ✅ Test explicite : valeur_unite_logement = 0
WHEN eul.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0) = 0
THEN COALESCE(NULLIF(eul.montant_locatif_annuel_declare, 0),
NULLIF(eul.montant_locatif_annuel_calcule, 0),
NULLIF(eul.montant_locatif_annuel_estime, 0), 0)
ELSE 0
END,
-- 🔧 CORRECTION : tfu_superficie_au_sol_reel (était hardcodé à 6/100)
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN eul.superficie_au_sol * brb.valeur_locative * v_taux_tfu_ratio
ELSE 0
END,
-- tfu_piscine
COALESCE(eul.nombre_piscine, 0) * v_tfu_piscine_unitaire,
-- ---------------------------------------------------------------
-- montant_taxe ← calculé directement (plus d'UPDATE)
-- ---------------------------------------------------------------
(
WITH calc AS (
SELECT
COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0) AS valeur_ul,
COALESCE(NULLIF(eul.montant_locatif_annuel_declare, 0),
NULLIF(eul.montant_locatif_annuel_calcule, 0),
NULLIF(eul.montant_locatif_annuel_estime, 0), 0) AS loyer,
eul.superficie_au_sol * brb.valeur_locative AS vla_reel,
(p.superficie * v_taux_defaut_sup_sol / 100.0)
* brb.valeur_locative AS vla_70,
COALESCE(eul.nombre_piscine, 0) * v_tfu_piscine_unitaire AS piscine_montant
)
SELECT
CASE
WHEN eul.categorie_usage = 'HABITATION'
AND eul.superficie_au_sol <> 0
THEN GREATEST(brb.tfu_minimum,
calc.vla_reel * v_taux_tfu_ratio
+ calc.piscine_montant)
WHEN eul.categorie_usage = 'HABITATION'
AND eul.superficie_au_sol = 0
THEN GREATEST(brb.tfu_minimum,
calc.vla_70 * v_taux_tfu_ratio
+ calc.piscine_montant)
WHEN eul.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.valeur_ul <> 0
THEN GREATEST(brb.tfu_minimum,
calc.valeur_ul * v_taux_vlp_ratio * v_taux_tfu_ratio)
WHEN eul.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.valeur_ul = 0
THEN GREATEST(brb.tfu_minimum,
calc.loyer * v_taux_tfu_ratio)
ELSE brb.tfu_minimum
END
FROM calc
),
v_taux_tfu,
p.id,
b.id,
ul.id
FROM parcelle p
-- Dernière enquête parcelle
LEFT JOIN LATERAL (
SELECT
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
WHERE parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- Rattachement structure via secteur
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
ORDER BY quartier_id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
-- Dernière enquête bâtiment
JOIN LATERAL (
SELECT
eb2.batiment_id,
eb2.superficie_au_sol,
eb2.nombre_piscine,
eb2.categorie_batiment_id,
eb2.date_enquete,
eb2.montant_locatif_annuel_declare,
eb2.montant_locatif_annuel_calcule,
eb2.montant_locatif_annuel_estime,
eb2.date_debut_excemption,
eb2.date_fin_excemption,
eb2.valeur_batiment_reel,
eb2.valeur_batiment_calcule,
eb2.valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb2
JOIN usage u ON u.id = eb2.usage_id
WHERE eb2.batiment_id = b.id
ORDER BY eb2.date_enquete DESC, eb2.id DESC
LIMIT 1
) eb ON TRUE
JOIN unite_logement ul ON ul.batiment_id = b.id
-- Dernière enquête unité logement
JOIN LATERAL (
SELECT
eul2.unite_logement_id,
pers1.id,
pers1.ifu,
pers1.npi,
pers1.tel1,
pers1.email,
pers1.nom,
pers1.prenom,
pers1.raison_sociale,
pers1.adresse,
eul2.nombre_piscine,
eul2.categorie_batiment_id,
eul2.superficie_au_sol,
eul2.superficie_louee,
eul2.nbre_piece,
eul2.date_enquete,
eul2.montant_locatif_annuel_calcule,
eul2.montant_locatif_annuel_declare,
eul2.montant_locatif_annuel_estime,
eul2.date_debut_exemption,
eul2.date_fin_exemption,
eul2.representant_nom,
eul2.representant_prenom,
eul2.representant_tel,
eul2.valeur_unite_logement_reel,
eul2.valeur_unite_logement_calcule,
eul2.valeur_unite_logement_estime,
u.categorie_usage
FROM enquete_unite_logement eul2
JOIN usage u ON u.id = eul2.usage_id
LEFT JOIN personne pers1 ON pers1.id = eul2.personne_id
WHERE eul2.unite_logement_id = ul.id
ORDER BY eul2.date_enquete DESC, eul2.id DESC
LIMIT 1
) eul ON TRUE
JOIN categorie_batiment cb ON cb.id = eul.categorie_batiment_id
-- Barème RFU bâti (inchangé)
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND EXISTS (
SELECT 1
FROM unite_logement ul2
WHERE ul2.batiment_id = b.id
)
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,34 @@
-- Tables E_AVIS et E_AVIS_DETAIL
CREATE TABLE e_avis (
id_avis BIGINT NOT NULL,
r_avis VARCHAR(50),
exercice BIGINT,
r_commune VARCHAR(50),
r_centre_impot VARCHAR(50),
id_contribuable_foncier BIGINT,
ifu VARCHAR(50),
npi VARCHAR(20),
nc VARCHAR(20),
raison_social VARCHAR(500),
nom VARCHAR(500),
prenom VARCHAR(500),
date_liquidation DATE,
date_information DATE
);
CREATE TABLE e_avis_detail (
id_avis_detail BIGINT NOT NULL,
id_avis BIGINT NOT NULL,
id_impot_nature VARCHAR(50),
id_unite_foncier BIGINT NOT NULL,
nup VARCHAR(20),
r_quartier VARCHAR(50),
qip_quartier VARCHAR(10),
qip_parcelle VARCHAR(10),
batiment VARCHAR(10),
unite_logement VARCHAR(10),
montant_base_imposition NUMERIC(22,3),
montant_valeur_locative NUMERIC(22,3),
taux NUMERIC(22,10),
montant_du NUMERIC(22,3)
);

View File

@@ -0,0 +1,136 @@
-----------------
create or replace view e_avis_view as
WITH first_parcelle_imposition AS (
SELECT DISTINCT ON (personne_id)
personne_id,
parcelle_id
FROM donnees_imposition_tfu
ORDER BY personne_id, annee,parcelle_id
),
cca_unique AS (
SELECT DISTINCT ON (cc.commune_id, cc.personne_id)
cc.structure_id,
cc.personne_id,
cc.commune_id,
COALESCE(qu.code, qu_imp.code) AS r_quartier_contact,
COALESCE(parc.q, parc_imp.q) AS q_contact,
COALESCE(parc.i, parc_imp.i) AS i_contact,
COALESCE(parc.p, parc_imp.p) AS p_contact
FROM commune_centre_assignation cc
LEFT JOIN parcelle parc
ON parc.id = cc.parcelle_id
LEFT JOIN quartier qu
ON qu.id = parc.quartier_id
LEFT JOIN first_parcelle_imposition dpi
ON dpi.personne_id = cc.personne_id
LEFT JOIN parcelle parc_imp
ON parc_imp.id = dpi.parcelle_id
LEFT JOIN quartier qu_imp
ON qu_imp.id = parc_imp.quartier_id
ORDER BY cc.commune_id, cc.personne_id, cc.structure_id
)
SELECT distinct
null as id_avis,
concat(c.code,'-',dimp.ifu,'-',exo.annee) as r_avis,
exo.annee as exercice,
c.code as r_commune,
st.code as r_centre_impot,
dimp.personne_id as id_contribuable_foncier,
dimp.ifu as ifu,
dimp.npi as npi,
dimp.ifu as nc,
dimp.raison_sociale as raison_sociale,
dimp.nom_prop as nom ,
dimp.prenom_prop as prenom,
imp.date_generation as date_liquidation,
current_date as date_information,
cca.r_quartier_contact,
cca.q_contact,
cca.i_contact,
cca.p_contact
FROM impositions_tfu imp
INNER JOIN donnees_imposition_tfu dimp
ON dimp.impositions_tfu_id = imp.id
LEFT JOIN exercice exo
ON exo.id = imp.exercice_id
LEFT JOIN commune c
ON c.id = imp.commune_id
LEFT JOIN cca_unique cca
ON cca.personne_id = dimp.personne_id
AND cca.commune_id = imp.commune_id
LEFT JOIN structure st
ON st.id = cca.structure_id
order by c.code,st.code,r_quartier_contact,i_contact,p_contact;
--left join structure st2 on st2.id=imp.structure_id; 8263
create or replace view e_avis_detail_view as
WITH cca_unique AS (
SELECT DISTINCT ON (personne_id, commune_id)
structure_id,
personne_id,
commune_id,
parcelle_id
FROM commune_centre_assignation
ORDER BY commune_id,personne_id,structure_id
)
SELECT distinct on (exo.annee,dimp.parcelle_id,dimp.nature_impot)
null as id_avis_detail,
null as id_avis,
dimp.id as id_externe_ligne_imposition,
concat(c.code,'-',dimp.ifu,'-',exo.annee) as r_avis,
dimp.nature_impot as id_impot_nature,
dimp.parcelle_id as id_unite_foncier,
dimp.nup as nup,
dimp.code_quartier_village as r_quartier,
dimp.q as qip_quartier,
dimp.ilot as qip_ilot,
dimp.parcelle as qip_parcelle,
dimp.num_batiment as batiment,
dimp.num_unite_logement as unite_logement,
case
when dimp.batie = false then dimp.valeur_admin_parcelle_nb
else dimp.valeur_locative_adm
end as montant_base_imposition,
dimp.valeur_locative_adm as montant_valeur_locative,
dimp.taux_tfu as taux,
dimp.montant_taxe as montant_du,
case
when cca.parcelle_id is not null then true
else false
end as booleen_parcelle_contact
FROM impositions_tfu imp
INNER JOIN donnees_imposition_tfu dimp
ON dimp.impositions_tfu_id = imp.id
LEFT JOIN exercice exo
ON exo.id = imp.exercice_id
LEFT JOIN commune c
ON c.id = imp.commune_id
LEFT JOIN cca_unique cca
ON cca.personne_id = dimp.personne_id
AND cca.commune_id = imp.commune_id
AND cca.parcelle_id = dimp.parcelle_id
LEFT JOIN structure st
ON st.id = cca.structure_id
where dimp.personne_id is not null ;
---------------------------------------------------
select * from e_avis_detail_view
where qip_quartier='6431' and qip_ilot='1656' and qip_parcelle='C' ;
'6431', '1656', 'C'

View File

@@ -0,0 +1,5 @@
-----------------
create or replace view parcelle_view as
select distinct q.code as r_quartier,q.nom,p.nup, p.q,p.i,p.p from parcelle p
inner join quartier q on q.id=p.quartier_id

View File

@@ -0,0 +1,629 @@
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS
$$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_valeur_locat_prof NUMERIC;
v_tfu_piscine_unitaire NUMERIC;
v_taux_irf NUMERIC;
BEGIN
-- récupération de l'année
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
join exercice ex on ex.id =it.exercice_id
WHERE it.id = p_impositions_tfu_id;
select value
into strict v_taux_defaut_sup_sol
from parameters
where name ='TAUX_DEFAUT_SUPERFICIE_AU_SOL';
select value
into STRICT v_taux_irf
from parameters
where name ='TAUX_IRF';
select value
into STRICT v_taux_valeur_locat_prof
from parameters
where name ='TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE';
select value
into STRICT v_tfu_piscine_unitaire
from parameters
where name ='TFU_PAR_PISCINE';
INSERT INTO donnees_imposition_tfu(
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at ,
created_by ,
"source",
updated_at ,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, ----tfu correspondant au 70%
valeur_locative_adm_sup_reel,
valeur_locative_adm, ----------valeur locative administrative
tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle
tfu_piscine,
montant_taxe, ----tfu finale
taux_tfu, ----taux tfu batie
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
TRUE,
(
CURRENT_DATE >= ep.date_debut_exemption
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
),
(
CURRENT_DATE >= eb.date_debut_excemption
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
),
cb.standing,
cb.nom,
eb.nombre_piscine,
eb.date_enquete,
st.id,
ep.zone_rfu_id,
'IRF',
p.superficie,
eb.superficie_au_sol,
case -------valeur_batiment
WHEN eb.valeur_batiment_reel IS NOT NULL AND eb.valeur_batiment_reel <> 0 THEN eb.valeur_batiment_reel
WHEN eb.valeur_batiment_calcule IS NOT NULL AND eb.valeur_batiment_calcule <> 0 THEN eb.valeur_batiment_calcule
WHEN eb.valeur_batiment_estime IS NOT NULL AND eb.valeur_batiment_estime <> 0 THEN eb.valeur_batiment_estime
ELSE 0
END,
brb.valeur_locative,
case ----- montant_loyer_annuel
WHEN eb.montant_locatif_annuel_declare IS NOT NULL AND eb.montant_locatif_annuel_declare <> 0 THEN eb.montant_locatif_annuel_declare
WHEN eb.montant_locatif_annuel_calcule IS NOT NULL AND eb.montant_locatif_annuel_calcule <> 0 THEN eb.montant_locatif_annuel_calcule
WHEN eb.montant_locatif_annuel_estime IS NOT NULL AND eb.montant_locatif_annuel_estime <> 0 THEN eb.montant_locatif_annuel_estime
ELSE 0
END,
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
false,
current_date ,
p_user_id ,
'FISCAD',
current_date ,
p_user_id,
eb.categorie_usage,
p.superficie*v_taux_defaut_sup_sol/100,---superficie_au_sol_70pour100
(p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative,
0,
eb.superficie_au_sol * brb.valeur_locative,
0, ------ valeur_locative_adm : en attente de update
0,
0,
0,
v_taux_irf,
p.id,
b.id,
null,
eb.superficie_louee
FROM parcelle p
LEFT JOIN (
SELECT DISTINCT ON (parcelle_id)
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
ORDER BY parcelle_id, date_enquete DESC, id DESC
) ep ON ep.parcelle_id = p.id
LEFT JOIN personne pers
ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
JOIN secteur_decoupage sd ON sd.quartier_id = q.id
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
JOIN (
SELECT DISTINCT ON (batiment_id)
batiment_id,
superficie_au_sol,
nombre_piscine,
categorie_batiment_id,
date_enquete,
montant_locatif_annuel_declare,
montant_locatif_annuel_calcule,
montant_locatif_annuel_estime,
date_debut_excemption,
date_fin_excemption,
valeur_batiment_reel,
valeur_batiment_calcule,
valeur_batiment_estime,
u.categorie_usage,
superficie_louee
FROM enquete_batiment eb
join usage u on u.id=eb.usage_id
where superficie_louee*montant_locatif_annuel_declare>0
ORDER BY batiment_id, date_enquete DESC, eb.id DESC
) eb ON eb.batiment_id = b.id
JOIN categorie_batiment cb
ON cb.id = eb.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND NOT EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = b.id
)
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
UPDATE donnees_imposition_tfu dtfu
SET
valeur_locative_adm=montant_loyer_annuel,
montant_taxe = montant_loyer_annuel * v_taux_irf/100
WHERE impositions_tfu_id = p_impositions_tfu_id
AND batie = TRUE
AND NOT EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = dtfu.batiment_id
);
RETURN v_rows_inserted;
END;
$$;*/
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_valeur_locat_prof NUMERIC;
v_tfu_piscine_unitaire NUMERIC;
v_taux_irf NUMERIC;
v_taux_irf_ratio NUMERIC; -- v_taux_irf / 100 (pré-calculé)
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- -------------------------------------------------------------------------
-- 2. Récupération des 4 paramètres en UNE seule requête
-- (évite 4 accès séquentiels à la table parameters)
-- -------------------------------------------------------------------------
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'),
MAX(value) FILTER (WHERE name = 'TFU_PAR_PISCINE'),
MAX(value) FILTER (WHERE name = 'TAUX_IRF')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_valeur_locat_prof,
v_tfu_piscine_unitaire,
v_taux_irf
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE',
'TFU_PAR_PISCINE',
'TAUX_IRF'
);
-- Ratio pré-calculé pour éviter la division répétée dans le SELECT
v_taux_irf_ratio := v_taux_irf / 100.0;
-- -------------------------------------------------------------------------
-- 3. INSERT avec calcul direct de valeur_locative_adm et montant_taxe
-- → supprime l'UPDATE post-INSERT (économie d'un second scan de table)
-- -------------------------------------------------------------------------
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- 0 pour IRF
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- = montant_loyer_annuel pour IRF
tfu_superficie_au_sol_reel, -- 0 pour IRF
tfu_piscine, -- 0 pour IRF
montant_taxe, -- IRF finale = loyer * taux_irf
taux_tfu, -- = taux_irf pour IRF
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue,
personne_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
TRUE,
-- exonere parcelle
(v_today BETWEEN ep.date_debut_exemption
AND COALESCE(ep.date_fin_exemption, v_today)),
-- exonere batiment
(v_today BETWEEN eb.date_debut_excemption
AND COALESCE(eb.date_fin_excemption, v_today)),
cb.standing,
cb.nom,
eb.nombre_piscine,
eb.date_enquete,
st.id,
ep.zone_rfu_id,
'IRF',
p.superficie,
eb.superficie_au_sol,
-- valeur_batiment : première valeur non nulle non zéro
COALESCE(
NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0),
0
),
brb.valeur_locative,
-- montant_loyer_annuel
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
),
-- 🔧 IRF : champs TFU mis à 0
0, -- tfu_metre_carre
0, -- tfu_minimum
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
eb.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
p.superficie * v_taux_defaut_sup_sol / 100.0,
-- valeur_locative_adm_taux_prop_parc
(p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative,
-- 🔧 IRF : tfu_calcule_taux_prop_parc → 0
0,
-- valeur_locative_adm_sup_reel
eb.superficie_au_sol * brb.valeur_locative,
-- ---------------------------------------------------------------
-- 🔧 IRF : valeur_locative_adm = montant_loyer_annuel (calculé directement)
-- ---------------------------------------------------------------
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
),
-- 🔧 IRF : tfu_superficie_au_sol_reel → 0
0,
-- 🔧 IRF : tfu_piscine → 0
0,
-- ---------------------------------------------------------------
-- 🔧 IRF : montant_taxe = montant_loyer_annuel * taux_irf (calculé directement)
-- ---------------------------------------------------------------
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
) * v_taux_irf_ratio,
-- 🔧 IRF : taux_tfu → taux_irf
v_taux_irf,
p.id,
b.id,
NULL,
eb.superficie_louee,
ep.personne_id
FROM parcelle p
-- Dernière enquête parcelle
LEFT JOIN LATERAL (
SELECT
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
WHERE parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- Rattachement structure via secteur (DISTINCT ON → LATERAL plus lisible)
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
ORDER BY quartier_id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
-- Bâtiments sans unités logement (anti-join via LEFT JOIN … IS NULL)
JOIN batiment b ON b.parcelle_id = p.id
LEFT JOIN unite_logement ul_filter ON ul_filter.batiment_id = b.id
-- 🔧 IRF : Dernière enquête bâtiment avec filtre spécifique IRF
JOIN LATERAL (
SELECT
eb2.batiment_id,
eb2.superficie_au_sol,
eb2.nombre_piscine,
eb2.categorie_batiment_id,
eb2.date_enquete,
eb2.montant_locatif_annuel_declare,
eb2.montant_locatif_annuel_calcule,
eb2.montant_locatif_annuel_estime,
eb2.date_debut_excemption,
eb2.date_fin_excemption,
eb2.valeur_batiment_reel,
eb2.valeur_batiment_calcule,
eb2.valeur_batiment_estime,
u.categorie_usage,
eb2.superficie_louee
FROM enquete_batiment eb2
JOIN usage u ON u.id = eb2.usage_id
WHERE eb2.batiment_id = b.id
-- 🔧 IRF : Filtre spécifique
AND eb2.superficie_louee * eb2.montant_locatif_annuel_declare > 0 ---s'assurer que la superficie au sol loue est renseignée
ORDER BY eb2.date_enquete DESC, eb2.id DESC
LIMIT 1
) eb ON TRUE
JOIN categorie_batiment cb ON cb.id = eb.categorie_batiment_id
-- Barème RFU bâti (inchangé)
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND ul_filter.batiment_id IS NULL -- anti-join : pas d'unité logement
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,350 @@
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie_une_parcelle(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT,
p_parcelle_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_valeur_locat_prof NUMERIC;
v_tfu_piscine_unitaire NUMERIC;
v_taux_irf NUMERIC;
v_taux_irf_ratio NUMERIC; -- v_taux_irf / 100 (pré-calculé)
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- -------------------------------------------------------------------------
-- 2. Récupération des 4 paramètres en UNE seule requête
-- (évite 4 accès séquentiels à la table parameters)
-- -------------------------------------------------------------------------
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'),
MAX(value) FILTER (WHERE name = 'TFU_PAR_PISCINE'),
MAX(value) FILTER (WHERE name = 'TAUX_IRF')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_valeur_locat_prof,
v_tfu_piscine_unitaire,
v_taux_irf
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE',
'TFU_PAR_PISCINE',
'TAUX_IRF'
);
-- Ratio pré-calculé pour éviter la division répétée dans le SELECT
v_taux_irf_ratio := v_taux_irf / 100.0;
-- -------------------------------------------------------------------------
-- 3. INSERT avec calcul direct de valeur_locative_adm et montant_taxe
-- → supprime l'UPDATE post-INSERT (économie d'un second scan de table)
-- -------------------------------------------------------------------------
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- 0 pour IRF
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- = montant_loyer_annuel pour IRF
tfu_superficie_au_sol_reel, -- 0 pour IRF
tfu_piscine, -- 0 pour IRF
montant_taxe, -- IRF finale = loyer * taux_irf
taux_tfu, -- = taux_irf pour IRF
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue,
personne_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
TRUE,
-- exonere parcelle
(v_today BETWEEN ep.date_debut_exemption
AND COALESCE(ep.date_fin_exemption, v_today)),
-- exonere batiment
(v_today BETWEEN eb.date_debut_excemption
AND COALESCE(eb.date_fin_excemption, v_today)),
cb.standing,
cb.nom,
eb.nombre_piscine,
eb.date_enquete,
st.id,
ep.zone_rfu_id,
'IRF',
p.superficie,
eb.superficie_au_sol,
-- valeur_batiment : première valeur non nulle non zéro
COALESCE(
NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0),
0
),
brb.valeur_locative,
-- montant_loyer_annuel
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
),
-- 🔧 IRF : champs TFU mis à 0
0, -- tfu_metre_carre
0, -- tfu_minimum
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
eb.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
p.superficie * v_taux_defaut_sup_sol / 100.0,
-- valeur_locative_adm_taux_prop_parc
(p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative,
-- 🔧 IRF : tfu_calcule_taux_prop_parc → 0
0,
-- valeur_locative_adm_sup_reel
eb.superficie_au_sol * brb.valeur_locative,
-- ---------------------------------------------------------------
-- 🔧 IRF : valeur_locative_adm = montant_loyer_annuel (calculé directement)
-- ---------------------------------------------------------------
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
),
-- 🔧 IRF : tfu_superficie_au_sol_reel → 0
0,
-- 🔧 IRF : tfu_piscine → 0
0,
-- ---------------------------------------------------------------
-- 🔧 IRF : montant_taxe = montant_loyer_annuel * taux_irf (calculé directement)
-- ---------------------------------------------------------------
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
) * v_taux_irf_ratio,
-- 🔧 IRF : taux_tfu → taux_irf
v_taux_irf,
p.id,
b.id,
NULL,
eb.superficie_louee,
ep.personne_id
FROM parcelle p
-- Dernière enquête parcelle
LEFT JOIN LATERAL (
SELECT
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
WHERE parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- Rattachement structure via secteur (DISTINCT ON → LATERAL plus lisible)
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
ORDER BY quartier_id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
-- Bâtiments sans unités logement (anti-join via LEFT JOIN … IS NULL)
JOIN batiment b ON b.parcelle_id = p.id
LEFT JOIN unite_logement ul_filter ON ul_filter.batiment_id = b.id
-- 🔧 IRF : Dernière enquête bâtiment avec filtre spécifique IRF
JOIN LATERAL (
SELECT
eb2.batiment_id,
eb2.superficie_au_sol,
eb2.nombre_piscine,
eb2.categorie_batiment_id,
eb2.date_enquete,
eb2.montant_locatif_annuel_declare,
eb2.montant_locatif_annuel_calcule,
eb2.montant_locatif_annuel_estime,
eb2.date_debut_excemption,
eb2.date_fin_excemption,
eb2.valeur_batiment_reel,
eb2.valeur_batiment_calcule,
eb2.valeur_batiment_estime,
u.categorie_usage,
eb2.superficie_louee
FROM enquete_batiment eb2
JOIN usage u ON u.id = eb2.usage_id
WHERE eb2.batiment_id = b.id
-- 🔧 IRF : Filtre spécifique
AND eb2.superficie_louee * eb2.montant_locatif_annuel_declare > 0 ---s'assurer que la superficie au sol loue est renseignée
ORDER BY eb2.date_enquete DESC, eb2.id DESC
LIMIT 1
) eb ON TRUE
JOIN categorie_batiment cb ON cb.id = eb.categorie_batiment_id
-- Barème RFU bâti (inchangé)
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND ul_filter.batiment_id IS NULL -- anti-join : pas d'unité logement
AND st.id = v_structure_id
AND p.id=p_parcelle_id
AND NOT EXISTS(select 1 from donnees_imposition_tfu dimptfu
where dimptfu.parcelle_id=p_parcelle_id
AND dimptfu.annee=v_annee
AND dimptfu.nature_impot='IRF'
AND dimptfu.batiment_id=b.id)
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,641 @@
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie_unite_logement(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS
$$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_irf NUMERIC;
v_taux_valeur_locat_prof NUMERIC;
v_tfu_piscine_unitaire NUMERIC;
BEGIN
-- récupération de l'année
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
join exercice ex on ex.id =it.exercice_id
WHERE it.id = p_impositions_tfu_id;
select value
into strict v_taux_defaut_sup_sol
from parameters
where name ='TAUX_DEFAUT_SUPERFICIE_AU_SOL';
select value
into STRICT v_taux_irf
from parameters
where name ='TAUX_IRF';
select value
into STRICT v_taux_valeur_locat_prof
from parameters
where name ='TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE';
select value
into STRICT v_tfu_piscine_unitaire
from parameters
where name ='TFU_PAR_PISCINE';
INSERT INTO donnees_imposition_tfu(
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
num_unite_logement,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
unite_logement_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
superficie_au_sol_ulog,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at ,
created_by ,
"source",
updated_at ,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, ----tfu correspondant au 70%
valeur_locative_adm_sup_reel,
valeur_locative_adm, ----------valeur locative administrative
tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle
tfu_piscine,
montant_taxe, ----tfu finale
taux_tfu, ----taux tfu batie
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
ul.nul,
eul.ifu,
eul.npi,
eul.tel1,
eul.email,
eul.nom,
eul.prenom,
eul.raison_sociale,
eul.adresse,
eul.representant_tel,
eul.representant_nom,
eul.representant_prenom,
p.longitude,
p.latitude,
TRUE,
(
CURRENT_DATE >= ep.date_debut_exemption
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
),
(
CURRENT_DATE >= eb.date_debut_excemption
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
),
(
CURRENT_DATE >= eul.date_debut_exemption
AND CURRENT_DATE <= COALESCE(eul.date_fin_exemption, CURRENT_DATE)
),
cb.standing,
cb.nom,
CASE
WHEN eul.nombre_piscine is null then 0
else eul.nombre_piscine
END,
eul.date_enquete,
st.id,
ep.zone_rfu_id,
'IRF',
p.superficie,
eb.superficie_au_sol,
eul.superficie_au_sol,
CASE -------valeur_batiment
WHEN eul.valeur_unite_logement_reel IS NOT NULL AND eul.valeur_unite_logement_reel <> 0 THEN eul.valeur_unite_logement_reel
WHEN eul.valeur_unite_logement_calcule IS NOT NULL AND eul.valeur_unite_logement_calcule <> 0 THEN eul.valeur_unite_logement_calcule
WHEN eul.valeur_unite_logement_estime IS NOT NULL AND eul.valeur_unite_logement_estime <> 0 THEN eul.valeur_unite_logement_estime
ELSE 0
END,
brb.valeur_locative,
CASE ----- montant_loyer_annuel
WHEN eul.montant_locatif_annuel_declare IS NOT NULL AND eul.montant_locatif_annuel_declare <> 0 THEN eul.montant_locatif_annuel_declare
WHEN eul.montant_locatif_annuel_calcule IS NOT NULL AND eul.montant_locatif_annuel_calcule <> 0 THEN eul.montant_locatif_annuel_calcule
WHEN eul.montant_locatif_annuel_estime IS NOT NULL AND eul.montant_locatif_annuel_estime <> 0 THEN eul.montant_locatif_annuel_estime
ELSE 0
END,
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
false,
current_date,
p_user_id,
'FISCAD',
current_date,
p_user_id,
eul.categorie_usage,
p.superficie * v_taux_defaut_sup_sol/100,---superficie_au_sol_70pour100
case ----valeur_locative_adm70pour100
when eul.categorie_usage = 'HABITATION' then (p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative
else 0
end,
0,
eul.superficie_au_sol * brb.valeur_locative,
0, ------ valeur_locative_adm : en attente de update
0,
0,
0,
v_taux_irf,
p.id,
b.id,
ul.id,
eul.superficie_louee
FROM parcelle p
LEFT JOIN (
SELECT DISTINCT ON (parcelle_id)
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
ORDER BY parcelle_id, date_enquete DESC, id DESC
) ep ON ep.parcelle_id = p.id
LEFT JOIN personne pers
ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
--JOIN secteur_decoupage sd ON sd.quartier_id = q.id
JOIN (
SELECT DISTINCT ON (quartier_id)
quartier_id,
secteur_id
FROM secteur_decoupage
ORDER BY quartier_id
) sd ON sd.quartier_id = q.id
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
JOIN (
SELECT DISTINCT ON (batiment_id)
batiment_id,
superficie_au_sol,
nombre_piscine,
categorie_batiment_id,
date_enquete,
montant_locatif_annuel_declare,
montant_locatif_annuel_calcule,
montant_locatif_annuel_estime,
date_debut_excemption,
date_fin_excemption,
valeur_batiment_reel,
valeur_batiment_calcule,
valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb
join usage u on u.id=eb.usage_id
ORDER BY batiment_id, date_enquete DESC, eb.id DESC
) eb ON eb.batiment_id = b.id
JOIN unite_logement ul on ul.batiment_id = b.id
JOIN (
SELECT DISTINCT ON (eult.unite_logement_id)
eult.unite_logement_id,
pers1.id,
pers1.ifu,
pers1.npi,
pers1.tel1,
pers1.email,
pers1.nom,
pers1.prenom,
pers1.raison_sociale,
pers1.adresse,
eult.nombre_piscine,
eult.categorie_batiment_id,
eult.superficie_au_sol,
eult.superficie_louee,
eult.nbre_piece,
eult.date_enquete,
eult.montant_locatif_annuel_calcule,
eult.montant_locatif_annuel_declare,
eult.montant_locatif_annuel_estime,
eult.date_debut_exemption,
eult.date_fin_exemption,
eult.representant_nom,
eult.representant_prenom,
eult.representant_tel,
eult.valeur_unite_logement_reel,
eult.valeur_unite_logement_calcule,
eult.valeur_unite_logement_estime,
u.categorie_usage
FROM enquete_unite_logement eult
join usage u on u.id=eult.usage_id
left join personne pers1 on pers1.id = eult.personne_id
where superficie_louee*montant_locatif_annuel_declare>0
ORDER BY unite_logement_id, date_enquete DESC, eult.id DESC
) eul ON eul.unite_logement_id = ul.id
JOIN categorie_batiment cb
ON cb.id = eul.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = b.id
)
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
UPDATE donnees_imposition_tfu dtfu
SET
valeur_locative_adm=montant_loyer_annuel,
montant_taxe = montant_loyer_annuel * v_taux_irf/100
WHERE impositions_tfu_id = p_impositions_tfu_id
AND batie = TRUE
AND EXISTS (
SELECT 1
FROM unite_logement ul
WHERE ul.batiment_id = dtfu.batiment_id
);
RETURN v_rows_inserted;
END;
$$;
*/
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie_unite_logement(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_irf NUMERIC;
v_taux_irf_ratio NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- 1. année + structure
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- 2. paramètres (UNE seule requête)
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_IRF')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_irf
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_IRF'
);
v_taux_irf_ratio := v_taux_irf / 100.0;
-- 3. INSERT optimisé
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
num_unite_logement,
ifu,
npi,
tel_prop,
email_prop,
nom_prop, prenom_prop, raison_sociale, adresse_prop,
tel_sc, nom_sc, prenom_sc,
longitude, latitude,
batie,
exonere, batiment_exonere, unite_logement_exonere,
standing_bat, categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
superficie_au_sol_ulog,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
source,
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc,
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc,
valeur_locative_adm_sup_reel,
valeur_locative_adm,
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe,
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue,
personne_id
)
SELECT
v_annee,
d.code, d.nom,
c.code, c.nom,
a.code, a.nom,
q.code, q.nom,
p.q, p.i, p.p, p.nup,
ep.numero_titre_foncier,
b.nub, ul.nul,
eul.ifu, eul.npi, eul.tel1, eul.email,
eul.nom, eul.prenom, eul.raison_sociale, eul.adresse,
eul.representant_tel, eul.representant_nom, eul.representant_prenom,
p.longitude, p.latitude,
TRUE,
(v_today BETWEEN ep.date_debut_exemption AND COALESCE(ep.date_fin_exemption, v_today)),
(v_today BETWEEN eb.date_debut_excemption AND COALESCE(eb.date_fin_excemption, v_today)),
(v_today BETWEEN eul.date_debut_exemption AND COALESCE(eul.date_fin_exemption, v_today)),
cb.standing,
cb.nom,
COALESCE(eul.nombre_piscine, 0),
eul.date_enquete,
st.id,
ep.zone_rfu_id,
'IRF',
p.superficie,
eb.superficie_au_sol,
eul.superficie_au_sol,
-- valeur logement
COALESCE(
NULLIF(eul.valeur_unite_logement_reel,0),
NULLIF(eul.valeur_unite_logement_calcule,0),
NULLIF(eul.valeur_unite_logement_estime,0),
0
),
brb.valeur_locative,
-- loyer
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare,0),
NULLIF(eul.montant_locatif_annuel_calcule,0),
NULLIF(eul.montant_locatif_annuel_estime,0),
0
),
0, 0,
p_impositions_tfu_id,
FALSE,
v_today, p_user_id, 'FISCAD',
v_today, p_user_id,
eul.categorie_usage,
p.superficie * v_taux_defaut_sup_sol / 100.0,
(p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative,
0,
eul.superficie_au_sol * brb.valeur_locative,
-- valeur locative = loyer
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare,0),
NULLIF(eul.montant_locatif_annuel_calcule,0),
NULLIF(eul.montant_locatif_annuel_estime,0),
0
),
0, 0,
-- montant taxe direct (PLUS D'UPDATE)
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare,0),
NULLIF(eul.montant_locatif_annuel_calcule,0),
NULLIF(eul.montant_locatif_annuel_estime,0),
0
) * v_taux_irf_ratio,
v_taux_irf,
p.id,
b.id,
ul.id,
eul.superficie_louee,
eul.personne_id
FROM parcelle p
LEFT JOIN LATERAL (
SELECT *
FROM enquete e
WHERE e.parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN structure st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
JOIN unite_logement ul ON ul.batiment_id = b.id
JOIN LATERAL (
SELECT eult.unite_logement_id,
pers1.id,
pers1.ifu,
pers1.npi,
pers1.tel1,
pers1.email,
pers1.nom,
pers1.prenom,
pers1.raison_sociale,
pers1.adresse,
eult.nombre_piscine,
eult.categorie_batiment_id,
eult.superficie_au_sol,
eult.superficie_louee,
eult.nbre_piece,
eult.date_enquete,
eult.montant_locatif_annuel_calcule,
eult.montant_locatif_annuel_declare,
eult.montant_locatif_annuel_estime,
eult.date_debut_exemption,
eult.date_fin_exemption,
eult.representant_nom,
eult.representant_prenom,
eult.representant_tel,
eult.valeur_unite_logement_reel,
eult.valeur_unite_logement_calcule,
eult.valeur_unite_logement_estime,
u.categorie_usage,
pers1.id as personne_id
FROM enquete_unite_logement eult
LEFT JOIN personne pers1 ON pers1.id = eult.personne_id
join usage u on u.id=eult.usage_id
WHERE eult.unite_logement_id = ul.id
AND eult.superficie_louee * eult.montant_locatif_annuel_declare > 0
ORDER BY date_enquete DESC, eult.id DESC
LIMIT 1
) eul ON TRUE
JOIN LATERAL (
SELECT *
FROM enquete_batiment eb2
WHERE eb2.batiment_id = b.id
ORDER BY date_enquete DESC
LIMIT 1
) eb ON TRUE
JOIN categorie_batiment cb ON cb.id = eul.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,305 @@
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie_ulo_une_parcelle(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT,
p_parcelle_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_irf NUMERIC;
v_taux_irf_ratio NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- 1. année + structure
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- 2. paramètres (UNE seule requête)
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_IRF')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_irf
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_IRF'
);
v_taux_irf_ratio := v_taux_irf / 100.0;
-- 3. INSERT optimisé
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
num_unite_logement,
ifu,
npi,
tel_prop,
email_prop,
nom_prop, prenom_prop, raison_sociale, adresse_prop,
tel_sc, nom_sc, prenom_sc,
longitude, latitude,
batie,
exonere, batiment_exonere, unite_logement_exonere,
standing_bat, categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
superficie_au_sol_ulog,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
source,
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc,
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc,
valeur_locative_adm_sup_reel,
valeur_locative_adm,
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe,
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue,
personne_id
)
SELECT
v_annee,
d.code, d.nom,
c.code, c.nom,
a.code, a.nom,
q.code, q.nom,
p.q, p.i, p.p, p.nup,
ep.numero_titre_foncier,
b.nub, ul.nul,
eul.ifu, eul.npi, eul.tel1, eul.email,
eul.nom, eul.prenom, eul.raison_sociale, eul.adresse,
eul.representant_tel, eul.representant_nom, eul.representant_prenom,
p.longitude, p.latitude,
TRUE,
(v_today BETWEEN ep.date_debut_exemption AND COALESCE(ep.date_fin_exemption, v_today)),
(v_today BETWEEN eb.date_debut_excemption AND COALESCE(eb.date_fin_excemption, v_today)),
(v_today BETWEEN eul.date_debut_exemption AND COALESCE(eul.date_fin_exemption, v_today)),
cb.standing,
cb.nom,
COALESCE(eul.nombre_piscine, 0),
eul.date_enquete,
st.id,
ep.zone_rfu_id,
'IRF',
p.superficie,
eb.superficie_au_sol,
eul.superficie_au_sol,
-- valeur logement
COALESCE(
NULLIF(eul.valeur_unite_logement_reel,0),
NULLIF(eul.valeur_unite_logement_calcule,0),
NULLIF(eul.valeur_unite_logement_estime,0),
0
),
brb.valeur_locative,
-- loyer
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare,0),
NULLIF(eul.montant_locatif_annuel_calcule,0),
NULLIF(eul.montant_locatif_annuel_estime,0),
0
),
0, 0,
p_impositions_tfu_id,
FALSE,
v_today, p_user_id, 'FISCAD',
v_today, p_user_id,
eul.categorie_usage,
p.superficie * v_taux_defaut_sup_sol / 100.0,
(p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative,
0,
eul.superficie_au_sol * brb.valeur_locative,
-- valeur locative = loyer
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare,0),
NULLIF(eul.montant_locatif_annuel_calcule,0),
NULLIF(eul.montant_locatif_annuel_estime,0),
0
),
0, 0,
-- montant taxe direct (PLUS D'UPDATE)
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare,0),
NULLIF(eul.montant_locatif_annuel_calcule,0),
NULLIF(eul.montant_locatif_annuel_estime,0),
0
) * v_taux_irf_ratio,
v_taux_irf,
p.id,
b.id,
ul.id,
eul.superficie_louee,
eul.personne_id
FROM parcelle p
LEFT JOIN LATERAL (
SELECT *
FROM enquete e
WHERE e.parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN structure st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
JOIN unite_logement ul ON ul.batiment_id = b.id
JOIN LATERAL (
SELECT eult.unite_logement_id,
pers1.id,
pers1.ifu,
pers1.npi,
pers1.tel1,
pers1.email,
pers1.nom,
pers1.prenom,
pers1.raison_sociale,
pers1.adresse,
eult.nombre_piscine,
eult.categorie_batiment_id,
eult.superficie_au_sol,
eult.superficie_louee,
eult.nbre_piece,
eult.date_enquete,
eult.montant_locatif_annuel_calcule,
eult.montant_locatif_annuel_declare,
eult.montant_locatif_annuel_estime,
eult.date_debut_exemption,
eult.date_fin_exemption,
eult.representant_nom,
eult.representant_prenom,
eult.representant_tel,
eult.valeur_unite_logement_reel,
eult.valeur_unite_logement_calcule,
eult.valeur_unite_logement_estime,
u.categorie_usage,
pers1.id as personne_id
FROM enquete_unite_logement eult
LEFT JOIN personne pers1 ON pers1.id = eult.personne_id
join usage u on u.id=eult.usage_id
WHERE eult.unite_logement_id = ul.id
AND eult.superficie_louee * eult.montant_locatif_annuel_declare > 0
ORDER BY date_enquete DESC, eult.id DESC
LIMIT 1
) eul ON TRUE
JOIN LATERAL (
SELECT *
FROM enquete_batiment eb2
WHERE eb2.batiment_id = b.id
ORDER BY date_enquete DESC
LIMIT 1
) eb ON TRUE
JOIN categorie_batiment cb ON cb.id = eul.categorie_batiment_id
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND st.id = v_structure_id
AND p.id=p_parcelle_id
AND NOT EXISTS(select 1 from donnees_imposition_tfu dimptfu
where dimptfu.parcelle_id=p_parcelle_id
AND dimptfu.annee=v_annee
AND dimptfu.nature_impot='IRF'
AND dimptfu.batiment_id=b.id
AND dimptfu.unite_logement_id=ul.id)
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,207 @@
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_montant_srtb NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
SELECT value
INTO STRICT v_montant_srtb
FROM parameters
WHERE name = 'TAXE_SRTB';
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- 0 pour IRF
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- = montant_loyer_annuel pour IRF
tfu_superficie_au_sol_reel, -- 0 pour IRF
tfu_piscine, -- 0 pour IRF
montant_taxe, -- IRF finale = loyer * taux_irf
taux_tfu, -- = taux_irf pour IRF
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue,
personne_id
)
SELECT
dimp.annee,
dimp.code_departement,
dimp.nom_departement,
dimp.code_commune,
dimp.nom_commune,
dimp.code_arrondissement,
dimp.nom_arrondissement,
dimp.code_quartier_village,
dimp.nom_quartier_village,
dimp.q,
dimp. ilot,
dimp.parcelle,
dimp.nup,
dimp.titre_foncier,
dimp. num_batiment,
dimp.ifu,
dimp. npi,
dimp.tel_prop,
dimp.email_prop,
dimp.nom_prop,
dimp.prenom_prop,
dimp.raison_sociale,
dimp.adresse_prop,
dimp.tel_sc,
dimp.nom_sc,
dimp.prenom_sc,
dimp.longitude,
dimp.latitude,
TRUE,
-- exonere parcelle
dimp.exonere,
-- exonere batiment
dimp.batiment_exonere,
dimp.standing_bat,
dimp.categorie_bat,
dimp.nombre_piscine,
dimp.date_enquete,
dimp.structure_id,
dimp.zone_rfu_id,
'SRTB',
dimp.superficie_parc,
dimp.superficie_au_sol_bat,
dimp.valeur_batiment,
dimp.tfu_metre_carre,
-- montant_loyer_annuel
dimp.montant_loyer_annuel,
-- 🔧 IRF : champs TFU mis à 0
0, -- tfu_metre_carre
0, -- tfu_minimum
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
dimp.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
dimp.superficie_au_sol_taux_prop_parc,
-- valeur_locative_adm_taux_prop_parc
dimp.valeur_locative_adm_taux_prop_parc,
-- 🔧 IRF : tfu_calcule_taux_prop_parc → 0
0,
-- valeur_locative_adm_sup_reel
dimp.valeur_locative_adm_sup_reel,
-- ---------------------------------------------------------------
-- 🔧 IRF : valeur_locative_adm = montant_loyer_annuel (calculé directement)
-- ---------------------------------------------------------------
dimp.valeur_locative_adm
,
-- 🔧 IRF : tfu_superficie_au_sol_reel → 0
0,
-- 🔧 IRF : tfu_piscine → 0
0,
-- ---------------------------------------------------------------
-- 🔧 IRF : montant_taxe = montant_loyer_annuel * taux_irf (calculé directement)
-- ---------------------------------------------------------------
v_montant_srtb,
-- 🔧 IRF : taux_tfu → taux_irf
0,
dimp.parcelle_id,
dimp.batiment_id,
dimp.unite_logement_id,
dimp.superficie_au_sol_loue,
dimp.personne_id
FROM donnees_imposition_tfu dimp
WHERE dimp.nature_impot= 'IRF'
AND dimp.impositions_tfu_id=p_impositions_tfu_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,213 @@
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie_une_parcelle(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT,
p_parcelle_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_montant_srtb NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
SELECT value
INTO STRICT v_montant_srtb
FROM parameters
WHERE name = 'TAXE_SRTB';
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- 0 pour IRF
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- = montant_loyer_annuel pour IRF
tfu_superficie_au_sol_reel, -- 0 pour IRF
tfu_piscine, -- 0 pour IRF
montant_taxe, -- IRF finale = loyer * taux_irf
taux_tfu, -- = taux_irf pour IRF
parcelle_id,
batiment_id,
unite_logement_id,
superficie_au_sol_loue,
personne_id
)
SELECT
dimp.annee,
dimp.code_departement,
dimp.nom_departement,
dimp.code_commune,
dimp.nom_commune,
dimp.code_arrondissement,
dimp.nom_arrondissement,
dimp.code_quartier_village,
dimp.nom_quartier_village,
dimp.q,
dimp. ilot,
dimp.parcelle,
dimp.nup,
dimp.titre_foncier,
dimp. num_batiment,
dimp.ifu,
dimp. npi,
dimp.tel_prop,
dimp.email_prop,
dimp.nom_prop,
dimp.prenom_prop,
dimp.raison_sociale,
dimp.adresse_prop,
dimp.tel_sc,
dimp.nom_sc,
dimp.prenom_sc,
dimp.longitude,
dimp.latitude,
TRUE,
-- exonere parcelle
dimp.exonere,
-- exonere batiment
dimp.batiment_exonere,
dimp.standing_bat,
dimp.categorie_bat,
dimp.nombre_piscine,
dimp.date_enquete,
dimp.structure_id,
dimp.zone_rfu_id,
'SRTB',
dimp.superficie_parc,
dimp.superficie_au_sol_bat,
dimp.valeur_batiment,
dimp.tfu_metre_carre,
-- montant_loyer_annuel
dimp.montant_loyer_annuel,
-- 🔧 IRF : champs TFU mis à 0
0, -- tfu_metre_carre
0, -- tfu_minimum
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
dimp.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
dimp.superficie_au_sol_taux_prop_parc,
-- valeur_locative_adm_taux_prop_parc
dimp.valeur_locative_adm_taux_prop_parc,
-- 🔧 IRF : tfu_calcule_taux_prop_parc → 0
0,
-- valeur_locative_adm_sup_reel
dimp.valeur_locative_adm_sup_reel,
-- ---------------------------------------------------------------
-- 🔧 IRF : valeur_locative_adm = montant_loyer_annuel (calculé directement)
-- ---------------------------------------------------------------
dimp.valeur_locative_adm
,
-- 🔧 IRF : tfu_superficie_au_sol_reel → 0
0,
-- 🔧 IRF : tfu_piscine → 0
0,
-- ---------------------------------------------------------------
-- 🔧 IRF : montant_taxe = montant_loyer_annuel * taux_irf (calculé directement)
-- ---------------------------------------------------------------
v_montant_srtb,
-- 🔧 IRF : taux_tfu → taux_irf
0,
dimp.parcelle_id,
dimp.batiment_id,
dimp.unite_logement_id,
dimp.superficie_au_sol_loue,
dimp.personne_id
FROM donnees_imposition_tfu dimp
WHERE dimp.nature_impot= 'IRF'
AND dimp.impositions_tfu_id=p_impositions_tfu_id
AND dimp.parcelle_id=p_parcelle_id
AND NOT EXISTS(select 1 from donnees_imposition_tfu dimptfu
where dimptfu.parcelle_id=p_parcelle_id
AND dimptfu.nature_impot='SRTB'
AND dimptfu.batiment_id=dimp.batiment_id)
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,458 @@
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_tfu NUMERIC;
v_taux_tfu_ratio NUMERIC; -- v_taux_tfu / 100 (pré-calculé)
v_taux_valeur_locat_prof NUMERIC;
v_taux_vlp_ratio NUMERIC; -- v_taux_valeur_locat_prof / 100 (pré-calculé)
v_tfu_piscine_unitaire NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- -------------------------------------------------------------------------
-- 2. Récupération des 4 paramètres en UNE seule requête
-- (évite 4 accès séquentiels à la table parameters)
-- -------------------------------------------------------------------------
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_TFU'),
MAX(value) FILTER (WHERE name = 'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'),
MAX(value) FILTER (WHERE name = 'TFU_PAR_PISCINE')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_tfu,
v_taux_valeur_locat_prof,
v_tfu_piscine_unitaire
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_TFU',
'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE',
'TFU_PAR_PISCINE'
);
-- Ratios pré-calculés pour éviter la division répétée dans le SELECT
v_taux_tfu_ratio := v_taux_tfu / 100.0;
v_taux_vlp_ratio := v_taux_valeur_locat_prof / 100.0;
-- -------------------------------------------------------------------------
-- 3. INSERT avec calcul complet de valeur_locative_adm et montant_taxe
-- → supprime l'UPDATE post-INSERT (économie d'un second scan de table)
-- -------------------------------------------------------------------------
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- TFU à 70 %
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- valeur locative administrative finale
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe_brut,
montant_taxe, -- TFU finale
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id,
personne_id,
nombre_ulog,
nombre_bat
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
TRUE,
-- exonere parcelle
(v_today BETWEEN ep.date_debut_exemption
AND COALESCE(ep.date_fin_exemption, v_today)),
-- exonere batiment
(v_today BETWEEN eb.date_debut_excemption
AND COALESCE(eb.date_fin_excemption, v_today)),
cb.standing,
cb.nom,
eb.nombre_piscine,
eb.date_enquete,
st.id,
ep.zone_rfu_id,
'FB',
p.superficie,
eb.superficie_au_sol,
-- valeur_batiment : première valeur non nulle non zéro
COALESCE(
NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0),
0
),
brb.valeur_locative,
-- montant_loyer_annuel
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
),
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
eb.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
p.superficie * v_taux_defaut_sup_sol / 100.0,
-- valeur_locative_adm_taux_prop_parc
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
ELSE 0
END,
-- tfu_calcule_taux_prop_parc
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative * v_taux_tfu_ratio
ELSE 0
END,
-- valeur_locative_adm_sup_reel
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN eb.superficie_au_sol * brb.valeur_locative
ELSE 0
END,
-- ---------------------------------------------------------------
-- 🔧 CORRECTION : valeur_locative_adm avec tests explicites
-- ---------------------------------------------------------------
CASE
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol <> 0
THEN eb.superficie_au_sol * brb.valeur_locative
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol = 0
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
-- ✅ Test explicite : valeur_batiment <> 0
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) <> 0
THEN COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0)
* v_taux_vlp_ratio
-- ✅ Test explicite : valeur_batiment = 0
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) = 0
THEN COALESCE(NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0), 0)
ELSE 0
END,
-- tfu_superficie_au_sol_reel
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN eb.superficie_au_sol * brb.valeur_locative * v_taux_tfu_ratio * eb.nombre_piscine * v_tfu_piscine_unitaire
ELSE 0
END,
-- tfu_piscine
eb.nombre_piscine * v_tfu_piscine_unitaire,
-- ---------------------------------------------------------------
-- montant_taxe_brut ← sans prise en compte du minimum
-- ---------------------------------------------------------------
(
-- On matérialise valeur_batiment et valeur_locative une seule fois
WITH calc AS (
SELECT
COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) AS vb,
COALESCE(NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0), 0) AS loyer,
eb.superficie_au_sol * brb.valeur_locative AS vla_reel,
(p.superficie * v_taux_defaut_sup_sol / 100.0)
* brb.valeur_locative AS vla_70
)
SELECT
CASE
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol <> 0
THEN calc.vla_reel * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol = 0
THEN calc.vla_70 * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb <> 0
THEN calc.vb * v_taux_vlp_ratio * v_taux_tfu_ratio
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb = 0
THEN calc.loyer * v_taux_tfu_ratio
ELSE brb.tfu_minimum
END
FROM calc
),
-- ---------------------------------------------------------------
-- montant_taxe ← calculé directement (plus d'UPDATE)
-- Utilise des CTE inline via expression pour éviter la redondance
-- ---------------------------------------------------------------
(
-- On matérialise valeur_batiment et valeur_locative une seule fois
WITH calc AS (
SELECT
COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) AS vb,
COALESCE(NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0), 0) AS loyer,
eb.superficie_au_sol * brb.valeur_locative AS vla_reel,
(p.superficie * v_taux_defaut_sup_sol / 100.0)
* brb.valeur_locative AS vla_70
)
SELECT
CASE
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol <> 0
THEN GREATEST(brb.tfu_minimum,
calc.vla_reel * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire)
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol = 0
THEN GREATEST(brb.tfu_minimum,
calc.vla_70 * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire)
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb <> 0
THEN GREATEST(brb.tfu_minimum,
calc.vb * v_taux_vlp_ratio * v_taux_tfu_ratio)
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb = 0
THEN GREATEST(brb.tfu_minimum,
calc.loyer * v_taux_tfu_ratio)
ELSE brb.tfu_minimum
END
FROM calc
),
v_taux_tfu,
p.id,
b.id,
NULL,
ep.personne_id,
(select count(*)
from unite_logement ulog
where ulog.batiment_id= b.id),
(select count(*)
from batiment bat
where bat.parcelle_id= p.id)
FROM parcelle p
-- Dernière enquête parcelle
LEFT JOIN LATERAL (
SELECT
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
WHERE parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- Rattachement structure via secteur (DISTINCT ON → LATERAL plus lisible)
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
ORDER BY quartier_id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
-- Bâtiments sans unités logement (anti-join via LEFT JOIN … IS NULL)
JOIN batiment b ON b.parcelle_id = p.id
LEFT JOIN unite_logement ul_filter ON ul_filter.batiment_id = b.id
-- Dernière enquête bâtiment
JOIN LATERAL (
SELECT
eb2.batiment_id,
eb2.superficie_au_sol,
eb2.nombre_piscine,
eb2.categorie_batiment_id,
eb2.date_enquete,
eb2.montant_locatif_annuel_declare,
eb2.montant_locatif_annuel_calcule,
eb2.montant_locatif_annuel_estime,
eb2.date_debut_excemption,
eb2.date_fin_excemption,
eb2.valeur_batiment_reel,
eb2.valeur_batiment_calcule,
eb2.valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb2
JOIN usage u ON u.id = eb2.usage_id
WHERE eb2.batiment_id = b.id
ORDER BY eb2.date_enquete DESC, eb2.id DESC
LIMIT 1
) eb ON TRUE
JOIN categorie_batiment cb ON cb.id = eb.categorie_batiment_id
-- Barème RFU bâti (inchangé)
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
--AND ul_filter.batiment_id IS NULL -- anti-join : pas d'unité logement
AND st.id = v_structure_id ;
-- ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,464 @@
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_batie_une_parcelle(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT,
p_parcelle_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_tfu NUMERIC;
v_taux_tfu_ratio NUMERIC; -- v_taux_tfu / 100 (pré-calculé)
v_taux_valeur_locat_prof NUMERIC;
v_taux_vlp_ratio NUMERIC; -- v_taux_valeur_locat_prof / 100 (pré-calculé)
v_tfu_piscine_unitaire NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- -------------------------------------------------------------------------
-- 2. Récupération des 4 paramètres en UNE seule requête
-- (évite 4 accès séquentiels à la table parameters)
-- -------------------------------------------------------------------------
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_TFU'),
MAX(value) FILTER (WHERE name = 'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'),
MAX(value) FILTER (WHERE name = 'TFU_PAR_PISCINE')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_tfu,
v_taux_valeur_locat_prof,
v_tfu_piscine_unitaire
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_TFU',
'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE',
'TFU_PAR_PISCINE'
);
-- Ratios pré-calculés pour éviter la division répétée dans le SELECT
v_taux_tfu_ratio := v_taux_tfu / 100.0;
v_taux_vlp_ratio := v_taux_valeur_locat_prof / 100.0;
-- -------------------------------------------------------------------------
-- 3. INSERT avec calcul complet de valeur_locative_adm et montant_taxe
-- → supprime l'UPDATE post-INSERT (économie d'un second scan de table)
-- -------------------------------------------------------------------------
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- TFU à 70 %
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- valeur locative administrative finale
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe_brut,
montant_taxe, -- TFU finale
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id,
personne_id,
nombre_ulog,
nombre_bat
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
TRUE,
-- exonere parcelle
(v_today BETWEEN ep.date_debut_exemption
AND COALESCE(ep.date_fin_exemption, v_today)),
-- exonere batiment
(v_today BETWEEN eb.date_debut_excemption
AND COALESCE(eb.date_fin_excemption, v_today)),
cb.standing,
cb.nom,
eb.nombre_piscine,
eb.date_enquete,
st.id,
ep.zone_rfu_id,
'FB',
p.superficie,
eb.superficie_au_sol,
-- valeur_batiment : première valeur non nulle non zéro
COALESCE(
NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0),
0
),
brb.valeur_locative,
-- montant_loyer_annuel
COALESCE(
NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0),
0
),
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
eb.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
p.superficie * v_taux_defaut_sup_sol / 100.0,
-- valeur_locative_adm_taux_prop_parc
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
ELSE 0
END,
-- tfu_calcule_taux_prop_parc
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative * v_taux_tfu_ratio
ELSE 0
END,
-- valeur_locative_adm_sup_reel
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN eb.superficie_au_sol * brb.valeur_locative
ELSE 0
END,
-- ---------------------------------------------------------------
-- 🔧 CORRECTION : valeur_locative_adm avec tests explicites
-- ---------------------------------------------------------------
CASE
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol <> 0
THEN eb.superficie_au_sol * brb.valeur_locative
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol = 0
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
-- ✅ Test explicite : valeur_batiment <> 0
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) <> 0
THEN COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0)
* v_taux_vlp_ratio
-- ✅ Test explicite : valeur_batiment = 0
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) = 0
THEN COALESCE(NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0), 0)
ELSE 0
END,
-- tfu_superficie_au_sol_reel
CASE WHEN eb.categorie_usage = 'HABITATION'
THEN eb.superficie_au_sol * brb.valeur_locative * v_taux_tfu_ratio * eb.nombre_piscine * v_tfu_piscine_unitaire
ELSE 0
END,
-- tfu_piscine
eb.nombre_piscine * v_tfu_piscine_unitaire,
-- ---------------------------------------------------------------
-- montant_taxe_brut ← sans prise en compte du minimum
-- ---------------------------------------------------------------
(
-- On matérialise valeur_batiment et valeur_locative une seule fois
WITH calc AS (
SELECT
COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) AS vb,
COALESCE(NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0), 0) AS loyer,
eb.superficie_au_sol * brb.valeur_locative AS vla_reel,
(p.superficie * v_taux_defaut_sup_sol / 100.0)
* brb.valeur_locative AS vla_70
)
SELECT
CASE
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol <> 0
THEN calc.vla_reel * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol = 0
THEN calc.vla_70 * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb <> 0
THEN calc.vb * v_taux_vlp_ratio * v_taux_tfu_ratio
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb = 0
THEN calc.loyer * v_taux_tfu_ratio
ELSE brb.tfu_minimum
END
FROM calc
),
-- ---------------------------------------------------------------
-- montant_taxe ← calculé directement (plus d'UPDATE)
-- Utilise des CTE inline via expression pour éviter la redondance
-- ---------------------------------------------------------------
(
-- On matérialise valeur_batiment et valeur_locative une seule fois
WITH calc AS (
SELECT
COALESCE(NULLIF(eb.valeur_batiment_reel, 0),
NULLIF(eb.valeur_batiment_calcule, 0),
NULLIF(eb.valeur_batiment_estime, 0), 0) AS vb,
COALESCE(NULLIF(eb.montant_locatif_annuel_declare, 0),
NULLIF(eb.montant_locatif_annuel_calcule, 0),
NULLIF(eb.montant_locatif_annuel_estime, 0), 0) AS loyer,
eb.superficie_au_sol * brb.valeur_locative AS vla_reel,
(p.superficie * v_taux_defaut_sup_sol / 100.0)
* brb.valeur_locative AS vla_70
)
SELECT
CASE
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol <> 0
THEN GREATEST(brb.tfu_minimum,
calc.vla_reel * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire)
WHEN eb.categorie_usage = 'HABITATION'
AND eb.superficie_au_sol = 0
THEN GREATEST(brb.tfu_minimum,
calc.vla_70 * v_taux_tfu_ratio
+ eb.nombre_piscine * v_tfu_piscine_unitaire)
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb <> 0
THEN GREATEST(brb.tfu_minimum,
calc.vb * v_taux_vlp_ratio * v_taux_tfu_ratio)
WHEN eb.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND calc.vb = 0
THEN GREATEST(brb.tfu_minimum,
calc.loyer * v_taux_tfu_ratio)
ELSE brb.tfu_minimum
END
FROM calc
),
v_taux_tfu,
p.id,
b.id,
NULL,
ep.personne_id,
(select count(*)
from unite_logement ulog
where ulog.batiment_id= b.id),
(select count(*)
from batiment bat
where bat.parcelle_id= p.id)
FROM parcelle p
-- Dernière enquête parcelle
LEFT JOIN LATERAL (
SELECT
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
WHERE parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- Rattachement structure via secteur (DISTINCT ON → LATERAL plus lisible)
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
ORDER BY quartier_id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
-- Bâtiments sans unités logement (anti-join via LEFT JOIN … IS NULL)
JOIN batiment b ON b.parcelle_id = p.id
LEFT JOIN unite_logement ul_filter ON ul_filter.batiment_id = b.id
-- Dernière enquête bâtiment
JOIN LATERAL (
SELECT
eb2.batiment_id,
eb2.superficie_au_sol,
eb2.nombre_piscine,
eb2.categorie_batiment_id,
eb2.date_enquete,
eb2.montant_locatif_annuel_declare,
eb2.montant_locatif_annuel_calcule,
eb2.montant_locatif_annuel_estime,
eb2.date_debut_excemption,
eb2.date_fin_excemption,
eb2.valeur_batiment_reel,
eb2.valeur_batiment_calcule,
eb2.valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb2
JOIN usage u ON u.id = eb2.usage_id
WHERE eb2.batiment_id = b.id
ORDER BY eb2.date_enquete DESC, eb2.id DESC
LIMIT 1
) eb ON TRUE
JOIN categorie_batiment cb ON cb.id = eb.categorie_batiment_id
-- Barème RFU bâti (inchangé)
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
--AND ul_filter.batiment_id IS NULL -- anti-join : pas d'unité logement
AND st.id = v_structure_id
AND p.id = p_parcelle_id
AND NOT EXISTS(select 1 from donnees_imposition_tfu dimptfu
where dimptfu.batiment_id=b.id
and dimptfu.annee=v_annee
and dimptfu.nature_impot='FB');
-- ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,442 @@
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_batie_unite_logement(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_tfu NUMERIC;
v_taux_tfu_ratio NUMERIC; -- v_taux_tfu / 100 (pré-calculé)
v_taux_valeur_locat_prof NUMERIC;
v_taux_vlp_ratio NUMERIC; -- v_taux_valeur_locat_prof / 100 (pré-calculé)
v_tfu_piscine_unitaire NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- -------------------------------------------------------------------------
-- 2. Récupération des 4 paramètres en UNE seule requête
-- (évite 4 accès séquentiels à la table parameters)
-- -------------------------------------------------------------------------
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_TFU'),
MAX(value) FILTER (WHERE name = 'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'),
MAX(value) FILTER (WHERE name = 'TFU_PAR_PISCINE')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_tfu,
v_taux_valeur_locat_prof,
v_tfu_piscine_unitaire
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_TFU',
'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE',
'TFU_PAR_PISCINE'
);
-- Ratios pré-calculés pour éviter la division répétée dans le SELECT
v_taux_tfu_ratio := v_taux_tfu / 100.0;
v_taux_vlp_ratio := v_taux_valeur_locat_prof / 100.0;
-- -------------------------------------------------------------------------
-- 3. INSERT avec calcul complet de valeur_locative_adm et montant_taxe
-- → supprime l'UPDATE post-INSERT (économie d'un second scan de table)
-- -------------------------------------------------------------------------
WITH uniteLogementSupTotal as (
WITH derniere_enquete_ulog AS (
SELECT
eul.*,
ROW_NUMBER() OVER (
PARTITION BY unite_logement_id
ORDER BY date_enquete DESC
) AS rn
FROM enquete_unite_logement eul
)
SELECT
ul.batiment_id,
dimp.montant_taxe,
SUM(ulog.superficie_au_sol) AS superficie_totale
FROM derniere_enquete_ulog ulog
inner join unite_logement ul on ul.id=ulog.unite_logement_id
inner join donnees_imposition_tfu dimp on dimp.batiment_id= ul.batiment_id
WHERE rn = 1
AND dimp.impositions_tfu_id = p_impositions_tfu_id
GROUP BY ul.batiment_id,dimp.montant_taxe
)
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
num_unite_logement,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
unite_logement_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
superficie_au_sol_ulog,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- TFU à 70 %
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- valeur locative administrative finale
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe, -- TFU finale
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
ul.nul,
eul.ifu,
eul.npi,
eul.tel1,
eul.email,
eul.nom,
eul.prenom,
eul.raison_sociale,
eul.adresse,
eul.representant_tel,
eul.representant_nom,
eul.representant_prenom,
p.longitude,
p.latitude,
TRUE,
-- exonere parcelle
(v_today BETWEEN ep.date_debut_exemption
AND COALESCE(ep.date_fin_exemption, v_today)),
-- exonere batiment
(v_today BETWEEN eb.date_debut_excemption
AND COALESCE(eb.date_fin_excemption, v_today)),
-- exonere unite logement
(v_today BETWEEN eul.date_debut_exemption
AND COALESCE(eul.date_fin_exemption, v_today)),
cb.standing,
cb.nom,
COALESCE(eul.nombre_piscine, 0),
eul.date_enquete,
st.id,
ep.zone_rfu_id,
'FB',
p.superficie,
eb.superficie_au_sol,
eul.superficie_au_sol,
-- valeur_batiment (unité logement) : première valeur non nulle non zéro
COALESCE(
NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0),
0
),
brb.valeur_locative,
-- montant_loyer_annuel
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare, 0),
NULLIF(eul.montant_locatif_annuel_calcule, 0),
NULLIF(eul.montant_locatif_annuel_estime, 0),
0
),
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
eul.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
p.superficie * v_taux_defaut_sup_sol / 100.0,
-- valeur_locative_adm_taux_prop_parc
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
ELSE 0
END,
-- tfu_calcule_taux_prop_parc
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative * v_taux_tfu_ratio
ELSE 0
END,
-- valeur_locative_adm_sup_reel
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN eul.superficie_au_sol * brb.valeur_locative
ELSE 0
END,
-- ---------------------------------------------------------------
-- valeur_locative_adm avec tests explicites (corrigée)
-- ---------------------------------------------------------------
CASE
WHEN eul.categorie_usage = 'HABITATION'
AND eul.superficie_au_sol <> 0
THEN eul.superficie_au_sol * brb.valeur_locative
WHEN eul.categorie_usage = 'HABITATION'
AND eul.superficie_au_sol = 0
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
-- ✅ Test explicite : valeur_unite_logement <> 0
WHEN eul.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0) <> 0
THEN COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0)
* v_taux_vlp_ratio
-- ✅ Test explicite : valeur_unite_logement = 0
WHEN eul.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0) = 0
THEN COALESCE(NULLIF(eul.montant_locatif_annuel_declare, 0),
NULLIF(eul.montant_locatif_annuel_calcule, 0),
NULLIF(eul.montant_locatif_annuel_estime, 0), 0)
ELSE 0
END,
-- 🔧 CORRECTION : tfu_superficie_au_sol_reel (était hardcodé à 6/100)
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN eul.superficie_au_sol * brb.valeur_locative * v_taux_tfu_ratio
ELSE 0
END,
-- tfu_piscine
COALESCE(eul.nombre_piscine, 0) * v_tfu_piscine_unitaire,
-- ---------------------------------------------------------------
-- montant_taxe ← calculé directement (plus d'UPDATE)
-- ---------------------------------------------------------------
case when ulost.superficie_totale > 0
then eul.superficie_au_sol * ulost.montant_taxe / ulost.superficie_totale
else 0
end,
v_taux_tfu,
p.id,
b.id,
ul.id
FROM parcelle p
-- Dernière enquête parcelle
LEFT JOIN LATERAL (
SELECT
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
WHERE parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- Rattachement structure via secteur
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
ORDER BY quartier_id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
-- Dernière enquête bâtiment
JOIN LATERAL (
SELECT
eb2.batiment_id,
eb2.superficie_au_sol,
eb2.nombre_piscine,
eb2.categorie_batiment_id,
eb2.date_enquete,
eb2.montant_locatif_annuel_declare,
eb2.montant_locatif_annuel_calcule,
eb2.montant_locatif_annuel_estime,
eb2.date_debut_excemption,
eb2.date_fin_excemption,
eb2.valeur_batiment_reel,
eb2.valeur_batiment_calcule,
eb2.valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb2
JOIN usage u ON u.id = eb2.usage_id
WHERE eb2.batiment_id = b.id
ORDER BY eb2.date_enquete DESC, eb2.id DESC
LIMIT 1
) eb ON TRUE
JOIN unite_logement ul ON ul.batiment_id = b.id
INNER JOIN uniteLogementSupTotal ulost on ulost.batiment_id=ul.batiment_id
-- Dernière enquête unité logement
JOIN LATERAL (
SELECT
eul2.unite_logement_id,
pers1.id,
pers1.ifu,
pers1.npi,
pers1.tel1,
pers1.email,
pers1.nom,
pers1.prenom,
pers1.raison_sociale,
pers1.adresse,
eul2.nombre_piscine,
eul2.categorie_batiment_id,
eul2.superficie_au_sol,
eul2.superficie_louee,
eul2.nbre_piece,
eul2.date_enquete,
eul2.montant_locatif_annuel_calcule,
eul2.montant_locatif_annuel_declare,
eul2.montant_locatif_annuel_estime,
eul2.date_debut_exemption,
eul2.date_fin_exemption,
eul2.representant_nom,
eul2.representant_prenom,
eul2.representant_tel,
eul2.valeur_unite_logement_reel,
eul2.valeur_unite_logement_calcule,
eul2.valeur_unite_logement_estime,
u.categorie_usage
FROM enquete_unite_logement eul2
JOIN usage u ON u.id = eul2.usage_id
LEFT JOIN personne pers1 ON pers1.id = eul2.personne_id
WHERE eul2.unite_logement_id = ul.id
ORDER BY eul2.date_enquete DESC, eul2.id DESC
LIMIT 1
) eul ON TRUE
JOIN categorie_batiment cb ON cb.id = eul.categorie_batiment_id
-- Barème RFU bâti (inchangé)
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND EXISTS (
SELECT 1
FROM unite_logement ul2
WHERE ul2.batiment_id = b.id
)
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,448 @@
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_batie_ulo_une_parcelle(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT,
p_parcelle_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS $$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
v_taux_defaut_sup_sol NUMERIC;
v_taux_tfu NUMERIC;
v_taux_tfu_ratio NUMERIC; -- v_taux_tfu / 100 (pré-calculé)
v_taux_valeur_locat_prof NUMERIC;
v_taux_vlp_ratio NUMERIC; -- v_taux_valeur_locat_prof / 100 (pré-calculé)
v_tfu_piscine_unitaire NUMERIC;
v_today DATE;
BEGIN
v_today := CURRENT_DATE;
-- -------------------------------------------------------------------------
-- 1. Récupération de l'année et de la structure (inchangée)
-- -------------------------------------------------------------------------
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
-- -------------------------------------------------------------------------
-- 2. Récupération des 4 paramètres en UNE seule requête
-- (évite 4 accès séquentiels à la table parameters)
-- -------------------------------------------------------------------------
SELECT
MAX(value) FILTER (WHERE name = 'TAUX_DEFAUT_SUPERFICIE_AU_SOL'),
MAX(value) FILTER (WHERE name = 'TAUX_TFU'),
MAX(value) FILTER (WHERE name = 'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE'),
MAX(value) FILTER (WHERE name = 'TFU_PAR_PISCINE')
INTO STRICT
v_taux_defaut_sup_sol,
v_taux_tfu,
v_taux_valeur_locat_prof,
v_tfu_piscine_unitaire
FROM parameters
WHERE name IN (
'TAUX_DEFAUT_SUPERFICIE_AU_SOL',
'TAUX_TFU',
'TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE',
'TFU_PAR_PISCINE'
);
-- Ratios pré-calculés pour éviter la division répétée dans le SELECT
v_taux_tfu_ratio := v_taux_tfu / 100.0;
v_taux_vlp_ratio := v_taux_valeur_locat_prof / 100.0;
-- -------------------------------------------------------------------------
-- 3. INSERT avec calcul complet de valeur_locative_adm et montant_taxe
-- → supprime l'UPDATE post-INSERT (économie d'un second scan de table)
-- -------------------------------------------------------------------------
WITH uniteLogementSupTotal as (
WITH derniere_enquete_ulog AS (
SELECT
eul.*,
ROW_NUMBER() OVER (
PARTITION BY unite_logement_id
ORDER BY date_enquete DESC
) AS rn
FROM enquete_unite_logement eul
)
SELECT
ul.batiment_id,
dimp.montant_taxe,
SUM(ulog.superficie_au_sol) AS superficie_totale
FROM derniere_enquete_ulog ulog
inner join unite_logement ul on ul.id=ulog.unite_logement_id
inner join donnees_imposition_tfu dimp on dimp.batiment_id= ul.batiment_id
WHERE rn = 1
AND dimp.impositions_tfu_id = p_impositions_tfu_id
GROUP BY ul.batiment_id,dimp.montant_taxe
)
INSERT INTO donnees_imposition_tfu (
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
num_batiment,
num_unite_logement,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
batiment_exonere,
unite_logement_exonere,
standing_bat,
categorie_bat,
nombre_piscine,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
superficie_au_sol_bat,
superficie_au_sol_ulog,
valeur_batiment,
valeur_locative_adm_metre_carre,
montant_loyer_annuel,
tfu_metre_carre,
tfu_minimum,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
categorie_usage,
superficie_au_sol_taux_prop_parc, -- 70 % superficie parcelle
valeur_locative_adm_taux_prop_parc,
tfu_calcule_taux_prop_parc, -- TFU à 70 %
valeur_locative_adm_sup_reel,
valeur_locative_adm, -- valeur locative administrative finale
tfu_superficie_au_sol_reel,
tfu_piscine,
montant_taxe, -- TFU finale
taux_tfu,
parcelle_id,
batiment_id,
unite_logement_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
b.nub,
ul.nul,
eul.ifu,
eul.npi,
eul.tel1,
eul.email,
eul.nom,
eul.prenom,
eul.raison_sociale,
eul.adresse,
eul.representant_tel,
eul.representant_nom,
eul.representant_prenom,
p.longitude,
p.latitude,
TRUE,
-- exonere parcelle
(v_today BETWEEN ep.date_debut_exemption
AND COALESCE(ep.date_fin_exemption, v_today)),
-- exonere batiment
(v_today BETWEEN eb.date_debut_excemption
AND COALESCE(eb.date_fin_excemption, v_today)),
-- exonere unite logement
(v_today BETWEEN eul.date_debut_exemption
AND COALESCE(eul.date_fin_exemption, v_today)),
cb.standing,
cb.nom,
COALESCE(eul.nombre_piscine, 0),
eul.date_enquete,
st.id,
ep.zone_rfu_id,
'FB',
p.superficie,
eb.superficie_au_sol,
eul.superficie_au_sol,
-- valeur_batiment (unité logement) : première valeur non nulle non zéro
COALESCE(
NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0),
0
),
brb.valeur_locative,
-- montant_loyer_annuel
COALESCE(
NULLIF(eul.montant_locatif_annuel_declare, 0),
NULLIF(eul.montant_locatif_annuel_calcule, 0),
NULLIF(eul.montant_locatif_annuel_estime, 0),
0
),
brb.tfu_metre_carre,
brb.tfu_minimum,
p_impositions_tfu_id,
FALSE,
v_today,
p_user_id,
'FISCAD',
v_today,
p_user_id,
eul.categorie_usage,
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
p.superficie * v_taux_defaut_sup_sol / 100.0,
-- valeur_locative_adm_taux_prop_parc
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
ELSE 0
END,
-- tfu_calcule_taux_prop_parc
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative * v_taux_tfu_ratio
ELSE 0
END,
-- valeur_locative_adm_sup_reel
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN eul.superficie_au_sol * brb.valeur_locative
ELSE 0
END,
-- ---------------------------------------------------------------
-- valeur_locative_adm avec tests explicites (corrigée)
-- ---------------------------------------------------------------
CASE
WHEN eul.categorie_usage = 'HABITATION'
AND eul.superficie_au_sol <> 0
THEN eul.superficie_au_sol * brb.valeur_locative
WHEN eul.categorie_usage = 'HABITATION'
AND eul.superficie_au_sol = 0
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
-- ✅ Test explicite : valeur_unite_logement <> 0
WHEN eul.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0) <> 0
THEN COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0)
* v_taux_vlp_ratio
-- ✅ Test explicite : valeur_unite_logement = 0
WHEN eul.categorie_usage IN ('PROFESSIONNELLE', 'MIXTE')
AND COALESCE(NULLIF(eul.valeur_unite_logement_reel, 0),
NULLIF(eul.valeur_unite_logement_calcule, 0),
NULLIF(eul.valeur_unite_logement_estime, 0), 0) = 0
THEN COALESCE(NULLIF(eul.montant_locatif_annuel_declare, 0),
NULLIF(eul.montant_locatif_annuel_calcule, 0),
NULLIF(eul.montant_locatif_annuel_estime, 0), 0)
ELSE 0
END,
-- 🔧 CORRECTION : tfu_superficie_au_sol_reel (était hardcodé à 6/100)
CASE WHEN eul.categorie_usage = 'HABITATION'
THEN eul.superficie_au_sol * brb.valeur_locative * v_taux_tfu_ratio
ELSE 0
END,
-- tfu_piscine
COALESCE(eul.nombre_piscine, 0) * v_tfu_piscine_unitaire,
-- ---------------------------------------------------------------
-- montant_taxe ← calculé directement (plus d'UPDATE)
-- ---------------------------------------------------------------
case when ulost.superficie_totale > 0
then eul.superficie_au_sol * ulost.montant_taxe / ulost.superficie_totale
else 0
end,
v_taux_tfu,
p.id,
b.id,
ul.id
FROM parcelle p
-- Dernière enquête parcelle
LEFT JOIN LATERAL (
SELECT
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
WHERE parcelle_id = p.id
ORDER BY date_enquete DESC, id DESC
LIMIT 1
) ep ON TRUE
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- Rattachement structure via secteur
JOIN LATERAL (
SELECT secteur_id
FROM secteur_decoupage
WHERE quartier_id = q.id
ORDER BY quartier_id
LIMIT 1
) sd ON TRUE
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
JOIN batiment b ON b.parcelle_id = p.id
-- Dernière enquête bâtiment
JOIN LATERAL (
SELECT
eb2.batiment_id,
eb2.superficie_au_sol,
eb2.nombre_piscine,
eb2.categorie_batiment_id,
eb2.date_enquete,
eb2.montant_locatif_annuel_declare,
eb2.montant_locatif_annuel_calcule,
eb2.montant_locatif_annuel_estime,
eb2.date_debut_excemption,
eb2.date_fin_excemption,
eb2.valeur_batiment_reel,
eb2.valeur_batiment_calcule,
eb2.valeur_batiment_estime,
u.categorie_usage
FROM enquete_batiment eb2
JOIN usage u ON u.id = eb2.usage_id
WHERE eb2.batiment_id = b.id
ORDER BY eb2.date_enquete DESC, eb2.id DESC
LIMIT 1
) eb ON TRUE
JOIN unite_logement ul ON ul.batiment_id = b.id
INNER JOIN uniteLogementSupTotal ulost on ulost.batiment_id=ul.batiment_id
-- Dernière enquête unité logement
JOIN LATERAL (
SELECT
eul2.unite_logement_id,
pers1.id,
pers1.ifu,
pers1.npi,
pers1.tel1,
pers1.email,
pers1.nom,
pers1.prenom,
pers1.raison_sociale,
pers1.adresse,
eul2.nombre_piscine,
eul2.categorie_batiment_id,
eul2.superficie_au_sol,
eul2.superficie_louee,
eul2.nbre_piece,
eul2.date_enquete,
eul2.montant_locatif_annuel_calcule,
eul2.montant_locatif_annuel_declare,
eul2.montant_locatif_annuel_estime,
eul2.date_debut_exemption,
eul2.date_fin_exemption,
eul2.representant_nom,
eul2.representant_prenom,
eul2.representant_tel,
eul2.valeur_unite_logement_reel,
eul2.valeur_unite_logement_calcule,
eul2.valeur_unite_logement_estime,
u.categorie_usage
FROM enquete_unite_logement eul2
JOIN usage u ON u.id = eul2.usage_id
LEFT JOIN personne pers1 ON pers1.id = eul2.personne_id
WHERE eul2.unite_logement_id = ul.id
ORDER BY eul2.date_enquete DESC, eul2.id DESC
LIMIT 1
) eul ON TRUE
JOIN categorie_batiment cb ON cb.id = eul.categorie_batiment_id
-- Barème RFU bâti (inchangé)
JOIN LATERAL (
SELECT *
FROM barem_rfu_bati br
WHERE br.categorie_batiment_id = cb.id
AND br.arrondissement_id = a.id
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
ORDER BY br.quartier_id DESC NULLS LAST
LIMIT 1
) brb ON TRUE
WHERE p.batie = TRUE
AND EXISTS (
SELECT 1
FROM unite_logement ul2
WHERE ul2.batiment_id = b.id
)
AND st.id = v_structure_id
AND p.id = p_parcelle_id
AND NOT exists(select 1 from donnees_imposition_tfu dimptfu
where dimptfu.annee=v_annee
and dimptfu.batiment_id=b.id
and dimptfu.unite_logement_id=ul.id
and dimptfu.nature_impot='FB')
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,347 @@
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_non_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS
$$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
BEGIN
-- récupération de l'année
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
join exercice ex on ex.id =it.exercice_id
WHERE it.id = p_impositions_tfu_id;
INSERT INTO donnees_imposition_tfu(
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
impositions_tfu_id,
deleted,
created_at ,
created_by ,
"source",
updated_at ,
updated_by,
taux_tfu,
valeur_admin_parcelle_nb,
valeur_admin_parcelle_nb_metre_carre,
montant_taxe
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
false batie,
(
CURRENT_DATE >= ep.date_debut_exemption
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
) exonere,
ep.date_enquete,
st.id,
ep.zone_rfu_id,
'TFU',
p.superficie,
p_impositions_tfu_id,
false,
current_date ,
p_user_id ,
'FISCAD',
current_date ,
p_user_id,
brnb.taux,
case brnb.au_metre_carre
when true then brnb.valeur_administrative_metre_carre * ep.superficie
else brnb.valeur_administrative
end as valeur_administrative,
brnb.valeur_administrative_metre_carre,
case brnb.au_metre_carre
when true then brnb.valeur_administrative_metre_carre * ep.superficie*brnb.taux/100
else brnb.valeur_administrative*brnb.taux/100
end as montant_taxe
FROM parcelle p
LEFT JOIN (
SELECT DISTINCT ON (parcelle_id)
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
ORDER BY parcelle_id, date_enquete DESC
) ep ON ep.parcelle_id = p.id
LEFT JOIN personne pers
ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
JOIN secteur_decoupage sd ON sd.quartier_id = q.id
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
left join barem_rfu_non_bati brnb on (brnb.commune_id =c.id and brnb.zone_rfu_id=ep.zone_rfu_id)
WHERE p.batie = false
AND st.id=v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;*/
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_non_batie(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS
$$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
BEGIN
-- récupération de l'année
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
INSERT INTO donnees_imposition_tfu(
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
taux_tfu,
valeur_admin_parcelle_nb,
valeur_admin_parcelle_nb_metre_carre,
montant_taxe,
parcelle_id,
personne_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
false,
(
CURRENT_DATE >= ep.date_debut_exemption
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
),
ep.date_enquete,
st.id,
ep.zone_rfu_id,
'FNB',
p.superficie,
p_impositions_tfu_id,
false,
current_date,
p_user_id,
'FISCAD',
current_date,
p_user_id,
brnb.taux,
CASE
WHEN brnb.au_metre_carre = true
THEN brnb.valeur_administrative_metre_carre * ep.superficie
ELSE brnb.valeur_administrative
END,
brnb.valeur_administrative_metre_carre,
CASE
WHEN brnb.au_metre_carre = true
THEN brnb.valeur_administrative_metre_carre * ep.superficie * brnb.taux / 100
ELSE brnb.valeur_administrative * brnb.taux / 100
END,
p.id,
ep.personne_id
FROM parcelle p
LEFT JOIN (
SELECT DISTINCT ON (parcelle_id)
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
ORDER BY parcelle_id, date_enquete DESC
) ep ON ep.parcelle_id = p.id
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- ✅ CORRECTION ICI
JOIN (
SELECT DISTINCT ON (quartier_id)
quartier_id,
secteur_id
FROM secteur_decoupage
ORDER BY quartier_id
) sd ON sd.quartier_id = q.id
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
LEFT JOIN barem_rfu_non_bati brnb
ON (brnb.commune_id = c.id AND brnb.zone_rfu_id = ep.zone_rfu_id)
WHERE p.batie = false
AND st.id = v_structure_id
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,190 @@
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_non_batie_une_parcelle(
p_impositions_tfu_id BIGINT,
p_user_id BIGINT,
p_parcelle_id BIGINT
)
RETURNS INTEGER
LANGUAGE plpgsql
AS
$$
DECLARE
v_rows_inserted INTEGER;
v_annee BIGINT;
v_structure_id BIGINT;
BEGIN
-- récupération de l'année
SELECT ex.annee, it.structure_id
INTO STRICT v_annee, v_structure_id
FROM impositions_tfu it
JOIN exercice ex ON ex.id = it.exercice_id
WHERE it.id = p_impositions_tfu_id;
INSERT INTO donnees_imposition_tfu(
annee,
code_departement,
nom_departement,
code_commune,
nom_commune,
code_arrondissement,
nom_arrondissement,
code_quartier_village,
nom_quartier_village,
q,
ilot,
parcelle,
nup,
titre_foncier,
ifu,
npi,
tel_prop,
email_prop,
nom_prop,
prenom_prop,
raison_sociale,
adresse_prop,
tel_sc,
nom_sc,
prenom_sc,
longitude,
latitude,
batie,
exonere,
date_enquete,
structure_id,
zone_rfu_id,
nature_impot,
superficie_parc,
impositions_tfu_id,
deleted,
created_at,
created_by,
"source",
updated_at,
updated_by,
taux_tfu,
valeur_admin_parcelle_nb,
valeur_admin_parcelle_nb_metre_carre,
montant_taxe,
parcelle_id,
personne_id
)
SELECT
v_annee,
d.code,
d.nom,
c.code,
c.nom,
a.code,
a.nom,
q.code,
q.nom,
p.q,
p.i,
p.p,
p.nup,
ep.numero_titre_foncier,
pers.ifu,
pers.npi,
pers.tel1,
pers.email,
pers.nom,
pers.prenom,
pers.raison_sociale,
pers.adresse,
ep.representant_tel,
ep.representant_nom,
ep.representant_prenom,
p.longitude,
p.latitude,
false,
(
CURRENT_DATE >= ep.date_debut_exemption
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
),
ep.date_enquete,
st.id,
ep.zone_rfu_id,
'FNB',
p.superficie,
p_impositions_tfu_id,
false,
current_date,
p_user_id,
'FISCAD',
current_date,
p_user_id,
brnb.taux,
CASE
WHEN brnb.au_metre_carre = true
THEN brnb.valeur_administrative_metre_carre * ep.superficie
ELSE brnb.valeur_administrative
END,
brnb.valeur_administrative_metre_carre,
CASE
WHEN brnb.au_metre_carre = true
THEN brnb.valeur_administrative_metre_carre * ep.superficie * brnb.taux / 100
ELSE brnb.valeur_administrative * brnb.taux / 100
END,
p.id,
ep.personne_id
FROM parcelle p
LEFT JOIN (
SELECT DISTINCT ON (parcelle_id)
parcelle_id,
superficie,
personne_id,
numero_titre_foncier,
date_enquete,
representant_tel,
representant_nom,
representant_prenom,
representant_npi,
date_debut_exemption,
date_fin_exemption,
zone_rfu_id
FROM enquete
ORDER BY parcelle_id, date_enquete DESC
) ep ON ep.parcelle_id = p.id
LEFT JOIN personne pers ON pers.id = ep.personne_id
JOIN quartier q ON q.id = p.quartier_id
JOIN arrondissement a ON a.id = q.arrondissement_id
JOIN commune c ON c.id = a.commune_id
JOIN departement d ON d.id = c.departement_id
-- ✅ CORRECTION ICI
JOIN (
SELECT DISTINCT ON (quartier_id)
quartier_id,
secteur_id
FROM secteur_decoupage
ORDER BY quartier_id
) sd ON sd.quartier_id = q.id
JOIN secteur sect ON sect.id = sd.secteur_id
JOIN section ses ON ses.id = sect.section_id
JOIN "structure" st ON st.id = ses.structure_id
LEFT JOIN barem_rfu_non_bati brnb
ON (brnb.commune_id = c.id AND brnb.zone_rfu_id = ep.zone_rfu_id)
WHERE p.batie = false
AND st.id = v_structure_id
AND p.id=p_parcelle_id
AND NOT EXISTS( select 1 from donnees_imposition_tfu dimptfu
where dimptfu.nature_impot='FNB'
and dimptfu.parcelle_id=p_parcelle_id
and dimptfu.annee=v_annee)
ON CONFLICT DO NOTHING;
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
RETURN v_rows_inserted;
END;
$$;

View File

@@ -0,0 +1,95 @@
SELECT dblink_connect(
'connexion_rfu',
'host=10.4.6.103 port=5432 dbname=rfu user=postgres password=Rfu@dm1N2@25TeMp0'
);
--SELECT dblink_disconnect('connexion_rfu');
--SELECT pg_size_pretty(pg_database_size('rfu'));
CREATE OR REPLACE PROCEDURE public.import_assignation_centre_personne_from_rfu_cotonou()
LANGUAGE plpgsql
AS $procedure$
BEGIN
INSERT INTO public.commune_centre_assignation (
nc,
ifu,
commune_id,
structure_id,
personne_id,
parcelle_id,
created_at,
created_by,
deleted,
updated_at,
updated_by,
source
)
SELECT
c.n0_contrib,
c.ifu,
70,
case rcdi
when 'A' then 61
when 'B' then 62
when 'C' then 63
when 'D' then 64
else null
end,
pers.id,
parc.id,
now(),
NULL::bigint,
false,
now(),
NULL::bigint,
'RFU'
FROM dblink(
'connexion_rfu',
$db$
SELECT distinct on (ifu,rcdi)
trim(ifu),
trim(n0_contrib),
trim(rcdi),
trim(quartier_c),
trim(ilot_c),
trim(parcel_c)
FROM stemichel.contrib
order by ifu,rcdi
$db$
) AS c (
ifu varchar,
n0_contrib varchar,
rcdi varchar,
quartier_c varchar,
ilot_c varchar,
parcel_c varchar
)
LEFT JOIN personne pers on trim(pers.ifu)=trim(c.ifu)
LEFT JOIN parcelle parc on (trim(parc.q) = trim(c.quartier_c)
and trim(parc.i) = trim(c.ilot_c)
and trim(parc.p) = trim(c.parcel_c))
WHERE NOT EXISTS (
SELECT 1
FROM public.commune_centre_assignation cca
WHERE cca.personne_id = pers.id
and cca.structure_id = case trim(c.rcdi)
when 'A' then 61
when 'B' then 62
when 'C' then 63
when 'D' then 64
else null
end
and cca.commune_id = 70
)
ON CONFLICT (structure_id, commune_id, personne_id) DO NOTHING;
END;
$procedure$;
call import_assignation_centre_personne_from_rfu_cotonou();
--delete from commune_centre_assignation;
--select * from commune_centre_assignation;

View File

@@ -0,0 +1,287 @@
CREATE OR REPLACE PROCEDURE public.import_batiment_and_enquetebati_from_rfu(nombreLimit integer)
LANGUAGE plpgsql
AS $$
DECLARE
l_count numeric := 0;
batiment_rfu record;
l_batiment_id_parent bigint;
l_parcelle_id_parent bigint ;
BEGIN
FOR batiment_rfu IN (
SELECT
c.n0bat,
--dtconst,
CASE
WHEN c.dtconst IS NULL OR c.dtconst = '' THEN NULL
-- format incorrect (pas exactement 8 chiffres)
WHEN c.dtconst !~ '^[0-9]{8}$' THEN NULL
-- date invalide réelle
WHEN to_char(to_date(c.dtconst, 'YYYYMMDD'), 'YYYYMMDD') <> c.dtconst THEN NULL
ELSE to_date(c.dtconst, 'YYYYMMDD')
end as dtconst,
c.quartier,
c.n0_ilot,
c.n0_parcel,
--c.surfsol,
CASE
WHEN replace(trim(c.surfsol), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.surfsol, ',', '.')::numeric
end as surfsol,
--c.surfacelo,
CASE
WHEN replace(trim(c.surfacelo), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.surfacelo, ',', '.')::numeric
end as surfacelo,
--c.vllcalcule,
CASE
WHEN replace(trim(c.vllcalcule), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.vllcalcule, ',', '.')::numeric
end as vllcalcule,
--c.bail,
CASE
WHEN replace(trim(c.bail), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.bail, ',', '.')::numeric
end as bail,
--c.valloest,
CASE
WHEN replace(trim(c.valloest), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.valloest, ',', '.')::numeric
end as valloest,
--c.nbetage,
CASE
WHEN replace(trim(c.nbetage), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.nbetage, ',', '.')::numeric
end as nbetage,
--c.vlcalcule,
CASE
WHEN replace(trim(c.vlcalcule), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.vlcalcule, ',', '.')::numeric
end as vlcalcule,
--c.utilisat,
CASE
WHEN replace(trim(c.utilisat), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.utilisat, ',', '.')::numeric
end as utilisat,
--c.finexempt,
CASE
WHEN c.finexempt IS NULL OR c.finexempt = '' THEN NULL
-- format incorrect (pas exactement 8 chiffres)
WHEN c.finexempt !~ '^[0-9]{8}$' THEN NULL
-- date invalide réelle
WHEN to_char(to_date(c.finexempt, 'YYYYMMDD'), 'YYYYMMDD') <> c.finexempt THEN NULL
ELSE to_date(c.finexempt, 'YYYYMMDD')
end as finexempt,
--c.nbunitlo,
CASE
WHEN replace(trim(c.nbunitlo), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.nbunitlo, ',', '.')::numeric
end as nbunitlo,
--c.toit
CASE
WHEN replace(trim(c.toit), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.toit, ',', '.')::numeric
end as toit,
--nbhabit,
CASE
WHEN replace(trim(c.nbhabit), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.nbhabit, ',', '.')::numeric
end as nbhabit,
--nbmenage,
CASE
WHEN replace(trim(c.nbmenage), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.nbmenage, ',', '.')::numeric
end as nbmenage,
--nbmois,
CASE
WHEN replace(trim(c.nbmois), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.nbmois, ',', '.')::numeric
end as nbmois,
--electric,
CASE
WHEN trim(c.electric)='Non'
THEN false
else
true
end as electric,
--eau,
CASE
WHEN trim(c.eau)='Non'
THEN false
else
true
end as eau,
--nbpiece,
CASE
WHEN replace(trim(c.nbpiece), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.nbpiece, ',', '.')::numeric
end as nbpiece,
--nbunite
CASE
WHEN replace(trim(c.nbunite), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.nbunite, ',', '.')::numeric
end as nbunite,
CASE
WHEN c.mdate IS NULL OR c.mdate = '' THEN NULL
-- format incorrect (pas exactement 8 chiffres)
WHEN c.mdate !~ '^[0-9]{8}$' THEN NULL
-- date invalide réelle
WHEN to_char(to_date(c.mdate, 'YYYYMMDD'), 'YYYYMMDD') <> c.mdate THEN NULL
ELSE to_date(c.mdate, 'YYYYMMDD')
end as mdate,
--c.murs,
CASE
WHEN replace(trim(c.murs), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.murs, ',', '.')::numeric
end as murs,
--standing
CASE
WHEN replace(trim(c.standing), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
THEN replace(c.standing, ',', '.')::numeric
end as standing
FROM dblink(
'connexion_rfu',
$db$
SELECT
b.n0bat,
b.dtconst,
b.quartier,
b.n0_ilot,
b.n0_parcel,
b.surfsol,
b.surfacelo,
b.vllcalcule,
b.bail,
b.valloest,
b.nbetage,
b.vlcalcule,
b.utilisat,
b.finexempt,
b.nbunitlo,
b.toit,
b.nbhabit,
b.nbmenage,
b.nbmois,
b.electric,
b.eau,
b.nbpiece,
b.nbunite,
b.mdate,
b.murs,
b.standing
FROM stemichel.batiment b
$db$
) AS c (
n0bat varchar,
dtconst varchar,
quartier varchar,
n0_ilot varchar,
n0_parcel varchar,
surfsol varchar,
surfacelo varchar,
vllcalcule varchar,
bail varchar,
valloest varchar,
nbetage varchar,
vlcalcule varchar,
utilisat varchar,
finexempt varchar,
nbunitlo varchar,
toit varchar,
nbhabit varchar,
nbmenage varchar,
nbmois varchar,
electric varchar,
eau varchar,
nbpiece varchar,
nbunite varchar,
mdate varchar,
murs varchar,
standing varchar
)
WHERE NOT EXISTS (
SELECT 1
FROM public.batiment b
WHERE b.code =
trim(c.quartier)||'-'||trim(c.n0_ilot)||'-'||trim(c.n0_parcel)||'-'||trim(c.n0bat)
)
limit nombreLimit
)
LOOP
-- Récupération ID parcelle locale
SELECT p.id
INTO l_parcelle_id_parent
FROM public.parcelle p
WHERE p.numero_parcelle =
trim(batiment_rfu.quartier)||'-'||trim(batiment_rfu.n0_ilot)||'-'||trim(batiment_rfu.n0_parcel)
LIMIT 1;
-- Insertion bâtiment local
INSERT INTO public.batiment (
created_at,
created_by,
deleted,
updated_at,
updated_by,
code,
nub,
date_construction,
parcelle_id,
source,
superficie_au_sol,
superficie_louee,
categorie_batiment_id,
montant_locatif_annuel_calcule,
montant_locatif_annuel_declare,
montant_locatif_annuel_estime,
nombre_etage,
valeur_batiment_calcule,
usage_id,
date_fin_exemption,
nbre_unite_logement,
id_toit_rfu
)
VALUES (
now(),
35,
false,
now(),
35,
trim(batiment_rfu.quartier)||'-'||trim(batiment_rfu.n0_ilot)||'-'||trim(batiment_rfu.n0_parcel)||'-'||trim(batiment_rfu.n0bat),
batiment_rfu.n0bat,
batiment_rfu.dtconst,
l_parcelle_id_parent,
'RFU',
batiment_rfu.surfsol,
batiment_rfu.surfacelo,
ProcedureRecupCategorieRFU(batiment_rfu.nbetage::integer,batiment_rfu.toit::integer),
batiment_rfu.vllcalcule,
batiment_rfu.bail,
batiment_rfu.valloest,
batiment_rfu.nbetage,
batiment_rfu.vlcalcule,
--------- batiment_rfu.utilisat,
CASE batiment_rfu.utilisat
WHEN 1 THEN 8
WHEN 2 THEN 14
WHEN 3 THEN 9
END,
batiment_rfu.finexempt,
batiment_rfu.nbunitlo,
batiment_rfu.toit
)
RETURNING id INTO l_batiment_id_parent ;
call public.import_enquetebati_from_rfu_cipe(batiment_rfu,l_batiment_id_parent);
l_count := l_count + 1;
END LOOP;
RAISE NOTICE 'Nombre de bâtiments insérés : %', l_count;
END;
$$;

View File

@@ -0,0 +1,158 @@
CREATE OR REPLACE PROCEDURE public.import_enquetebati_from_rfu_cipe(
IN batiment_rfu record,
IN batiment_id_param numeric
)
LANGUAGE plpgsql
AS $procedure$
DECLARE
enquete_batiment_id_parent bigint;
BEGIN
INSERT INTO enquete_batiment (
created_at,
created_by,
deleted,
updated_at,
updated_by,
date_fin_excemption,
nbre_habitant,
nbre_menage,
nbre_mois_location,
nbre_unite_location,
sbee,
soneb,
batiment_id,
personne_id,
user_id,
montant_locatif_annuel_declare,
nbre_etage,
source,
date_enquete,
observation,
superficie_au_sol,
superficie_louee,
statut_enquete,
categorie_batiment_id,
montant_locatif_annuel_calcule,
usage_id,
montant_locatif_annuel_estime,
nbre_piece,
nbre_unite_logement,
valeur_batiment_calcule,
nbre_lot_unite
) select
now(),
35,
false,
now(),
35,
batiment_rfu.finexempt,
batiment_rfu.nbhabit,
batiment_rfu.nbmenage,
batiment_rfu.nbmois,
batiment_rfu.nbunitlo,
batiment_rfu.electric,
batiment_rfu.eau,
batiment_id_param,
e.personne_id,
35,
batiment_rfu.bail,
batiment_rfu.nbetage,
'RFU',
batiment_rfu.mdate,
'MIGRATION',
batiment_rfu.surfsol,
batiment_rfu.surfacelo,
'CLOTURE',
ProcedureRecupCategorieRFU(batiment_rfu.nbetage::integer,batiment_rfu.toit::integer),
batiment_rfu.vllcalcule,
--batiment_rfu.utilisat,
CASE batiment_rfu.utilisat
WHEN 1 THEN 8
WHEN 2 THEN 14
WHEN 3 THEN 9
end,
batiment_rfu.valloest,
batiment_rfu.nbpiece,
batiment_rfu.nbunite,
batiment_rfu.vlcalcule,
batiment_rfu.nbunitlo
from batiment b
left join parcelle p on p.id=b.parcelle_id
left join enquete e on e.parcelle_id=p.id
where b.id = batiment_id_param
and not exists (
select 1
from enquete_batiment eb
where eb.batiment_id = b.id
)
RETURNING id INTO enquete_batiment_id_parent ;
----------MAJ Caractéristique parcelle
INSERT INTO caracteristique_batiment (
created_by,
created_at,
updated_by,
updated_at,
deleted,
caracteristique_id,
enquete_batiment_id
)
SELECT 35, now(), 35, now(),false,
CASE batiment_rfu.toit
WHEN 1 THEN 55
WHEN 2 THEN 56
WHEN 3 THEN 57
WHEN 4 THEN 58
WHEN 5 THEN 59
WHEN 6 THEN 60
END,
enquete_batiment_id_parent
WHERE batiment_rfu.toit IS NOT NULL
UNION ALL
SELECT 35, now(), 35, now(),false,
CASE batiment_rfu.murs
WHEN 1 THEN 49
WHEN 2 THEN 50
WHEN 3 THEN 51
WHEN 4 THEN 52
WHEN 5 THEN 53
else
54
END,
enquete_batiment_id_parent
WHERE batiment_rfu.murs IS NOT null
UNION ALL
SELECT 35, now(), 35, now(),false,
CASE batiment_rfu.standing
WHEN 1 THEN 81
WHEN 2 THEN 82
WHEN 3 THEN 83
WHEN 4 THEN 84
END,
enquete_batiment_id_parent
WHERE batiment_rfu.standing IS NOT null
UNION ALL
SELECT 35, now(), 35, now(),false,
CASE batiment_rfu.utilisat
WHEN 1 THEN 35
WHEN 2 THEN 36
WHEN 3 THEN 37
END,
enquete_batiment_id_parent
WHERE batiment_rfu.utilisat IS NOT null;
------MAJ Exercice
UPDATE enquete_batiment eb
SET exercice_id = e.id
FROM exercice e
WHERE e.annee = 2025
AND eb.id = enquete_batiment_id_parent;
END;
$procedure$;

View File

@@ -0,0 +1,153 @@
CREATE OR REPLACE PROCEDURE public.import_enqueteparc_from_rfu_cipe(
IN parcelle_rfu record,
IN p_parcelle_id numeric
)
LANGUAGE plpgsql
AS $procedure$
DECLARE
enquete_id_parent bigint;
BEGIN
INSERT INTO enquete (
created_at,
created_by,
deleted,
updated_at,
updated_by,
date_enquete,
litige,
parcelle_id,
user_id,
date_finalisation,
date_synchronisation,
date_validation,
status_enquete,
synchronise,
code_parcelle,
nbre_batiment,
nbre_co_proprietaire,
nom_rue,
num_enter_parcelle,
num_rue,
superficie,
equipe_id,
zone_rfu_id,
campagne_id,
origine_enquete,
nc_proprietaire,
source
) select
now(),
35,
false,
now(),
35,
now(),
false,
p_parcelle_id,
35,
now(),
now(),
now(),
'CLOTURE',
true,
parcelle_rfu.numero_parcelle,
CASE
WHEN trim(parcelle_rfu.nb_bat) ~ '^[0-9]+$'
THEN parcelle_rfu.nb_bat::integer
ELSE NULL
END,
CASE
WHEN trim(parcelle_rfu.nb_prop) ~ '^[0-9]+$'
THEN parcelle_rfu.nb_prop::integer
ELSE NULL
END,
parcelle_rfu.numero_rue,
parcelle_rfu.num_entree_parcelle,
parcelle_rfu.numero_rue,
CASE
WHEN trim(parcelle_rfu.surface) ~ '^[0-9]+$'
THEN parcelle_rfu.surface::float
ELSE NULL
END,
1,
CASE parcelle_rfu.zones
WHEN '1' THEN 1
WHEN '2' THEN 2
WHEN '3' THEN 3
WHEN '4' THEN 4
ELSE NULL
END,
1,
'RFU',
parcelle_rfu.n0_contrib,
'RFU'
--from parcelle p
where not exists (
select 1
from enquete e
where e.parcelle_id= p_parcelle_id
)
RETURNING id INTO enquete_id_parent ;
----------MAJ Caractéristique parcelle
INSERT INTO caracteristique_parcelle (
created_by,
created_at,
updated_by,
updated_at,
deleted,
caracteristique_id,
enquete_id
)
SELECT 35, now(), 35, now(), false,
CASE parcelle_rfu.acces
WHEN '1' THEN 31
WHEN '2' THEN 32
WHEN '3' THEN 33
WHEN '4' THEN 34
END,
enquete_id_parent
WHERE parcelle_rfu.acces IS NOT NULL
UNION ALL
SELECT 35, now(), 35, now(),false,
CASE parcelle_rfu.cloture
WHEN '1' THEN 28
WHEN '2' THEN 29
WHEN '3' THEN 30
END,
enquete_id_parent
WHERE parcelle_rfu.cloture IS NOT NULL;
------MAJ Exercice
UPDATE enquete q
SET exercice_id = e.id
FROM exercice e
WHERE e.annee = 2025
AND q.id = enquete_id_parent;
------MAJ prietaire
UPDATE enquete q
SET personne_id = p.id,
proprietaire_id = p.id,
nom_proprietaire_parcelle = coalesce (trim(p.raison_sociale), trim(p.nom) || ' '|| trim(p.prenom) )
FROM personne p
WHERE p.nc = parcelle_rfu.n0_contrib
AND q.id = enquete_id_parent;
--quartier_id --commune_id --departement_id --arrondissement_id
UPDATE enquete e
SET quartier_id = q.id,
commune_id=c.id,
departement_id=c.departement_id,
arrondissement_id= a.id
FROM parcelle p
inner join quartier q on q.id = p.quartier_id
inner join arrondissement a on a.id = q.arrondissement_id
inner join commune c on c.id = a.commune_id
WHERE p.id = p_parcelle_id
AND e.id = enquete_id_parent;
END;
$procedure$;

View File

@@ -0,0 +1,156 @@
CREATE OR REPLACE PROCEDURE public.import_enqueteUnitLog_from_rfu_cipe(
IN uniteLogement_rfu record,
IN uniteLogement_id_param numeric,
IN l_personne_id_parent numeric
)
LANGUAGE plpgsql
AS $procedure$
DECLARE
enquete_uniteLogement_id_parent bigint;
BEGIN
INSERT INTO enquete_unite_logement (
created_at,
created_by,
deleted,
updated_at,
updated_by,
en_location,
montant_locatif_annuel_declare,
nbre_habitant,
nbre_menage,
nbre_piece,
sbee,
soneb,
personne_id,
unite_logement_id,
user_id,
nbre_mois_location,
valeur_unite_logement_estime,
source,
date_enquete,
observation,
date_fin_exemption,
superficie_au_sol,
superficie_louee,
statut_enquete,
categorie_batiment_id,
montant_locatif_annuel_calcule,
montant_mensuel_location,
usage_id,
valeur_unite_logement_calcule
)select
now(),
35,
false,
now(),
35,
case
when uniteLogement_rfu.nbmois=0 then false
else true
end,
uniteLogement_rfu.montmenl*12,
uniteLogement_rfu.nbhabit,
uniteLogement_rfu.nbmenage,
uniteLogement_rfu.nbpiece,
uniteLogement_rfu.electric,
uniteLogement_rfu.eau,
l_personne_id_parent,
uniteLogement_id_param,
35,
uniteLogement_rfu.nbmois,
uniteLogement_rfu.vlcalcule,
'RFU',
uniteLogement_rfu.mdate,
'MIGRATION',
uniteLogement_rfu.finexempt,
uniteLogement_rfu.surfsol,
uniteLogement_rfu.surfacelo,
'CLOTURE',
ProcedureRecupCategorieRFU(uniteLogement_rfu.n0etage::integer,uniteLogement_rfu.toit::integer),
uniteLogement_rfu.vllcalcule,
uniteLogement_rfu.montmenl,
CASE uniteLogement_rfu.utilisat
WHEN 1 THEN 8
WHEN 2 THEN 14
WHEN 3 THEN 9
END,
uniteLogement_rfu.vlcalcule
from unite_logement ul
where ul.id = uniteLogement_id_param
and not exists (
select 1
from enquete_unite_logement eul
where eul.unite_logement_id = ul.id
)
RETURNING id INTO enquete_uniteLogement_id_parent ;
----------MAJ Caractéristique Unite de logement
INSERT INTO caracteristique_unite_logement (
created_by,
created_at,
updated_by,
updated_at,
deleted,
caracteristique_id,
enquete_unite_logement_id
)
SELECT 35, now(), 35, now(),false,
CASE uniteLogement_rfu.toit
WHEN 1 THEN 55
WHEN 2 THEN 56
WHEN 3 THEN 57
WHEN 4 THEN 58
WHEN 5 THEN 59
WHEN 6 THEN 60
END,
enquete_uniteLogement_id_parent
WHERE uniteLogement_rfu.toit IS NOT NULL
UNION ALL
SELECT 35, now(), 35, now(),false,
CASE uniteLogement_rfu.murs
WHEN 1 THEN 49
WHEN 2 THEN 50
WHEN 3 THEN 51
WHEN 4 THEN 52
WHEN 5 THEN 53
else
54
END,
enquete_uniteLogement_id_parent
WHERE uniteLogement_rfu.murs IS NOT null
UNION ALL
SELECT 35, now(), 35, now(),false,
CASE uniteLogement_rfu.standing
WHEN 1 THEN 81
WHEN 2 THEN 82
WHEN 3 THEN 83
WHEN 4 THEN 84
END,
enquete_uniteLogement_id_parent
WHERE uniteLogement_rfu.standing IS NOT null
UNION ALL
SELECT 35, now(), 35, now(),false,
CASE uniteLogement_rfu.utilisat
WHEN 1 THEN 35
WHEN 2 THEN 36
WHEN 3 THEN 37
END,
enquete_uniteLogement_id_parent
WHERE uniteLogement_rfu.standing IS NOT null;
------MAJ Exercice
UPDATE enquete_unite_logement eul
SET exercice_id = e.id
FROM exercice e
WHERE e.annee = 2025
AND eul.id = enquete_uniteLogement_id_parent;
END;
$procedure$;

View File

@@ -0,0 +1,99 @@
SELECT dblink_connect(
'connexion_rfu',
'host=10.4.6.103 port=5432 dbname=rfu user=postgres password=Rfu@dm1N2@25TeMp0'
);
CREATE OR REPLACE PROCEDURE public.import_imposition_rfu_cotonou(in exercice varchar(10), in nombreLimit numeric)
LANGUAGE plpgsql
AS $procedure$
DECLARE
l_count numeric := 0;
imposition_rfu record;
l_parcelle_id_parent bigint;
l_code_quartier varchar(20);
BEGIN
FOR imposition_rfu IN (
SELECT FROM dblink(
'connexion_rfu',
$db$
SELECT
i.article ,
i.ifu ,
i.n0_contrib ,
i.denome ,
i.annees ,
i.nature ,
n.libnature ,
i.quartier,
q.libquart ,
i.n0_ilot ,
i.n0_parcel ,
i.nn,
COALESCE(i.montant,0) droit_simple,
COALESCE(i.penalite,0) penalite,
COALESCE(i.majorat,0) majoration,
COALESCE(i.montant,0)+COALESCE(i.penalite,0)+COALESCE(i.majorat,0) total_imposition
FROM stemichel.impotsra i
join agla.nature n on n.nature=i.nature
left join (select distinct
n0_ilot,
quartier,
libquart
from agla.quartier)q on (q.n0_ilot=i.n0_ilot and q.quartier=i.quartier)
-- WHERE i.annees = '2025' or (i.annees ='2024' and trim(i.nature) in ('3N', '4N', 'YN'))
limit 100
$db$
) AS c (
terrain varchar,
n0_ilot varchar,
n0_parcel varchar,
quartier varchar,
hauteur varchar,
rue varchar,
entree varchar,
vlcalcule varchar,
vllcalcule varchar,
)
WHERE NOT EXISTS (
SELECT 1
FROM public.parcelle p
WHERE p.numero_parcelle =
trim(c.quartier)||'-'||trim(c.n0_ilot)||'-'||trim(c.n0_parcel)
) and exists (
select 1
from public.ref_rfu_q_quartier_cotonou rq
where rq.rfu_q = trim(c.quartier)
)
limit nombreLimit
) LOOP
BEGIN
INSERT INTO parcelle (
created_at,
created_by,
deleted,
updated_at,
updated_by,
parcelle_id,
source
)
SELECT
now(),
35,
false,
now(),
35,
parcelle_id,
'RFU'
FROM ref_rfu_q_quartier_cotonou rq
WHERE rq.rfu_q = parcelle_rfu.q
RETURNING id, code_quartier
INTO l_parcelle_id_parent, l_code_quartier;
RAISE NOTICE 'Nombre impositions migrées : %', l_count;
END ;
END LOOP ;
END;
$procedure$;

Some files were not shown because too many files have changed in this diff Show More