Compare commits
2 Commits
41e55da1df
...
e2468328fd
| Author | SHA1 | Date | |
|---|---|---|---|
| e2468328fd | |||
| d06d6336de |
@@ -247,4 +247,28 @@ public class BatimentController {
|
|||||||
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/all/by-quartier-id/{quartierId}")
|
||||||
|
public ResponseEntity<?> getAllBatimentByQuartier(@PathVariable Long quartierId) {
|
||||||
|
try {
|
||||||
|
return new ResponseEntity<>(
|
||||||
|
new ApiResponse<>(true, batimentService.getBatimentListByquartier(quartierId), "Liste des batiments chargée avec succès."),
|
||||||
|
HttpStatus.OK
|
||||||
|
);
|
||||||
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
||||||
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
||||||
|
FileStorageException e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,4 +273,28 @@ public class UniteLogementController {
|
|||||||
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/all/by-quartier-id/{quartierId}")
|
||||||
|
public ResponseEntity<?> getAllUniteLogementByQuartier(@PathVariable Long quartierId) {
|
||||||
|
try {
|
||||||
|
return new ResponseEntity<>(
|
||||||
|
new ApiResponse<>(true, enqueteUniteLogementService.getUniteLogementListByQuartier(quartierId), "Liste des unites de logements chargée avec succès."),
|
||||||
|
HttpStatus.OK
|
||||||
|
);
|
||||||
|
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
||||||
|
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
||||||
|
FileStorageException e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error(e.getLocalizedMessage());
|
||||||
|
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ public class DonneesImpositionTfu extends BaseEntity implements Serializable {
|
|||||||
private String latitude;
|
private String latitude;
|
||||||
private int superficieParc;
|
private int superficieParc;
|
||||||
private Long superficieAuSolBat;
|
private Long superficieAuSolBat;
|
||||||
|
private Long superficieAuSolLoue;
|
||||||
private Long superficieAuSolUlog;
|
private Long superficieAuSolUlog;
|
||||||
private Boolean batie;
|
private Boolean batie;
|
||||||
private Boolean exonere;
|
private Boolean exonere;
|
||||||
|
|||||||
@@ -2,5 +2,6 @@ package io.gmss.fiscad.enums;
|
|||||||
|
|
||||||
public enum NatureImpot {
|
public enum NatureImpot {
|
||||||
TFU,
|
TFU,
|
||||||
IRF
|
IRF,
|
||||||
|
SRTB
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,5 +16,7 @@ public enum ParametersType {
|
|||||||
TAUX_TFU,
|
TAUX_TFU,
|
||||||
TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE,
|
TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE,
|
||||||
TAUX_DEFAUT_SUPERFICIE_AU_SOL,
|
TAUX_DEFAUT_SUPERFICIE_AU_SOL,
|
||||||
|
TAUX_IRF,
|
||||||
|
TAXE_SRTB,
|
||||||
TFU_PAR_PISCINE;
|
TFU_PAR_PISCINE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ package io.gmss.fiscad.enums;
|
|||||||
|
|
||||||
public enum StatusAvis {
|
public enum StatusAvis {
|
||||||
EN_COURS,
|
EN_COURS,
|
||||||
|
|
||||||
CLOTURE,
|
CLOTURE,
|
||||||
GENERATION_AUTORISE,
|
GENERATION_AUTORISE,
|
||||||
|
|
||||||
REJETE,
|
REJETE,
|
||||||
TFU_FNB_GENERE,
|
TFU_FNB_GENERE,
|
||||||
GENERE
|
GENERE
|
||||||
|
|||||||
@@ -123,4 +123,9 @@ public class BatimentServiceImpl implements BatimentService {
|
|||||||
public Page<BatimentPaylaodWeb> getBatimentListByquartierPageable(Long quartierId, Pageable pageable) {
|
public Page<BatimentPaylaodWeb> getBatimentListByquartierPageable(Long quartierId, Pageable pageable) {
|
||||||
return batimentRepository.findAllBatimentsAvecOccupantCourantByQuartierToDtoPageble(quartierId,pageable);
|
return batimentRepository.findAllBatimentsAvecOccupantCourantByQuartierToDtoPageble(quartierId,pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BatimentPaylaodWeb> getBatimentListByquartier(Long quartierId) {
|
||||||
|
return batimentRepository.findAllBatimentsAvecOccupantCourantByQuartierToDto(quartierId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,6 +117,14 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ
|
|||||||
|
|
||||||
Integer nbulo= donneesImpositionTfuRepository.genererDonneesTfuBatieUniteLogement(impositionsTfuPaylaodWeb.getId(),userId);
|
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);
|
||||||
|
|
||||||
|
Integer nbsrtbulo= donneesImpositionTfuRepository.genererDonneesSrtbBatieUniteLogement(impositionsTfuPaylaodWeb.getId(),userId);
|
||||||
|
|
||||||
|
|
||||||
ImpositionsTfu impositionsTfu = entityFromPayLoadService.getImpositionsTfuFromPayLoadWeb(impositionsTfuPaylaodWeb);
|
ImpositionsTfu impositionsTfu = entityFromPayLoadService.getImpositionsTfuFromPayLoadWeb(impositionsTfuPaylaodWeb);
|
||||||
impositionsTfu.setStatusAvis(StatusAvis.GENERE);
|
impositionsTfu.setStatusAvis(StatusAvis.GENERE);
|
||||||
@@ -165,6 +173,26 @@ public class DonneesImpositionTfuServiceImpl implements DonneesImpositionTfuServ
|
|||||||
return donneesImpositionTfuRepository.findAllByImpositionTfuIdBatieUniteLogPageable(impositionsTfuId,pageable);
|
return donneesImpositionTfuRepository.findAllByImpositionTfuIdBatieUniteLogPageable(impositionsTfuId,pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionIrfIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionIrfIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionSrtbIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionSrtbIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByExerciceAndStructureIdPageable(Long exerciceId, Long structureId, Pageable pageable) {
|
public Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByExerciceAndStructureIdPageable(Long exerciceId, Long structureId, Pageable pageable) {
|
||||||
return donneesImpositionTfuRepository.findAllByExericeIdStructureIdPageable(exerciceId,structureId,pageable);
|
return donneesImpositionTfuRepository.findAllByExericeIdStructureIdPageable(exerciceId,structureId,pageable);
|
||||||
|
|||||||
@@ -116,4 +116,9 @@ public class UniteLogementServiceImpl implements UniteLogementService {
|
|||||||
public Page<UniteLogementPaylaodWeb> getUniteLogementListByQuartierPageable(Long quartierId, Pageable pageable) {
|
public Page<UniteLogementPaylaodWeb> getUniteLogementListByQuartierPageable(Long quartierId, Pageable pageable) {
|
||||||
return uniteLogementRepository.findUnitesLogementAvecOccupantCourantByQuartierToDtoPageable(quartierId,pageable);
|
return uniteLogementRepository.findUnitesLogementAvecOccupantCourantByQuartierToDtoPageable(quartierId,pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UniteLogementPaylaodWeb> getUniteLogementListByQuartier(Long quartierId) {
|
||||||
|
return uniteLogementRepository.findUnitesLogementAvecOccupantCourantByQuartierToDto(quartierId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,4 +31,6 @@ public interface BatimentService {
|
|||||||
|
|
||||||
Page<BatimentPaylaodWeb> getBatimentListByquartierPageable(Long quartierId, Pageable pageable);
|
Page<BatimentPaylaodWeb> getBatimentListByquartierPageable(Long quartierId, Pageable pageable);
|
||||||
|
|
||||||
|
List<BatimentPaylaodWeb> getBatimentListByquartier(Long quartierId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,13 @@ public interface DonneesImpositionTfuService {
|
|||||||
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdNonBatiePageable(Long impositionsTfuId, Pageable pageable);
|
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdNonBatiePageable(Long impositionsTfuId, Pageable pageable);
|
||||||
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable);
|
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable);
|
||||||
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable);
|
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionTfuIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable);
|
||||||
|
|
||||||
|
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionIrfIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable);
|
||||||
|
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionIrfIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable);
|
||||||
|
|
||||||
|
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionSrtbIdBatieBatimentPageable(Long impositionsTfuId, Pageable pageable);
|
||||||
|
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByImpositionSrtbIdBatieUniteLogPageable(Long impositionsTfuId, Pageable pageable);
|
||||||
|
|
||||||
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByExerciceAndStructureIdPageable(Long exerciceId, Long structureId, Pageable pageable);
|
Page<DonneesImpositionPaylaodWeb> getDonneesFiscalesByExerciceAndStructureIdPageable(Long exerciceId, Long structureId, Pageable pageable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,6 @@ public interface UniteLogementService {
|
|||||||
|
|
||||||
Page<UniteLogementPaylaodWeb> getUniteLogementListByQuartierPageable(Long quartierId, Pageable pageable);
|
Page<UniteLogementPaylaodWeb> getUniteLogementListByQuartierPageable(Long quartierId, Pageable pageable);
|
||||||
|
|
||||||
|
List<UniteLogementPaylaodWeb> getUniteLogementListByQuartier(Long quartierId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,295 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie(
|
||||||
|
p_impositions_tfu_id BIGINT,
|
||||||
|
p_user_id BIGINT
|
||||||
|
)
|
||||||
|
RETURNS INTEGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
DECLARE
|
||||||
|
v_rows_inserted INTEGER;
|
||||||
|
v_annee BIGINT;
|
||||||
|
v_structure_id BIGINT;
|
||||||
|
v_taux_defaut_sup_sol NUMERIC;
|
||||||
|
v_taux_valeur_locat_prof NUMERIC;
|
||||||
|
v_tfu_piscine_unitaire NUMERIC;
|
||||||
|
v_taux_irf NUMERIC;
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
-- récupération de l'année
|
||||||
|
SELECT ex.annee, it.structure_id
|
||||||
|
INTO STRICT v_annee, v_structure_id
|
||||||
|
FROM impositions_tfu it
|
||||||
|
join exercice ex on ex.id =it.exercice_id
|
||||||
|
WHERE it.id = p_impositions_tfu_id;
|
||||||
|
|
||||||
|
|
||||||
|
select value
|
||||||
|
into strict v_taux_defaut_sup_sol
|
||||||
|
from parameters
|
||||||
|
where name ='TAUX_DEFAUT_SUPERFICIE_AU_SOL';
|
||||||
|
|
||||||
|
select value
|
||||||
|
into STRICT v_taux_irf
|
||||||
|
from parameters
|
||||||
|
where name ='TAUX_IRF';
|
||||||
|
|
||||||
|
|
||||||
|
select value
|
||||||
|
into STRICT v_taux_valeur_locat_prof
|
||||||
|
from parameters
|
||||||
|
where name ='TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE';
|
||||||
|
|
||||||
|
select value
|
||||||
|
into STRICT v_tfu_piscine_unitaire
|
||||||
|
from parameters
|
||||||
|
where name ='TFU_PAR_PISCINE';
|
||||||
|
|
||||||
|
INSERT INTO donnees_imposition_tfu(
|
||||||
|
annee,
|
||||||
|
code_departement,
|
||||||
|
nom_departement,
|
||||||
|
code_commune,
|
||||||
|
nom_commune,
|
||||||
|
code_arrondissement,
|
||||||
|
nom_arrondissement,
|
||||||
|
code_quartier_village,
|
||||||
|
nom_quartier_village,
|
||||||
|
q,
|
||||||
|
ilot,
|
||||||
|
parcelle,
|
||||||
|
nup,
|
||||||
|
titre_foncier,
|
||||||
|
num_batiment,
|
||||||
|
ifu,
|
||||||
|
npi,
|
||||||
|
tel_prop,
|
||||||
|
email_prop,
|
||||||
|
nom_prop,
|
||||||
|
prenom_prop,
|
||||||
|
raison_sociale,
|
||||||
|
adresse_prop,
|
||||||
|
tel_sc,
|
||||||
|
nom_sc,
|
||||||
|
prenom_sc,
|
||||||
|
longitude,
|
||||||
|
latitude,
|
||||||
|
batie,
|
||||||
|
exonere,
|
||||||
|
batiment_exonere,
|
||||||
|
standing_bat,
|
||||||
|
categorie_bat,
|
||||||
|
nombre_piscine,
|
||||||
|
date_enquete,
|
||||||
|
structure_id,
|
||||||
|
zone_rfu_id,
|
||||||
|
nature_impot,
|
||||||
|
superficie_parc,
|
||||||
|
superficie_au_sol_bat,
|
||||||
|
valeur_batiment,
|
||||||
|
valeur_locative_adm_metre_carre,
|
||||||
|
montant_loyer_annuel,
|
||||||
|
tfu_metre_carre,
|
||||||
|
tfu_minimum,
|
||||||
|
impositions_tfu_id,
|
||||||
|
deleted,
|
||||||
|
created_at ,
|
||||||
|
created_by ,
|
||||||
|
"source",
|
||||||
|
updated_at ,
|
||||||
|
updated_by,
|
||||||
|
categorie_usage,
|
||||||
|
superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle
|
||||||
|
valeur_locative_adm_taux_prop_parc,
|
||||||
|
tfu_calcule_taux_prop_parc, ----tfu correspondant au 70%
|
||||||
|
valeur_locative_adm_sup_reel,
|
||||||
|
valeur_locative_adm, ----------valeur locative administrative
|
||||||
|
tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle
|
||||||
|
tfu_piscine,
|
||||||
|
montant_taxe, ----tfu finale
|
||||||
|
taux_tfu, ----taux tfu batie
|
||||||
|
parcelle_id,
|
||||||
|
batiment_id,
|
||||||
|
unite_logement_id,
|
||||||
|
superficie_au_sol_loue
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
v_annee,
|
||||||
|
d.code,
|
||||||
|
d.nom,
|
||||||
|
c.code,
|
||||||
|
c.nom,
|
||||||
|
a.code,
|
||||||
|
a.nom,
|
||||||
|
q.code,
|
||||||
|
q.nom,
|
||||||
|
p.q,
|
||||||
|
p.i,
|
||||||
|
p.p,
|
||||||
|
p.nup,
|
||||||
|
ep.numero_titre_foncier,
|
||||||
|
b.nub,
|
||||||
|
pers.ifu,
|
||||||
|
pers.npi,
|
||||||
|
pers.tel1,
|
||||||
|
pers.email,
|
||||||
|
pers.nom,
|
||||||
|
pers.prenom,
|
||||||
|
pers.raison_sociale,
|
||||||
|
pers.adresse,
|
||||||
|
ep.representant_tel,
|
||||||
|
ep.representant_nom,
|
||||||
|
ep.representant_prenom,
|
||||||
|
p.longitude,
|
||||||
|
p.latitude,
|
||||||
|
TRUE,
|
||||||
|
(
|
||||||
|
CURRENT_DATE >= ep.date_debut_exemption
|
||||||
|
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
|
||||||
|
),
|
||||||
|
(
|
||||||
|
CURRENT_DATE >= eb.date_debut_excemption
|
||||||
|
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
|
||||||
|
),
|
||||||
|
cb.standing,
|
||||||
|
cb.nom,
|
||||||
|
eb.nombre_piscine,
|
||||||
|
eb.date_enquete,
|
||||||
|
st.id,
|
||||||
|
ep.zone_rfu_id,
|
||||||
|
'IRF',
|
||||||
|
p.superficie,
|
||||||
|
eb.superficie_au_sol,
|
||||||
|
case -------valeur_batiment
|
||||||
|
WHEN eb.valeur_batiment_reel IS NOT NULL AND eb.valeur_batiment_reel <> 0 THEN eb.valeur_batiment_reel
|
||||||
|
WHEN eb.valeur_batiment_calcule IS NOT NULL AND eb.valeur_batiment_calcule <> 0 THEN eb.valeur_batiment_calcule
|
||||||
|
WHEN eb.valeur_batiment_estime IS NOT NULL AND eb.valeur_batiment_estime <> 0 THEN eb.valeur_batiment_estime
|
||||||
|
ELSE 0
|
||||||
|
END,
|
||||||
|
brb.valeur_locative,
|
||||||
|
case ----- montant_loyer_annuel
|
||||||
|
WHEN eb.montant_locatif_annuel_declare IS NOT NULL AND eb.montant_locatif_annuel_declare <> 0 THEN eb.montant_locatif_annuel_declare
|
||||||
|
WHEN eb.montant_locatif_annuel_calcule IS NOT NULL AND eb.montant_locatif_annuel_calcule <> 0 THEN eb.montant_locatif_annuel_calcule
|
||||||
|
WHEN eb.montant_locatif_annuel_estime IS NOT NULL AND eb.montant_locatif_annuel_estime <> 0 THEN eb.montant_locatif_annuel_estime
|
||||||
|
ELSE 0
|
||||||
|
END,
|
||||||
|
brb.tfu_metre_carre,
|
||||||
|
brb.tfu_minimum,
|
||||||
|
p_impositions_tfu_id,
|
||||||
|
false,
|
||||||
|
current_date ,
|
||||||
|
p_user_id ,
|
||||||
|
'FISCAD',
|
||||||
|
current_date ,
|
||||||
|
p_user_id,
|
||||||
|
eb.categorie_usage,
|
||||||
|
p.superficie*v_taux_defaut_sup_sol/100,---superficie_au_sol_70pour100
|
||||||
|
(p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative,
|
||||||
|
0,
|
||||||
|
eb.superficie_au_sol * brb.valeur_locative,
|
||||||
|
0, ------ valeur_locative_adm : en attente de update
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
v_taux_irf,
|
||||||
|
p.id,
|
||||||
|
b.id,
|
||||||
|
null,
|
||||||
|
eb.superficie_louee
|
||||||
|
FROM parcelle p
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT ON (parcelle_id)
|
||||||
|
parcelle_id,
|
||||||
|
superficie,
|
||||||
|
personne_id,
|
||||||
|
numero_titre_foncier,
|
||||||
|
date_enquete,
|
||||||
|
representant_tel,
|
||||||
|
representant_nom,
|
||||||
|
representant_prenom,
|
||||||
|
representant_npi,
|
||||||
|
date_debut_exemption,
|
||||||
|
date_fin_exemption,
|
||||||
|
zone_rfu_id
|
||||||
|
FROM enquete
|
||||||
|
ORDER BY parcelle_id, date_enquete DESC, id DESC
|
||||||
|
) ep ON ep.parcelle_id = p.id
|
||||||
|
LEFT JOIN personne pers
|
||||||
|
ON pers.id = ep.personne_id
|
||||||
|
JOIN quartier q ON q.id = p.quartier_id
|
||||||
|
JOIN arrondissement a ON a.id = q.arrondissement_id
|
||||||
|
JOIN commune c ON c.id = a.commune_id
|
||||||
|
JOIN departement d ON d.id = c.departement_id
|
||||||
|
JOIN secteur_decoupage sd ON sd.quartier_id = q.id
|
||||||
|
JOIN secteur sect ON sect.id = sd.secteur_id
|
||||||
|
JOIN section ses ON ses.id = sect.section_id
|
||||||
|
JOIN "structure" st ON st.id = ses.structure_id
|
||||||
|
JOIN batiment b ON b.parcelle_id = p.id
|
||||||
|
JOIN (
|
||||||
|
SELECT DISTINCT ON (batiment_id)
|
||||||
|
batiment_id,
|
||||||
|
superficie_au_sol,
|
||||||
|
nombre_piscine,
|
||||||
|
categorie_batiment_id,
|
||||||
|
date_enquete,
|
||||||
|
montant_locatif_annuel_declare,
|
||||||
|
montant_locatif_annuel_calcule,
|
||||||
|
montant_locatif_annuel_estime,
|
||||||
|
date_debut_excemption,
|
||||||
|
date_fin_excemption,
|
||||||
|
valeur_batiment_reel,
|
||||||
|
valeur_batiment_calcule,
|
||||||
|
valeur_batiment_estime,
|
||||||
|
u.categorie_usage,
|
||||||
|
superficie_louee
|
||||||
|
FROM enquete_batiment eb
|
||||||
|
join usage u on u.id=eb.usage_id
|
||||||
|
where superficie_louee*montant_locatif_annuel_declare>0
|
||||||
|
ORDER BY batiment_id, date_enquete DESC, eb.id DESC
|
||||||
|
) eb ON eb.batiment_id = b.id
|
||||||
|
JOIN categorie_batiment cb
|
||||||
|
ON cb.id = eb.categorie_batiment_id
|
||||||
|
JOIN LATERAL (
|
||||||
|
SELECT *
|
||||||
|
FROM barem_rfu_bati br
|
||||||
|
WHERE br.categorie_batiment_id = cb.id
|
||||||
|
AND br.arrondissement_id = a.id
|
||||||
|
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
|
||||||
|
ORDER BY br.quartier_id DESC NULLS LAST
|
||||||
|
LIMIT 1
|
||||||
|
) brb ON TRUE
|
||||||
|
WHERE p.batie = TRUE
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM unite_logement ul
|
||||||
|
WHERE ul.batiment_id = b.id
|
||||||
|
)
|
||||||
|
AND st.id = v_structure_id
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
|
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||||
|
|
||||||
|
UPDATE donnees_imposition_tfu dtfu
|
||||||
|
SET
|
||||||
|
valeur_locative_adm=montant_loyer_annuel,
|
||||||
|
montant_taxe = montant_loyer_annuel * v_taux_irf/100
|
||||||
|
WHERE impositions_tfu_id = p_impositions_tfu_id
|
||||||
|
AND batie = TRUE
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM unite_logement ul
|
||||||
|
WHERE ul.batiment_id = dtfu.batiment_id
|
||||||
|
);
|
||||||
|
RETURN v_rows_inserted;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
|
||||||
|
delete from donnees_imposition_tfu;
|
||||||
|
|
||||||
|
|
||||||
|
select donnees_imposition_tfu.superficie_au_sol_loue,valeur_locative_adm,taux_tfu,montant_taxe, * from donnees_imposition_tfu
|
||||||
|
where nature_impot='IRF';
|
||||||
|
|
||||||
|
select generer_donnees_imposition_irf_batie(4,35);
|
||||||
|
|
||||||
@@ -0,0 +1,342 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_irf_batie_unite_logement(
|
||||||
|
p_impositions_tfu_id BIGINT,
|
||||||
|
p_user_id BIGINT
|
||||||
|
)
|
||||||
|
RETURNS INTEGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
DECLARE
|
||||||
|
v_rows_inserted INTEGER;
|
||||||
|
v_annee BIGINT;
|
||||||
|
v_structure_id BIGINT;
|
||||||
|
v_taux_defaut_sup_sol NUMERIC;
|
||||||
|
v_taux_irf NUMERIC;
|
||||||
|
v_taux_valeur_locat_prof NUMERIC;
|
||||||
|
v_tfu_piscine_unitaire NUMERIC;
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
-- récupération de l'année
|
||||||
|
SELECT ex.annee, it.structure_id
|
||||||
|
INTO STRICT v_annee, v_structure_id
|
||||||
|
FROM impositions_tfu it
|
||||||
|
join exercice ex on ex.id =it.exercice_id
|
||||||
|
WHERE it.id = p_impositions_tfu_id;
|
||||||
|
|
||||||
|
|
||||||
|
select value
|
||||||
|
into strict v_taux_defaut_sup_sol
|
||||||
|
from parameters
|
||||||
|
where name ='TAUX_DEFAUT_SUPERFICIE_AU_SOL';
|
||||||
|
|
||||||
|
select value
|
||||||
|
into STRICT v_taux_irf
|
||||||
|
from parameters
|
||||||
|
where name ='TAUX_IRF';
|
||||||
|
|
||||||
|
select value
|
||||||
|
into STRICT v_taux_valeur_locat_prof
|
||||||
|
from parameters
|
||||||
|
where name ='TAUX_VALEUR_LOCATIVE_PROFESSIONNELLE';
|
||||||
|
|
||||||
|
select value
|
||||||
|
into STRICT v_tfu_piscine_unitaire
|
||||||
|
from parameters
|
||||||
|
where name ='TFU_PAR_PISCINE';
|
||||||
|
|
||||||
|
INSERT INTO donnees_imposition_tfu(
|
||||||
|
annee,
|
||||||
|
code_departement,
|
||||||
|
nom_departement,
|
||||||
|
code_commune,
|
||||||
|
nom_commune,
|
||||||
|
code_arrondissement,
|
||||||
|
nom_arrondissement,
|
||||||
|
code_quartier_village,
|
||||||
|
nom_quartier_village,
|
||||||
|
q,
|
||||||
|
ilot,
|
||||||
|
parcelle,
|
||||||
|
nup,
|
||||||
|
titre_foncier,
|
||||||
|
num_batiment,
|
||||||
|
num_unite_logement,
|
||||||
|
ifu,
|
||||||
|
npi,
|
||||||
|
tel_prop,
|
||||||
|
email_prop,
|
||||||
|
nom_prop,
|
||||||
|
prenom_prop,
|
||||||
|
raison_sociale,
|
||||||
|
adresse_prop,
|
||||||
|
tel_sc,
|
||||||
|
nom_sc,
|
||||||
|
prenom_sc,
|
||||||
|
longitude,
|
||||||
|
latitude,
|
||||||
|
batie,
|
||||||
|
exonere,
|
||||||
|
batiment_exonere,
|
||||||
|
unite_logement_exonere,
|
||||||
|
standing_bat,
|
||||||
|
categorie_bat,
|
||||||
|
nombre_piscine,
|
||||||
|
date_enquete,
|
||||||
|
structure_id,
|
||||||
|
zone_rfu_id,
|
||||||
|
nature_impot,
|
||||||
|
superficie_parc,
|
||||||
|
superficie_au_sol_bat,
|
||||||
|
superficie_au_sol_ulog,
|
||||||
|
valeur_batiment,
|
||||||
|
valeur_locative_adm_metre_carre,
|
||||||
|
montant_loyer_annuel,
|
||||||
|
tfu_metre_carre,
|
||||||
|
tfu_minimum,
|
||||||
|
impositions_tfu_id,
|
||||||
|
deleted,
|
||||||
|
created_at ,
|
||||||
|
created_by ,
|
||||||
|
"source",
|
||||||
|
updated_at ,
|
||||||
|
updated_by,
|
||||||
|
categorie_usage,
|
||||||
|
superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle
|
||||||
|
valeur_locative_adm_taux_prop_parc,
|
||||||
|
tfu_calcule_taux_prop_parc, ----tfu correspondant au 70%
|
||||||
|
valeur_locative_adm_sup_reel,
|
||||||
|
valeur_locative_adm, ----------valeur locative administrative
|
||||||
|
tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle
|
||||||
|
tfu_piscine,
|
||||||
|
montant_taxe, ----tfu finale
|
||||||
|
taux_tfu, ----taux tfu batie
|
||||||
|
parcelle_id,
|
||||||
|
batiment_id,
|
||||||
|
unite_logement_id,
|
||||||
|
superficie_au_sol_loue
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
v_annee,
|
||||||
|
d.code,
|
||||||
|
d.nom,
|
||||||
|
c.code,
|
||||||
|
c.nom,
|
||||||
|
a.code,
|
||||||
|
a.nom,
|
||||||
|
q.code,
|
||||||
|
q.nom,
|
||||||
|
p.q,
|
||||||
|
p.i,
|
||||||
|
p.p,
|
||||||
|
p.nup,
|
||||||
|
ep.numero_titre_foncier,
|
||||||
|
b.nub,
|
||||||
|
ul.nul,
|
||||||
|
eul.ifu,
|
||||||
|
eul.npi,
|
||||||
|
eul.tel1,
|
||||||
|
eul.email,
|
||||||
|
eul.nom,
|
||||||
|
eul.prenom,
|
||||||
|
eul.raison_sociale,
|
||||||
|
eul.adresse,
|
||||||
|
eul.representant_tel,
|
||||||
|
eul.representant_nom,
|
||||||
|
eul.representant_prenom,
|
||||||
|
p.longitude,
|
||||||
|
p.latitude,
|
||||||
|
TRUE,
|
||||||
|
(
|
||||||
|
CURRENT_DATE >= ep.date_debut_exemption
|
||||||
|
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
|
||||||
|
),
|
||||||
|
(
|
||||||
|
CURRENT_DATE >= eb.date_debut_excemption
|
||||||
|
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
|
||||||
|
),
|
||||||
|
(
|
||||||
|
CURRENT_DATE >= eul.date_debut_exemption
|
||||||
|
AND CURRENT_DATE <= COALESCE(eul.date_fin_exemption, CURRENT_DATE)
|
||||||
|
),
|
||||||
|
cb.standing,
|
||||||
|
cb.nom,
|
||||||
|
CASE
|
||||||
|
WHEN eul.nombre_piscine is null then 0
|
||||||
|
else eul.nombre_piscine
|
||||||
|
END,
|
||||||
|
eul.date_enquete,
|
||||||
|
st.id,
|
||||||
|
ep.zone_rfu_id,
|
||||||
|
'IRF',
|
||||||
|
p.superficie,
|
||||||
|
eb.superficie_au_sol,
|
||||||
|
eul.superficie_au_sol,
|
||||||
|
CASE -------valeur_batiment
|
||||||
|
WHEN eul.valeur_unite_logement_reel IS NOT NULL AND eul.valeur_unite_logement_reel <> 0 THEN eul.valeur_unite_logement_reel
|
||||||
|
WHEN eul.valeur_unite_logement_calcule IS NOT NULL AND eul.valeur_unite_logement_calcule <> 0 THEN eul.valeur_unite_logement_calcule
|
||||||
|
WHEN eul.valeur_unite_logement_estime IS NOT NULL AND eul.valeur_unite_logement_estime <> 0 THEN eul.valeur_unite_logement_estime
|
||||||
|
ELSE 0
|
||||||
|
END,
|
||||||
|
brb.valeur_locative,
|
||||||
|
CASE ----- montant_loyer_annuel
|
||||||
|
WHEN eul.montant_locatif_annuel_declare IS NOT NULL AND eul.montant_locatif_annuel_declare <> 0 THEN eul.montant_locatif_annuel_declare
|
||||||
|
WHEN eul.montant_locatif_annuel_calcule IS NOT NULL AND eul.montant_locatif_annuel_calcule <> 0 THEN eul.montant_locatif_annuel_calcule
|
||||||
|
WHEN eul.montant_locatif_annuel_estime IS NOT NULL AND eul.montant_locatif_annuel_estime <> 0 THEN eul.montant_locatif_annuel_estime
|
||||||
|
ELSE 0
|
||||||
|
END,
|
||||||
|
brb.tfu_metre_carre,
|
||||||
|
brb.tfu_minimum,
|
||||||
|
p_impositions_tfu_id,
|
||||||
|
false,
|
||||||
|
current_date,
|
||||||
|
p_user_id,
|
||||||
|
'FISCAD',
|
||||||
|
current_date,
|
||||||
|
p_user_id,
|
||||||
|
eul.categorie_usage,
|
||||||
|
p.superficie * v_taux_defaut_sup_sol/100,---superficie_au_sol_70pour100
|
||||||
|
case ----valeur_locative_adm70pour100
|
||||||
|
when eul.categorie_usage = 'HABITATION' then (p.superficie * v_taux_defaut_sup_sol/100) * brb.valeur_locative
|
||||||
|
else 0
|
||||||
|
end,
|
||||||
|
0,
|
||||||
|
eul.superficie_au_sol * brb.valeur_locative,
|
||||||
|
0, ------ valeur_locative_adm : en attente de update
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
v_taux_irf,
|
||||||
|
p.id,
|
||||||
|
b.id,
|
||||||
|
ul.id,
|
||||||
|
eul.superficie_louee
|
||||||
|
FROM parcelle p
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT ON (parcelle_id)
|
||||||
|
parcelle_id,
|
||||||
|
superficie,
|
||||||
|
personne_id,
|
||||||
|
numero_titre_foncier,
|
||||||
|
date_enquete,
|
||||||
|
representant_tel,
|
||||||
|
representant_nom,
|
||||||
|
representant_prenom,
|
||||||
|
representant_npi,
|
||||||
|
date_debut_exemption,
|
||||||
|
date_fin_exemption,
|
||||||
|
zone_rfu_id
|
||||||
|
FROM enquete
|
||||||
|
ORDER BY parcelle_id, date_enquete DESC, id DESC
|
||||||
|
) ep ON ep.parcelle_id = p.id
|
||||||
|
LEFT JOIN personne pers
|
||||||
|
ON pers.id = ep.personne_id
|
||||||
|
JOIN quartier q ON q.id = p.quartier_id
|
||||||
|
JOIN arrondissement a ON a.id = q.arrondissement_id
|
||||||
|
JOIN commune c ON c.id = a.commune_id
|
||||||
|
JOIN departement d ON d.id = c.departement_id
|
||||||
|
JOIN secteur_decoupage sd ON sd.quartier_id = q.id
|
||||||
|
JOIN secteur sect ON sect.id = sd.secteur_id
|
||||||
|
JOIN section ses ON ses.id = sect.section_id
|
||||||
|
JOIN "structure" st ON st.id = ses.structure_id
|
||||||
|
JOIN batiment b ON b.parcelle_id = p.id
|
||||||
|
JOIN (
|
||||||
|
SELECT DISTINCT ON (batiment_id)
|
||||||
|
batiment_id,
|
||||||
|
superficie_au_sol,
|
||||||
|
nombre_piscine,
|
||||||
|
categorie_batiment_id,
|
||||||
|
date_enquete,
|
||||||
|
montant_locatif_annuel_declare,
|
||||||
|
montant_locatif_annuel_calcule,
|
||||||
|
montant_locatif_annuel_estime,
|
||||||
|
date_debut_excemption,
|
||||||
|
date_fin_excemption,
|
||||||
|
valeur_batiment_reel,
|
||||||
|
valeur_batiment_calcule,
|
||||||
|
valeur_batiment_estime,
|
||||||
|
u.categorie_usage
|
||||||
|
FROM enquete_batiment eb
|
||||||
|
join usage u on u.id=eb.usage_id
|
||||||
|
ORDER BY batiment_id, date_enquete DESC, eb.id DESC
|
||||||
|
) eb ON eb.batiment_id = b.id
|
||||||
|
JOIN unite_logement ul on ul.batiment_id = b.id
|
||||||
|
JOIN (
|
||||||
|
SELECT DISTINCT ON (eult.unite_logement_id)
|
||||||
|
eult.unite_logement_id,
|
||||||
|
pers1.id,
|
||||||
|
pers1.ifu,
|
||||||
|
pers1.npi,
|
||||||
|
pers1.tel1,
|
||||||
|
pers1.email,
|
||||||
|
pers1.nom,
|
||||||
|
pers1.prenom,
|
||||||
|
pers1.raison_sociale,
|
||||||
|
pers1.adresse,
|
||||||
|
eult.nombre_piscine,
|
||||||
|
eult.categorie_batiment_id,
|
||||||
|
eult.superficie_au_sol,
|
||||||
|
eult.superficie_louee,
|
||||||
|
eult.nbre_piece,
|
||||||
|
eult.date_enquete,
|
||||||
|
eult.montant_locatif_annuel_calcule,
|
||||||
|
eult.montant_locatif_annuel_declare,
|
||||||
|
eult.montant_locatif_annuel_estime,
|
||||||
|
eult.date_debut_exemption,
|
||||||
|
eult.date_fin_exemption,
|
||||||
|
eult.representant_nom,
|
||||||
|
eult.representant_prenom,
|
||||||
|
eult.representant_tel,
|
||||||
|
eult.valeur_unite_logement_reel,
|
||||||
|
eult.valeur_unite_logement_calcule,
|
||||||
|
eult.valeur_unite_logement_estime,
|
||||||
|
u.categorie_usage
|
||||||
|
FROM enquete_unite_logement eult
|
||||||
|
join usage u on u.id=eult.usage_id
|
||||||
|
left join personne pers1 on pers1.id = eult.personne_id
|
||||||
|
where superficie_louee*montant_locatif_annuel_declare>0
|
||||||
|
ORDER BY unite_logement_id, date_enquete DESC, eult.id DESC
|
||||||
|
) eul ON eul.unite_logement_id = ul.id
|
||||||
|
JOIN categorie_batiment cb
|
||||||
|
ON cb.id = eul.categorie_batiment_id
|
||||||
|
JOIN LATERAL (
|
||||||
|
SELECT *
|
||||||
|
FROM barem_rfu_bati br
|
||||||
|
WHERE br.categorie_batiment_id = cb.id
|
||||||
|
AND br.arrondissement_id = a.id
|
||||||
|
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
|
||||||
|
ORDER BY br.quartier_id DESC NULLS LAST
|
||||||
|
LIMIT 1
|
||||||
|
) brb ON TRUE
|
||||||
|
WHERE p.batie = TRUE
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM unite_logement ul
|
||||||
|
WHERE ul.batiment_id = b.id
|
||||||
|
)
|
||||||
|
AND st.id = v_structure_id
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
|
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||||
|
|
||||||
|
UPDATE donnees_imposition_tfu dtfu
|
||||||
|
SET
|
||||||
|
valeur_locative_adm=montant_loyer_annuel,
|
||||||
|
montant_taxe = montant_loyer_annuel * v_taux_irf/100
|
||||||
|
WHERE impositions_tfu_id = p_impositions_tfu_id
|
||||||
|
AND batie = TRUE
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM unite_logement ul
|
||||||
|
WHERE ul.batiment_id = dtfu.batiment_id
|
||||||
|
);
|
||||||
|
RETURN v_rows_inserted;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
|
||||||
|
delete from donnees_imposition_tfu;
|
||||||
|
|
||||||
|
select generer_donnees_imposition_irf_batie_unite_logement(4,35);
|
||||||
|
|
||||||
|
select donnees_imposition_tfu.superficie_au_sol_loue,valeur_locative_adm,taux_tfu,montant_taxe, * from donnees_imposition_tfu
|
||||||
|
where nature_impot='IRF';
|
||||||
@@ -0,0 +1,265 @@
|
|||||||
|
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 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;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
|
||||||
|
--delete from donnees_imposition_tfu;
|
||||||
|
|
||||||
|
|
||||||
|
select donnees_imposition_tfu.superficie_au_sol_loue,valeur_locative_adm,taux_tfu,montant_taxe, * from donnees_imposition_tfu
|
||||||
|
where nature_impot='SRTB';
|
||||||
|
|
||||||
|
select generer_donnees_imposition_srtb_batie(4,35);
|
||||||
|
|
||||||
@@ -0,0 +1,311 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_srtb_batie_unite_logement(
|
||||||
|
p_impositions_tfu_id BIGINT,
|
||||||
|
p_user_id BIGINT
|
||||||
|
)
|
||||||
|
RETURNS INTEGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
DECLARE
|
||||||
|
v_rows_inserted INTEGER;
|
||||||
|
v_annee BIGINT;
|
||||||
|
v_structure_id BIGINT;
|
||||||
|
v_montant_srtb NUMERIC;
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
-- récupération de l'année
|
||||||
|
SELECT ex.annee, it.structure_id
|
||||||
|
INTO STRICT v_annee, v_structure_id
|
||||||
|
FROM impositions_tfu it
|
||||||
|
join exercice ex on ex.id =it.exercice_id
|
||||||
|
WHERE it.id = p_impositions_tfu_id;
|
||||||
|
|
||||||
|
|
||||||
|
select value
|
||||||
|
into STRICT v_montant_srtb
|
||||||
|
from parameters
|
||||||
|
where name ='TAXE_SRTB';
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO donnees_imposition_tfu(
|
||||||
|
annee,
|
||||||
|
code_departement,
|
||||||
|
nom_departement,
|
||||||
|
code_commune,
|
||||||
|
nom_commune,
|
||||||
|
code_arrondissement,
|
||||||
|
nom_arrondissement,
|
||||||
|
code_quartier_village,
|
||||||
|
nom_quartier_village,
|
||||||
|
q,
|
||||||
|
ilot,
|
||||||
|
parcelle,
|
||||||
|
nup,
|
||||||
|
titre_foncier,
|
||||||
|
num_batiment,
|
||||||
|
num_unite_logement,
|
||||||
|
ifu,
|
||||||
|
npi,
|
||||||
|
tel_prop,
|
||||||
|
email_prop,
|
||||||
|
nom_prop,
|
||||||
|
prenom_prop,
|
||||||
|
raison_sociale,
|
||||||
|
adresse_prop,
|
||||||
|
tel_sc,
|
||||||
|
nom_sc,
|
||||||
|
prenom_sc,
|
||||||
|
longitude,
|
||||||
|
latitude,
|
||||||
|
batie,
|
||||||
|
exonere,
|
||||||
|
batiment_exonere,
|
||||||
|
unite_logement_exonere,
|
||||||
|
standing_bat,
|
||||||
|
categorie_bat,
|
||||||
|
nombre_piscine,
|
||||||
|
date_enquete,
|
||||||
|
structure_id,
|
||||||
|
zone_rfu_id,
|
||||||
|
nature_impot,
|
||||||
|
superficie_parc,
|
||||||
|
superficie_au_sol_bat,
|
||||||
|
superficie_au_sol_ulog,
|
||||||
|
valeur_batiment,
|
||||||
|
valeur_locative_adm_metre_carre,
|
||||||
|
montant_loyer_annuel,
|
||||||
|
tfu_metre_carre,
|
||||||
|
tfu_minimum,
|
||||||
|
impositions_tfu_id,
|
||||||
|
deleted,
|
||||||
|
created_at ,
|
||||||
|
created_by ,
|
||||||
|
"source",
|
||||||
|
updated_at ,
|
||||||
|
updated_by,
|
||||||
|
categorie_usage,
|
||||||
|
superficie_au_sol_taux_prop_parc, ---70% de la surperficie au sol de la parcelle
|
||||||
|
valeur_locative_adm_taux_prop_parc,
|
||||||
|
tfu_calcule_taux_prop_parc, ----tfu correspondant au 70%
|
||||||
|
valeur_locative_adm_sup_reel,
|
||||||
|
valeur_locative_adm, ----------valeur locative administrative
|
||||||
|
tfu_superficie_au_sol_reel, ----tfu correspondant à la superficie au sol reelle
|
||||||
|
tfu_piscine,
|
||||||
|
montant_taxe, ----tfu finale
|
||||||
|
taux_tfu, ----taux tfu batie
|
||||||
|
parcelle_id,
|
||||||
|
batiment_id,
|
||||||
|
unite_logement_id,
|
||||||
|
superficie_au_sol_loue
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
v_annee,
|
||||||
|
d.code,
|
||||||
|
d.nom,
|
||||||
|
c.code,
|
||||||
|
c.nom,
|
||||||
|
a.code,
|
||||||
|
a.nom,
|
||||||
|
q.code,
|
||||||
|
q.nom,
|
||||||
|
p.q,
|
||||||
|
p.i,
|
||||||
|
p.p,
|
||||||
|
p.nup,
|
||||||
|
ep.numero_titre_foncier,
|
||||||
|
b.nub,
|
||||||
|
ul.nul,
|
||||||
|
eul.ifu,
|
||||||
|
eul.npi,
|
||||||
|
eul.tel1,
|
||||||
|
eul.email,
|
||||||
|
eul.nom,
|
||||||
|
eul.prenom,
|
||||||
|
eul.raison_sociale,
|
||||||
|
eul.adresse,
|
||||||
|
eul.representant_tel,
|
||||||
|
eul.representant_nom,
|
||||||
|
eul.representant_prenom,
|
||||||
|
p.longitude,
|
||||||
|
p.latitude,
|
||||||
|
TRUE,
|
||||||
|
(
|
||||||
|
CURRENT_DATE >= ep.date_debut_exemption
|
||||||
|
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
|
||||||
|
),
|
||||||
|
(
|
||||||
|
CURRENT_DATE >= eb.date_debut_excemption
|
||||||
|
AND CURRENT_DATE <= COALESCE(eb.date_fin_excemption, CURRENT_DATE)
|
||||||
|
),
|
||||||
|
(
|
||||||
|
CURRENT_DATE >= eul.date_debut_exemption
|
||||||
|
AND CURRENT_DATE <= COALESCE(eul.date_fin_exemption, CURRENT_DATE)
|
||||||
|
),
|
||||||
|
cb.standing,
|
||||||
|
cb.nom,
|
||||||
|
CASE
|
||||||
|
WHEN eul.nombre_piscine is null then 0
|
||||||
|
else eul.nombre_piscine
|
||||||
|
END,
|
||||||
|
eul.date_enquete,
|
||||||
|
st.id,
|
||||||
|
ep.zone_rfu_id,
|
||||||
|
'IRF',
|
||||||
|
p.superficie,
|
||||||
|
eb.superficie_au_sol,
|
||||||
|
eul.superficie_au_sol,
|
||||||
|
CASE -------valeur_batiment
|
||||||
|
WHEN eul.valeur_unite_logement_reel IS NOT NULL AND eul.valeur_unite_logement_reel <> 0 THEN eul.valeur_unite_logement_reel
|
||||||
|
WHEN eul.valeur_unite_logement_calcule IS NOT NULL AND eul.valeur_unite_logement_calcule <> 0 THEN eul.valeur_unite_logement_calcule
|
||||||
|
WHEN eul.valeur_unite_logement_estime IS NOT NULL AND eul.valeur_unite_logement_estime <> 0 THEN eul.valeur_unite_logement_estime
|
||||||
|
ELSE 0
|
||||||
|
END,
|
||||||
|
brb.valeur_locative,
|
||||||
|
CASE ----- montant_loyer_annuel
|
||||||
|
WHEN eul.montant_locatif_annuel_declare IS NOT NULL AND eul.montant_locatif_annuel_declare <> 0 THEN eul.montant_locatif_annuel_declare
|
||||||
|
WHEN eul.montant_locatif_annuel_calcule IS NOT NULL AND eul.montant_locatif_annuel_calcule <> 0 THEN eul.montant_locatif_annuel_calcule
|
||||||
|
WHEN eul.montant_locatif_annuel_estime IS NOT NULL AND eul.montant_locatif_annuel_estime <> 0 THEN eul.montant_locatif_annuel_estime
|
||||||
|
ELSE 0
|
||||||
|
END,
|
||||||
|
brb.tfu_metre_carre,
|
||||||
|
brb.tfu_minimum,
|
||||||
|
p_impositions_tfu_id,
|
||||||
|
false,
|
||||||
|
current_date,
|
||||||
|
p_user_id,
|
||||||
|
'FISCAD',
|
||||||
|
current_date,
|
||||||
|
p_user_id,
|
||||||
|
eul.categorie_usage,
|
||||||
|
0,---superficie_au_sol_70pour100
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
eul.superficie_au_sol * brb.valeur_locative,
|
||||||
|
0, ------ valeur_locative_adm : en attente de update
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
v_montant_srtb,
|
||||||
|
0,
|
||||||
|
p.id,
|
||||||
|
b.id,
|
||||||
|
ul.id,
|
||||||
|
eul.superficie_louee
|
||||||
|
FROM parcelle p
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT ON (parcelle_id)
|
||||||
|
parcelle_id,
|
||||||
|
superficie,
|
||||||
|
personne_id,
|
||||||
|
numero_titre_foncier,
|
||||||
|
date_enquete,
|
||||||
|
representant_tel,
|
||||||
|
representant_nom,
|
||||||
|
representant_prenom,
|
||||||
|
representant_npi,
|
||||||
|
date_debut_exemption,
|
||||||
|
date_fin_exemption,
|
||||||
|
zone_rfu_id
|
||||||
|
FROM enquete
|
||||||
|
ORDER BY parcelle_id, date_enquete DESC, id DESC
|
||||||
|
) ep ON ep.parcelle_id = p.id
|
||||||
|
LEFT JOIN personne pers
|
||||||
|
ON pers.id = ep.personne_id
|
||||||
|
JOIN quartier q ON q.id = p.quartier_id
|
||||||
|
JOIN arrondissement a ON a.id = q.arrondissement_id
|
||||||
|
JOIN commune c ON c.id = a.commune_id
|
||||||
|
JOIN departement d ON d.id = c.departement_id
|
||||||
|
JOIN secteur_decoupage sd ON sd.quartier_id = q.id
|
||||||
|
JOIN secteur sect ON sect.id = sd.secteur_id
|
||||||
|
JOIN section ses ON ses.id = sect.section_id
|
||||||
|
JOIN "structure" st ON st.id = ses.structure_id
|
||||||
|
JOIN batiment b ON b.parcelle_id = p.id
|
||||||
|
JOIN (
|
||||||
|
SELECT DISTINCT ON (batiment_id)
|
||||||
|
batiment_id,
|
||||||
|
superficie_au_sol,
|
||||||
|
nombre_piscine,
|
||||||
|
categorie_batiment_id,
|
||||||
|
date_enquete,
|
||||||
|
montant_locatif_annuel_declare,
|
||||||
|
montant_locatif_annuel_calcule,
|
||||||
|
montant_locatif_annuel_estime,
|
||||||
|
date_debut_excemption,
|
||||||
|
date_fin_excemption,
|
||||||
|
valeur_batiment_reel,
|
||||||
|
valeur_batiment_calcule,
|
||||||
|
valeur_batiment_estime,
|
||||||
|
u.categorie_usage
|
||||||
|
FROM enquete_batiment eb
|
||||||
|
join usage u on u.id=eb.usage_id
|
||||||
|
ORDER BY batiment_id, date_enquete DESC, eb.id DESC
|
||||||
|
) eb ON eb.batiment_id = b.id
|
||||||
|
JOIN unite_logement ul on ul.batiment_id = b.id
|
||||||
|
JOIN (
|
||||||
|
SELECT DISTINCT ON (eult.unite_logement_id)
|
||||||
|
eult.unite_logement_id,
|
||||||
|
pers1.id,
|
||||||
|
pers1.ifu,
|
||||||
|
pers1.npi,
|
||||||
|
pers1.tel1,
|
||||||
|
pers1.email,
|
||||||
|
pers1.nom,
|
||||||
|
pers1.prenom,
|
||||||
|
pers1.raison_sociale,
|
||||||
|
pers1.adresse,
|
||||||
|
eult.nombre_piscine,
|
||||||
|
eult.categorie_batiment_id,
|
||||||
|
eult.superficie_au_sol,
|
||||||
|
eult.superficie_louee,
|
||||||
|
eult.nbre_piece,
|
||||||
|
eult.date_enquete,
|
||||||
|
eult.montant_locatif_annuel_calcule,
|
||||||
|
eult.montant_locatif_annuel_declare,
|
||||||
|
eult.montant_locatif_annuel_estime,
|
||||||
|
eult.date_debut_exemption,
|
||||||
|
eult.date_fin_exemption,
|
||||||
|
eult.representant_nom,
|
||||||
|
eult.representant_prenom,
|
||||||
|
eult.representant_tel,
|
||||||
|
eult.valeur_unite_logement_reel,
|
||||||
|
eult.valeur_unite_logement_calcule,
|
||||||
|
eult.valeur_unite_logement_estime,
|
||||||
|
u.categorie_usage
|
||||||
|
FROM enquete_unite_logement eult
|
||||||
|
join usage u on u.id=eult.usage_id
|
||||||
|
left join personne pers1 on pers1.id = eult.personne_id
|
||||||
|
ORDER BY unite_logement_id, date_enquete DESC, eult.id DESC
|
||||||
|
) eul ON eul.unite_logement_id = ul.id
|
||||||
|
JOIN categorie_batiment cb
|
||||||
|
ON cb.id = eul.categorie_batiment_id
|
||||||
|
JOIN LATERAL (
|
||||||
|
SELECT *
|
||||||
|
FROM barem_rfu_bati br
|
||||||
|
WHERE br.categorie_batiment_id = cb.id
|
||||||
|
AND br.arrondissement_id = a.id
|
||||||
|
AND (br.quartier_id = q.id OR br.quartier_id IS NULL)
|
||||||
|
ORDER BY br.quartier_id DESC NULLS LAST
|
||||||
|
LIMIT 1
|
||||||
|
) brb ON TRUE
|
||||||
|
WHERE p.batie = TRUE
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM unite_logement ul
|
||||||
|
WHERE ul.batiment_id = b.id
|
||||||
|
)
|
||||||
|
AND st.id = v_structure_id
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
|
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||||
|
|
||||||
|
RETURN v_rows_inserted;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
|
||||||
|
delete from donnees_imposition_tfu;
|
||||||
|
|
||||||
|
select generer_donnees_imposition_srtb_batie_unite_logement(4,35);
|
||||||
|
|
||||||
|
select donnees_imposition_tfu.superficie_au_sol_loue,valeur_locative_adm,taux_tfu,montant_taxe, * from donnees_imposition_tfu
|
||||||
|
where nature_impot='SRTB';
|
||||||
@@ -0,0 +1,338 @@
|
|||||||
|
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,
|
||||||
|
case -------valeur_batiment
|
||||||
|
WHEN eb.valeur_batiment_reel IS NOT NULL AND eb.valeur_batiment_reel <> 0 THEN eb.valeur_batiment_reel
|
||||||
|
WHEN eb.valeur_batiment_calcule IS NOT NULL AND eb.valeur_batiment_calcule <> 0 THEN eb.valeur_batiment_calcule
|
||||||
|
WHEN eb.valeur_batiment_estime IS NOT NULL AND eb.valeur_batiment_estime <> 0 THEN eb.valeur_batiment_estime
|
||||||
|
ELSE 0
|
||||||
|
END,
|
||||||
|
brb.valeur_locative,
|
||||||
|
case ----- montant_loyer_annuel
|
||||||
|
WHEN eb.montant_locatif_annuel_declare IS NOT NULL AND eb.montant_locatif_annuel_declare <> 0 THEN eb.montant_locatif_annuel_declare
|
||||||
|
WHEN eb.montant_locatif_annuel_calcule IS NOT NULL AND eb.montant_locatif_annuel_calcule <> 0 THEN eb.montant_locatif_annuel_calcule
|
||||||
|
WHEN eb.montant_locatif_annuel_estime IS NOT NULL AND eb.montant_locatif_annuel_estime <> 0 THEN eb.montant_locatif_annuel_estime
|
||||||
|
ELSE 0
|
||||||
|
END,
|
||||||
|
brb.tfu_metre_carre,
|
||||||
|
brb.tfu_minimum,
|
||||||
|
p_impositions_tfu_id,
|
||||||
|
false,
|
||||||
|
current_date ,
|
||||||
|
p_user_id ,
|
||||||
|
'FISCAD',
|
||||||
|
current_date ,
|
||||||
|
p_user_id,
|
||||||
|
eb.categorie_usage,
|
||||||
|
p.superficie*v_taux_defaut_sup_sol/100,---superficie_au_sol_70pour100
|
||||||
|
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
|
||||||
|
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 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;
|
||||||
|
$$;
|
||||||
@@ -0,0 +1,388 @@
|
|||||||
|
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 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;
|
||||||
|
$$;
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION public.generer_donnees_imposition_tfu_non_batie(
|
||||||
|
p_impositions_tfu_id BIGINT,
|
||||||
|
p_user_id BIGINT
|
||||||
|
)
|
||||||
|
RETURNS INTEGER
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
DECLARE
|
||||||
|
v_rows_inserted INTEGER;
|
||||||
|
v_annee BIGINT;
|
||||||
|
v_structure_id BIGINT;
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
-- récupération de l'année
|
||||||
|
SELECT ex.annee, it.structure_id
|
||||||
|
INTO STRICT v_annee, v_structure_id
|
||||||
|
FROM impositions_tfu it
|
||||||
|
join exercice ex on ex.id =it.exercice_id
|
||||||
|
WHERE it.id = p_impositions_tfu_id;
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO donnees_imposition_tfu(
|
||||||
|
annee,
|
||||||
|
code_departement,
|
||||||
|
nom_departement,
|
||||||
|
code_commune,
|
||||||
|
nom_commune,
|
||||||
|
code_arrondissement,
|
||||||
|
nom_arrondissement,
|
||||||
|
code_quartier_village,
|
||||||
|
nom_quartier_village,
|
||||||
|
q,
|
||||||
|
ilot,
|
||||||
|
parcelle,
|
||||||
|
nup,
|
||||||
|
titre_foncier,
|
||||||
|
ifu,
|
||||||
|
npi,
|
||||||
|
tel_prop,
|
||||||
|
email_prop,
|
||||||
|
nom_prop,
|
||||||
|
prenom_prop,
|
||||||
|
raison_sociale,
|
||||||
|
adresse_prop,
|
||||||
|
tel_sc,
|
||||||
|
nom_sc,
|
||||||
|
prenom_sc,
|
||||||
|
longitude,
|
||||||
|
latitude,
|
||||||
|
batie,
|
||||||
|
exonere,
|
||||||
|
date_enquete,
|
||||||
|
structure_id,
|
||||||
|
zone_rfu_id,
|
||||||
|
nature_impot,
|
||||||
|
superficie_parc,
|
||||||
|
impositions_tfu_id,
|
||||||
|
deleted,
|
||||||
|
created_at ,
|
||||||
|
created_by ,
|
||||||
|
"source",
|
||||||
|
updated_at ,
|
||||||
|
updated_by,
|
||||||
|
taux_tfu,
|
||||||
|
valeur_admin_parcelle_nb,
|
||||||
|
valeur_admin_parcelle_nb_metre_carre,
|
||||||
|
montant_taxe
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
v_annee,
|
||||||
|
d.code,
|
||||||
|
d.nom,
|
||||||
|
c.code,
|
||||||
|
c.nom,
|
||||||
|
a.code,
|
||||||
|
a.nom,
|
||||||
|
q.code,
|
||||||
|
q.nom,
|
||||||
|
p.q,
|
||||||
|
p.i,
|
||||||
|
p.p,
|
||||||
|
p.nup,
|
||||||
|
ep.numero_titre_foncier,
|
||||||
|
pers.ifu,
|
||||||
|
pers.npi,
|
||||||
|
pers.tel1,
|
||||||
|
pers.email,
|
||||||
|
pers.nom,
|
||||||
|
pers.prenom,
|
||||||
|
pers.raison_sociale,
|
||||||
|
pers.adresse,
|
||||||
|
ep.representant_tel,
|
||||||
|
ep.representant_nom,
|
||||||
|
ep.representant_prenom,
|
||||||
|
p.longitude,
|
||||||
|
p.latitude,
|
||||||
|
false batie,
|
||||||
|
(
|
||||||
|
CURRENT_DATE >= ep.date_debut_exemption
|
||||||
|
AND CURRENT_DATE <= COALESCE(ep.date_fin_exemption, CURRENT_DATE)
|
||||||
|
) exonere,
|
||||||
|
ep.date_enquete,
|
||||||
|
st.id,
|
||||||
|
ep.zone_rfu_id,
|
||||||
|
'TFU',
|
||||||
|
p.superficie,
|
||||||
|
p_impositions_tfu_id,
|
||||||
|
false,
|
||||||
|
current_date ,
|
||||||
|
p_user_id ,
|
||||||
|
'FISCAD',
|
||||||
|
current_date ,
|
||||||
|
p_user_id,
|
||||||
|
brnb.taux,
|
||||||
|
case brnb.au_metre_carre
|
||||||
|
when true then brnb.valeur_administrative_metre_carre * ep.superficie
|
||||||
|
else brnb.valeur_administrative
|
||||||
|
end as valeur_administrative,
|
||||||
|
brnb.valeur_administrative_metre_carre,
|
||||||
|
case brnb.au_metre_carre
|
||||||
|
when true then brnb.valeur_administrative_metre_carre * ep.superficie*brnb.taux/100
|
||||||
|
else brnb.valeur_administrative*brnb.taux/100
|
||||||
|
end as montant_taxe
|
||||||
|
FROM parcelle p
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT DISTINCT ON (parcelle_id)
|
||||||
|
parcelle_id,
|
||||||
|
superficie,
|
||||||
|
personne_id,
|
||||||
|
numero_titre_foncier,
|
||||||
|
date_enquete,
|
||||||
|
representant_tel,
|
||||||
|
representant_nom,
|
||||||
|
representant_prenom,
|
||||||
|
representant_npi,
|
||||||
|
date_debut_exemption,
|
||||||
|
date_fin_exemption,
|
||||||
|
zone_rfu_id
|
||||||
|
FROM enquete
|
||||||
|
ORDER BY parcelle_id, date_enquete DESC
|
||||||
|
) ep ON ep.parcelle_id = p.id
|
||||||
|
LEFT JOIN personne pers
|
||||||
|
ON pers.id = ep.personne_id
|
||||||
|
JOIN quartier q ON q.id = p.quartier_id
|
||||||
|
JOIN arrondissement a ON a.id = q.arrondissement_id
|
||||||
|
JOIN commune c ON c.id = a.commune_id
|
||||||
|
JOIN departement d ON d.id = c.departement_id
|
||||||
|
JOIN secteur_decoupage sd ON sd.quartier_id = q.id
|
||||||
|
JOIN secteur sect ON sect.id = sd.secteur_id
|
||||||
|
JOIN section ses ON ses.id = sect.section_id
|
||||||
|
JOIN "structure" st ON st.id = ses.structure_id
|
||||||
|
left join barem_rfu_non_bati brnb on (brnb.commune_id =c.id and brnb.zone_rfu_id=ep.zone_rfu_id)
|
||||||
|
WHERE p.batie = false
|
||||||
|
AND st.id=v_structure_id
|
||||||
|
ON CONFLICT DO NOTHING;
|
||||||
|
|
||||||
|
GET DIAGNOSTICS v_rows_inserted = ROW_COUNT;
|
||||||
|
|
||||||
|
RETURN v_rows_inserted;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
@@ -0,0 +1,287 @@
|
|||||||
|
CREATE OR REPLACE PROCEDURE public.import_batiment_and_enquetebati_from_rfu(nombreLimit integer)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
l_count numeric := 0;
|
||||||
|
batiment_rfu record;
|
||||||
|
l_batiment_id_parent bigint;
|
||||||
|
l_parcelle_id_parent bigint ;
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
FOR batiment_rfu IN (
|
||||||
|
SELECT
|
||||||
|
c.n0bat,
|
||||||
|
--dtconst,
|
||||||
|
CASE
|
||||||
|
WHEN c.dtconst IS NULL OR c.dtconst = '' THEN NULL
|
||||||
|
-- format incorrect (pas exactement 8 chiffres)
|
||||||
|
WHEN c.dtconst !~ '^[0-9]{8}$' THEN NULL
|
||||||
|
-- date invalide réelle
|
||||||
|
WHEN to_char(to_date(c.dtconst, 'YYYYMMDD'), 'YYYYMMDD') <> c.dtconst THEN NULL
|
||||||
|
ELSE to_date(c.dtconst, 'YYYYMMDD')
|
||||||
|
end as dtconst,
|
||||||
|
c.quartier,
|
||||||
|
c.n0_ilot,
|
||||||
|
c.n0_parcel,
|
||||||
|
--c.surfsol,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.surfsol), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.surfsol, ',', '.')::numeric
|
||||||
|
end as surfsol,
|
||||||
|
--c.surfacelo,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.surfacelo), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.surfacelo, ',', '.')::numeric
|
||||||
|
end as surfacelo,
|
||||||
|
--c.vllcalcule,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.vllcalcule), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.vllcalcule, ',', '.')::numeric
|
||||||
|
end as vllcalcule,
|
||||||
|
--c.bail,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.bail), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.bail, ',', '.')::numeric
|
||||||
|
end as bail,
|
||||||
|
--c.valloest,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.valloest), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.valloest, ',', '.')::numeric
|
||||||
|
end as valloest,
|
||||||
|
--c.nbetage,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbetage), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbetage, ',', '.')::numeric
|
||||||
|
end as nbetage,
|
||||||
|
--c.vlcalcule,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.vlcalcule), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.vlcalcule, ',', '.')::numeric
|
||||||
|
end as vlcalcule,
|
||||||
|
--c.utilisat,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.utilisat), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.utilisat, ',', '.')::numeric
|
||||||
|
end as utilisat,
|
||||||
|
--c.finexempt,
|
||||||
|
CASE
|
||||||
|
WHEN c.finexempt IS NULL OR c.finexempt = '' THEN NULL
|
||||||
|
-- format incorrect (pas exactement 8 chiffres)
|
||||||
|
WHEN c.finexempt !~ '^[0-9]{8}$' THEN NULL
|
||||||
|
-- date invalide réelle
|
||||||
|
WHEN to_char(to_date(c.finexempt, 'YYYYMMDD'), 'YYYYMMDD') <> c.finexempt THEN NULL
|
||||||
|
ELSE to_date(c.finexempt, 'YYYYMMDD')
|
||||||
|
end as finexempt,
|
||||||
|
--c.nbunitlo,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbunitlo), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbunitlo, ',', '.')::numeric
|
||||||
|
end as nbunitlo,
|
||||||
|
--c.toit
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.toit), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.toit, ',', '.')::numeric
|
||||||
|
end as toit,
|
||||||
|
--nbhabit,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbhabit), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbhabit, ',', '.')::numeric
|
||||||
|
end as nbhabit,
|
||||||
|
--nbmenage,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbmenage), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbmenage, ',', '.')::numeric
|
||||||
|
end as nbmenage,
|
||||||
|
--nbmois,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbmois), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbmois, ',', '.')::numeric
|
||||||
|
end as nbmois,
|
||||||
|
--electric,
|
||||||
|
CASE
|
||||||
|
WHEN trim(c.electric)='Non'
|
||||||
|
THEN false
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end as electric,
|
||||||
|
--eau,
|
||||||
|
CASE
|
||||||
|
WHEN trim(c.eau)='Non'
|
||||||
|
THEN false
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end as eau,
|
||||||
|
--nbpiece,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbpiece), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbpiece, ',', '.')::numeric
|
||||||
|
end as nbpiece,
|
||||||
|
--nbunite
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbunite), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbunite, ',', '.')::numeric
|
||||||
|
end as nbunite,
|
||||||
|
CASE
|
||||||
|
WHEN c.mdate IS NULL OR c.mdate = '' THEN NULL
|
||||||
|
-- format incorrect (pas exactement 8 chiffres)
|
||||||
|
WHEN c.mdate !~ '^[0-9]{8}$' THEN NULL
|
||||||
|
-- date invalide réelle
|
||||||
|
WHEN to_char(to_date(c.mdate, 'YYYYMMDD'), 'YYYYMMDD') <> c.mdate THEN NULL
|
||||||
|
ELSE to_date(c.mdate, 'YYYYMMDD')
|
||||||
|
end as mdate,
|
||||||
|
--c.murs,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.murs), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.murs, ',', '.')::numeric
|
||||||
|
end as murs,
|
||||||
|
--standing
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.standing), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.standing, ',', '.')::numeric
|
||||||
|
end as standing
|
||||||
|
FROM dblink(
|
||||||
|
'connexion_rfu',
|
||||||
|
$db$
|
||||||
|
SELECT
|
||||||
|
b.n0bat,
|
||||||
|
b.dtconst,
|
||||||
|
b.quartier,
|
||||||
|
b.n0_ilot,
|
||||||
|
b.n0_parcel,
|
||||||
|
b.surfsol,
|
||||||
|
b.surfacelo,
|
||||||
|
b.vllcalcule,
|
||||||
|
b.bail,
|
||||||
|
b.valloest,
|
||||||
|
b.nbetage,
|
||||||
|
b.vlcalcule,
|
||||||
|
b.utilisat,
|
||||||
|
b.finexempt,
|
||||||
|
b.nbunitlo,
|
||||||
|
b.toit,
|
||||||
|
b.nbhabit,
|
||||||
|
b.nbmenage,
|
||||||
|
b.nbmois,
|
||||||
|
b.electric,
|
||||||
|
b.eau,
|
||||||
|
b.nbpiece,
|
||||||
|
b.nbunite,
|
||||||
|
b.mdate,
|
||||||
|
b.murs,
|
||||||
|
b.standing
|
||||||
|
FROM stemichel.batiment b
|
||||||
|
$db$
|
||||||
|
) AS c (
|
||||||
|
n0bat varchar,
|
||||||
|
dtconst varchar,
|
||||||
|
quartier varchar,
|
||||||
|
n0_ilot varchar,
|
||||||
|
n0_parcel varchar,
|
||||||
|
surfsol varchar,
|
||||||
|
surfacelo varchar,
|
||||||
|
vllcalcule varchar,
|
||||||
|
bail varchar,
|
||||||
|
valloest varchar,
|
||||||
|
nbetage varchar,
|
||||||
|
vlcalcule varchar,
|
||||||
|
utilisat varchar,
|
||||||
|
finexempt varchar,
|
||||||
|
nbunitlo varchar,
|
||||||
|
toit varchar,
|
||||||
|
nbhabit varchar,
|
||||||
|
nbmenage varchar,
|
||||||
|
nbmois varchar,
|
||||||
|
electric varchar,
|
||||||
|
eau varchar,
|
||||||
|
nbpiece varchar,
|
||||||
|
nbunite varchar,
|
||||||
|
mdate varchar,
|
||||||
|
murs varchar,
|
||||||
|
standing varchar
|
||||||
|
|
||||||
|
)
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM public.batiment b
|
||||||
|
WHERE b.code =
|
||||||
|
trim(c.quartier)||'-'||trim(c.n0_ilot)||'-'||trim(c.n0_parcel)||'-'||trim(c.n0bat)
|
||||||
|
)
|
||||||
|
limit nombreLimit
|
||||||
|
)
|
||||||
|
LOOP
|
||||||
|
-- Récupération ID parcelle locale
|
||||||
|
SELECT p.id
|
||||||
|
INTO l_parcelle_id_parent
|
||||||
|
FROM public.parcelle p
|
||||||
|
WHERE p.numero_parcelle =
|
||||||
|
trim(batiment_rfu.quartier)||'-'||trim(batiment_rfu.n0_ilot)||'-'||trim(batiment_rfu.n0_parcel)
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
|
||||||
|
-- Insertion bâtiment local
|
||||||
|
INSERT INTO public.batiment (
|
||||||
|
created_at,
|
||||||
|
created_by,
|
||||||
|
deleted,
|
||||||
|
updated_at,
|
||||||
|
updated_by,
|
||||||
|
code,
|
||||||
|
nub,
|
||||||
|
date_construction,
|
||||||
|
parcelle_id,
|
||||||
|
source,
|
||||||
|
superficie_au_sol,
|
||||||
|
superficie_louee,
|
||||||
|
categorie_batiment_id,
|
||||||
|
montant_locatif_annuel_calcule,
|
||||||
|
montant_locatif_annuel_declare,
|
||||||
|
montant_locatif_annuel_estime,
|
||||||
|
nombre_etage,
|
||||||
|
valeur_batiment_calcule,
|
||||||
|
usage_id,
|
||||||
|
date_fin_exemption,
|
||||||
|
nbre_unite_logement,
|
||||||
|
id_toit_rfu
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
false,
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
trim(batiment_rfu.quartier)||'-'||trim(batiment_rfu.n0_ilot)||'-'||trim(batiment_rfu.n0_parcel)||'-'||trim(batiment_rfu.n0bat),
|
||||||
|
batiment_rfu.n0bat,
|
||||||
|
batiment_rfu.dtconst,
|
||||||
|
l_parcelle_id_parent,
|
||||||
|
'RFU',
|
||||||
|
batiment_rfu.surfsol,
|
||||||
|
batiment_rfu.surfacelo,
|
||||||
|
ProcedureRecupCategorieRFU(batiment_rfu.nbetage::integer,batiment_rfu.toit::integer),
|
||||||
|
batiment_rfu.vllcalcule,
|
||||||
|
batiment_rfu.bail,
|
||||||
|
batiment_rfu.valloest,
|
||||||
|
batiment_rfu.nbetage,
|
||||||
|
batiment_rfu.vlcalcule,
|
||||||
|
--------- batiment_rfu.utilisat,
|
||||||
|
CASE batiment_rfu.utilisat
|
||||||
|
WHEN 1 THEN 8
|
||||||
|
WHEN 2 THEN 14
|
||||||
|
WHEN 3 THEN 9
|
||||||
|
END,
|
||||||
|
batiment_rfu.finexempt,
|
||||||
|
batiment_rfu.nbunitlo,
|
||||||
|
batiment_rfu.toit
|
||||||
|
)
|
||||||
|
|
||||||
|
RETURNING id INTO l_batiment_id_parent ;
|
||||||
|
|
||||||
|
call public.import_enquetebati_from_rfu_cipe(batiment_rfu,l_batiment_id_parent);
|
||||||
|
|
||||||
|
l_count := l_count + 1;
|
||||||
|
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
RAISE NOTICE 'Nombre de bâtiments insérés : %', l_count;
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
CREATE OR REPLACE PROCEDURE public.import_enquetebati_from_rfu_cipe(
|
||||||
|
IN batiment_rfu record,
|
||||||
|
IN batiment_id_param numeric
|
||||||
|
)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $procedure$
|
||||||
|
DECLARE
|
||||||
|
enquete_batiment_id_parent bigint;
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO enquete_batiment (
|
||||||
|
created_at,
|
||||||
|
created_by,
|
||||||
|
deleted,
|
||||||
|
updated_at,
|
||||||
|
updated_by,
|
||||||
|
date_fin_excemption,
|
||||||
|
nbre_habitant,
|
||||||
|
nbre_menage,
|
||||||
|
nbre_mois_location,
|
||||||
|
nbre_unite_location,
|
||||||
|
sbee,
|
||||||
|
soneb,
|
||||||
|
batiment_id,
|
||||||
|
personne_id,
|
||||||
|
user_id,
|
||||||
|
montant_locatif_annuel_declare,
|
||||||
|
nbre_etage,
|
||||||
|
source,
|
||||||
|
date_enquete,
|
||||||
|
observation,
|
||||||
|
superficie_au_sol,
|
||||||
|
superficie_louee,
|
||||||
|
statut_enquete,
|
||||||
|
categorie_batiment_id,
|
||||||
|
montant_locatif_annuel_calcule,
|
||||||
|
usage_id,
|
||||||
|
montant_locatif_annuel_estime,
|
||||||
|
nbre_piece,
|
||||||
|
nbre_unite_logement,
|
||||||
|
valeur_batiment_calcule,
|
||||||
|
nbre_lot_unite
|
||||||
|
) select
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
false,
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
batiment_rfu.finexempt,
|
||||||
|
batiment_rfu.nbhabit,
|
||||||
|
batiment_rfu.nbmenage,
|
||||||
|
batiment_rfu.nbmois,
|
||||||
|
batiment_rfu.nbunitlo,
|
||||||
|
batiment_rfu.electric,
|
||||||
|
batiment_rfu.eau,
|
||||||
|
batiment_id_param,
|
||||||
|
e.personne_id,
|
||||||
|
35,
|
||||||
|
batiment_rfu.bail,
|
||||||
|
batiment_rfu.nbetage,
|
||||||
|
'RFU',
|
||||||
|
batiment_rfu.mdate,
|
||||||
|
'MIGRATION',
|
||||||
|
batiment_rfu.surfsol,
|
||||||
|
batiment_rfu.surfacelo,
|
||||||
|
'CLOTURE',
|
||||||
|
ProcedureRecupCategorieRFU(batiment_rfu.nbetage::integer,batiment_rfu.toit::integer),
|
||||||
|
batiment_rfu.vllcalcule,
|
||||||
|
--batiment_rfu.utilisat,
|
||||||
|
CASE batiment_rfu.utilisat
|
||||||
|
WHEN 1 THEN 8
|
||||||
|
WHEN 2 THEN 14
|
||||||
|
WHEN 3 THEN 9
|
||||||
|
end,
|
||||||
|
batiment_rfu.valloest,
|
||||||
|
batiment_rfu.nbpiece,
|
||||||
|
batiment_rfu.nbunite,
|
||||||
|
batiment_rfu.vlcalcule,
|
||||||
|
batiment_rfu.nbunitlo
|
||||||
|
from batiment b
|
||||||
|
left join parcelle p on p.id=b.parcelle_id
|
||||||
|
left join enquete e on e.parcelle_id=p.id
|
||||||
|
where b.id = batiment_id_param
|
||||||
|
and not exists (
|
||||||
|
select 1
|
||||||
|
from enquete_batiment eb
|
||||||
|
where eb.batiment_id = b.id
|
||||||
|
)
|
||||||
|
|
||||||
|
RETURNING id INTO enquete_batiment_id_parent ;
|
||||||
|
|
||||||
|
----------MAJ Caractéristique parcelle
|
||||||
|
INSERT INTO caracteristique_batiment (
|
||||||
|
created_by,
|
||||||
|
created_at,
|
||||||
|
updated_by,
|
||||||
|
updated_at,
|
||||||
|
deleted,
|
||||||
|
caracteristique_id,
|
||||||
|
enquete_batiment_id
|
||||||
|
)
|
||||||
|
SELECT 35, now(), 35, now(),false,
|
||||||
|
CASE batiment_rfu.toit
|
||||||
|
WHEN 1 THEN 55
|
||||||
|
WHEN 2 THEN 56
|
||||||
|
WHEN 3 THEN 57
|
||||||
|
WHEN 4 THEN 58
|
||||||
|
WHEN 5 THEN 59
|
||||||
|
WHEN 6 THEN 60
|
||||||
|
END,
|
||||||
|
enquete_batiment_id_parent
|
||||||
|
WHERE batiment_rfu.toit IS NOT NULL
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT 35, now(), 35, now(),false,
|
||||||
|
CASE batiment_rfu.murs
|
||||||
|
WHEN 1 THEN 49
|
||||||
|
WHEN 2 THEN 50
|
||||||
|
WHEN 3 THEN 51
|
||||||
|
WHEN 4 THEN 52
|
||||||
|
WHEN 5 THEN 53
|
||||||
|
else
|
||||||
|
54
|
||||||
|
END,
|
||||||
|
enquete_batiment_id_parent
|
||||||
|
WHERE batiment_rfu.murs IS NOT null
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT 35, now(), 35, now(),false,
|
||||||
|
CASE batiment_rfu.standing
|
||||||
|
WHEN 1 THEN 81
|
||||||
|
WHEN 2 THEN 82
|
||||||
|
WHEN 3 THEN 83
|
||||||
|
WHEN 4 THEN 84
|
||||||
|
END,
|
||||||
|
enquete_batiment_id_parent
|
||||||
|
WHERE batiment_rfu.standing IS NOT null
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT 35, now(), 35, now(),false,
|
||||||
|
CASE batiment_rfu.utilisat
|
||||||
|
WHEN 1 THEN 35
|
||||||
|
WHEN 2 THEN 36
|
||||||
|
WHEN 3 THEN 37
|
||||||
|
END,
|
||||||
|
enquete_batiment_id_parent
|
||||||
|
WHERE batiment_rfu.utilisat IS NOT null;
|
||||||
|
|
||||||
|
------MAJ Exercice
|
||||||
|
UPDATE enquete_batiment eb
|
||||||
|
SET exercice_id = e.id
|
||||||
|
FROM exercice e
|
||||||
|
WHERE e.annee = 2025
|
||||||
|
AND eb.id = enquete_batiment_id_parent;
|
||||||
|
END;
|
||||||
|
$procedure$;
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
CREATE OR REPLACE PROCEDURE public.import_enqueteparc_from_rfu_cipe(
|
||||||
|
IN parcelle_rfu record,
|
||||||
|
IN p_parcelle_id numeric
|
||||||
|
)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $procedure$
|
||||||
|
DECLARE
|
||||||
|
enquete_id_parent bigint;
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO enquete (
|
||||||
|
created_at,
|
||||||
|
created_by,
|
||||||
|
deleted,
|
||||||
|
updated_at,
|
||||||
|
updated_by,
|
||||||
|
date_enquete,
|
||||||
|
litige,
|
||||||
|
parcelle_id,
|
||||||
|
user_id,
|
||||||
|
date_finalisation,
|
||||||
|
date_synchronisation,
|
||||||
|
date_validation,
|
||||||
|
status_enquete,
|
||||||
|
synchronise,
|
||||||
|
code_parcelle,
|
||||||
|
nbre_batiment,
|
||||||
|
nbre_co_proprietaire,
|
||||||
|
nom_rue,
|
||||||
|
num_enter_parcelle,
|
||||||
|
num_rue,
|
||||||
|
superficie,
|
||||||
|
equipe_id,
|
||||||
|
zone_rfu_id,
|
||||||
|
campagne_id,
|
||||||
|
origine_enquete,
|
||||||
|
nc_proprietaire,
|
||||||
|
source
|
||||||
|
) select
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
false,
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
now(),
|
||||||
|
false,
|
||||||
|
p_parcelle_id,
|
||||||
|
35,
|
||||||
|
now(),
|
||||||
|
now(),
|
||||||
|
now(),
|
||||||
|
'CLOTURE',
|
||||||
|
true,
|
||||||
|
parcelle_rfu.numero_parcelle,
|
||||||
|
CASE
|
||||||
|
WHEN trim(parcelle_rfu.nb_bat) ~ '^[0-9]+$'
|
||||||
|
THEN parcelle_rfu.nb_bat::integer
|
||||||
|
ELSE NULL
|
||||||
|
END,
|
||||||
|
CASE
|
||||||
|
WHEN trim(parcelle_rfu.nb_prop) ~ '^[0-9]+$'
|
||||||
|
THEN parcelle_rfu.nb_prop::integer
|
||||||
|
ELSE NULL
|
||||||
|
END,
|
||||||
|
parcelle_rfu.numero_rue,
|
||||||
|
parcelle_rfu.num_entree_parcelle,
|
||||||
|
parcelle_rfu.numero_rue,
|
||||||
|
CASE
|
||||||
|
WHEN trim(parcelle_rfu.surface) ~ '^[0-9]+$'
|
||||||
|
THEN parcelle_rfu.surface::float
|
||||||
|
ELSE NULL
|
||||||
|
END,
|
||||||
|
1,
|
||||||
|
CASE parcelle_rfu.zones
|
||||||
|
WHEN '1' THEN 1
|
||||||
|
WHEN '2' THEN 2
|
||||||
|
WHEN '3' THEN 3
|
||||||
|
WHEN '4' THEN 4
|
||||||
|
ELSE NULL
|
||||||
|
END,
|
||||||
|
1,
|
||||||
|
'RFU',
|
||||||
|
parcelle_rfu.n0_contrib,
|
||||||
|
'RFU'
|
||||||
|
--from parcelle p
|
||||||
|
where not exists (
|
||||||
|
select 1
|
||||||
|
from enquete e
|
||||||
|
where e.parcelle_id= p_parcelle_id
|
||||||
|
)
|
||||||
|
|
||||||
|
RETURNING id INTO enquete_id_parent ;
|
||||||
|
|
||||||
|
----------MAJ Caractéristique parcelle
|
||||||
|
INSERT INTO caracteristique_parcelle (
|
||||||
|
created_by,
|
||||||
|
created_at,
|
||||||
|
updated_by,
|
||||||
|
updated_at,
|
||||||
|
deleted,
|
||||||
|
caracteristique_id,
|
||||||
|
enquete_id
|
||||||
|
)
|
||||||
|
SELECT 35, now(), 35, now(), false,
|
||||||
|
CASE parcelle_rfu.acces
|
||||||
|
WHEN '1' THEN 31
|
||||||
|
WHEN '2' THEN 32
|
||||||
|
WHEN '3' THEN 33
|
||||||
|
WHEN '4' THEN 34
|
||||||
|
END,
|
||||||
|
enquete_id_parent
|
||||||
|
WHERE parcelle_rfu.acces IS NOT NULL
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT 35, now(), 35, now(),false,
|
||||||
|
CASE parcelle_rfu.cloture
|
||||||
|
WHEN '1' THEN 28
|
||||||
|
WHEN '2' THEN 29
|
||||||
|
WHEN '3' THEN 30
|
||||||
|
END,
|
||||||
|
enquete_id_parent
|
||||||
|
WHERE parcelle_rfu.cloture IS NOT NULL;
|
||||||
|
|
||||||
|
------MAJ Exercice
|
||||||
|
UPDATE enquete q
|
||||||
|
SET exercice_id = e.id
|
||||||
|
FROM exercice e
|
||||||
|
WHERE e.annee = 2025
|
||||||
|
AND q.id = enquete_id_parent;
|
||||||
|
|
||||||
|
------MAJ prietaire
|
||||||
|
UPDATE enquete q
|
||||||
|
SET personne_id = p.id,
|
||||||
|
proprietaire_id = p.id,
|
||||||
|
nom_proprietaire_parcelle = coalesce (trim(p.raison_sociale), trim(p.nom) || ' '|| trim(p.prenom) )
|
||||||
|
FROM personne p
|
||||||
|
WHERE p.nc = parcelle_rfu.n0_contrib
|
||||||
|
AND q.id = enquete_id_parent;
|
||||||
|
|
||||||
|
--quartier_id --commune_id --departement_id --arrondissement_id
|
||||||
|
UPDATE enquete e
|
||||||
|
SET quartier_id = q.id,
|
||||||
|
commune_id=c.id,
|
||||||
|
departement_id=c.departement_id,
|
||||||
|
arrondissement_id= a.id
|
||||||
|
FROM parcelle p
|
||||||
|
inner join quartier q on q.id = p.quartier_id
|
||||||
|
inner join arrondissement a on a.id = q.arrondissement_id
|
||||||
|
inner join commune c on c.id = a.commune_id
|
||||||
|
WHERE p.id = p_parcelle_id
|
||||||
|
AND e.id = enquete_id_parent;
|
||||||
|
END;
|
||||||
|
$procedure$;
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
CREATE OR REPLACE PROCEDURE public.import_enqueteUnitLog_from_rfu_cipe(
|
||||||
|
IN uniteLogement_rfu record,
|
||||||
|
IN uniteLogement_id_param numeric,
|
||||||
|
IN l_personne_id_parent numeric
|
||||||
|
)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $procedure$
|
||||||
|
DECLARE
|
||||||
|
enquete_uniteLogement_id_parent bigint;
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO enquete_unite_logement (
|
||||||
|
created_at,
|
||||||
|
created_by,
|
||||||
|
deleted,
|
||||||
|
updated_at,
|
||||||
|
updated_by,
|
||||||
|
en_location,
|
||||||
|
montant_locatif_annuel_declare,
|
||||||
|
nbre_habitant,
|
||||||
|
nbre_menage,
|
||||||
|
nbre_piece,
|
||||||
|
sbee,
|
||||||
|
soneb,
|
||||||
|
personne_id,
|
||||||
|
unite_logement_id,
|
||||||
|
user_id,
|
||||||
|
nbre_mois_location,
|
||||||
|
valeur_unite_logement_estime,
|
||||||
|
source,
|
||||||
|
date_enquete,
|
||||||
|
observation,
|
||||||
|
date_fin_exemption,
|
||||||
|
superficie_au_sol,
|
||||||
|
superficie_louee,
|
||||||
|
statut_enquete,
|
||||||
|
categorie_batiment_id,
|
||||||
|
montant_locatif_annuel_calcule,
|
||||||
|
montant_mensuel_location,
|
||||||
|
usage_id,
|
||||||
|
valeur_unite_logement_calcule
|
||||||
|
)select
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
false,
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
case
|
||||||
|
when uniteLogement_rfu.nbmois=0 then false
|
||||||
|
else true
|
||||||
|
end,
|
||||||
|
uniteLogement_rfu.montmenl*12,
|
||||||
|
uniteLogement_rfu.nbhabit,
|
||||||
|
uniteLogement_rfu.nbmenage,
|
||||||
|
uniteLogement_rfu.nbpiece,
|
||||||
|
uniteLogement_rfu.electric,
|
||||||
|
uniteLogement_rfu.eau,
|
||||||
|
l_personne_id_parent,
|
||||||
|
uniteLogement_id_param,
|
||||||
|
35,
|
||||||
|
uniteLogement_rfu.nbmois,
|
||||||
|
uniteLogement_rfu.vlcalcule,
|
||||||
|
'RFU',
|
||||||
|
uniteLogement_rfu.mdate,
|
||||||
|
'MIGRATION',
|
||||||
|
uniteLogement_rfu.finexempt,
|
||||||
|
uniteLogement_rfu.surfsol,
|
||||||
|
uniteLogement_rfu.surfacelo,
|
||||||
|
'CLOTURE',
|
||||||
|
ProcedureRecupCategorieRFU(uniteLogement_rfu.n0etage::integer,uniteLogement_rfu.toit::integer),
|
||||||
|
uniteLogement_rfu.vllcalcule,
|
||||||
|
uniteLogement_rfu.montmenl,
|
||||||
|
CASE uniteLogement_rfu.utilisat
|
||||||
|
WHEN 1 THEN 8
|
||||||
|
WHEN 2 THEN 14
|
||||||
|
WHEN 3 THEN 9
|
||||||
|
END,
|
||||||
|
uniteLogement_rfu.vlcalcule
|
||||||
|
from unite_logement ul
|
||||||
|
where ul.id = uniteLogement_id_param
|
||||||
|
and not exists (
|
||||||
|
select 1
|
||||||
|
from enquete_unite_logement eul
|
||||||
|
where eul.unite_logement_id = ul.id
|
||||||
|
)
|
||||||
|
|
||||||
|
RETURNING id INTO enquete_uniteLogement_id_parent ;
|
||||||
|
|
||||||
|
----------MAJ Caractéristique Unite de logement
|
||||||
|
INSERT INTO caracteristique_unite_logement (
|
||||||
|
created_by,
|
||||||
|
created_at,
|
||||||
|
updated_by,
|
||||||
|
updated_at,
|
||||||
|
deleted,
|
||||||
|
caracteristique_id,
|
||||||
|
enquete_unite_logement_id
|
||||||
|
)
|
||||||
|
SELECT 35, now(), 35, now(),false,
|
||||||
|
CASE uniteLogement_rfu.toit
|
||||||
|
WHEN 1 THEN 55
|
||||||
|
WHEN 2 THEN 56
|
||||||
|
WHEN 3 THEN 57
|
||||||
|
WHEN 4 THEN 58
|
||||||
|
WHEN 5 THEN 59
|
||||||
|
WHEN 6 THEN 60
|
||||||
|
END,
|
||||||
|
enquete_uniteLogement_id_parent
|
||||||
|
WHERE uniteLogement_rfu.toit IS NOT NULL
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT 35, now(), 35, now(),false,
|
||||||
|
CASE uniteLogement_rfu.murs
|
||||||
|
WHEN 1 THEN 49
|
||||||
|
WHEN 2 THEN 50
|
||||||
|
WHEN 3 THEN 51
|
||||||
|
WHEN 4 THEN 52
|
||||||
|
WHEN 5 THEN 53
|
||||||
|
else
|
||||||
|
54
|
||||||
|
END,
|
||||||
|
enquete_uniteLogement_id_parent
|
||||||
|
WHERE uniteLogement_rfu.murs IS NOT null
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT 35, now(), 35, now(),false,
|
||||||
|
CASE uniteLogement_rfu.standing
|
||||||
|
WHEN 1 THEN 81
|
||||||
|
WHEN 2 THEN 82
|
||||||
|
WHEN 3 THEN 83
|
||||||
|
WHEN 4 THEN 84
|
||||||
|
END,
|
||||||
|
enquete_uniteLogement_id_parent
|
||||||
|
WHERE uniteLogement_rfu.standing IS NOT null
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
|
||||||
|
SELECT 35, now(), 35, now(),false,
|
||||||
|
CASE uniteLogement_rfu.utilisat
|
||||||
|
WHEN 1 THEN 35
|
||||||
|
WHEN 2 THEN 36
|
||||||
|
WHEN 3 THEN 37
|
||||||
|
END,
|
||||||
|
enquete_uniteLogement_id_parent
|
||||||
|
WHERE uniteLogement_rfu.standing IS NOT null;
|
||||||
|
|
||||||
|
------MAJ Exercice
|
||||||
|
UPDATE enquete_unite_logement eul
|
||||||
|
SET exercice_id = e.id
|
||||||
|
FROM exercice e
|
||||||
|
WHERE e.annee = 2025
|
||||||
|
AND eul.id = enquete_uniteLogement_id_parent;
|
||||||
|
END;
|
||||||
|
$procedure$;
|
||||||
@@ -0,0 +1,250 @@
|
|||||||
|
CREATE OR REPLACE PROCEDURE public.import_parcelle_and_enqueteparc_from_rfu_cipe(in nombreLimit numeric)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $procedure$
|
||||||
|
DECLARE
|
||||||
|
l_count numeric := 0;
|
||||||
|
parcelle_rfu record;
|
||||||
|
l_parcelle_id_parent bigint;
|
||||||
|
l_code_quartier varchar(20);
|
||||||
|
BEGIN
|
||||||
|
FOR parcelle_rfu IN (
|
||||||
|
SELECT
|
||||||
|
trim(quartier)||'-'||trim(n0_ilot)||'-'||trim(n0_parcel) AS numero_parcelle,
|
||||||
|
terrain,
|
||||||
|
trim(n0_ilot) AS i,
|
||||||
|
trim(n0_parcel) AS p,
|
||||||
|
trim(quartier) AS q,
|
||||||
|
hauteur,
|
||||||
|
rue AS numero_rue,
|
||||||
|
entree AS num_entree_parcelle,
|
||||||
|
surface,
|
||||||
|
vlcalcule,
|
||||||
|
vllcalcule,
|
||||||
|
loue,
|
||||||
|
zones,
|
||||||
|
acces,
|
||||||
|
cloture,
|
||||||
|
inonde,
|
||||||
|
finexempt,
|
||||||
|
habite,
|
||||||
|
ordures,
|
||||||
|
"usage",
|
||||||
|
wc,
|
||||||
|
choix,
|
||||||
|
occupant,
|
||||||
|
nb_bat,
|
||||||
|
nb_prop,
|
||||||
|
nb_log,
|
||||||
|
nb_unit,
|
||||||
|
nb_mena,
|
||||||
|
nb_habit,
|
||||||
|
nb_act,
|
||||||
|
nb_contrib,
|
||||||
|
typeparc,
|
||||||
|
prixm2ne,
|
||||||
|
ifu,
|
||||||
|
n0_contrib,
|
||||||
|
secteur,
|
||||||
|
cipe
|
||||||
|
FROM dblink(
|
||||||
|
'connexion_rfu',
|
||||||
|
$db$
|
||||||
|
SELECT
|
||||||
|
terrain,
|
||||||
|
n0_ilot,
|
||||||
|
n0_parcel,
|
||||||
|
quartier,
|
||||||
|
hauteur,
|
||||||
|
rue,
|
||||||
|
entree,
|
||||||
|
vlcalcule,
|
||||||
|
vllcalcule,
|
||||||
|
loue,
|
||||||
|
zones,
|
||||||
|
acces,
|
||||||
|
cloture,
|
||||||
|
inonde,
|
||||||
|
finexempt,
|
||||||
|
habite,
|
||||||
|
ordures,
|
||||||
|
surface,
|
||||||
|
"usage",
|
||||||
|
wc,
|
||||||
|
choix,
|
||||||
|
occupant,
|
||||||
|
nb_bat,
|
||||||
|
nb_prop,
|
||||||
|
nb_log,
|
||||||
|
nb_unit,
|
||||||
|
nb_mena,
|
||||||
|
nb_habit,
|
||||||
|
nb_act,
|
||||||
|
nb_contrib,
|
||||||
|
typeparc,
|
||||||
|
prixm2ne,
|
||||||
|
ifu,
|
||||||
|
n0_contrib,
|
||||||
|
secteur,
|
||||||
|
cipe
|
||||||
|
FROM stemichel.parcelle
|
||||||
|
$db$
|
||||||
|
) AS c (
|
||||||
|
terrain varchar,
|
||||||
|
n0_ilot varchar,
|
||||||
|
n0_parcel varchar,
|
||||||
|
quartier varchar,
|
||||||
|
hauteur varchar,
|
||||||
|
rue varchar,
|
||||||
|
entree varchar,
|
||||||
|
vlcalcule varchar,
|
||||||
|
vllcalcule varchar,
|
||||||
|
loue varchar,
|
||||||
|
zones varchar,
|
||||||
|
acces varchar,
|
||||||
|
cloture varchar,
|
||||||
|
inonde varchar,
|
||||||
|
finexempt varchar,
|
||||||
|
habite varchar,
|
||||||
|
ordures varchar,
|
||||||
|
surface varchar,
|
||||||
|
"usage" varchar,
|
||||||
|
wc varchar,
|
||||||
|
choix varchar,
|
||||||
|
occupant varchar,
|
||||||
|
nb_bat varchar,
|
||||||
|
nb_prop varchar,
|
||||||
|
nb_log varchar,
|
||||||
|
nb_unit varchar,
|
||||||
|
nb_mena varchar,
|
||||||
|
nb_habit varchar,
|
||||||
|
nb_act varchar,
|
||||||
|
nb_contrib varchar,
|
||||||
|
typeparc varchar,
|
||||||
|
prixm2ne varchar,
|
||||||
|
ifu varchar,
|
||||||
|
n0_contrib varchar,
|
||||||
|
secteur varchar,
|
||||||
|
cipe 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,
|
||||||
|
numero_parcelle,
|
||||||
|
qip,
|
||||||
|
type_domaine_id,
|
||||||
|
i,
|
||||||
|
p,
|
||||||
|
q,
|
||||||
|
code_quartier,
|
||||||
|
nature_domaine_id,
|
||||||
|
superficie,
|
||||||
|
altitude,
|
||||||
|
num_entree_parcelle,
|
||||||
|
numero_rue,
|
||||||
|
usage_id,
|
||||||
|
source
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
false,
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
parcelle_rfu.numero_parcelle,
|
||||||
|
parcelle_rfu.numero_parcelle,
|
||||||
|
CASE parcelle_rfu.terrain
|
||||||
|
WHEN '1' THEN 2
|
||||||
|
WHEN '2' THEN 5
|
||||||
|
WHEN '3' THEN 4
|
||||||
|
END,
|
||||||
|
parcelle_rfu.i,
|
||||||
|
parcelle_rfu.p,
|
||||||
|
parcelle_rfu.q,
|
||||||
|
rq.code_quartier,
|
||||||
|
CASE parcelle_rfu.typeparc
|
||||||
|
WHEN '1' THEN 23
|
||||||
|
WHEN '2' THEN 27
|
||||||
|
WHEN '3' THEN 28
|
||||||
|
WHEN '4' THEN 29
|
||||||
|
END,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(parcelle_rfu.surface), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(parcelle_rfu.surface, ',', '.')::numeric
|
||||||
|
END,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(parcelle_rfu.hauteur), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(parcelle_rfu.hauteur, ',', '.')::numeric
|
||||||
|
END,
|
||||||
|
parcelle_rfu.num_entree_parcelle,
|
||||||
|
parcelle_rfu.numero_rue,
|
||||||
|
case parcelle_rfu.usage
|
||||||
|
WHEN '01' THEN 3
|
||||||
|
WHEN '02' THEN 4
|
||||||
|
WHEN '03' THEN 5
|
||||||
|
WHEN '04' THEN 6
|
||||||
|
WHEN '05' THEN 7
|
||||||
|
WHEN '11' THEN 8
|
||||||
|
WHEN '12' THEN 9
|
||||||
|
WHEN '13' THEN 10
|
||||||
|
WHEN '14' THEN 11
|
||||||
|
WHEN '21' THEN 12
|
||||||
|
WHEN '22' THEN 13
|
||||||
|
WHEN '23' THEN 14
|
||||||
|
WHEN '24' THEN 15
|
||||||
|
WHEN '25' THEN 16
|
||||||
|
END,
|
||||||
|
'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;
|
||||||
|
EXCEPTION WHEN NO_DATA_FOUND THEN
|
||||||
|
RAISE NOTICE 'Quartier RFU non trouvé pour %', parcelle_rfu.q;
|
||||||
|
CONTINUE;
|
||||||
|
--RAISE NOTICE 'Parcelle insérée : %, %', l_parcelle_id_parent, parcelle_rfu.q;
|
||||||
|
END;
|
||||||
|
------------------------------appel de enquete_parcelle------------------
|
||||||
|
CALL import_enqueteparc_from_rfu_cipe(parcelle_rfu, l_parcelle_id_parent);
|
||||||
|
|
||||||
|
INSERT INTO secteur_decoupage (
|
||||||
|
created_at, created_by, deleted, updated_at, updated_by,
|
||||||
|
date_debut, quartier_id, secteur_id, arrondissement_id, source
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
now(), 35, false, now(), 35,
|
||||||
|
now(), q.id, s.id,a.id, 'RFU'
|
||||||
|
FROM ref_cipe_secteur_rfu_cotonou rcs
|
||||||
|
JOIN secteur s ON s.code= rcs.code_secteur
|
||||||
|
JOIN quartier q ON q.code = l_code_quartier
|
||||||
|
left join arrondissement a on a.id=q.arrondissement_id
|
||||||
|
WHERE rcs.cipe = parcelle_rfu.cipe
|
||||||
|
AND rcs.secteur = parcelle_rfu.secteur
|
||||||
|
ON CONFLICT (quartier_id, secteur_id) DO NOTHING;
|
||||||
|
|
||||||
|
l_count := l_count + 1;
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
UPDATE parcelle p
|
||||||
|
SET quartier_id = q.id
|
||||||
|
FROM quartier q
|
||||||
|
WHERE q.code = p.code_quartier;
|
||||||
|
|
||||||
|
RAISE NOTICE 'Nombre de parcelles migrées : %', l_count;
|
||||||
|
END;
|
||||||
|
$procedure$;
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
CREATE OR REPLACE PROCEDURE public.import_personne_from_rfu()
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $procedure$
|
||||||
|
BEGIN
|
||||||
|
INSERT INTO public.personne (
|
||||||
|
date_naissance_ou_consti,
|
||||||
|
ifu,
|
||||||
|
lieu_naissance,
|
||||||
|
nom,
|
||||||
|
prenom,
|
||||||
|
raison_sociale,
|
||||||
|
npi,
|
||||||
|
num_ravip,
|
||||||
|
tel1,
|
||||||
|
tel2,
|
||||||
|
adresse,
|
||||||
|
created_at,
|
||||||
|
created_by,
|
||||||
|
deleted,
|
||||||
|
updated_at,
|
||||||
|
updated_by,
|
||||||
|
nc,
|
||||||
|
sexe,
|
||||||
|
profession,
|
||||||
|
source
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
CASE
|
||||||
|
WHEN c.date_nais IS NULL OR c.date_nais = '' THEN NULL
|
||||||
|
|
||||||
|
-- format incorrect (pas exactement 8 chiffres)
|
||||||
|
WHEN c.date_nais !~ '^[0-9]{8}$' THEN NULL
|
||||||
|
|
||||||
|
-- date invalide réelle
|
||||||
|
WHEN to_char(to_date(c.date_nais, 'YYYYMMDD'), 'YYYYMMDD') <> c.date_nais THEN NULL
|
||||||
|
|
||||||
|
ELSE to_date(c.date_nais, 'YYYYMMDD')
|
||||||
|
END,
|
||||||
|
c.ifu,
|
||||||
|
c.lieu_nais,
|
||||||
|
case
|
||||||
|
when (trim(c.nom_c)<>'' and trim(c.prenoms_c)<>'') then c.nom_c
|
||||||
|
when (trim(c.nom_c)='' and trim(c.prenoms_c)='' and trim(c.prenoms)<>'') then c.nom
|
||||||
|
end as nom,
|
||||||
|
case
|
||||||
|
when (trim(c.nom_c)<>'' and trim(c.prenoms_c)<>'') then c.prenoms_c
|
||||||
|
when (trim(c.nom_c)='' and trim(c.prenoms_c)='' and trim(c.prenoms)<>'') then c.prenoms
|
||||||
|
end as prenom,
|
||||||
|
case
|
||||||
|
when (trim(c.nom_c)='' and trim(c.prenoms_c)='' and trim(c.prenoms)='') then c.nom
|
||||||
|
when (trim(c.nom_c)<>'' and trim(c.prenoms_c)<>'' and trim(c.prenoms)='') then c.nom
|
||||||
|
end as raison_sociale,
|
||||||
|
--c.nom,
|
||||||
|
NULL::varchar,
|
||||||
|
NULL::varchar,
|
||||||
|
--c.prenoms,
|
||||||
|
c.autradr1,
|
||||||
|
c.autradr2,
|
||||||
|
COALESCE(c.quartier_c, '') || '_' ||
|
||||||
|
COALESCE(c.ilot_c, '') || '_' ||
|
||||||
|
COALESCE(c.parcel_c, ''),
|
||||||
|
now(),
|
||||||
|
NULL::bigint,
|
||||||
|
false,
|
||||||
|
now(),
|
||||||
|
NULL::bigint,
|
||||||
|
c.n0_contrib,
|
||||||
|
CASE c.sexe
|
||||||
|
WHEN '1' THEN 'MASCULIN'
|
||||||
|
WHEN '2' THEN 'FEMININ'
|
||||||
|
ELSE NULL
|
||||||
|
END,
|
||||||
|
c.profession,
|
||||||
|
'RFU'
|
||||||
|
FROM dblink(
|
||||||
|
'connexion_rfu',
|
||||||
|
$db$
|
||||||
|
SELECT
|
||||||
|
date_nais,
|
||||||
|
ifu,
|
||||||
|
lieu_nais,
|
||||||
|
nom,
|
||||||
|
prenoms,
|
||||||
|
nom_c,
|
||||||
|
prenoms_c,
|
||||||
|
autradr1,
|
||||||
|
autradr2,
|
||||||
|
quartier_c,
|
||||||
|
ilot_c,
|
||||||
|
parcel_c,
|
||||||
|
n0_contrib,
|
||||||
|
sexe,
|
||||||
|
profession
|
||||||
|
FROM stemichel.contrib
|
||||||
|
-- WHERE ifu IS NOT NULL
|
||||||
|
$db$
|
||||||
|
) AS c (
|
||||||
|
date_nais varchar,
|
||||||
|
ifu varchar,
|
||||||
|
lieu_nais varchar,
|
||||||
|
nom varchar,
|
||||||
|
prenoms varchar,
|
||||||
|
nom_c varchar,
|
||||||
|
prenoms_c varchar,
|
||||||
|
autradr1 varchar,
|
||||||
|
autradr2 varchar,
|
||||||
|
quartier_c varchar,
|
||||||
|
ilot_c varchar,
|
||||||
|
parcel_c varchar,
|
||||||
|
n0_contrib varchar,
|
||||||
|
sexe varchar,
|
||||||
|
profession varchar
|
||||||
|
)
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM public.personne p
|
||||||
|
WHERE p.nc = c.n0_contrib
|
||||||
|
);
|
||||||
|
END;
|
||||||
|
$procedure$;
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
|
||||||
|
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 dblink_connect(
|
||||||
|
'connexion_sigibe_lecture',
|
||||||
|
'host=10.4.80.71 port=5433 dbname=sigibe user=sigibe_lecture password=lec243R6Khsg'
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE OR REPLACE PROCEDURE public.maj_personne_from_sigibe()
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $procedure$
|
||||||
|
DECLARE
|
||||||
|
|
||||||
|
BEGIN
|
||||||
|
UPDATE personne p
|
||||||
|
SET
|
||||||
|
nom = CASE
|
||||||
|
WHEN s.nom IS NOT NULL THEN s.nom
|
||||||
|
ELSE p.nom
|
||||||
|
END,
|
||||||
|
prenom = CASE
|
||||||
|
WHEN s.prenom IS NOT NULL THEN s.prenom
|
||||||
|
ELSE p.prenom
|
||||||
|
END,
|
||||||
|
raison_sociale = CASE
|
||||||
|
WHEN s.id_tiers_type = 'PM'
|
||||||
|
AND s.l_contribuable IS NOT NULL
|
||||||
|
THEN s.l_contribuable
|
||||||
|
ELSE p.raison_sociale
|
||||||
|
END,
|
||||||
|
tel1 = s.telephone,
|
||||||
|
numero_rccm = s.numero_rccm,
|
||||||
|
date_rccm = CASE
|
||||||
|
WHEN s.date_rccm IS NOT NULL
|
||||||
|
AND trim(s.date_rccm) <> ''
|
||||||
|
THEN s.date_rccm::date
|
||||||
|
ELSE p.date_rccm
|
||||||
|
END,
|
||||||
|
email = s.email,
|
||||||
|
npi = s.numero_piece_identite,
|
||||||
|
etat_identification_personne = 'IFU'
|
||||||
|
FROM (
|
||||||
|
SELECT *
|
||||||
|
FROM dblink(
|
||||||
|
'connexion_sigibe_lecture',
|
||||||
|
'
|
||||||
|
SELECT
|
||||||
|
c.r_contribuable,
|
||||||
|
t.nom,
|
||||||
|
t.prenom,
|
||||||
|
t.id_tiers_type,
|
||||||
|
t.telephone,
|
||||||
|
t.numero_rccm,
|
||||||
|
t.date_rccm,
|
||||||
|
t.email,
|
||||||
|
t.numero_piece_identite,
|
||||||
|
c.l_contribuable
|
||||||
|
FROM t_contribuable c
|
||||||
|
JOIN t_tiers t ON t.id_tiers = c.id_tiers
|
||||||
|
'
|
||||||
|
)
|
||||||
|
AS s(
|
||||||
|
r_contribuable varchar,
|
||||||
|
nom varchar,
|
||||||
|
prenom varchar,
|
||||||
|
id_tiers_type varchar,
|
||||||
|
telephone varchar,
|
||||||
|
numero_rccm varchar,
|
||||||
|
date_rccm varchar,
|
||||||
|
email varchar,
|
||||||
|
numero_piece_identite varchar,
|
||||||
|
l_contribuable varchar
|
||||||
|
)
|
||||||
|
) s
|
||||||
|
WHERE trim(p.ifu) = s.r_contribuable;
|
||||||
|
END;
|
||||||
|
$procedure$;
|
||||||
@@ -0,0 +1,297 @@
|
|||||||
|
CREATE OR REPLACE PROCEDURE public.import_uniteLogement_and_enqueteUnitLog_from_rfu(nombreLimit integer)
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $procedure$
|
||||||
|
DECLARE
|
||||||
|
l_count numeric := 0;
|
||||||
|
uniteLogement_rfu record;
|
||||||
|
l_uniteLogement_id_parent bigint;
|
||||||
|
l_batiment_id_parent bigint ;
|
||||||
|
l_personne_id_parent bigint ;
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
FOR uniteLogement_rfu IN (
|
||||||
|
SELECT
|
||||||
|
c.n0bat,
|
||||||
|
c.n0ul,
|
||||||
|
--c.n0etage,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.n0etage), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.n0etage, ',', '.')::numeric
|
||||||
|
end as n0etage,
|
||||||
|
c.quartier,
|
||||||
|
c.n0_ilot,
|
||||||
|
c.n0_parcel,
|
||||||
|
c.n0_contrib,
|
||||||
|
--c.montmenl,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.montmenl), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.montmenl, ',', '.')::numeric
|
||||||
|
end as montmenl,
|
||||||
|
--c.surfsol,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.surfsol), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.surfsol, ',', '.')::numeric
|
||||||
|
end as surfsol,
|
||||||
|
--c.surfacelo,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.surfacelo), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.surfacelo, ',', '.')::numeric
|
||||||
|
end as surfacelo,
|
||||||
|
--c.vllcalcule,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.vllcalcule), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.vllcalcule, ',', '.')::numeric
|
||||||
|
end as vllcalcule,
|
||||||
|
--c.bail,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.bail), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.bail, ',', '.')::numeric
|
||||||
|
end as bail,
|
||||||
|
--c.nbetage,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbetage), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbetage, ',', '.')::numeric
|
||||||
|
end as nbetage,
|
||||||
|
--c.vlcalcule,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.vlcalcule), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.vlcalcule, ',', '.')::numeric
|
||||||
|
end as vlcalcule,
|
||||||
|
--c.utilisat,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.utilisat), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.utilisat, ',', '.')::numeric
|
||||||
|
end as utilisat,
|
||||||
|
--c.finexempt,
|
||||||
|
CASE
|
||||||
|
WHEN c.finexempt IS NULL OR c.finexempt = '' THEN NULL
|
||||||
|
-- format incorrect (pas exactement 8 chiffres)
|
||||||
|
WHEN c.finexempt !~ '^[0-9]{8}$' THEN NULL
|
||||||
|
-- date invalide réelle
|
||||||
|
WHEN to_char(to_date(c.finexempt, 'YYYYMMDD'), 'YYYYMMDD') <> c.finexempt THEN NULL
|
||||||
|
ELSE to_date(c.finexempt, 'YYYYMMDD')
|
||||||
|
end as finexempt,
|
||||||
|
--c.toit
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.toit), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.toit, ',', '.')::numeric
|
||||||
|
end as toit,
|
||||||
|
--nbhabit,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbhabit), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbhabit, ',', '.')::numeric
|
||||||
|
end as nbhabit,
|
||||||
|
--nbmenage,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbmenage), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbmenage, ',', '.')::numeric
|
||||||
|
end as nbmenage,
|
||||||
|
--nbmois,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbmois), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbmois, ',', '.')::numeric
|
||||||
|
end as nbmois,
|
||||||
|
--electric,
|
||||||
|
CASE
|
||||||
|
WHEN trim(c.electric)='Non'
|
||||||
|
THEN false
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end as electric,
|
||||||
|
--eau,
|
||||||
|
CASE
|
||||||
|
WHEN trim(c.eau)='Non'
|
||||||
|
THEN false
|
||||||
|
else
|
||||||
|
true
|
||||||
|
end as eau,
|
||||||
|
--nbpiece,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbpiece), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbpiece, ',', '.')::numeric
|
||||||
|
end as nbpiece,
|
||||||
|
--nbunite
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.nbunite), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.nbunite, ',', '.')::numeric
|
||||||
|
end as nbunite,
|
||||||
|
CASE
|
||||||
|
WHEN c.mdate IS NULL OR c.mdate = '' THEN NULL
|
||||||
|
-- format incorrect (pas exactement 8 chiffres)
|
||||||
|
WHEN c.mdate !~ '^[0-9]{8}$' THEN NULL
|
||||||
|
-- date invalide réelle
|
||||||
|
WHEN to_char(to_date(c.mdate, 'YYYYMMDD'), 'YYYYMMDD') <> c.mdate THEN NULL
|
||||||
|
ELSE to_date(c.mdate, 'YYYYMMDD')
|
||||||
|
end as mdate,
|
||||||
|
--c.murs,
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.murs), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.murs, ',', '.')::numeric
|
||||||
|
end as murs,
|
||||||
|
--standing
|
||||||
|
CASE
|
||||||
|
WHEN replace(trim(c.standing), ',', '.') ~ '^[0-9]+(\.[0-9]+)?$'
|
||||||
|
THEN replace(c.standing, ',', '.')::numeric
|
||||||
|
end as standing
|
||||||
|
FROM dblink(
|
||||||
|
'connexion_rfu',
|
||||||
|
$db$
|
||||||
|
select distinct
|
||||||
|
ul.n0bat,
|
||||||
|
ul.n0ul,
|
||||||
|
ul.n0etage,
|
||||||
|
ul.quartier,
|
||||||
|
ul.n0_ilot,
|
||||||
|
ul.n0_parcel,
|
||||||
|
ul.n0_contrib,
|
||||||
|
ul.montmenl,
|
||||||
|
ul.surfsol,
|
||||||
|
ul.surfacelo,
|
||||||
|
ul.vllcalcule,
|
||||||
|
ul.bail,
|
||||||
|
--ul.valloest,
|
||||||
|
ul.nbetage,
|
||||||
|
ul.vlcalcule,
|
||||||
|
ul.utilisat,
|
||||||
|
ul.finexempt,
|
||||||
|
ul.nbunitlo,
|
||||||
|
ul.toit,
|
||||||
|
ul.nbhabit,
|
||||||
|
ul.nbmenage,
|
||||||
|
ul.nbmois,
|
||||||
|
ul.electric,
|
||||||
|
ul.eau,
|
||||||
|
ul.nbpiece,
|
||||||
|
ul.nbunite,
|
||||||
|
ul.mdate,
|
||||||
|
ul.murs,
|
||||||
|
ul.standing
|
||||||
|
FROM akpakpa.unitlog ul
|
||||||
|
$db$
|
||||||
|
) AS c (
|
||||||
|
n0bat varchar,
|
||||||
|
n0ul varchar,
|
||||||
|
n0etage varchar,
|
||||||
|
quartier varchar,
|
||||||
|
n0_ilot varchar,
|
||||||
|
n0_parcel varchar,
|
||||||
|
n0_contrib varchar,
|
||||||
|
montmenl varchar,
|
||||||
|
surfsol varchar,
|
||||||
|
surfacelo varchar,
|
||||||
|
vllcalcule varchar,
|
||||||
|
bail varchar,
|
||||||
|
--valloest varchar,
|
||||||
|
nbetage varchar,
|
||||||
|
vlcalcule varchar,
|
||||||
|
utilisat varchar,
|
||||||
|
finexempt varchar,
|
||||||
|
nbunitlo varchar,
|
||||||
|
toit varchar,
|
||||||
|
nbhabit varchar,
|
||||||
|
nbmenage varchar,
|
||||||
|
nbmois varchar,
|
||||||
|
electric varchar,
|
||||||
|
eau varchar,
|
||||||
|
nbpiece varchar,
|
||||||
|
nbunite varchar,
|
||||||
|
mdate varchar,
|
||||||
|
murs varchar,
|
||||||
|
standing varchar
|
||||||
|
)
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM public.unite_logement ul
|
||||||
|
WHERE ul.code =
|
||||||
|
trim(c.quartier)||'-'||trim(c.n0_ilot)||'-'||trim(c.n0_parcel)||'-'||trim(c.n0bat)||'-'||trim(c.n0ul)
|
||||||
|
)
|
||||||
|
limit nombreLimit
|
||||||
|
)
|
||||||
|
LOOP
|
||||||
|
-- Récupération ID batiment locale
|
||||||
|
SELECT b.id
|
||||||
|
INTO l_batiment_id_parent
|
||||||
|
FROM public.batiment b
|
||||||
|
WHERE b.code =
|
||||||
|
trim(uniteLogement_rfu.quartier)||'-'||trim(uniteLogement_rfu.n0_ilot)||'-'||trim(uniteLogement_rfu.n0_parcel)||'-'||trim(uniteLogement_rfu.n0bat)
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
-- Récupération ID personne locale
|
||||||
|
SELECT p.id
|
||||||
|
INTO l_personne_id_parent
|
||||||
|
FROM public.personne p
|
||||||
|
WHERE p.nc =trim(uniteLogement_rfu.n0_contrib)
|
||||||
|
LIMIT 1;
|
||||||
|
|
||||||
|
|
||||||
|
-- Insertion unite logement local
|
||||||
|
INSERT INTO public.unite_logement(
|
||||||
|
created_at,
|
||||||
|
created_by,
|
||||||
|
deleted,
|
||||||
|
updated_at,
|
||||||
|
updated_by,
|
||||||
|
code,
|
||||||
|
nul,
|
||||||
|
numero_etage,
|
||||||
|
batiment_id,
|
||||||
|
--personne_id,
|
||||||
|
source,
|
||||||
|
superficie_au_sol,
|
||||||
|
superficie_louee,
|
||||||
|
categorie_batiment_id,
|
||||||
|
montant_locatif_annuel_calcule,
|
||||||
|
montant_locatif_annuel_declare,
|
||||||
|
montant_mensuel_location,
|
||||||
|
valeur_unite_logement_estime,
|
||||||
|
usage_id,
|
||||||
|
date_fin_exemption,
|
||||||
|
id_toit_rfu,
|
||||||
|
valeur_unite_logement_calcule,
|
||||||
|
nombre_etage
|
||||||
|
)
|
||||||
|
VALUES (
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
false,
|
||||||
|
now(),
|
||||||
|
35,
|
||||||
|
trim(uniteLogement_rfu.quartier)||'-'||trim(uniteLogement_rfu.n0_ilot)||'-'||trim(uniteLogement_rfu.n0_parcel)||'-'||trim(uniteLogement_rfu.n0bat)||'-'||trim(uniteLogement_rfu.n0ul),
|
||||||
|
uniteLogement_rfu.n0ul,
|
||||||
|
uniteLogement_rfu.n0etage,
|
||||||
|
l_batiment_id_parent,
|
||||||
|
-- l_personne_id_parent,
|
||||||
|
'RFU',
|
||||||
|
uniteLogement_rfu.surfsol,
|
||||||
|
uniteLogement_rfu.surfacelo,
|
||||||
|
ProcedureRecupCategorieRFU(uniteLogement_rfu.nbetage::integer,uniteLogement_rfu.toit::integer),
|
||||||
|
uniteLogement_rfu.vllcalcule,
|
||||||
|
uniteLogement_rfu.bail,
|
||||||
|
uniteLogement_rfu.montmenl,
|
||||||
|
uniteLogement_rfu.vlcalcule,
|
||||||
|
CASE uniteLogement_rfu.utilisat
|
||||||
|
WHEN 1 THEN 8
|
||||||
|
WHEN 2 THEN 14
|
||||||
|
WHEN 3 THEN 9
|
||||||
|
END,
|
||||||
|
uniteLogement_rfu.finexempt,
|
||||||
|
uniteLogement_rfu.toit,
|
||||||
|
uniteLogement_rfu.vlcalcule,
|
||||||
|
uniteLogement_rfu.nbetage
|
||||||
|
)
|
||||||
|
RETURNING id INTO l_uniteLogement_id_parent;
|
||||||
|
|
||||||
|
call public.import_enqueteUnitLog_from_rfu_cipe(
|
||||||
|
uniteLogement_rfu,
|
||||||
|
l_uniteLogement_id_parent,
|
||||||
|
l_personne_id_parent
|
||||||
|
);
|
||||||
|
|
||||||
|
l_count := l_count + 1;
|
||||||
|
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
RAISE NOTICE 'Nombre de unité de logement insérés : %', l_count;
|
||||||
|
|
||||||
|
END;
|
||||||
|
$procedure$;
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
WITH src AS (
|
||||||
|
SELECT
|
||||||
|
pcct.*,
|
||||||
|
upper(regexp_replace(quartier_insae_code,'(\d{2})(\d{1})(\d{2})(\d{2})','\1.\2.\3.\4')) AS code_quartier,
|
||||||
|
upper((regexp_match(local_parcel_identification,
|
||||||
|
'Lot:\s*([0-9]+)\s*Parcelle:\s*([A-Za-z0-9]+)'))[1]) AS ilot,
|
||||||
|
upper((regexp_match(local_parcel_identification,
|
||||||
|
'Lot:\s*([0-9]+)\s*Parcelle:\s*([A-Za-z0-9]+)'))[2]) AS p
|
||||||
|
FROM parcelle_cadastre_cotonou_tmp pcct
|
||||||
|
)
|
||||||
|
|
||||||
|
INSERT INTO parcelle_geom
|
||||||
|
(
|
||||||
|
geometry,
|
||||||
|
code_instad,
|
||||||
|
departement_id,
|
||||||
|
commune_id,
|
||||||
|
q,
|
||||||
|
ilot,
|
||||||
|
p,
|
||||||
|
superficie,
|
||||||
|
quartier_id,
|
||||||
|
arrondissement_id,
|
||||||
|
nom_village_quartier,
|
||||||
|
nup
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
s.geom,
|
||||||
|
s.code_quartier,
|
||||||
|
15,
|
||||||
|
70,
|
||||||
|
refq.rfu_q,
|
||||||
|
s.ilot,
|
||||||
|
s.p,
|
||||||
|
s.calculated_area,
|
||||||
|
q.id,
|
||||||
|
a.id,
|
||||||
|
s.quartier_name,
|
||||||
|
s.nup
|
||||||
|
FROM src s
|
||||||
|
LEFT JOIN quartier q
|
||||||
|
ON q.code = s.code_quartier
|
||||||
|
LEFT JOIN arrondissement a
|
||||||
|
ON a.id = q.arrondissement_id
|
||||||
|
LEFT JOIN ref_rfu_q_quartier_cotonou refq
|
||||||
|
ON refq.code_quartier = q.code
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM parcelle_geom pg
|
||||||
|
WHERE (pg.q = refq.rfu_q
|
||||||
|
AND pg.ilot = s.ilot
|
||||||
|
AND pg.p = s.p)
|
||||||
|
OR pg.nup = s.nup
|
||||||
|
);
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
CREATE OR REPLACE FUNCTION public.ProcedureRecupCategorieRFU(
|
||||||
|
p_nbetage integer,
|
||||||
|
p_toit integer
|
||||||
|
)
|
||||||
|
RETURNS integer
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
AS $$
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
-- Sécurisation null
|
||||||
|
IF p_nbetage IS NULL THEN
|
||||||
|
RETURN NULL;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- Cas 0 étage
|
||||||
|
IF p_nbetage = 0 THEN
|
||||||
|
IF p_toit IN (2,3,4,5,6) THEN
|
||||||
|
RETURN 1;
|
||||||
|
ELSIF p_toit = 1 THEN
|
||||||
|
RETURN 2;
|
||||||
|
ELSE
|
||||||
|
RETURN 1; -- valeur par défaut si toit inconnu
|
||||||
|
END IF;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- 1 ou 2 étages
|
||||||
|
IF p_nbetage IN (1,2) THEN
|
||||||
|
RETURN 3;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- 3 ou 4 étages
|
||||||
|
IF p_nbetage IN (3,4) THEN
|
||||||
|
RETURN 4;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- > 5 étages
|
||||||
|
IF p_nbetage > 5 THEN
|
||||||
|
RETURN 5;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
RETURN NULL;
|
||||||
|
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
@@ -363,4 +363,59 @@ public interface BatimentRepository extends JpaRepository<Batiment, Long> {
|
|||||||
Pageable pageable
|
Pageable pageable
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"""
|
||||||
|
SELECT new io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb(
|
||||||
|
b.id,
|
||||||
|
b.nub,
|
||||||
|
b.code,
|
||||||
|
b.dateConstruction,
|
||||||
|
p.id,
|
||||||
|
p.nup,
|
||||||
|
p.q,
|
||||||
|
p.i,
|
||||||
|
p.p,
|
||||||
|
per.id,
|
||||||
|
per.nom,
|
||||||
|
per.prenom,
|
||||||
|
per.raisonSociale,
|
||||||
|
eb.superficieAuSol,
|
||||||
|
eb.superficieLouee,
|
||||||
|
eb.id,
|
||||||
|
cb.id,
|
||||||
|
cb.code,
|
||||||
|
cb.standing,
|
||||||
|
eb.nombrePiscine,
|
||||||
|
eb.montantLocatifAnnuelDeclare,
|
||||||
|
eb.montantLocatifAnnuelCalcule,
|
||||||
|
eb.valeurBatimentEstime,
|
||||||
|
eb.valeurBatimentReel,
|
||||||
|
eb.montantMensuelLocation,
|
||||||
|
us.id,
|
||||||
|
us.nom ,
|
||||||
|
eb.montantLocatifAnnuelEstime,
|
||||||
|
eb.valeurBatimentCalcule,
|
||||||
|
eb.nbreUniteLogement
|
||||||
|
)
|
||||||
|
FROM Batiment b
|
||||||
|
JOIN b.parcelle p
|
||||||
|
JOIN p.quartier q
|
||||||
|
LEFT JOIN b.categorieBatiment cb
|
||||||
|
LEFT JOIN EnqueteBatiment eb
|
||||||
|
ON eb.batiment = b
|
||||||
|
AND eb.dateEnquete = (
|
||||||
|
SELECT MAX(eb2.dateEnquete)
|
||||||
|
FROM EnqueteBatiment eb2
|
||||||
|
WHERE eb2.batiment = b
|
||||||
|
)
|
||||||
|
LEFT JOIN eb.personne per
|
||||||
|
LEFT JOIN eb.usage us
|
||||||
|
WHERE q.id = :quartierId
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
List<BatimentPaylaodWeb> findAllBatimentsAvecOccupantCourantByQuartierToDto(
|
||||||
|
@Param("quartierId") Long quartierId
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -528,6 +528,30 @@ SELECT new io.gmss.fiscad.paylaods.request.crudweb.DonneesImpositionPaylaodWeb(
|
|||||||
@Param("impositionId") Long impositionId
|
@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
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -412,4 +412,61 @@ public interface UniteLogementRepository extends JpaRepository<UniteLogement, Lo
|
|||||||
@Param("quartierId") Long quartierId,
|
@Param("quartierId") Long quartierId,
|
||||||
Pageable pageable
|
Pageable pageable
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@Query(
|
||||||
|
"""
|
||||||
|
SELECT new io.gmss.fiscad.paylaods.request.crudweb.UniteLogementPaylaodWeb(
|
||||||
|
ul.id,
|
||||||
|
ul.nul,
|
||||||
|
ul.numeroEtage,
|
||||||
|
ul.code,
|
||||||
|
|
||||||
|
b.id,
|
||||||
|
eul.superficieAuSol,
|
||||||
|
eul.superficieLouee,
|
||||||
|
b.nub,
|
||||||
|
eul.observation,
|
||||||
|
ul.dateConstruction,
|
||||||
|
|
||||||
|
per.id,
|
||||||
|
per.nom,
|
||||||
|
per.prenom,
|
||||||
|
per.raisonSociale,
|
||||||
|
eul.id,
|
||||||
|
cb.id,
|
||||||
|
cb.code,
|
||||||
|
cb.standing,
|
||||||
|
eul.montantMensuelLocation,
|
||||||
|
eul.montantLocatifAnnuelDeclare,
|
||||||
|
eul.montantLocatifAnnuelCalcule,
|
||||||
|
eul.valeurUniteLogementEstime,
|
||||||
|
eul.valeurUniteLogementReel,
|
||||||
|
eul.nombrePiscine ,
|
||||||
|
us.id,
|
||||||
|
us.nom ,
|
||||||
|
eul.montantLocatifAnnuelEstime ,
|
||||||
|
eul.valeurUniteLogementCalcule
|
||||||
|
)
|
||||||
|
FROM UniteLogement ul
|
||||||
|
JOIN ul.batiment b
|
||||||
|
JOIN b.parcelle p
|
||||||
|
JOIN p.quartier q
|
||||||
|
LEFT JOIN ul.categorieBatiment cb
|
||||||
|
LEFT JOIN EnqueteUniteLogement eul
|
||||||
|
ON eul.uniteLogement = ul
|
||||||
|
AND eul.dateEnquete = (
|
||||||
|
SELECT MAX(eul2.dateEnquete)
|
||||||
|
FROM EnqueteUniteLogement eul2
|
||||||
|
WHERE eul2.uniteLogement = ul
|
||||||
|
)
|
||||||
|
LEFT JOIN eul.personne per
|
||||||
|
LEFT JOIN eul.usage us
|
||||||
|
WHERE q.id = :quartierId
|
||||||
|
"""
|
||||||
|
|
||||||
|
)
|
||||||
|
List<UniteLogementPaylaodWeb> findUnitesLogementAvecOccupantCourantByQuartierToDto(
|
||||||
|
@Param("quartierId") Long quartierId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user