Compare commits
98 Commits
features/f
...
8bcae0751a
| Author | SHA1 | Date | |
|---|---|---|---|
| 8bcae0751a | |||
| 34d1502334 | |||
| e2468328fd | |||
| 41e55da1df | |||
| 705af14b4e | |||
| 9063162c33 | |||
| 3f9cdcdad3 | |||
| e58e338123 | |||
| 253332bbd3 | |||
| 6dcd549889 | |||
| 0d27aaebac | |||
| afbf525af5 | |||
| 8ee2f7c9b0 | |||
| 6bdfa3ad1e | |||
| b8ba15c6fb | |||
| 698b7e7c99 | |||
| 9e597386f8 | |||
| cb2faeea32 | |||
| 6b3ab8fc43 | |||
| 906a74571f | |||
| 6494fe235e | |||
| 28da361054 | |||
| 3993d28d51 | |||
| 09d8b21909 | |||
| 274b47d116 | |||
| bdb08b88fd | |||
| b86c685cd0 | |||
| d46a14626e | |||
| 920c70c877 | |||
| 2ab5b9299c | |||
| bf19ab6e6a | |||
| 84451d5a15 | |||
| e687a9a904 | |||
| 9685c73513 | |||
| 650470efff | |||
| 9f5cc61726 | |||
| 41175d93f0 | |||
| 1ecaecdee3 | |||
| 122dfcbead | |||
| d168b68d4b | |||
| 2af14dd4cd | |||
| 76f0d34e79 | |||
| 666779ecce | |||
| 7fcd676fc0 | |||
| fffdef7103 | |||
| 95c0dacd1e | |||
| 7ac6b953d3 | |||
| e010100472 | |||
| 177a9c7b56 | |||
| 3054930a86 | |||
| 4397abd041 | |||
| a4b403ca20 | |||
| ff7b88f9f8 | |||
| 37fdba1d85 | |||
| f50ed9aa5f | |||
| 966fd2ca7a | |||
| a10253b2e8 | |||
| 08b68f9e08 | |||
| be487d6a03 | |||
| 3be64e7f44 | |||
| 03a661cdc0 | |||
| a68ec444cc | |||
| 58f517bf31 | |||
| 7f18f22efb | |||
| af3218412f | |||
| f35670c72e | |||
| a77c0e854d | |||
| e75eff4e20 | |||
| 40d078c653 | |||
| 31dd11d017 | |||
| 6dfd12fae8 | |||
| a4ad0a4556 | |||
| 411a6c0c2d | |||
| bed73b2b16 | |||
| 5a0814a0ba | |||
| 126254ea94 | |||
| f9e4681af4 | |||
| 84089d3639 | |||
| 02b0a937b4 | |||
| c0096457fb | |||
| b6062ba4d1 | |||
| 8dc8c974d3 | |||
| 957416df9e | |||
| 8d8af75108 | |||
| 555f13508e | |||
| d92a2b2503 | |||
| 5ccfdb6a3f | |||
| 87b3bfbe83 | |||
| 62f25ea726 | |||
| 6125fcbd0b | |||
| 211af6103a | |||
| d27b622db8 | |||
| c80b40082c | |||
| 4a88af6487 | |||
| 966b0af1c2 | |||
| 58aa088ac3 | |||
| 033b430051 | |||
| b8dbc7f625 |
@@ -1,314 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class DeclarationNcController {
|
||||
|
||||
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<?> createDeclarationNc(@RequestBody DeclarationNcPayloadWeb declarationNcPayloadWeb) {
|
||||
public ResponseEntity<?> createDeclarationNc(@RequestBody @Valid @Validated DeclarationNcPayloadWeb declarationNcPayloadWeb) {
|
||||
try {
|
||||
declarationNcPayloadWeb = declarationNcService.createDeclarationNc(declarationNcPayloadWeb);
|
||||
return new ResponseEntity<>(
|
||||
|
||||
@@ -116,52 +116,52 @@ public class DonneesImpositionTfuController {
|
||||
}
|
||||
}
|
||||
|
||||
// @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")
|
||||
public ResponseEntity<?> getAllDonneesImpositionTfuList() {
|
||||
try {
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesImpositionTfuList(), "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")
|
||||
// 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-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 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-page/by-imposition-id/{impositionId}")
|
||||
@@ -169,7 +169,7 @@ public class DonneesImpositionTfuController {
|
||||
try {
|
||||
Pageable pageable = PageRequest.of(pageNo, pageSize);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdPageable(impositionId, pageable), "Liste des impositions chargée avec succès."),
|
||||
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdPageable(impositionId, pageable), "Liste des caractéristiques chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -193,7 +193,7 @@ public class DonneesImpositionTfuController {
|
||||
try {
|
||||
Pageable pageable = PageRequest.of(pageNo, pageSize);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdNonBatiePageable(impositionId, pageable), "Liste des impositions chargée avec succès."),
|
||||
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdNonBatiePageable(impositionId, pageable), "Liste des caractéristiques chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -218,7 +218,7 @@ public class DonneesImpositionTfuController {
|
||||
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."),
|
||||
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdBatieBatimentPageable(impositionId, pageable), "Liste des caractéristiques chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -242,7 +242,7 @@ public class DonneesImpositionTfuController {
|
||||
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."),
|
||||
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByImpositionTfuIdBatieUniteLogPageable(impositionId, pageable), "Liste des caractéristiques chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -333,59 +333,6 @@ public class DonneesImpositionTfuController {
|
||||
}
|
||||
|
||||
|
||||
@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")
|
||||
@@ -437,59 +384,6 @@ public class DonneesImpositionTfuController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@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
|
||||
);
|
||||
|
||||
} 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 = "Récuperer les avis d'id d'une imposition")
|
||||
@GetMapping("/by-impositions-id/{impositionsId}")
|
||||
public ResponseEntity<?> getDonneesFiscale(@PathVariable Long impositionsId) {
|
||||
@@ -548,7 +442,7 @@ public class DonneesImpositionTfuController {
|
||||
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."),
|
||||
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByExerciceAndStructureIdPageable(exerciceId,structureId, pageable), "Liste des caractéristiques chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -572,32 +466,7 @@ public class DonneesImpositionTfuController {
|
||||
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."),
|
||||
new ApiResponse<>(true, donneesImpositionTfuService.getDonneesFiscalesByExerciceAndStructureId(exerciceId,structureId,quartierId), "Liste des caractéristiques chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
|
||||
@@ -41,7 +41,6 @@ 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;
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
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;
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
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 ;
|
||||
}
|
||||
@@ -36,22 +36,19 @@ 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
|
||||
|
||||
@@ -8,7 +8,6 @@ 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;
|
||||
@@ -114,11 +113,6 @@ public class DonneesImpositionTfu extends BaseEntity implements Serializable {
|
||||
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;
|
||||
@@ -147,10 +141,4 @@ public class DonneesImpositionTfu extends BaseEntity implements Serializable {
|
||||
private UniteLogement uniteLogementImposee ;
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private Personne personne ;
|
||||
|
||||
private Boolean parcelleContact;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package io.gmss.fiscad.enums;
|
||||
|
||||
public enum NatureImpot {
|
||||
FB,
|
||||
FNB,
|
||||
TFU,
|
||||
IRF,
|
||||
SRTB
|
||||
}
|
||||
|
||||
@@ -3,11 +3,7 @@ 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
|
||||
}
|
||||
|
||||
@@ -136,7 +136,6 @@ public class SecteurDecoupageServiceImpl implements SecteurDecoupageService {
|
||||
.map(Secteur::getId)
|
||||
.toList();
|
||||
System.out.println(statutEnquete);
|
||||
System.out.println(secteurIds);
|
||||
return enqueteBatimentRepository.findStatsEnqueteBatimentBySecteurs(secteurIds,statutEnquete);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,11 +86,6 @@ 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;
|
||||
@@ -258,28 +253,12 @@ 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))
|
||||
@@ -322,48 +301,29 @@ public class PersonneServiceImpl implements PersonneService {
|
||||
personne.setEtatIdentificationPersonne(EtatIdentificationPersonne.IFU);
|
||||
result.add(personne);
|
||||
}
|
||||
return result;
|
||||
|
||||
} catch (Exception e) {
|
||||
return new ArrayList<>();
|
||||
// logger.error("Erreur appel IFU EN LIGNE", e);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// 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 ;
|
||||
// }
|
||||
private List<PersonnePayLoadWeb> recherchePersonneLocal(RecherchePersonneResquestBody recherchePersonneResquestBody) {
|
||||
|
||||
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
|
||||
);
|
||||
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()
|
||||
);
|
||||
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();
|
||||
|
||||
|
||||
@@ -1,187 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,11 +38,6 @@ 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);
|
||||
|
||||
@@ -109,66 +109,21 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ
|
||||
return impositionsTfuRepository.findByIdToDto(impositionsTfu.getId()).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@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);
|
||||
// Integer nbirfbt= donneesImpositionTfuRepository.genererDonneesIrfBatie(impositionsTfuPaylaodWeb.getId(),userId);
|
||||
//
|
||||
// Integer nbirfulo= donneesImpositionTfuRepository.genererDonneesIrfBatieUniteLogement(impositionsTfuPaylaodWeb.getId(),userId);
|
||||
//
|
||||
// Integer nbsrtbbt= donneesImpositionTfuRepository.genererDonneesSrtbBatie(impositionsTfuPaylaodWeb.getId(),userId);
|
||||
//
|
||||
// Integer nbsrtbulo= donneesImpositionTfuRepository.genererDonneesSrtbBatieUniteLogement(impositionsTfuPaylaodWeb.getId(),userId);
|
||||
|
||||
|
||||
ImpositionsTfu impositionsTfu = entityFromPayLoadService.getImpositionsTfuFromPayLoadWeb(impositionsTfuPaylaodWeb);
|
||||
@@ -247,9 +202,4 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ 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à ce centre et le même exercice ");
|
||||
throw new BadRequestException("Une Imposition non annulée existe déjà");
|
||||
}
|
||||
List<StatusAvis> statusAvis= new ArrayList<>();
|
||||
statusAvis.add(StatusAvis.EN_COURS);
|
||||
|
||||
@@ -21,7 +21,6 @@ public interface PersonneService {
|
||||
void deletePersonne(Long id) throws NotFoundException;
|
||||
|
||||
Page<PersonnePayLoadWeb> getPersonneList(Pageable pageable);
|
||||
Page<PersonnePayLoadWeb> getPersonneListNonAssigneePage(Pageable pageable);
|
||||
|
||||
List<PersonnePayLoadWeb> getPersonneList();
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -27,7 +27,6 @@ public interface DonneesImpositionTfuService {
|
||||
|
||||
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);
|
||||
@@ -46,9 +45,4 @@ public interface DonneesImpositionTfuService {
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,6 @@ 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;
|
||||
@@ -29,14 +24,7 @@ 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,
|
||||
String q,
|
||||
String i,
|
||||
String p,
|
||||
String numeroTitreFoncier,
|
||||
String nup
|
||||
) {
|
||||
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) {
|
||||
this.id = id;
|
||||
this.dateDerniereDeclaration = dateDerniereDeclaration;
|
||||
this.dateDeclarationNc = dateDeclarationNc;
|
||||
@@ -48,11 +36,6 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,497 +0,0 @@
|
||||
/*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;
|
||||
$$;
|
||||
|
||||
|
||||
@@ -1,754 +0,0 @@
|
||||
/*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;
|
||||
$$;
|
||||
@@ -1,855 +0,0 @@
|
||||
/*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;
|
||||
$$;
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
-- 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)
|
||||
);
|
||||
@@ -1,136 +0,0 @@
|
||||
-----------------
|
||||
|
||||
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'
|
||||
@@ -1,5 +0,0 @@
|
||||
-----------------
|
||||
|
||||
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
|
||||
@@ -1,4 +1,4 @@
|
||||
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie(
|
||||
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie(
|
||||
p_impositions_tfu_id BIGINT,
|
||||
p_user_id BIGINT
|
||||
)
|
||||
@@ -282,348 +282,4 @@ WHERE impositions_tfu_id = p_impositions_tfu_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;
|
||||
$$;
|
||||
|
||||
|
||||
@@ -1,350 +0,0 @@
|
||||
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;
|
||||
$$;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie_unite_logement(
|
||||
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie_unite_logement(
|
||||
p_impositions_tfu_id BIGINT,
|
||||
p_user_id BIGINT
|
||||
)
|
||||
@@ -339,303 +339,3 @@ WHERE impositions_tfu_id = p_impositions_tfu_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;
|
||||
$$;
|
||||
|
||||
@@ -1,305 +0,0 @@
|
||||
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;
|
||||
$$;
|
||||
@@ -1,207 +1,264 @@
|
||||
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie(
|
||||
p_impositions_tfu_id BIGINT,
|
||||
p_user_id BIGINT
|
||||
p_user_id BIGINT
|
||||
)
|
||||
RETURNS INTEGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
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;
|
||||
v_rows_inserted INTEGER;
|
||||
v_annee BIGINT;
|
||||
v_structure_id BIGINT;
|
||||
v_montant_srtb NUMERIC;
|
||||
BEGIN
|
||||
|
||||
v_today := CURRENT_DATE;
|
||||
-- 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;
|
||||
|
||||
-- -------------------------------------------------------------------------
|
||||
-- 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';
|
||||
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
|
||||
|
||||
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,
|
||||
unite_logement_id,
|
||||
superficie_au_sol_loue,
|
||||
personne_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
|
||||
)
|
||||
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,
|
||||
AND st.id = v_structure_id
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
-- superficie_au_sol_taux_prop_parc (70 % parcelle)
|
||||
dimp.superficie_au_sol_taux_prop_parc,
|
||||
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||
|
||||
-- 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;
|
||||
RETURN v_rows_inserted;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
|
||||
@@ -1,213 +0,0 @@
|
||||
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;
|
||||
$$;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie_unite_logement(
|
||||
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie_unite_logement(
|
||||
p_impositions_tfu_id BIGINT,
|
||||
p_user_id BIGINT
|
||||
)
|
||||
@@ -309,239 +309,3 @@ 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;
|
||||
$$;
|
||||
@@ -1,3 +1,349 @@
|
||||
/*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
|
||||
@@ -120,15 +466,11 @@ BEGIN
|
||||
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
|
||||
unite_logement_id
|
||||
)
|
||||
SELECT
|
||||
v_annee,
|
||||
@@ -172,7 +514,7 @@ BEGIN
|
||||
eb.date_enquete,
|
||||
st.id,
|
||||
ep.zone_rfu_id,
|
||||
'FB',
|
||||
'TFU',
|
||||
p.superficie,
|
||||
eb.superficie_au_sol,
|
||||
-- valeur_batiment : première valeur non nulle non zéro
|
||||
@@ -208,19 +550,19 @@ BEGIN
|
||||
CASE WHEN eb.categorie_usage = 'HABITATION'
|
||||
THEN (p.superficie * v_taux_defaut_sup_sol / 100.0) * brb.valeur_locative
|
||||
ELSE 0
|
||||
END,
|
||||
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,
|
||||
END,
|
||||
|
||||
-- valeur_locative_adm_sup_reel
|
||||
CASE WHEN eb.categorie_usage = 'HABITATION'
|
||||
THEN eb.superficie_au_sol * brb.valeur_locative
|
||||
ELSE 0
|
||||
END,
|
||||
END,
|
||||
|
||||
-- ---------------------------------------------------------------
|
||||
-- 🔧 CORRECTION : valeur_locative_adm avec tests explicites
|
||||
@@ -254,58 +596,17 @@ BEGIN
|
||||
NULLIF(eb.montant_locatif_annuel_estime, 0), 0)
|
||||
|
||||
ELSE 0
|
||||
END,
|
||||
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
|
||||
THEN eb.superficie_au_sol * brb.valeur_locative * v_taux_tfu_ratio
|
||||
ELSE 0
|
||||
END,
|
||||
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
|
||||
@@ -352,18 +653,14 @@ BEGIN
|
||||
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)
|
||||
NULL
|
||||
|
||||
FROM parcelle p
|
||||
|
||||
-- Dernière enquête parcelle
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT
|
||||
@@ -446,13 +743,17 @@ BEGIN
|
||||
) 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 ul_filter.batiment_id IS NULL -- anti-join : pas d'unité logement
|
||||
AND st.id = v_structure_id
|
||||
|
||||
-- ON CONFLICT DO NOTHING;
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||
|
||||
RETURN v_rows_inserted;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
select * from donnees_imposition_tfu
|
||||
where batie =true;
|
||||
@@ -1,464 +0,0 @@
|
||||
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;
|
||||
$$;
|
||||
@@ -1,442 +1,395 @@
|
||||
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_batie_unite_logement(
|
||||
p_impositions_tfu_id BIGINT,
|
||||
p_user_id BIGINT
|
||||
p_user_id BIGINT
|
||||
)
|
||||
RETURNS INTEGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
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_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_taux_vlp_ratio NUMERIC; -- v_taux_valeur_locat_prof / 100 (pré-calculé)
|
||||
v_tfu_piscine_unitaire NUMERIC;
|
||||
v_today DATE;
|
||||
v_tfu_piscine_unitaire NUMERIC;
|
||||
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'
|
||||
);
|
||||
-- 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';
|
||||
|
||||
-- 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;
|
||||
select value
|
||||
into STRICT v_taux_tfu
|
||||
from parameters
|
||||
where name ='TAUX_TFU';
|
||||
|
||||
-- -------------------------------------------------------------------------
|
||||
-- 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
|
||||
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)
|
||||
),
|
||||
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
|
||||
(
|
||||
CURRENT_DATE >= eb.date_debut_excemption
|
||||
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
|
||||
),
|
||||
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
|
||||
(
|
||||
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,
|
||||
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
|
||||
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
|
||||
) 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
|
||||
) 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
|
||||
AND st.id = v_structure_id
|
||||
ON CONFLICT DO NOTHING;
|
||||
|
||||
ON CONFLICT DO NOTHING;
|
||||
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||
|
||||
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
|
||||
|
||||
RETURN v_rows_inserted;
|
||||
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;
|
||||
$$;
|
||||
|
||||
|
||||
@@ -1,448 +0,0 @@
|
||||
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;
|
||||
$$;
|
||||
|
||||
@@ -228,9 +228,7 @@ BEGIN
|
||||
taux_tfu,
|
||||
valeur_admin_parcelle_nb,
|
||||
valeur_admin_parcelle_nb_metre_carre,
|
||||
montant_taxe,
|
||||
parcelle_id,
|
||||
personne_id
|
||||
montant_taxe
|
||||
)
|
||||
SELECT
|
||||
v_annee,
|
||||
@@ -268,7 +266,7 @@ BEGIN
|
||||
ep.date_enquete,
|
||||
st.id,
|
||||
ep.zone_rfu_id,
|
||||
'FNB',
|
||||
'TFU',
|
||||
p.superficie,
|
||||
p_impositions_tfu_id,
|
||||
false,
|
||||
@@ -288,10 +286,9 @@ BEGIN
|
||||
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
|
||||
END
|
||||
FROM parcelle p
|
||||
|
||||
LEFT JOIN (
|
||||
SELECT DISTINCT ON (parcelle_id)
|
||||
parcelle_id,
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
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;
|
||||
$$;
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
|
||||
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;
|
||||
@@ -1,99 +0,0 @@
|
||||
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$;
|
||||
@@ -1,103 +0,0 @@
|
||||
/**
|
||||
- recuperation et cumul des acomptes par exercice, commune, ifu et parcelle
|
||||
- recuperation et cumul des rirf par exercice, commune, ifu et parcelle
|
||||
*/
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.maj_donnees_imposition_tfu_irf_(
|
||||
p_impositions_tfu_id BIGINT
|
||||
)
|
||||
RETURNS INTEGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_rows_inserted INTEGER;
|
||||
v_annee INTEGER;
|
||||
v_structure_id INTEGER;
|
||||
BEGIN
|
||||
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;
|
||||
|
||||
WITH cumulRetenu as (
|
||||
select ifu_retenue,
|
||||
r_commune,
|
||||
r_quartier,
|
||||
qip_quartier,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
nup,
|
||||
exercice,
|
||||
sum(montant_payer) as cumul_retenu
|
||||
from epaiement_retenu
|
||||
where exercice = v_annee
|
||||
group by ifu_retenue, r_commune, r_quartier,
|
||||
qip_quartier, qip_ilot, qip_parcelle,
|
||||
nup, exercice
|
||||
)
|
||||
UPDATE donnees_imposition_tfu dimp
|
||||
SET
|
||||
retenu_irf = coalesce(cr.cumul_retenu,0),
|
||||
montant_restant = dimp.montant_taxe
|
||||
- coalesce(cr.cumul_retenu,0)
|
||||
FROM donnees_imposition_tfu dimp2
|
||||
LEFT JOIN cumulRetenu cr ON (
|
||||
cr.exercice = dimp2.annee
|
||||
AND cr.r_commune = dimp2.code_commune
|
||||
AND cr.ifu_retenue = dimp2.ifu
|
||||
AND cr.r_quartier = dimp2.code_quartier_village
|
||||
AND cr.qip_quartier = dimp2.q
|
||||
AND cr.qip_ilot = dimp2.ilot
|
||||
AND cr.qip_parcelle = dimp2.parcelle
|
||||
AND cr.nup = dimp2.nup
|
||||
AND cr.nup = dimp2.nup
|
||||
)
|
||||
WHERE dimp.id = dimp2.id
|
||||
AND dimp.impositions_tfu_id = p_impositions_tfu_id
|
||||
AND dimp.nature_impot ='IRF';
|
||||
|
||||
|
||||
WITH cumulAcompte as (
|
||||
select ifu,
|
||||
r_commune,
|
||||
r_quartier,
|
||||
qip_quartier,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
nup,
|
||||
exercice,
|
||||
sum(montant_payer) as cumul_acompte
|
||||
from epaiement_acompte
|
||||
where exercice = v_annee
|
||||
group by ifu, r_commune, r_quartier,
|
||||
qip_quartier, qip_ilot, qip_parcelle,
|
||||
nup, exercice
|
||||
)
|
||||
UPDATE donnees_imposition_tfu dimp
|
||||
SET
|
||||
acompte = coalesce(ac.cumul_acompte,0),
|
||||
montant_restant = dimp.montant_taxe
|
||||
- coalesce(ac.cumul_acompte,0)
|
||||
FROM donnees_imposition_tfu dimp2
|
||||
LEFT JOIN cumulAcompte ac ON (
|
||||
ac.exercice = dimp2.annee
|
||||
AND ac.r_commune = dimp2.code_commune
|
||||
AND ac.ifu = dimp2.ifu
|
||||
AND ac.r_quartier = dimp2.code_quartier_village
|
||||
AND ac.qip_quartier = dimp2.q
|
||||
AND ac.qip_ilot = dimp2.ilot
|
||||
AND ac.qip_parcelle = dimp2.parcelle
|
||||
AND ac.nup = dimp2.nup
|
||||
)
|
||||
WHERE dimp.id = dimp2.id
|
||||
AND dimp.impositions_tfu_id = p_impositions_tfu_id
|
||||
AND dimp.nature_impot in ('FNB','FB');
|
||||
|
||||
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||
|
||||
RETURN v_rows_inserted;
|
||||
END;
|
||||
$$ ;
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/**
|
||||
- consider les parcelles avec plusieurs batiment
|
||||
- faire la somme (som_tfu_calcule) des TFU calculées
|
||||
- on recupere la tfu minimum (max_tfu_min) de la catégorie la plus élévée des batiment
|
||||
- si montant_tfu= Max(som_tfu_calcule, max_tfu_min)
|
||||
*/
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.maj_donnees_imposition_tfu_batie_plusBati(
|
||||
p_impositions_tfu_id BIGINT
|
||||
)
|
||||
RETURNS INTEGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_rows_inserted INTEGER;
|
||||
BEGIN
|
||||
|
||||
------MAJ pour les parcelles ayants plusieurs batiment
|
||||
WITH donnees_imposition_plusieurs_bat AS (
|
||||
SELECT
|
||||
dimp.parcelle_id,
|
||||
GREATEST(
|
||||
MAX(dimp.tfu_minimum),
|
||||
SUM(dimp.montant_taxe_brut)
|
||||
) AS montant_tfu_parcelle,
|
||||
COUNT(*) AS nombre_bat
|
||||
FROM donnees_imposition_tfu dimp
|
||||
LEFT JOIN unite_logement ul_filter on dimp.unite_logement_id = ul_filter.id
|
||||
where impositions_tfu_id=p_impositions_tfu_id
|
||||
AND batie=true and ul_filter.id is null
|
||||
AND nature_impot='FB'
|
||||
GROUP BY dimp.parcelle_id
|
||||
HAVING COUNT(*) > 1
|
||||
)
|
||||
UPDATE donnees_imposition_tfu dimp
|
||||
SET
|
||||
montant_taxe = dippb.montant_tfu_parcelle,
|
||||
nombre_bat = dippb.nombre_bat
|
||||
FROM donnees_imposition_plusieurs_bat dippb
|
||||
WHERE dimp.parcelle_id = dippb.parcelle_id
|
||||
AND dimp.impositions_tfu_id=p_impositions_tfu_id;
|
||||
|
||||
------FIN MAJ pour les parcelles ayants plusieurs batiment
|
||||
|
||||
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||
|
||||
RETURN v_rows_inserted;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
- consider les parcelles avec plusieurs batiment
|
||||
- faire la somme (som_tfu_calcule) des TFU calculées
|
||||
- on recupere la tfu minimum (max_tfu_min) de la catégorie la plus élévée des batiment
|
||||
- si montant_tfu= Max(som_tfu_calcule, max_tfu_min)
|
||||
*/
|
||||
|
||||
CREATE OR REPLACE FUNCTION public.maj_donnees_imposition_tfu_batie_plusBati_une_parcelle(
|
||||
p_impositions_tfu_id BIGINT,
|
||||
p_parcelle_id BIGINT
|
||||
)
|
||||
RETURNS INTEGER
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_rows_inserted INTEGER;
|
||||
BEGIN
|
||||
|
||||
------MAJ pour les parcelles ayants plusieurs batiment
|
||||
WITH donnees_imposition_plusieurs_bat AS (
|
||||
SELECT
|
||||
dimp.parcelle_id,
|
||||
GREATEST(
|
||||
MAX(dimp.tfu_minimum),
|
||||
SUM(dimp.montant_taxe_brut)
|
||||
) AS montant_tfu_parcelle,
|
||||
COUNT(*) AS nombre_bat
|
||||
FROM donnees_imposition_tfu dimp
|
||||
LEFT JOIN unite_logement ul_filter on dimp.unite_logement_id = ul_filter.id
|
||||
where impositions_tfu_id=p_impositions_tfu_id
|
||||
AND batie=true and ul_filter.id is null
|
||||
AND nature_impot='FB'
|
||||
AND dimp.parcelle_id=p_parcelle_id
|
||||
GROUP BY dimp.parcelle_id
|
||||
HAVING COUNT(*) > 1
|
||||
)
|
||||
UPDATE donnees_imposition_tfu dimp
|
||||
SET
|
||||
montant_taxe = dippb.montant_tfu_parcelle,
|
||||
nombre_bat = dippb.nombre_bat
|
||||
FROM donnees_imposition_plusieurs_bat dippb
|
||||
WHERE dimp.parcelle_id = dippb.parcelle_id
|
||||
AND dimp.impositions_tfu_id=p_impositions_tfu_id;
|
||||
|
||||
------FIN MAJ pour les parcelles ayants plusieurs batiment
|
||||
|
||||
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||
|
||||
RETURN v_rows_inserted;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
@@ -256,95 +256,46 @@ public interface EnqueteRepository extends JpaRepository<Enquete, Long> {
|
||||
List<Enquete> findAllByParcelle_Id(Long parcelleId);
|
||||
|
||||
|
||||
// @Query(
|
||||
// value = """
|
||||
// SELECT DISTINCT
|
||||
// d.id AS departement_id,
|
||||
// d.code AS departement_code,
|
||||
// d.nom AS departement_nom,
|
||||
// COUNT(e.id) OVER (PARTITION BY d.id) AS nb_enquetes_departement,
|
||||
//
|
||||
// c.id AS commune_id,
|
||||
// c.code AS commune_code,
|
||||
// c.nom AS commune_nom,
|
||||
// COUNT(e.id) OVER (PARTITION BY c.id) AS nb_enquetes_commune,
|
||||
//
|
||||
// a.id AS arrondissement_id,
|
||||
// a.code AS arrondissement_code,
|
||||
// a.nom AS arrondissement_nom,
|
||||
// COUNT(e.id) OVER (PARTITION BY a.id) AS nb_enquetes_arrondissement,
|
||||
//
|
||||
// q.id AS quartier_id,
|
||||
// q.code AS quartier_code,
|
||||
// q.nom AS quartier_nom,
|
||||
// COUNT(e.id) OVER (PARTITION BY q.id) AS nb_enquetes_quartier
|
||||
//
|
||||
// FROM enquete e
|
||||
// JOIN parcelle p ON p.id = e.parcelle_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
|
||||
//
|
||||
// WHERE EXISTS (
|
||||
// SELECT 1
|
||||
// FROM secteur_decoupage sd
|
||||
// WHERE sd.quartier_id = q.id
|
||||
// AND sd.secteur_id IN (:secteurIds)
|
||||
// )
|
||||
// AND e.statut_enquete = :statutEnqueteParam
|
||||
//
|
||||
// ORDER BY d.nom, c.nom, a.nom, q.nom;
|
||||
// """,
|
||||
// nativeQuery = true
|
||||
// )
|
||||
// List<ParcelleStatsProjectionUnSecteur> findStatsEnqueteBySecteurs(
|
||||
// @Param("secteurIds") List<Long> secteurIds,
|
||||
// @Param("statutEnqueteParam") String statutEnqueteParam
|
||||
// );
|
||||
|
||||
@Query(
|
||||
value = """
|
||||
SELECT DISTINCT
|
||||
d.id AS departementId,
|
||||
d.code AS departementCode,
|
||||
d.nom AS departementNom,
|
||||
COUNT(e.id) OVER (PARTITION BY d.id) AS nbParcellesDepartement,
|
||||
SELECT DISTINCT
|
||||
d.id AS departement_id,
|
||||
d.code AS departement_code,
|
||||
d.nom AS departement_nom,
|
||||
COUNT(e.id) OVER (PARTITION BY d.id) AS nb_enquetes_departement,
|
||||
|
||||
c.id AS communeId,
|
||||
c.code AS communeCode,
|
||||
c.nom AS communeNom,
|
||||
COUNT(e.id) OVER (PARTITION BY c.id) AS nbParcellesCommune,
|
||||
c.id AS commune_id,
|
||||
c.code AS commune_code,
|
||||
c.nom AS commune_nom,
|
||||
COUNT(e.id) OVER (PARTITION BY c.id) AS nb_enquetes_commune,
|
||||
|
||||
a.id AS arrondissementId,
|
||||
a.code AS arrondissementCode,
|
||||
a.nom AS arrondissementNom,
|
||||
COUNT(e.id) OVER (PARTITION BY a.id) AS nbParcellesArrondissement,
|
||||
a.id AS arrondissement_id,
|
||||
a.code AS arrondissement_code,
|
||||
a.nom AS arrondissement_nom,
|
||||
COUNT(e.id) OVER (PARTITION BY a.id) AS nb_enquetes_arrondissement,
|
||||
|
||||
q.id AS quartierId,
|
||||
q.code AS quartierCode,
|
||||
q.nom AS quartierNom,
|
||||
COUNT(e.id) OVER (PARTITION BY q.id) AS nbParcellesQuartier
|
||||
q.id AS quartier_id,
|
||||
q.code AS quartier_code,
|
||||
q.nom AS quartier_nom,
|
||||
COUNT(e.id) OVER (PARTITION BY q.id) AS nb_enquetes_quartier
|
||||
|
||||
FROM quartier q
|
||||
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 parcelle p ON p.quartier_id = q.id
|
||||
FROM enquete e
|
||||
JOIN parcelle p ON p.id = e.parcelle_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
|
||||
|
||||
LEFT JOIN enquete e
|
||||
ON e.parcelle_id = p.id
|
||||
AND e.statut_enquete = :statutEnqueteParam
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM secteur_decoupage sd
|
||||
WHERE sd.quartier_id = q.id
|
||||
AND sd.secteur_id IN (:secteurIds)
|
||||
)
|
||||
AND e.statut_enquete = :statutEnqueteParam
|
||||
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM secteur_decoupage sd
|
||||
WHERE sd.quartier_id = q.id
|
||||
AND sd.secteur_id IN (:secteurIds)
|
||||
)
|
||||
|
||||
ORDER BY d.nom, c.nom, a.nom, q.nom
|
||||
""",
|
||||
ORDER BY d.nom, c.nom, a.nom, q.nom;
|
||||
""",
|
||||
nativeQuery = true
|
||||
)
|
||||
List<ParcelleStatsProjectionUnSecteur> findStatsEnqueteBySecteurs(
|
||||
|
||||
@@ -98,22 +98,22 @@ public interface ParcelleRepository extends JpaRepository<Parcelle, Long>, JpaSp
|
||||
d.id AS departement_id,
|
||||
d.code AS departement_code,
|
||||
d.nom AS departement_nom,
|
||||
COUNT(p.id) OVER (PARTITION BY d.id) AS nbParcellesDepartement,
|
||||
COUNT(p.id) OVER (PARTITION BY d.id) AS nb_parcelles_departement,
|
||||
|
||||
c.id AS commune_id,
|
||||
c.code AS commune_code,
|
||||
c.nom AS commune_nom,
|
||||
COUNT(p.id) OVER (PARTITION BY c.id) AS nbParcellesCommune,
|
||||
COUNT(p.id) OVER (PARTITION BY c.id) AS nb_parcelles_commune,
|
||||
|
||||
a.id AS arrondissement_id,
|
||||
a.code AS arrondissement_code,
|
||||
a.nom AS arrondissement_nom,
|
||||
COUNT(p.id) OVER (PARTITION BY a.id) AS nbParcellesArrondissement,
|
||||
COUNT(p.id) OVER (PARTITION BY a.id) AS nb_parcelles_arrondissement,
|
||||
|
||||
q.id AS quartier_id,
|
||||
q.code AS quartier_code,
|
||||
q.nom AS quartier_nom,
|
||||
COUNT(p.id) OVER (PARTITION BY q.id) AS nbParcellesQuartier
|
||||
COUNT(p.id) OVER (PARTITION BY q.id) AS nb_parcelles_quartier
|
||||
|
||||
FROM quartier q
|
||||
JOIN arrondissement a ON a.id = q.arrondissement_id
|
||||
|
||||
@@ -69,73 +69,43 @@ public interface PersonneRepository extends JpaRepository<Personne, Long> {
|
||||
List<StatistiqueTypeNombreResponse> getNombrePersonnesResponse();
|
||||
|
||||
|
||||
// @Query( """
|
||||
// SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb(
|
||||
// p.id,
|
||||
// p.ifu,
|
||||
// p.nom,
|
||||
// p.prenom,
|
||||
// p.raisonSociale,
|
||||
// p.numRavip,
|
||||
// p.npi,
|
||||
// p.dateNaissanceOuConsti,
|
||||
// p.lieuNaissance,
|
||||
// p.tel1,
|
||||
// p.nomJeuneFille,
|
||||
// p.nomMere,
|
||||
// io.gmss.fiscad.enums.EtatIdentificationPersonne.RFU
|
||||
// )
|
||||
// FROM Personne p
|
||||
// WHERE
|
||||
// p.etatIdentificationPersonne <> io.gmss.fiscad.enums.EtatIdentificationPersonne.NEANT
|
||||
// AND (:ifu IS NULL OR UPPER(trim(p.ifu)) LIKE (CONCAT('%', :ifu, '%')))
|
||||
// AND (:npi IS NULL OR UPPER(trim(p.npi)) LIKE (CONCAT('%', :npi, '%')))
|
||||
// AND (:nom IS NULL OR UPPER(trim(p.nom)) LIKE (CONCAT('%', :nom, '%')))
|
||||
// AND (:prenom IS NULL OR UPPER(trim(p.prenom)) LIKE (CONCAT('%', :prenom, '%')))
|
||||
// AND (:raisonSociale IS NULL OR UPPER(trim(p.raisonSociale)) LIKE (CONCAT('%', :raisonSociale, '%')))
|
||||
// AND (:nomMere IS NULL OR UPPER(trim(p.nomMere)) LIKE (CONCAT('%', :nomMere, '%')))
|
||||
// AND p.dateNaissanceOuConsti =COALESCE(:dateNaissance, p.dateNaissanceOuConsti)
|
||||
// """
|
||||
// )
|
||||
// List<PersonnePayLoadWeb> findByFiltersInBaseIfuNpiCorrecte(
|
||||
// @Param("ifu") String ifu,
|
||||
// @Param("npi") String npi,
|
||||
// @Param("nom") String nom,
|
||||
// @Param("prenom") String prenom,
|
||||
// @Param("raisonSociale") String raisonSociale,
|
||||
// @Param("nomMere") String nomMere,
|
||||
// @Param("dateNaissance") LocalDate dateNaissance
|
||||
// );
|
||||
|
||||
@Query("""
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb(
|
||||
p.id,
|
||||
p.ifu,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.numRavip,
|
||||
p.npi,
|
||||
p.dateNaissanceOuConsti,
|
||||
p.lieuNaissance,
|
||||
p.tel1,
|
||||
p.nomJeuneFille,
|
||||
p.nomMere,
|
||||
p.etatIdentificationPersonne
|
||||
)
|
||||
FROM Personne p
|
||||
WHERE p.etatIdentificationPersonne <> io.gmss.fiscad.enums.EtatIdentificationPersonne.NEANT
|
||||
AND (:nom IS NULL OR UPPER(p.nom) LIKE :nom)
|
||||
AND (:prenom IS NULL OR UPPER(p.prenom) LIKE :prenom)
|
||||
AND (:raisonSociale IS NULL OR UPPER(p.raisonSociale) LIKE :raisonSociale)
|
||||
AND (:nomMere IS NULL OR UPPER(p.nomMere) LIKE :nomMere)
|
||||
""")
|
||||
List<PersonnePayLoadWeb> findByFiltersInBaseIfuNpiCorrecte(
|
||||
@Param("nom") String nom,
|
||||
@Param("prenom") String prenom,
|
||||
@Param("raisonSociale") String raisonSociale,
|
||||
@Param("nomMere") String nomMere
|
||||
);
|
||||
@Query( """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb(
|
||||
p.id,
|
||||
p.ifu,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.numRavip,
|
||||
p.npi,
|
||||
p.dateNaissanceOuConsti,
|
||||
p.lieuNaissance,
|
||||
p.tel1,
|
||||
p.nomJeuneFille,
|
||||
p.nomMere,
|
||||
io.gmss.fiscad.enums.EtatIdentificationPersonne.RFU
|
||||
)
|
||||
FROM Personne p
|
||||
WHERE
|
||||
p.etatIdentificationPersonne <> io.gmss.fiscad.enums.EtatIdentificationPersonne.NEANT
|
||||
AND (:ifu IS NULL OR LOWER(trim(p.ifu)) LIKE (CONCAT('%', :ifu, '%')))
|
||||
AND (:npi IS NULL OR LOWER(trim(p.npi)) LIKE (CONCAT('%', :npi, '%')))
|
||||
AND (:nom IS NULL OR LOWER(trim(p.nom)) LIKE (CONCAT('%', :nom, '%')))
|
||||
AND (:prenom IS NULL OR LOWER(trim(p.prenom)) LIKE (CONCAT('%', :prenom, '%')))
|
||||
AND (:raisonSociale IS NULL OR LOWER(trim(p.raisonSociale)) LIKE (CONCAT('%', :raisonSociale, '%')))
|
||||
AND (:nomMere IS NULL OR LOWER(trim(p.nomMere)) LIKE (CONCAT('%', :nomMere, '%')))
|
||||
AND p.dateNaissanceOuConsti =COALESCE(:dateNaissance, p.dateNaissanceOuConsti)
|
||||
"""
|
||||
)
|
||||
List<PersonnePayLoadWeb> findByFiltersInBaseIfuNpiCorrecte(
|
||||
@Param("ifu") String ifu,
|
||||
@Param("npi") String npi,
|
||||
@Param("nom") String nom,
|
||||
@Param("prenom") String prenom,
|
||||
@Param("raisonSociale") String raisonSociale,
|
||||
@Param("nomMere") String nomMere,
|
||||
@Param("dateNaissance") LocalDate dateNaissance
|
||||
);
|
||||
|
||||
|
||||
// AND (:dateNaissance IS NULL OR p.dateNaissanceOuConsti = :dateNaissance)
|
||||
@@ -216,83 +186,4 @@ public interface PersonneRepository extends JpaRepository<Personne, Long> {
|
||||
|
||||
|
||||
|
||||
@Query( """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb(
|
||||
p.id,
|
||||
p.ifu,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.numRavip,
|
||||
p.npi,
|
||||
p.dateNaissanceOuConsti,
|
||||
p.lieuNaissance,
|
||||
p.tel1,
|
||||
p.nomJeuneFille,
|
||||
p.nomMere,
|
||||
p.etatIdentificationPersonne
|
||||
)
|
||||
FROM Personne p
|
||||
where p.ifu= :ifu
|
||||
"""
|
||||
)
|
||||
List<PersonnePayLoadWeb> findAllPersonneByIfuToDto(
|
||||
@Param("ifu") String ifu
|
||||
);
|
||||
|
||||
@Query( """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb(
|
||||
p.id,
|
||||
p.ifu,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.numRavip,
|
||||
p.npi,
|
||||
p.dateNaissanceOuConsti,
|
||||
p.lieuNaissance,
|
||||
p.tel1,
|
||||
p.nomJeuneFille,
|
||||
p.nomMere,
|
||||
p.etatIdentificationPersonne
|
||||
)
|
||||
FROM Personne p
|
||||
where p.npi= :npi
|
||||
"""
|
||||
)
|
||||
List<PersonnePayLoadWeb> findAllPersonneByNpiToDto(
|
||||
@Param("npi") String npi
|
||||
);
|
||||
|
||||
|
||||
@Query(value = """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb(
|
||||
p.id,
|
||||
p.ifu,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.numRavip,
|
||||
p.npi,
|
||||
p.dateNaissanceOuConsti,
|
||||
p.lieuNaissance,
|
||||
p.tel1,
|
||||
p.nomJeuneFille,
|
||||
p.nomMere,
|
||||
p.etatIdentificationPersonne
|
||||
)
|
||||
FROM Personne p
|
||||
where not exists (
|
||||
select 1 from CommuneCentreAssignation cca
|
||||
where cca.personne.id=p.id)
|
||||
""",
|
||||
countQuery = """
|
||||
SELECT COUNT(p)
|
||||
FROM Personne p
|
||||
where not exists (
|
||||
select 1 from CommuneCentreAssignation cca
|
||||
where cca.personne.id=p.id)
|
||||
"""
|
||||
)
|
||||
Page<PersonnePayLoadWeb> findAllPersonneNonAssigneCentreToDto(Pageable pageable);
|
||||
}
|
||||
|
||||
@@ -1,304 +0,0 @@
|
||||
package io.gmss.fiscad.persistence.repositories.rfu.metier;
|
||||
|
||||
import io.gmss.fiscad.entities.rfu.metier.Batiment;
|
||||
import io.gmss.fiscad.entities.rfu.metier.CommuneCentreAssignation;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb;
|
||||
import io.gmss.fiscad.paylaods.response.restoration.BatimentPayloadRestor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public interface CommuneCentreAssignationRepository extends JpaRepository<CommuneCentreAssignation, Long> {
|
||||
@Query(
|
||||
value = """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb(
|
||||
cca.id,
|
||||
c.id,
|
||||
c.code,
|
||||
c.nom,
|
||||
s.id,
|
||||
s.code,
|
||||
s.nom,
|
||||
p.id,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.ifu,
|
||||
p.nc,
|
||||
p.npi,
|
||||
parc.id,
|
||||
q.code,
|
||||
parc.q,
|
||||
parc.i,
|
||||
parc.p,
|
||||
cca.adresseContact
|
||||
)
|
||||
FROM CommuneCentreAssignation cca
|
||||
LEFT JOIN cca.commune c
|
||||
LEFT JOIN cca.structure s
|
||||
LEFT JOIN cca.personne p
|
||||
LEFT JOIN cca.parcelle parc
|
||||
LEFT JOIN parc.quartier q
|
||||
""",
|
||||
countQuery = """
|
||||
SELECT COUNT(cca.id)
|
||||
FROM CommuneCentreAssignation cca
|
||||
"""
|
||||
)
|
||||
Page<CommuneCentreAssignationPaylaodWeb> findAllPayload(Pageable pageable);
|
||||
|
||||
@Query(
|
||||
value = """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb(
|
||||
cca.id,
|
||||
c.id,
|
||||
c.code,
|
||||
c.nom,
|
||||
s.id,
|
||||
s.code,
|
||||
s.nom,
|
||||
p.id,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.ifu,
|
||||
p.nc,
|
||||
p.npi,
|
||||
parc.id,
|
||||
q.code,
|
||||
parc.q,
|
||||
parc.i,
|
||||
parc.p,
|
||||
cca.adresseContact
|
||||
)
|
||||
FROM CommuneCentreAssignation cca
|
||||
JOIN cca.structure s
|
||||
LEFT JOIN cca.commune c
|
||||
LEFT JOIN cca.personne p
|
||||
LEFT JOIN cca.parcelle parc
|
||||
LEFT JOIN parc.quartier q
|
||||
WHERE s.id = :structureId
|
||||
""",
|
||||
countQuery = """
|
||||
SELECT COUNT(cca.id)
|
||||
FROM CommuneCentreAssignation cca
|
||||
WHERE cca.structure.id = :structureId
|
||||
"""
|
||||
)
|
||||
Page<CommuneCentreAssignationPaylaodWeb> findByStructureId(
|
||||
Long structureId,
|
||||
Pageable pageable
|
||||
);
|
||||
|
||||
|
||||
@Query(
|
||||
value = """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb(
|
||||
cca.id,
|
||||
c.id,
|
||||
c.code,
|
||||
c.nom,
|
||||
s.id,
|
||||
s.code,
|
||||
s.nom,
|
||||
p.id,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.ifu,
|
||||
p.nc,
|
||||
p.npi,
|
||||
parc.id,
|
||||
q.code,
|
||||
parc.q,
|
||||
parc.i,
|
||||
parc.p,
|
||||
cca.adresseContact
|
||||
)
|
||||
FROM CommuneCentreAssignation cca
|
||||
JOIN cca.commune c
|
||||
LEFT JOIN cca.structure s
|
||||
LEFT JOIN cca.personne p
|
||||
LEFT JOIN cca.parcelle parc
|
||||
LEFT JOIN parc.quartier q
|
||||
WHERE c.id = :communeId
|
||||
""",
|
||||
countQuery = """
|
||||
SELECT COUNT(cca.id)
|
||||
FROM CommuneCentreAssignation cca
|
||||
WHERE cca.commune.id = :communeId
|
||||
"""
|
||||
)
|
||||
Page<CommuneCentreAssignationPaylaodWeb> findByCommuneId(
|
||||
Long communeId,
|
||||
Pageable pageable
|
||||
);
|
||||
|
||||
@Query(
|
||||
value = """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb(
|
||||
cca.id,
|
||||
c.id,
|
||||
c.code,
|
||||
c.nom,
|
||||
s.id,
|
||||
s.code,
|
||||
s.nom,
|
||||
p.id,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.ifu,
|
||||
p.nc,
|
||||
p.npi,
|
||||
parc.id,
|
||||
q.code,
|
||||
parc.q,
|
||||
parc.i,
|
||||
parc.p,
|
||||
cca.adresseContact
|
||||
)
|
||||
FROM CommuneCentreAssignation cca
|
||||
JOIN cca.structure s
|
||||
JOIN cca.commune c
|
||||
LEFT JOIN cca.personne p
|
||||
LEFT JOIN cca.parcelle parc
|
||||
LEFT JOIN parc.quartier q
|
||||
WHERE s.id = :structureId
|
||||
AND c.id = :communeId
|
||||
""",
|
||||
countQuery = """
|
||||
SELECT COUNT(cca.id)
|
||||
FROM CommuneCentreAssignation cca
|
||||
WHERE cca.structure.id = :structureId
|
||||
AND cca.commune.id = :communeId
|
||||
"""
|
||||
)
|
||||
Page<CommuneCentreAssignationPaylaodWeb> findByStructureAndCommune(
|
||||
Long structureId,
|
||||
Long communeId,
|
||||
Pageable pageable
|
||||
);
|
||||
|
||||
|
||||
@Query("""
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb(
|
||||
cca.id,
|
||||
c.id,
|
||||
c.code,
|
||||
c.nom,
|
||||
s.id,
|
||||
s.code,
|
||||
s.nom,
|
||||
p.id,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.ifu,
|
||||
p.nc,
|
||||
p.npi,
|
||||
parc.id,
|
||||
q.code,
|
||||
parc.q,
|
||||
parc.i,
|
||||
parc.p,
|
||||
cca.adresseContact
|
||||
)
|
||||
FROM CommuneCentreAssignation cca
|
||||
JOIN cca.structure s
|
||||
JOIN cca.commune c
|
||||
JOIN cca.personne p
|
||||
LEFT JOIN cca.parcelle parc
|
||||
LEFT JOIN parc.quartier q
|
||||
WHERE s.id = :structureId
|
||||
AND c.id = :communeId
|
||||
AND p.id = :personneId
|
||||
""")
|
||||
Optional<CommuneCentreAssignationPaylaodWeb> findUnique(
|
||||
Long structureId,
|
||||
Long communeId,
|
||||
Long personneId
|
||||
);
|
||||
|
||||
|
||||
@Query("""
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb(
|
||||
cca.id,
|
||||
c.id,
|
||||
c.code,
|
||||
c.nom,
|
||||
s.id,
|
||||
s.code,
|
||||
s.nom,
|
||||
p.id,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.ifu,
|
||||
p.nc,
|
||||
p.npi,
|
||||
parc.id,
|
||||
q.code,
|
||||
parc.q,
|
||||
parc.i,
|
||||
parc.p,
|
||||
cca.adresseContact
|
||||
)
|
||||
FROM CommuneCentreAssignation cca
|
||||
JOIN cca.structure s
|
||||
JOIN cca.commune c
|
||||
JOIN cca.personne p
|
||||
LEFT JOIN cca.parcelle parc
|
||||
LEFT JOIN parc.quartier q
|
||||
WHERE cca.id = :id
|
||||
""")
|
||||
Optional<CommuneCentreAssignationPaylaodWeb> findUnique(
|
||||
Long id
|
||||
);
|
||||
|
||||
|
||||
|
||||
@Query("""
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.CommuneCentreAssignationPaylaodWeb(
|
||||
cca.id,
|
||||
c.id,
|
||||
c.code,
|
||||
c.nom,
|
||||
s.id,
|
||||
s.code,
|
||||
s.nom,
|
||||
p.id,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.ifu,
|
||||
p.nc,
|
||||
p.npi,
|
||||
parc.id,
|
||||
q.code,
|
||||
parc.q,
|
||||
parc.i,
|
||||
parc.p,
|
||||
cca.adresseContact
|
||||
)
|
||||
FROM CommuneCentreAssignation cca
|
||||
JOIN cca.structure s
|
||||
JOIN cca.commune c
|
||||
JOIN cca.personne p
|
||||
LEFT JOIN cca.parcelle parc
|
||||
LEFT JOIN parc.quartier q
|
||||
WHERE c.id = :communeId
|
||||
AND p.id = :personneId
|
||||
""")
|
||||
Optional<CommuneCentreAssignationPaylaodWeb> findbyCommuneAndPersonne(
|
||||
Long communeId,
|
||||
Long personneId
|
||||
);
|
||||
}
|
||||
@@ -28,12 +28,7 @@ public interface DeclarationNcRepository extends JpaRepository<DeclarationNc, Lo
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
d.observation,
|
||||
d.q,
|
||||
d.i,
|
||||
d.p,
|
||||
d.numeroTitreFoncier,
|
||||
d.nup
|
||||
d.observation
|
||||
)
|
||||
FROM DeclarationNc d
|
||||
LEFT JOIN d.structure s
|
||||
@@ -55,12 +50,7 @@ public interface DeclarationNcRepository extends JpaRepository<DeclarationNc, Lo
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
d.observation,
|
||||
d.q,
|
||||
d.i,
|
||||
d.p,
|
||||
d.numeroTitreFoncier,
|
||||
d.nup
|
||||
d.observation
|
||||
)
|
||||
FROM DeclarationNc d
|
||||
LEFT JOIN d.structure s
|
||||
@@ -81,12 +71,7 @@ public interface DeclarationNcRepository extends JpaRepository<DeclarationNc, Lo
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
d.observation,
|
||||
d.q,
|
||||
d.i,
|
||||
d.p,
|
||||
d.numeroTitreFoncier,
|
||||
d.nup
|
||||
d.observation
|
||||
)
|
||||
FROM DeclarationNc d
|
||||
LEFT JOIN d.structure s
|
||||
@@ -108,12 +93,7 @@ public interface DeclarationNcRepository extends JpaRepository<DeclarationNc, Lo
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
d.observation,
|
||||
d.q,
|
||||
d.i,
|
||||
d.p,
|
||||
d.numeroTitreFoncier,
|
||||
d.nup
|
||||
d.observation
|
||||
)
|
||||
FROM DeclarationNc d
|
||||
LEFT JOIN d.structure s
|
||||
@@ -136,12 +116,7 @@ public interface DeclarationNcRepository extends JpaRepository<DeclarationNc, Lo
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
d.observation,
|
||||
d.q,
|
||||
d.i,
|
||||
d.p,
|
||||
d.numeroTitreFoncier,
|
||||
d.nup
|
||||
d.observation
|
||||
)
|
||||
FROM DeclarationNc d
|
||||
LEFT JOIN d.structure s
|
||||
@@ -160,34 +135,4 @@ public interface DeclarationNcRepository extends JpaRepository<DeclarationNc, Lo
|
||||
Pageable pageable
|
||||
);
|
||||
|
||||
|
||||
@Query("""
|
||||
SELECT distinct new io.gmss.fiscad.paylaods.request.crudweb.DeclarationNcPayloadWeb(
|
||||
d.id,
|
||||
d.dateDerniereDeclaration,
|
||||
d.dateDeclarationNc,
|
||||
d.nc,
|
||||
s.id,
|
||||
s.code,
|
||||
s.nom,
|
||||
p.id,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
d.observation,
|
||||
d.q,
|
||||
d.i,
|
||||
d.p,
|
||||
d.numeroTitreFoncier,
|
||||
d.nup
|
||||
)
|
||||
FROM DeclarationNc d
|
||||
LEFT JOIN d.structure s
|
||||
LEFT JOIN d.personne p
|
||||
WHERE d.nc= :nc
|
||||
and p.id <> :personneId
|
||||
""")
|
||||
List<DeclarationNcPayloadWeb> findAllDeclarationNcByNcNotPersonneToDto(@Param("nc") String nc, @Param("personneId") Long personneId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -508,114 +508,52 @@ SELECT new io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb(
|
||||
Pageable pageable
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_tfu_batie(:impositionId, :userId)", nativeQuery = true)
|
||||
@Query(value = "SELECT generer_donnees_imposition_tfu_batie(:structureId, :impositionId)", nativeQuery = true)
|
||||
Integer genererDonneesTfuBatie(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_tfu_batie_une_parcelle(:impositionId, :userId,:parcelleId)", nativeQuery = true)
|
||||
Integer genererDonneesTfuBatie(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("parcelleId") Long parcelleId
|
||||
);
|
||||
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_tfu_batie_unite_logement(:impositionId, :userId)", nativeQuery = true)
|
||||
Integer genererDonneesTfuBatieUniteLogement(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_tfu_batie_ulo_une_parcelle(:impositionId, :userId,:parcelleId)", nativeQuery = true)
|
||||
Integer genererDonneesTfuBatieUniteLogement(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("parcelleId") Long parcelleId
|
||||
);
|
||||
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_tfu_non_batie(:impositionId, :userId)", nativeQuery = true)
|
||||
Integer genererDonneesTfuNonBatie(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_tfu_non_batie_une_parcelle(:impositionId, :userId, :parcelleId)", nativeQuery = true)
|
||||
Integer genererDonneesTfuNonBatie(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("parcelleId") Long parcelleId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_irf_batie(:impositionId, :userId)", nativeQuery = true)
|
||||
Integer genererDonneesIrfBatie(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_irf_batie_une_parcelle(:impositionId, :userId, :parcelleId)", nativeQuery = true)
|
||||
Integer genererDonneesIrfBatie(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("parcelleId") Long parcelleId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_srtb_batie(:impositionId, :userId)", nativeQuery = true)
|
||||
Integer genererDonneesSrtbBatie(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_srtb_batie_une_parcelle(:impositionId, :userId, :parcelleId)", nativeQuery = true)
|
||||
Integer genererDonneesSrtbBatie(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("parcelleId") Long parcelleId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_irf_batie_unite_logement(:impositionId, :userId)", nativeQuery = true)
|
||||
Integer genererDonneesIrfBatieUniteLogement(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId
|
||||
);
|
||||
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_irf_batie_ulo_une_parcelle(:impositionId, :userId, :parcelleId)", nativeQuery = true)
|
||||
Integer genererDonneesIrfBatieUniteLogement(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("userId") Long userId,
|
||||
@Param("parcelleId") Long parcelleId
|
||||
);
|
||||
|
||||
// @Query(value = "SELECT generer_donnees_imposition_srtb_batie_unite_logement(:impositionId, :userId)", nativeQuery = true)
|
||||
// Integer genererDonneesSrtbBatieUniteLogement(
|
||||
// @Param("impositionId") Long impositionId,
|
||||
// @Param("userId") Long userId
|
||||
// );
|
||||
|
||||
// @Query(value = "SELECT generer_donnees_imposition_srtb_batie_u(:impositionId, :userId)", nativeQuery = true)
|
||||
// Integer genererDonneesSrtbBatieUniteLogement(
|
||||
// @Param("impositionId") Long impositionId,
|
||||
// @Param("userId") Long userId
|
||||
// );
|
||||
|
||||
|
||||
|
||||
|
||||
@Query(value = "SELECT maj_donnees_imposition_tfu_batie_plusBati(:impositionId)", nativeQuery = true)
|
||||
Integer majDonneesTfuBatiePlusieursBatiment(
|
||||
@Param("structureId") Long structureId,
|
||||
@Param("impositionId") Long impositionId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT maj_donnees_imposition_tfu_batie_plusbati_une_parcelle(:impositionId,:parcelleId)", nativeQuery = true)
|
||||
Integer majDonneesTfuBatiePlusieursBatiment(
|
||||
@Param("impositionId") Long impositionId,
|
||||
@Param("parcelleId") Long parcelleId
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_tfu_batie_unite_logement(:structureId, :impositionId)", nativeQuery = true)
|
||||
Integer genererDonneesTfuBatieUniteLogement(
|
||||
@Param("structureId") Long structureId,
|
||||
@Param("impositionId") Long impositionId
|
||||
);
|
||||
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_tfu_non_batie(:structureId, :impositionId)", nativeQuery = true)
|
||||
Integer genererDonneesTfuNonBatie(
|
||||
@Param("structureId") Long structureId,
|
||||
@Param("impositionId") Long impositionId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_irf_batie(:structureId, :impositionId)", nativeQuery = true)
|
||||
Integer genererDonneesIrfBatie(
|
||||
@Param("structureId") Long structureId,
|
||||
@Param("impositionId") Long impositionId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_srtb_batie(:structureId, :impositionId)", nativeQuery = true)
|
||||
Integer genererDonneesSrtbBatie(
|
||||
@Param("structureId") Long structureId,
|
||||
@Param("impositionId") Long impositionId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_irf_batie_unite_logement(:structureId, :impositionId)", nativeQuery = true)
|
||||
Integer genererDonneesIrfBatieUniteLogement(
|
||||
@Param("structureId") Long structureId,
|
||||
@Param("impositionId") Long impositionId
|
||||
);
|
||||
|
||||
@Query(value = "SELECT generer_donnees_imposition_srtb_batie_unite_logement(:structureId, :impositionId)", nativeQuery = true)
|
||||
Integer genererDonneesSrtbBatieUniteLogement(
|
||||
@Param("structureId") Long structureId,
|
||||
@Param("impositionId") Long impositionId
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
@Query(value = """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb(
|
||||
@@ -784,82 +722,4 @@ SELECT new io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb(
|
||||
Long structureId,
|
||||
Long quartierId
|
||||
);
|
||||
|
||||
|
||||
|
||||
@Query("""
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb(
|
||||
d.id,
|
||||
d.annee,
|
||||
d.codeDepartement,
|
||||
d.nomDepartement,
|
||||
d.codeCommune,
|
||||
d.nomCommune,
|
||||
d.codeArrondissement,
|
||||
d.nomArrondissement,
|
||||
d.codeQuartierVillage,
|
||||
d.nomQuartierVillage,
|
||||
d.q,
|
||||
d.ilot,
|
||||
d.parcelle,
|
||||
d.nup,
|
||||
d.titreFoncier,
|
||||
d.numBatiment,
|
||||
d.numUniteLogement,
|
||||
d.ifu,
|
||||
d.npi,
|
||||
d.telProp,
|
||||
d.emailProp,
|
||||
d.nomProp,
|
||||
d.prenomProp,
|
||||
d.raisonSociale,
|
||||
d.adresseProp,
|
||||
d.telSc,
|
||||
d.emailSc,
|
||||
d.nomSc,
|
||||
d.prenomSc,
|
||||
d.adresseSc,
|
||||
d.longitude,
|
||||
d.latitude,
|
||||
d.superficieParc,
|
||||
d.superficieAuSolBat,
|
||||
d.superficieAuSolUlog,
|
||||
d.batie,
|
||||
d.exonere,
|
||||
d.batimentExonere,
|
||||
d.uniteLogementExonere,
|
||||
d.valeurLocativeAdm,
|
||||
d.montantLoyerAnnuel,
|
||||
d.tfuMetreCarre,
|
||||
d.tfuMinimum,
|
||||
d.standingBat,
|
||||
d.categorieBat,
|
||||
d.nombrePiscine,
|
||||
d.nombreUlog,
|
||||
d.nombreBat,
|
||||
d.dateEnquete,
|
||||
s.id,
|
||||
z.id,
|
||||
d.valeurAdminParcelleNb,
|
||||
d.natureImpot,
|
||||
s.code,
|
||||
z.nom,
|
||||
d.valeurBatiment,
|
||||
d.valeurParcelle,
|
||||
d.valeurLocativeAdmMetreCarre,
|
||||
d.valeurAdminParcelleNbMetreCarre,
|
||||
d.montantTaxe
|
||||
)
|
||||
FROM DonneesImpositionTfu d
|
||||
JOIN d.impositionsTfu itfu
|
||||
JOIN d.parcelleImposee parc
|
||||
JOIN parc.quartier quart
|
||||
LEFT join d.structure s
|
||||
LEFT join d.zoneRfu z
|
||||
WHERE d.personne.id = :personneId
|
||||
order by d.nomProp,d.nomProp asc
|
||||
""")
|
||||
List<DonneesImpositionPaylaodWeb> findAllByPersonneId(
|
||||
@Param("personneId") Long personneId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -480,89 +480,36 @@ public interface EnqueteBatimentRepository extends JpaRepository<EnqueteBatiment
|
||||
);
|
||||
|
||||
|
||||
// @Query(
|
||||
// value = """
|
||||
// SELECT DISTINCT
|
||||
// d.id AS departement_id,
|
||||
// d.code AS departement_code,
|
||||
// d.nom AS departement_nom,
|
||||
// COUNT(eb.id) OVER (PARTITION BY d.id) AS nb_enquetes_departement,
|
||||
//
|
||||
// c.id AS commune_id,
|
||||
// c.code AS commune_code,
|
||||
// c.nom AS commune_nom,
|
||||
// COUNT(eb.id) OVER (PARTITION BY c.id) AS nb_enquetes_commune,
|
||||
//
|
||||
// a.id AS arrondissement_id,
|
||||
// a.code AS arrondissement_code,
|
||||
// a.nom AS arrondissement_nom,
|
||||
// COUNT(eb.id) OVER (PARTITION BY a.id) AS nb_enquetes_arrondissement,
|
||||
//
|
||||
// q.id AS quartier_id,
|
||||
// q.code AS quartier_code,
|
||||
// q.nom AS quartier_nom,
|
||||
// COUNT(eb.id) OVER (PARTITION BY q.id) AS nb_enquetes_quartier
|
||||
//
|
||||
// FROM enquete_batiment eb
|
||||
// JOIN batiment b ON b.id = eb.batiment_id
|
||||
// JOIN parcelle p ON p.id = b.parcelle_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
|
||||
//
|
||||
// WHERE EXISTS (
|
||||
// SELECT 1
|
||||
// FROM secteur_decoupage sd
|
||||
// WHERE sd.quartier_id = q.id
|
||||
// AND sd.secteur_id IN (:secteurIds)
|
||||
// )
|
||||
// AND eb.statut_enquete = :statutEnqueteParam
|
||||
//
|
||||
// ORDER BY d.nom, c.nom, a.nom, q.nom;
|
||||
// """,
|
||||
// nativeQuery = true
|
||||
// )
|
||||
// List<ParcelleStatsProjectionUnSecteur> findStatsEnqueteBatimentBySecteurs(
|
||||
// @Param("secteurIds") List<Long> secteurIds,
|
||||
// @Param("statutEnqueteParam") String statutEnqueteParam
|
||||
// );
|
||||
|
||||
|
||||
@Query(
|
||||
value = """
|
||||
SELECT DISTINCT
|
||||
SELECT DISTINCT
|
||||
d.id AS departement_id,
|
||||
d.code AS departement_code,
|
||||
d.nom AS departement_nom,
|
||||
COUNT(eb.id) OVER (PARTITION BY d.id) AS nbParcellesDepartement,
|
||||
COUNT(e.id) OVER (PARTITION BY d.id) AS nb_enquetes_departement,
|
||||
|
||||
c.id AS commune_id,
|
||||
c.code AS commune_code,
|
||||
c.nom AS commune_nom,
|
||||
COUNT(eb.id) OVER (PARTITION BY c.id) AS nbParcellesCommune,
|
||||
COUNT(e.id) OVER (PARTITION BY c.id) AS nb_enquetes_commune,
|
||||
|
||||
a.id AS arrondissement_id,
|
||||
a.code AS arrondissement_code,
|
||||
a.nom AS arrondissement_nom,
|
||||
COUNT(eb.id) OVER (PARTITION BY a.id) AS nbParcellesArrondissement,
|
||||
COUNT(e.id) OVER (PARTITION BY a.id) AS nb_enquetes_arrondissement,
|
||||
|
||||
q.id AS quartier_id,
|
||||
q.code AS quartier_code,
|
||||
q.nom AS quartier_nom,
|
||||
COUNT(eb.id) OVER (PARTITION BY q.id) AS nbParcellesQuartier
|
||||
COUNT(e.id) OVER (PARTITION BY q.id) AS nb_enquetes_quartier
|
||||
|
||||
FROM quartier q
|
||||
FROM enquete_batiment eb
|
||||
JOIN batiment b ON b.id = eb.batiment_id
|
||||
JOIN parcelle p ON p.id = b.parcelle_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 parcelle p ON p.quartier_id = q.id
|
||||
JOIN batiment b ON b.parcelle_id = p.id
|
||||
|
||||
-- LEFT JOIN ici
|
||||
LEFT JOIN enquete_batiment eb
|
||||
ON eb.batiment_id = b.id
|
||||
AND eb.statut_enquete = :statutEnqueteParam
|
||||
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
@@ -570,6 +517,7 @@ public interface EnqueteBatimentRepository extends JpaRepository<EnqueteBatiment
|
||||
WHERE sd.quartier_id = q.id
|
||||
AND sd.secteur_id IN (:secteurIds)
|
||||
)
|
||||
AND e.statut_enquete = :statutEnqueteParam
|
||||
|
||||
ORDER BY d.nom, c.nom, a.nom, q.nom;
|
||||
""",
|
||||
|
||||
@@ -602,104 +602,55 @@ public interface EnqueteUniteLogementRepository extends JpaRepository<EnqueteUni
|
||||
);
|
||||
|
||||
|
||||
// @Query(
|
||||
// value = """
|
||||
// SELECT DISTINCT
|
||||
// d.id AS departement_id,
|
||||
// d.code AS departement_code,
|
||||
// d.nom AS departement_nom,
|
||||
// COUNT(eul.id) OVER (PARTITION BY d.id) AS nb_enquetes_departement,
|
||||
//
|
||||
// c.id AS commune_id,
|
||||
// c.code AS commune_code,
|
||||
// c.nom AS commune_nom,
|
||||
// COUNT(eul.id) OVER (PARTITION BY c.id) AS nb_enquetes_commune,
|
||||
//
|
||||
// a.id AS arrondissement_id,
|
||||
// a.code AS arrondissement_code,
|
||||
// a.nom AS arrondissement_nom,
|
||||
// COUNT(eul.id) OVER (PARTITION BY a.id) AS nb_enquetes_arrondissement,
|
||||
//
|
||||
// q.id AS quartier_id,
|
||||
// q.code AS quartier_code,
|
||||
// q.nom AS quartier_nom,
|
||||
// COUNT(eul.id) OVER (PARTITION BY q.id) AS nb_enquetes_quartier
|
||||
//
|
||||
// FROM enquete_unite_logement eul
|
||||
// JOIN unite_logement ul on ul.id = eul.unite_logement_id
|
||||
// JOIN batiment b ON b.id = ul.batiment_id
|
||||
// JOIN parcelle p ON p.id = b.parcelle_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
|
||||
//
|
||||
// WHERE EXISTS (
|
||||
// SELECT 1
|
||||
// FROM secteur_decoupage sd
|
||||
// WHERE sd.quartier_id = q.id
|
||||
// AND sd.secteur_id IN (:secteurIds)
|
||||
// )
|
||||
// AND eul.statut_enquete = :statutEnqueteParam
|
||||
//
|
||||
// ORDER BY d.nom, c.nom, a.nom, q.nom;
|
||||
// """,
|
||||
// nativeQuery = true
|
||||
// )
|
||||
// List<ParcelleStatsProjectionUnSecteur> findStatsEnqueteBatimentBySecteurs(
|
||||
// @Param("secteurIds") List<Long> secteurIds,
|
||||
// @Param("statutEnqueteParam") String statutEnqueteParam
|
||||
// );
|
||||
@Query(
|
||||
value = """
|
||||
SELECT DISTINCT
|
||||
d.id AS departementId,
|
||||
d.code AS departementCode,
|
||||
d.nom AS departementNom,
|
||||
COUNT(eul.id) OVER (PARTITION BY d.id) AS nbParcellesDepartement,
|
||||
@Query(
|
||||
value = """
|
||||
SELECT DISTINCT
|
||||
d.id AS departement_id,
|
||||
d.code AS departement_code,
|
||||
d.nom AS departement_nom,
|
||||
COUNT(e.id) OVER (PARTITION BY d.id) AS nb_enquetes_departement,
|
||||
|
||||
c.id AS communeId,
|
||||
c.code AS communeCode,
|
||||
c.nom AS communeNom,
|
||||
COUNT(eul.id) OVER (PARTITION BY c.id) AS nbParcellesCommune,
|
||||
c.id AS commune_id,
|
||||
c.code AS commune_code,
|
||||
c.nom AS commune_nom,
|
||||
COUNT(e.id) OVER (PARTITION BY c.id) AS nb_enquetes_commune,
|
||||
|
||||
a.id AS arrondissementId,
|
||||
a.code AS arrondissementCode,
|
||||
a.nom AS arrondissementNom,
|
||||
COUNT(eul.id) OVER (PARTITION BY a.id) AS nbParcellesArrondissement,
|
||||
a.id AS arrondissement_id,
|
||||
a.code AS arrondissement_code,
|
||||
a.nom AS arrondissement_nom,
|
||||
COUNT(e.id) OVER (PARTITION BY a.id) AS nb_enquetes_arrondissement,
|
||||
|
||||
q.id AS quartierId,
|
||||
q.code AS quartierCode,
|
||||
q.nom AS quartierNom,
|
||||
COUNT(eul.id) OVER (PARTITION BY q.id) AS nbParcellesQuartier
|
||||
q.id AS quartier_id,
|
||||
q.code AS quartier_code,
|
||||
q.nom AS quartier_nom,
|
||||
COUNT(e.id) OVER (PARTITION BY q.id) AS nb_enquetes_quartier
|
||||
|
||||
FROM quartier q
|
||||
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 parcelle p ON p.quartier_id = q.id
|
||||
JOIN batiment b ON b.parcelle_id = p.id
|
||||
JOIN unite_logement ul ON ul.batiment_id = b.id
|
||||
FROM enquete_unite_logement eul
|
||||
JOIN unite_logement ul on ul.id = eul.unite_logement_id
|
||||
JOIN batiment b ON b.id = ul.batiment_id
|
||||
JOIN parcelle p ON p.id = b.parcelle_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
|
||||
|
||||
LEFT JOIN enquete_unite_logement eul
|
||||
ON eul.unite_logement_id = ul.id
|
||||
AND eul.statut_enquete = :statutEnqueteParam
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM secteur_decoupage sd
|
||||
WHERE sd.quartier_id = q.id
|
||||
AND sd.secteur_id IN (:secteurIds)
|
||||
)
|
||||
AND e.statut_enquete = :statutEnqueteParam
|
||||
|
||||
WHERE EXISTS (
|
||||
SELECT 1
|
||||
FROM secteur_decoupage sd
|
||||
WHERE sd.quartier_id = q.id
|
||||
AND sd.secteur_id IN (:secteurIds)
|
||||
)
|
||||
ORDER BY d.nom, c.nom, a.nom, q.nom;
|
||||
""",
|
||||
nativeQuery = true
|
||||
)
|
||||
List<ParcelleStatsProjectionUnSecteur> findStatsEnqueteBatimentBySecteurs(
|
||||
@Param("secteurIds") List<Long> secteurIds,
|
||||
@Param("statutEnqueteParam") String statutEnqueteParam
|
||||
);
|
||||
|
||||
ORDER BY d.nom, c.nom, a.nom, q.nom
|
||||
""",
|
||||
nativeQuery = true
|
||||
)
|
||||
List<ParcelleStatsProjectionUnSecteur> findStatsEnqueteBatimentBySecteurs(
|
||||
@Param("secteurIds") List<Long> secteurIds,
|
||||
@Param("statutEnqueteParam") String statutEnqueteParam
|
||||
);
|
||||
|
||||
|
||||
@Query(
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface ImpositionsTfuRepository extends JpaRepository<ImpositionsTfu,
|
||||
" inner join commune c on c.id=i.commune_id" +
|
||||
" inner join exercice e on e.id=i.exercice_id" +
|
||||
" inner join structure s on s.id=i.structure_id" +
|
||||
" where status_avis in ('EN_COURS','CLOTURE','TFU_FNB_GENERE','GENERATION_AUTORISE','GENERE') " +
|
||||
" where status_avis in ('VALIDE','CREE','GENERE') " +
|
||||
" and s.id= ?1 and e.id = ?2 " +
|
||||
" and i.deleted is false ", nativeQuery = true)
|
||||
List<ImpositionsTfu> getImpositionsTfuByStructureAndExercice(Long structureId,Long exerciceId);
|
||||
|
||||
@@ -74,7 +74,6 @@ public class EntityFromPayLoadService {
|
||||
private final RueRepository rueRepository ;
|
||||
private final NatureDomaineRepository natureDomaineRepository ;
|
||||
private final TypeDomaineRepository typeDomaineRepository ;
|
||||
private final CommuneCentreAssignationRepository communeCentreAssignationRepository ;
|
||||
|
||||
|
||||
public CaracteristiqueParcelle getCaracteristiqueParcelleFromPayLoadWeb(CaracteristiqueParcellePayloadWeb caracteristiqueParcellePayloadWeb){
|
||||
@@ -211,11 +210,6 @@ public class EntityFromPayLoadService {
|
||||
declarationNc.setStructure(optionalStructure.orElse(null));
|
||||
declarationNc.setPersonne(optionalPersonne.orElse(null));
|
||||
declarationNc.setNc(declarationNcPayloadWeb.getNc());
|
||||
declarationNc.setQ(declarationNcPayloadWeb.getQ());
|
||||
declarationNc.setI(declarationNcPayloadWeb.getI());
|
||||
declarationNc.setP(declarationNcPayloadWeb.getP());
|
||||
declarationNc.setNumeroTitreFoncier(declarationNcPayloadWeb.getNumeroTitreFoncier());
|
||||
declarationNc.setNup(declarationNcPayloadWeb.getNup());
|
||||
declarationNc.setDateDerniereDeclaration(declarationNcPayloadWeb.getDateDerniereDeclaration());
|
||||
declarationNc.setDateDeclarationNc(declarationNcPayloadWeb.getDateDeclarationNc());
|
||||
return declarationNc ;
|
||||
@@ -1003,38 +997,4 @@ public class EntityFromPayLoadService {
|
||||
parcelle.setSuperficie(parcellePayLoadWeb.getSuperficie());
|
||||
return parcelle;
|
||||
}
|
||||
|
||||
public CommuneCentreAssignation getCommuneCentreAssignationFromPayLoadWeb(CommuneCentreAssignationPaylaodWeb communeCentreAssignationPaylaodWeb) {
|
||||
CommuneCentreAssignation communeCentreAssignation = new CommuneCentreAssignation();
|
||||
if (communeCentreAssignationPaylaodWeb.getId()!=null)
|
||||
communeCentreAssignation=communeCentreAssignationRepository.findById(communeCentreAssignationPaylaodWeb.getId()).orElse(new CommuneCentreAssignation());
|
||||
|
||||
if (communeCentreAssignationPaylaodWeb.getPersonneId() != null) {
|
||||
Personne personne = new Personne();
|
||||
personne.setId(communeCentreAssignationPaylaodWeb.getPersonneId());
|
||||
communeCentreAssignation.setPersonne(personne);
|
||||
}
|
||||
|
||||
communeCentreAssignation.setAdresseContact(communeCentreAssignationPaylaodWeb.getAdresseContact());
|
||||
|
||||
// if (communeCentreAssignationPaylaodWeb.getCommuneId() != null) {
|
||||
// Commune commune = new Commune();
|
||||
// commune.setId(communeCentreAssignationPaylaodWeb.getCommuneId());
|
||||
// communeCentreAssignation.setCommune(commune);
|
||||
// }
|
||||
|
||||
// if (communeCentreAssignationPaylaodWeb.getStructureId() != null) {
|
||||
// Structure structure = new Structure();
|
||||
// structure.setId(communeCentreAssignationPaylaodWeb.getStructureId());
|
||||
// communeCentreAssignation.setStructure(structure);
|
||||
// }
|
||||
|
||||
if (communeCentreAssignationPaylaodWeb.getParcelleContactId() != null) {
|
||||
Parcelle parcelle = new Parcelle();
|
||||
parcelle.setId(communeCentreAssignationPaylaodWeb.getParcelleContactId());
|
||||
communeCentreAssignation.setParcelle(parcelle);
|
||||
}
|
||||
|
||||
return communeCentreAssignation;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user