Merge pull request 'develop' (#253) from develop into main
All checks were successful
CD - Deploy on main / deploy (push) Successful in 51s
All checks were successful
CD - Deploy on main / deploy (push) Successful in 51s
Reviewed-on: #253
This commit was merged in pull request #253.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
package io.gmss.fiscad.controllers.rfu.metier;
|
||||
|
||||
|
||||
import io.gmss.fiscad.exceptions.*;
|
||||
import io.gmss.fiscad.interfaces.rfu.metier.SituationFiscaleParcelleService;
|
||||
import io.gmss.fiscad.paylaods.ApiResponse;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.SituationFiscaleParcellePayloadWeb;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "api/situation-fiscale-parcelle", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@SecurityRequirement(name = "bearer")
|
||||
@Tag(name = "Situation fiscale parcelle")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class SituationFiscaleParcelleController {
|
||||
|
||||
private final SituationFiscaleParcelleService situationFiscaleParcelleService;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SituationFiscaleParcelleController.class);
|
||||
|
||||
public SituationFiscaleParcelleController(SituationFiscaleParcelleService situationFiscaleParcelleService) {
|
||||
this.situationFiscaleParcelleService = situationFiscaleParcelleService;
|
||||
}
|
||||
|
||||
@GetMapping("/all/by-parcelle-id/{parcelleId}")
|
||||
@PreAuthorize("hasAuthority('READ_SITUATIONFISCALEPARCELLE')")
|
||||
public ResponseEntity<?> getAllSituationFiscaleParcelleByParcelleList(@PathVariable Long parcelleId) {
|
||||
try {
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, situationFiscaleParcelleService.getSituationFiscaleParcelleListByParcelle(parcelleId), "Liste des situation par année 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import io.gmss.fiscad.entities.BaseEntity;
|
||||
import io.gmss.fiscad.entities.infocad.metier.Parcelle;
|
||||
import io.gmss.fiscad.entities.infocad.metier.Tpe;
|
||||
import io.gmss.fiscad.entities.rfu.parametre.Exercice;
|
||||
import io.gmss.fiscad.enums.NatureImpot;
|
||||
import io.gmss.fiscad.enums.StatutParcelle;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -38,8 +39,11 @@ public class SituationFiscaleParcelle extends BaseEntity implements Serializable
|
||||
private Exercice exercice ;
|
||||
private Long montantDu ;
|
||||
private Long montantPaye ;
|
||||
private Long montantDegeve ;
|
||||
private Long resteAPayer ;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
private LocalDate dateSync;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private NatureImpot natureImpot;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.gmss.fiscad.implementations.rfu.metier;
|
||||
|
||||
import io.gmss.fiscad.entities.rfu.metier.SituationFiscaleParcelle;
|
||||
import io.gmss.fiscad.exceptions.BadRequestException;
|
||||
import io.gmss.fiscad.exceptions.NotFoundException;
|
||||
import io.gmss.fiscad.interfaces.rfu.metier.SituationFiscaleParcelleService;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.SituationFiscaleParcellePayloadWeb;
|
||||
import io.gmss.fiscad.persistence.repositories.infocad.metier.ParcelleRepository;
|
||||
import io.gmss.fiscad.persistence.repositories.rfu.metier.SituationFiscaleParcelleRepository;
|
||||
import io.gmss.fiscad.service.EntityFromPayLoadService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Service
|
||||
public class SituationFiscaleParcelleServiceImpl implements SituationFiscaleParcelleService {
|
||||
|
||||
private final SituationFiscaleParcelleRepository situationFiscaleParcelleRepository;
|
||||
private final ParcelleRepository parcelleRepository;
|
||||
private final EntityFromPayLoadService entityFromPayLoadService;
|
||||
|
||||
@Override
|
||||
public SituationFiscaleParcellePayloadWeb createSituationFiscaleParcelle(SituationFiscaleParcellePayloadWeb situationFiscaleParcellePayloadWeb) throws BadRequestException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SituationFiscaleParcellePayloadWeb updateSituationFiscaleParcelle(Long id, SituationFiscaleParcellePayloadWeb situationFiscaleParcellePayloadWeb) throws NotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSituationFiscaleParcelle(Long id) throws NotFoundException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SituationFiscaleParcellePayloadWeb> getSituationFiscaleParcelleList(Pageable pageable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<SituationFiscaleParcellePayloadWeb> getSituationFiscaleParcelleListByParcellePageable(Long parcelleId, Pageable pageable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SituationFiscaleParcellePayloadWeb> getSituationFiscaleParcelleListByParcelle(Long parcelleId) {
|
||||
return situationFiscaleParcelleRepository.findAllPayloadByParcelleId(parcelleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<SituationFiscaleParcellePayloadWeb> getSituationFiscaleParcelleById(Long id) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.gmss.fiscad.interfaces.rfu.metier;
|
||||
|
||||
import io.gmss.fiscad.exceptions.BadRequestException;
|
||||
import io.gmss.fiscad.exceptions.NotFoundException;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.SituationFiscaleParcellePayloadWeb;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface SituationFiscaleParcelleService {
|
||||
|
||||
SituationFiscaleParcellePayloadWeb createSituationFiscaleParcelle(SituationFiscaleParcellePayloadWeb situationFiscaleParcellePayloadWeb) throws BadRequestException;
|
||||
|
||||
SituationFiscaleParcellePayloadWeb updateSituationFiscaleParcelle(Long id,SituationFiscaleParcellePayloadWeb situationFiscaleParcellePayloadWeb) throws NotFoundException;
|
||||
|
||||
void deleteSituationFiscaleParcelle(Long id) throws NotFoundException;
|
||||
|
||||
Page<SituationFiscaleParcellePayloadWeb> getSituationFiscaleParcelleList(Pageable pageable);
|
||||
|
||||
Page<SituationFiscaleParcellePayloadWeb> getSituationFiscaleParcelleListByParcellePageable(Long parcelleId, Pageable pageable);
|
||||
|
||||
List<SituationFiscaleParcellePayloadWeb> getSituationFiscaleParcelleListByParcelle(Long parcelleId);
|
||||
|
||||
Optional<SituationFiscaleParcellePayloadWeb> getSituationFiscaleParcelleById(Long id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.gmss.fiscad.paylaods.request.crudweb;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import io.gmss.fiscad.deserializer.LocalDateDeserializer;
|
||||
import io.gmss.fiscad.entities.infocad.metier.Parcelle;
|
||||
import io.gmss.fiscad.entities.rfu.parametre.Exercice;
|
||||
import io.gmss.fiscad.enums.NatureImpot;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class SituationFiscaleParcellePayloadWeb {
|
||||
private Long id;
|
||||
private Long parcelleId ;
|
||||
private String parcelleQ ;
|
||||
private String parcelleI ;
|
||||
private String parcelleP ;
|
||||
private String quartierCode ;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
private LocalDate dateDernierPaiement;
|
||||
private Long exerciceId ;
|
||||
private Integer exerciceAnnee ;
|
||||
private Long montantDu ;
|
||||
private Long montantPaye ;
|
||||
private Long montantDegeve ;
|
||||
private Long resteAPayer ;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
private LocalDate dateSync;
|
||||
private NatureImpot natureImpot;
|
||||
|
||||
public SituationFiscaleParcellePayloadWeb(Long id, Long parcelleId, String parcelleQ, String parcelleI, String parcelleP, String quartierCode, LocalDate dateDernierPaiement, Long exerciceId, Integer exerciceAnnee, Long montantDu, Long montantPaye, Long montantDegeve, Long resteAPayer, LocalDate dateSync, NatureImpot natureImpot) {
|
||||
this.id = id;
|
||||
this.parcelleId = parcelleId;
|
||||
this.parcelleQ = parcelleQ;
|
||||
this.parcelleI = parcelleI;
|
||||
this.parcelleP = parcelleP;
|
||||
this.quartierCode = quartierCode;
|
||||
this.dateDernierPaiement = dateDernierPaiement;
|
||||
this.exerciceId = exerciceId;
|
||||
this.exerciceAnnee = exerciceAnnee;
|
||||
this.montantDu = montantDu;
|
||||
this.montantPaye = montantPaye;
|
||||
this.montantDegeve = montantDegeve;
|
||||
this.resteAPayer = resteAPayer;
|
||||
this.dateSync = dateSync;
|
||||
this.natureImpot = natureImpot;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
----------------
|
||||
/*
|
||||
create or replace view e_avis_view as
|
||||
WITH first_parcelle_imposition AS (
|
||||
SELECT DISTINCT ON (personne_id)
|
||||
@@ -66,7 +67,73 @@ FROM impositions_tfu imp
|
||||
AND cca.commune_id = imp.commune_id
|
||||
LEFT JOIN structure st
|
||||
ON st.id = cca.structure_id
|
||||
order by c.code,st.code,r_quartier_contact,i_contact,p_contact;
|
||||
order by c.code,st.code,r_quartier_contact,i_contact,p_contact; */
|
||||
|
||||
|
||||
create or replace view e_avis_view as
|
||||
WITH first_parcelle_imposition AS (
|
||||
SELECT DISTINCT ON (personne_id)
|
||||
personne_id,
|
||||
parcelle_id
|
||||
FROM donnees_imposition_tfu
|
||||
ORDER BY personne_id, annee,parcelle_id
|
||||
),
|
||||
cca_unique AS (
|
||||
SELECT DISTINCT ON (cc.commune_id, cc.personne_id)
|
||||
cc.structure_id,
|
||||
cc.personne_id,
|
||||
cc.commune_id,
|
||||
COALESCE(qu.code, qu_imp.code) AS r_quartier_contact,
|
||||
COALESCE(parc.q, parc_imp.q) AS q_contact,
|
||||
COALESCE(parc.i, parc_imp.i) AS i_contact,
|
||||
COALESCE(parc.p, parc_imp.p) AS p_contact
|
||||
|
||||
FROM commune_centre_assignation cc
|
||||
|
||||
LEFT JOIN parcelle parc
|
||||
ON parc.id = cc.parcelle_id
|
||||
|
||||
LEFT JOIN quartier qu
|
||||
ON qu.id = parc.quartier_id
|
||||
|
||||
LEFT JOIN first_parcelle_imposition dpi
|
||||
ON dpi.personne_id = cc.personne_id
|
||||
|
||||
LEFT JOIN parcelle parc_imp
|
||||
ON parc_imp.id = dpi.parcelle_id
|
||||
|
||||
LEFT JOIN quartier qu_imp
|
||||
ON qu_imp.id = parc_imp.quartier_id
|
||||
ORDER BY cc.commune_id, cc.personne_id, cc.structure_id
|
||||
)
|
||||
SELECT distinct on (c.code,dimp.ifu,exo.annee)
|
||||
null as id_avis,
|
||||
concat(c.code,'-',dimp.ifu,'-',exo.annee) as r_avis,
|
||||
exo.annee as exercice,
|
||||
c.code as r_commune,
|
||||
st.code as r_centre_impot,
|
||||
dimp.personne_id as id_contribuable_foncier,
|
||||
dimp.ifu as ifu,
|
||||
dimp.npi as npi,
|
||||
dimp.ifu as nc,
|
||||
dimp.raison_sociale as raison_sociale,
|
||||
dimp.nom_prop as nom ,
|
||||
dimp.prenom_prop as prenom,
|
||||
imp.date_generation as date_liquidation,
|
||||
current_date as date_information
|
||||
FROM impositions_tfu imp
|
||||
INNER JOIN donnees_imposition_tfu dimp
|
||||
ON dimp.impositions_tfu_id = imp.id
|
||||
LEFT JOIN exercice exo
|
||||
ON exo.id = imp.exercice_id
|
||||
LEFT JOIN commune c
|
||||
ON c.id = imp.commune_id
|
||||
LEFT JOIN cca_unique cca
|
||||
ON cca.personne_id = dimp.personne_id
|
||||
AND cca.commune_id = imp.commune_id
|
||||
LEFT JOIN structure st
|
||||
ON st.id = cca.structure_id
|
||||
order by c.code,dimp.ifu,exo.annee;
|
||||
|
||||
|
||||
|
||||
@@ -83,8 +150,8 @@ WITH cca_unique AS (
|
||||
ORDER BY commune_id,personne_id,structure_id
|
||||
)
|
||||
SELECT distinct on (exo.annee,dimp.parcelle_id,dimp.nature_impot)
|
||||
null as id_avis_detail,
|
||||
null as id_avis,
|
||||
dimp.id as id_avis_detail,
|
||||
eavis.id_avis as id_avis,
|
||||
dimp.id as id_externe_ligne_imposition,
|
||||
concat(c.code,'-',dimp.ifu,'-',exo.annee) as r_avis,
|
||||
dimp.nature_impot as id_impot_nature,
|
||||
@@ -111,9 +178,9 @@ SELECT distinct on (exo.annee,dimp.parcelle_id,dimp.nature_impot)
|
||||
FROM impositions_tfu imp
|
||||
INNER JOIN donnees_imposition_tfu dimp
|
||||
ON dimp.impositions_tfu_id = imp.id
|
||||
LEFT JOIN exercice exo
|
||||
INNER JOIN exercice exo
|
||||
ON exo.id = imp.exercice_id
|
||||
LEFT JOIN commune c
|
||||
INNER JOIN commune c
|
||||
ON c.id = imp.commune_id
|
||||
LEFT JOIN cca_unique cca
|
||||
ON cca.personne_id = dimp.personne_id
|
||||
@@ -121,6 +188,7 @@ FROM impositions_tfu imp
|
||||
AND cca.parcelle_id = dimp.parcelle_id
|
||||
LEFT JOIN structure st
|
||||
ON st.id = cca.structure_id
|
||||
INNER JOIN eavis on eavis.r_avis = concat(c.code,'-',dimp.ifu,'-',exo.annee)
|
||||
where dimp.personne_id is not null
|
||||
order by exo.annee,dimp.parcelle_id,dimp.nature_impot, dimp.montant_taxe-coalesce(dimp.acompte,0)-coalesce(dimp.retenu_irf,0) desc ;
|
||||
-- and dimp.ifu='208558';
|
||||
@@ -144,4 +212,6 @@ where not exists(select 1 from parcelle_view pv
|
||||
select penalite
|
||||
from donnees_imposition_tfu;
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
CREATE OR REPLACE PROCEDURE public.integrer_eavis()
|
||||
LANGUAGE plpgsql
|
||||
AS
|
||||
$$
|
||||
DECLARE
|
||||
|
||||
BEGIN
|
||||
MERGE INTO eavis e
|
||||
USING e_avis_view v
|
||||
ON e.r_avis = v.r_avis
|
||||
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET
|
||||
exercice = v.exercice,
|
||||
r_commune = v.r_commune,
|
||||
r_centre_impot = v.r_centre_impot,
|
||||
id_contribuable_foncier = v.id_contribuable_foncier,
|
||||
ifu = v.ifu,
|
||||
npi = v.npi,
|
||||
nc = v.nc,
|
||||
raison_social = v.raison_sociale,
|
||||
nom = v.nom,
|
||||
prenom = v.prenom,
|
||||
date_liquidation = v.date_liquidation,
|
||||
date_information = v.date_information
|
||||
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT
|
||||
(
|
||||
r_avis,
|
||||
exercice,
|
||||
r_commune,
|
||||
r_centre_impot,
|
||||
id_contribuable_foncier,
|
||||
ifu,
|
||||
npi,
|
||||
nc,
|
||||
raison_social,
|
||||
nom,
|
||||
prenom,
|
||||
date_liquidation,
|
||||
date_information
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
v.r_avis,
|
||||
v.exercice,
|
||||
v.r_commune,
|
||||
v.r_centre_impot,
|
||||
v.id_contribuable_foncier,
|
||||
v.ifu,
|
||||
v.npi,
|
||||
v.nc,
|
||||
v.raison_sociale,
|
||||
v.nom,
|
||||
v.prenom,
|
||||
v.date_liquidation,
|
||||
v.date_information
|
||||
);
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
call integrer_eavis();
|
||||
|
||||
select * from eavis
|
||||
|
||||
delete from eavis;
|
||||
@@ -0,0 +1,73 @@
|
||||
CREATE OR REPLACE PROCEDURE public.integrer_eavis_detail()
|
||||
LANGUAGE plpgsql
|
||||
AS
|
||||
$$
|
||||
DECLARE
|
||||
|
||||
BEGIN
|
||||
MERGE INTO eavis_detail d
|
||||
USING e_avis_detail_view v
|
||||
ON d.id_avis_detail = v.id_avis_detail
|
||||
|
||||
WHEN MATCHED THEN
|
||||
UPDATE SET
|
||||
id_avis = v.id_avis,
|
||||
id_impot_nature = v.id_impot_nature,
|
||||
id_unite_foncier = v.id_unite_foncier,
|
||||
nup = v.nup,
|
||||
r_quartier = v.r_quartier,
|
||||
qip_quartier = v.qip_quartier,
|
||||
qip_ilot = v.qip_ilot,
|
||||
qip_parcelle = v.qip_parcelle,
|
||||
batiment = v.batiment,
|
||||
unite_logement = v.unite_logement,
|
||||
montant_base_imposition = v.montant_base_imposition,
|
||||
montant_valeur_locative = v.montant_valeur_locative,
|
||||
taux = v.taux,
|
||||
montant_du = v.montant_du,
|
||||
booleen_parcelle_contact = v.booleen_parcelle_contact,
|
||||
penalite = v.penalite
|
||||
|
||||
WHEN NOT MATCHED THEN
|
||||
INSERT
|
||||
(
|
||||
id_avis_detail,
|
||||
id_avis,
|
||||
id_impot_nature,
|
||||
id_unite_foncier,
|
||||
nup,
|
||||
r_quartier,
|
||||
qip_quartier,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
batiment,
|
||||
unite_logement,
|
||||
montant_base_imposition,
|
||||
montant_valeur_locative,
|
||||
taux,
|
||||
montant_du,
|
||||
booleen_parcelle_contact,
|
||||
penalite
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
v.id_avis_detail,
|
||||
v.id_avis,
|
||||
v.id_impot_nature,
|
||||
v.id_unite_foncier,
|
||||
v.nup,
|
||||
v.r_quartier,
|
||||
v.qip_quartier,
|
||||
v.qip_ilot,
|
||||
v.qip_parcelle,
|
||||
v.batiment,
|
||||
v.unite_logement,
|
||||
v.montant_base_imposition,
|
||||
v.montant_valeur_locative,
|
||||
v.taux,
|
||||
v.montant_du,
|
||||
v.booleen_parcelle_contact,
|
||||
v.penalite
|
||||
);
|
||||
END;
|
||||
$$;
|
||||
@@ -0,0 +1,149 @@
|
||||
CREATE OR REPLACE PROCEDURE integrer_situation_fiscale_depuis_sigibe(IN commune_id varchar(20))
|
||||
LANGUAGE plpgsql
|
||||
AS
|
||||
$$
|
||||
DECLARE
|
||||
v_conn TEXT;
|
||||
v_nb_importe INTEGER;
|
||||
v_ids TEXT;
|
||||
BEGIN
|
||||
|
||||
v_conn := get_dblink_connection_sigibe();
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Chargement des données distantes
|
||||
----------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS tmp_situation_migration;
|
||||
|
||||
CREATE TEMP TABLE tmp_situation_migration
|
||||
ON COMMIT DROP
|
||||
AS
|
||||
SELECT *
|
||||
FROM dblink
|
||||
(
|
||||
v_conn,
|
||||
format($SQL$
|
||||
SELECT
|
||||
exercice,
|
||||
CASE
|
||||
WHEN nature='1L' THEN 'FNB'
|
||||
WHEN nature='2L' THEN 'FB'
|
||||
WHEN nature IN ('3N','4N','YN') THEN 'IRF'
|
||||
WHEN nature IN ('2N','7N','8N') THEN 'SRTB'
|
||||
END AS nature,
|
||||
id_quartier,
|
||||
ilot,
|
||||
parcelle,
|
||||
SUM(COALESCE(montant,0)) AS montant,
|
||||
SUM(COALESCE(majoration,0)) AS majoration,
|
||||
SUM(COALESCE(penalite,0)) AS penalite,
|
||||
SUM(COALESCE(montant_paye,0)) AS montant_paye,
|
||||
SUM(COALESCE(montant_degreve,0)) AS montant_degreve,
|
||||
SUM(COALESCE(montant_restant,0)) AS montant_restant
|
||||
FROM sigibe.w_rfu_impot
|
||||
WHERE id_commune = %L
|
||||
AND trim(nature) in ('2L','2L','3N','4N','YN','2N','7N','8N')
|
||||
GROUP BY
|
||||
exercice,
|
||||
CASE
|
||||
WHEN nature='1L' THEN 'FNB'
|
||||
WHEN nature='2L' THEN 'FB'
|
||||
WHEN nature IN ('3N','4N','YN') THEN 'IRF'
|
||||
WHEN nature IN ('2N','7N','8N') THEN 'SRTB'
|
||||
END,
|
||||
id_quartier,
|
||||
ilot,
|
||||
parcelle
|
||||
|
||||
$SQL$, commune_id)
|
||||
)
|
||||
AS src
|
||||
(
|
||||
exercice numeric,
|
||||
nature varchar(10),
|
||||
id_quartier varchar(20),
|
||||
ilot varchar(10),
|
||||
parcelle varchar(10),
|
||||
montant numeric,
|
||||
majoration numeric,
|
||||
penalite numeric,
|
||||
montant_paye numeric,
|
||||
montant_degreve numeric,
|
||||
montant_restant numeric
|
||||
);
|
||||
----------------------------------------------------------------------
|
||||
-- Insertion
|
||||
----------------------------------------------------------------------
|
||||
|
||||
INSERT INTO situation_fiscale_parcelle
|
||||
(
|
||||
created_at,
|
||||
created_by,
|
||||
deleted,
|
||||
source,
|
||||
updated_at,
|
||||
updated_by,
|
||||
parcelle_id,
|
||||
date_sync,
|
||||
montant_du,
|
||||
montant_paye,
|
||||
montant_degeve,
|
||||
resteapayer,
|
||||
exercice_id,
|
||||
nature_impot
|
||||
)
|
||||
SELECT distinct on(parc.id,e.id,t.nature)
|
||||
clock_timestamp(),
|
||||
NULL,
|
||||
FALSE,
|
||||
'SIGIBE',
|
||||
clock_timestamp(),
|
||||
NULL,
|
||||
parc.id,
|
||||
clock_timestamp(),
|
||||
t.montant + t.penalite + t.majoration,
|
||||
t.montant_paye,
|
||||
t.montant_degreve,
|
||||
t.montant + t.majoration + t.penalite - t.montant_paye - t.montant_degreve,
|
||||
e.id,
|
||||
t.nature
|
||||
FROM tmp_situation_migration t
|
||||
INNER JOIN (select distinct p.id, p.i, p.p, quartier.code_sigibe as code_sigibe from parcelle p inner join quartier on p.quartier_id = quartier.id) parc
|
||||
ON parc.code_sigibe = t.id_quartier and parc.i=t.ilot and parc.p=t.parcelle
|
||||
INNER JOIN exercice e on e.annee=t.exercice
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM situation_fiscale_parcelle sfp
|
||||
WHERE sfp.parcelle_id = parc.id and sfp.exercice_id=e.id and sfp.nature_impot=t.nature
|
||||
)
|
||||
order by parc.id,e.id,t.nature ;
|
||||
|
||||
|
||||
RAISE NOTICE 'déclaration(s) intégrée(s).';
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
RAISE EXCEPTION
|
||||
'Erreur dans integrer_edeclaration_propriete_depuis_sigibe : %',
|
||||
SQLERRM;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
--'host=193.181.208.4 port=5433 dbname=sigibe_test user=sigibe_test_user password=sigibe_test_pwd',
|
||||
--'
|
||||
|
||||
call integrer_situation_fiscale_depuis_sigibe('08.1');
|
||||
|
||||
select count(*) from situation_fiscale_parcelle;
|
||||
|
||||
select distinct code_quartier
|
||||
from parcelle
|
||||
inner join public.quartier q on q.id = parcelle.quartier_id
|
||||
where q.code='08.1.09.02' and parcelle.i= '3715'
|
||||
|
||||
select * from arrondissement
|
||||
where code like '08.1%'
|
||||
|
||||
select left(code,4) as code_commune_fiscad, code as code_quartier_fiscad,nom as nom_quartier_fiscad
|
||||
from quartier;
|
||||
@@ -0,0 +1,120 @@
|
||||
CREATE OR REPLACE PROCEDURE public.exporter_eavis()
|
||||
LANGUAGE plpgsql
|
||||
AS
|
||||
$$
|
||||
DECLARE
|
||||
v_nb_update INTEGER;
|
||||
v_nb_insert INTEGER;
|
||||
v_nb_exporte INTEGER;
|
||||
BEGIN
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Nombre de lignes à exporter
|
||||
------------------------------------------------------------------
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO v_nb_exporte
|
||||
FROM eavis
|
||||
WHERE integre = 0;
|
||||
|
||||
IF v_nb_exporte = 0 THEN
|
||||
RAISE NOTICE 'Aucun avis à exporter.';
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Mise à jour des avis existants dans SIGIBE
|
||||
------------------------------------------------------------------
|
||||
UPDATE interface_sigibe.e_avis d
|
||||
SET r_avis = s.r_avis,
|
||||
exercice = s.exercice,
|
||||
r_commune = s.r_commune,
|
||||
r_centre_impot = s.r_centre_impot,
|
||||
id_contribuable_foncier = s.id_contribuable_foncier,
|
||||
ifu = s.ifu,
|
||||
npi = s.npi,
|
||||
nc = s.nc,
|
||||
raison_social = s.raison_social,
|
||||
nom = s.nom,
|
||||
prenom = s.prenom,
|
||||
date_liquidation = s.date_liquidation,
|
||||
date_information = s.date_information,
|
||||
integre = 1
|
||||
FROM eavis s
|
||||
WHERE s.integre = 0
|
||||
AND d.id_avis = s.id_avis;
|
||||
|
||||
GET DIAGNOSTICS v_nb_update = ROW_COUNT;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Insertion des nouveaux avis
|
||||
------------------------------------------------------------------
|
||||
|
||||
INSERT INTO interface_sigibe.e_avis
|
||||
(
|
||||
id_avis,
|
||||
r_avis,
|
||||
exercice,
|
||||
r_commune,
|
||||
r_centre_impot,
|
||||
id_contribuable_foncier,
|
||||
ifu,
|
||||
npi,
|
||||
nc,
|
||||
raison_social,
|
||||
nom,
|
||||
prenom,
|
||||
date_liquidation,
|
||||
date_information,
|
||||
integre
|
||||
)
|
||||
SELECT
|
||||
s.id_avis,
|
||||
s.r_avis,
|
||||
s.exercice,
|
||||
s.r_commune,
|
||||
s.r_centre_impot,
|
||||
s.id_contribuable_foncier,
|
||||
s.ifu,
|
||||
s.npi,
|
||||
s.nc,
|
||||
s.raison_social,
|
||||
s.nom,
|
||||
s.prenom,
|
||||
s.date_liquidation,
|
||||
s.date_information,
|
||||
1
|
||||
FROM eavis s
|
||||
WHERE s.integre = 0
|
||||
AND NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM interface_sigibe.e_avis d
|
||||
WHERE d.id_avis = s.id_avis
|
||||
);
|
||||
|
||||
GET DIAGNOSTICS v_nb_insert = ROW_COUNT;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Marquage local des avis exportés
|
||||
------------------------------------------------------------------
|
||||
|
||||
UPDATE eavis
|
||||
SET integre = 1
|
||||
WHERE integre = 0;
|
||||
|
||||
RAISE NOTICE
|
||||
'% avis exportés (% mis à jour, % insérés).',
|
||||
v_nb_exporte,
|
||||
v_nb_update,
|
||||
v_nb_insert;
|
||||
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_eavis_detail_integre
|
||||
ON eavis_detail(integre);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_eavis_detail_id
|
||||
ON eavis_detail(id_avis_detail);
|
||||
@@ -0,0 +1,122 @@
|
||||
CREATE OR REPLACE PROCEDURE public.exporter_eavis_detail()
|
||||
LANGUAGE plpgsql
|
||||
AS
|
||||
$$
|
||||
DECLARE
|
||||
v_nb_update INTEGER;
|
||||
v_nb_insert INTEGER;
|
||||
v_nb_exporte INTEGER;
|
||||
BEGIN
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Nombre de lignes à exporter
|
||||
------------------------------------------------------------------
|
||||
|
||||
SELECT COUNT(*)
|
||||
INTO v_nb_exporte
|
||||
FROM eavis_detail
|
||||
WHERE integre = 0;
|
||||
|
||||
IF v_nb_exporte = 0 THEN
|
||||
RAISE NOTICE 'Aucun détail d''avis à exporter.';
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Mise à jour des lignes existantes dans SIGIBE
|
||||
------------------------------------------------------------------
|
||||
|
||||
UPDATE interface_sigibe.e_avis_detail d
|
||||
SET id_avis = s.id_avis,
|
||||
id_impot_nature = s.id_impot_nature,
|
||||
id_unite_foncier = s.id_unite_foncier,
|
||||
nup = s.nup,
|
||||
r_quartier = s.r_quartier,
|
||||
qip_quartier = s.qip_quartier,
|
||||
qip_ilot = s.qip_ilot,
|
||||
qip_parcelle = s.qip_parcelle,
|
||||
batiment = s.batiment,
|
||||
unite_logement = s.unite_logement,
|
||||
montant_base_imposition = s.montant_base_imposition,
|
||||
montant_valeur_locative = s.montant_valeur_locative,
|
||||
taux = s.taux,
|
||||
montant_du = s.montant_du,
|
||||
booleen_parcelle_contact = s.booleen_parcelle_contact,
|
||||
penalite = s.penalite,
|
||||
integre = 1
|
||||
FROM eavis_detail s
|
||||
WHERE s.integre = 0
|
||||
AND d.id_avis_detail = s.id_avis_detail;
|
||||
|
||||
GET DIAGNOSTICS v_nb_update = ROW_COUNT;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Insertion des nouvelles lignes
|
||||
------------------------------------------------------------------
|
||||
|
||||
INSERT INTO interface_sigibe.e_avis_detail
|
||||
(
|
||||
id_avis_detail,
|
||||
id_avis,
|
||||
id_impot_nature,
|
||||
id_unite_foncier,
|
||||
nup,
|
||||
r_quartier,
|
||||
qip_quartier,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
batiment,
|
||||
unite_logement,
|
||||
montant_base_imposition,
|
||||
montant_valeur_locative,
|
||||
taux,
|
||||
montant_du,
|
||||
booleen_parcelle_contact,
|
||||
penalite,
|
||||
integre
|
||||
)
|
||||
SELECT
|
||||
s.id_avis_detail,
|
||||
s.id_avis,
|
||||
s.id_impot_nature,
|
||||
s.id_unite_foncier,
|
||||
s.nup,
|
||||
s.r_quartier,
|
||||
s.qip_quartier,
|
||||
s.qip_ilot,
|
||||
s.qip_parcelle,
|
||||
s.batiment,
|
||||
s.unite_logement,
|
||||
s.montant_base_imposition,
|
||||
s.montant_valeur_locative,
|
||||
s.taux,
|
||||
s.montant_du,
|
||||
s.booleen_parcelle_contact,
|
||||
s.penalite,
|
||||
1
|
||||
FROM eavis_detail s
|
||||
WHERE s.integre = 0
|
||||
AND NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM interface_sigibe.e_avis_detail d
|
||||
WHERE d.id_avis_detail = s.id_avis_detail
|
||||
);
|
||||
|
||||
GET DIAGNOSTICS v_nb_insert = ROW_COUNT;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Marquage local des lignes exportées
|
||||
------------------------------------------------------------------
|
||||
|
||||
UPDATE eavis_detail
|
||||
SET integre = 1
|
||||
WHERE integre = 0;
|
||||
|
||||
RAISE NOTICE
|
||||
'% détail(s) d''avis exporté(s) (% mis à jour, % inséré(s)).',
|
||||
v_nb_exporte,
|
||||
v_nb_update,
|
||||
v_nb_insert;
|
||||
END;
|
||||
$$;
|
||||
@@ -0,0 +1,119 @@
|
||||
CREATE OR REPLACE PROCEDURE public.exporter_eparcelle()
|
||||
LANGUAGE plpgsql
|
||||
AS
|
||||
$$
|
||||
DECLARE
|
||||
v_nb_update INTEGER;
|
||||
v_nb_insert INTEGER;
|
||||
v_nb_exporte INTEGER;
|
||||
BEGIN
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Nombre de lignes à exporter
|
||||
------------------------------------------------------------------
|
||||
SELECT COUNT(*)
|
||||
INTO v_nb_exporte
|
||||
FROM parcelle
|
||||
WHERE integre = 0;
|
||||
|
||||
IF v_nb_exporte = 0 THEN
|
||||
RAISE NOTICE 'Aucun avis à exporter.';
|
||||
RETURN;
|
||||
END IF;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Mise à jour des avis existants dans SIGIBE
|
||||
------------------------------------------------------------------
|
||||
UPDATE interface_sigibe.e_avis d
|
||||
SET r_avis = s.r_avis,
|
||||
exercice = s.exercice,
|
||||
r_commune = s.r_commune,
|
||||
r_centre_impot = s.r_centre_impot,
|
||||
id_contribuable_foncier = s.id_contribuable_foncier,
|
||||
ifu = s.ifu,
|
||||
npi = s.npi,
|
||||
nc = s.nc,
|
||||
raison_social = s.raison_social,
|
||||
nom = s.nom,
|
||||
prenom = s.prenom,
|
||||
date_liquidation = s.date_liquidation,
|
||||
date_information = s.date_information,
|
||||
integre = 1
|
||||
FROM eavis s
|
||||
WHERE s.integre = 0
|
||||
AND d.id_avis = s.id_avis;
|
||||
|
||||
GET DIAGNOSTICS v_nb_update = ROW_COUNT;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Insertion des nouveaux avis
|
||||
------------------------------------------------------------------
|
||||
|
||||
INSERT INTO interface_sigibe.e_avis
|
||||
(
|
||||
id_avis,
|
||||
r_avis,
|
||||
exercice,
|
||||
r_commune,
|
||||
r_centre_impot,
|
||||
id_contribuable_foncier,
|
||||
ifu,
|
||||
npi,
|
||||
nc,
|
||||
raison_social,
|
||||
nom,
|
||||
prenom,
|
||||
date_liquidation,
|
||||
date_information,
|
||||
integre
|
||||
)
|
||||
SELECT
|
||||
s.id_avis,
|
||||
s.r_avis,
|
||||
s.exercice,
|
||||
s.r_commune,
|
||||
s.r_centre_impot,
|
||||
s.id_contribuable_foncier,
|
||||
s.ifu,
|
||||
s.npi,
|
||||
s.nc,
|
||||
s.raison_social,
|
||||
s.nom,
|
||||
s.prenom,
|
||||
s.date_liquidation,
|
||||
s.date_information,
|
||||
1
|
||||
FROM eavis s
|
||||
WHERE s.integre = 0
|
||||
AND NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM interface_sigibe.e_avis d
|
||||
WHERE d.id_avis = s.id_avis
|
||||
);
|
||||
|
||||
GET DIAGNOSTICS v_nb_insert = ROW_COUNT;
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Marquage local des avis exportés
|
||||
------------------------------------------------------------------
|
||||
|
||||
UPDATE eavis
|
||||
SET integre = 1
|
||||
WHERE integre = 0;
|
||||
|
||||
RAISE NOTICE
|
||||
'% avis exportés (% mis à jour, % insérés).',
|
||||
v_nb_exporte,
|
||||
v_nb_update,
|
||||
v_nb_insert;
|
||||
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_eavis_detail_integre
|
||||
ON eavis_detail(integre);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_eavis_detail_id
|
||||
ON eavis_detail(id_avis_detail);
|
||||
@@ -1,83 +1,27 @@
|
||||
create or replace procedure integrer_edeclaration_propriete_depuis_sigibe()
|
||||
language plpgsql
|
||||
as
|
||||
CREATE OR REPLACE PROCEDURE integrer_edeclaration_propriete_depuis_sigibe()
|
||||
LANGUAGE plpgsql
|
||||
AS
|
||||
$$
|
||||
DECLARE
|
||||
v_inserted_count integer;
|
||||
v_conn TEXT;
|
||||
v_nb_importe INTEGER;
|
||||
v_ids TEXT;
|
||||
BEGIN
|
||||
|
||||
INSERT INTO public.edeclaration_propriete
|
||||
(
|
||||
created_at,
|
||||
created_by,
|
||||
deleted,
|
||||
source,
|
||||
updated_at,
|
||||
updated_by,
|
||||
bati,
|
||||
commentaire,
|
||||
date_construction,
|
||||
date_information,
|
||||
date_validation,
|
||||
gps_latitude,
|
||||
gps_longitude,
|
||||
id_impot,
|
||||
ifu,
|
||||
montant_locatif_annuel,
|
||||
nub,
|
||||
nul,
|
||||
nup,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
qip_quartier,
|
||||
r_commune,
|
||||
r_impot,
|
||||
r_quartier,
|
||||
superficie_parcelle,
|
||||
superficie_sol_bat,
|
||||
superficie_sol_ulo,
|
||||
usage,
|
||||
valeur_batiment,
|
||||
personne_id,
|
||||
quartier_id,
|
||||
statut_edeclaration_propriete
|
||||
)
|
||||
SELECT
|
||||
now() AS created_at,
|
||||
NULL::bigint AS created_by,
|
||||
false AS deleted,
|
||||
'SIGIBE' AS source,
|
||||
NULL::timestamp with time zone AS updated_at,
|
||||
NULL::bigint AS updated_by,
|
||||
src.bati,
|
||||
src.commentaire,
|
||||
src.date_construction,
|
||||
src.date_information,
|
||||
src.date_validation,
|
||||
src.gps_latitude,
|
||||
src.gps_longitude,
|
||||
src.id_impot,
|
||||
src.ifu,
|
||||
src.montant_locatif_annuel,
|
||||
src.nub,
|
||||
src.nul,
|
||||
src.nup,
|
||||
src.qip_ilot,
|
||||
src.qip_parcelle,
|
||||
src.qip_quartier,
|
||||
src.r_commune,
|
||||
src.r_impot,
|
||||
src.r_quartier,
|
||||
src.superficie_parcelle,
|
||||
src.superficie_sol_bat,
|
||||
src.superficie_sol_ulo,
|
||||
src.usage,
|
||||
src.valeur_batiment,
|
||||
p.id AS personne_id,
|
||||
q.id AS quartier_id,
|
||||
'EN_ATTENTE'
|
||||
FROM dblink(
|
||||
get_dblink_connection(),
|
||||
v_conn := get_dblink_connection();
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Chargement des données distantes
|
||||
----------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS tmp_declaration_propriete;
|
||||
|
||||
CREATE TEMP TABLE tmp_declaration_propriete
|
||||
ON COMMIT DROP
|
||||
AS
|
||||
SELECT *
|
||||
FROM dblink
|
||||
(
|
||||
v_conn,
|
||||
'
|
||||
SELECT
|
||||
bati,
|
||||
@@ -104,46 +48,180 @@ BEGIN
|
||||
superficie_sol_ulo,
|
||||
usage,
|
||||
valeur_batiment
|
||||
FROM public.e_declaration_propriete
|
||||
FROM e_declaration_propriete
|
||||
WHERE COALESCE(integre,0)=0
|
||||
ORDER BY id_impot
|
||||
'
|
||||
) AS src
|
||||
)
|
||||
AS src
|
||||
(
|
||||
bati boolean,
|
||||
commentaire varchar(255),
|
||||
date_construction date,
|
||||
date_information date,
|
||||
date_validation date,
|
||||
gps_latitude varchar(255),
|
||||
gps_longitude varchar(255),
|
||||
id_impot bigint,
|
||||
ifu varchar(255),
|
||||
montant_locatif_annuel bigint,
|
||||
nub bigint,
|
||||
nul bigint,
|
||||
nup varchar(255),
|
||||
qip_ilot varchar(255),
|
||||
qip_parcelle varchar(255),
|
||||
qip_quartier varchar(255),
|
||||
r_commune varchar(255),
|
||||
r_impot varchar(255),
|
||||
r_quartier varchar(255),
|
||||
superficie_parcelle real,
|
||||
superficie_sol_bat real,
|
||||
superficie_sol_ulo real,
|
||||
usage varchar(255),
|
||||
valeur_batiment bigint
|
||||
)
|
||||
left join personne p on p.ifu=src.ifu
|
||||
left join quartier q on q.code=src.r_quartier
|
||||
where not exists( select 1
|
||||
from edeclaration_propriete edp
|
||||
where edp.id_impot=src.id_impot
|
||||
);
|
||||
bati BOOLEAN,
|
||||
commentaire VARCHAR(255),
|
||||
date_construction DATE,
|
||||
date_information DATE,
|
||||
date_validation DATE,
|
||||
gps_latitude VARCHAR(255),
|
||||
gps_longitude VARCHAR(255),
|
||||
id_impot BIGINT,
|
||||
ifu VARCHAR(255),
|
||||
montant_locatif_annuel BIGINT,
|
||||
nub BIGINT,
|
||||
nul BIGINT,
|
||||
nup VARCHAR(255),
|
||||
qip_ilot VARCHAR(255),
|
||||
qip_parcelle VARCHAR(255),
|
||||
qip_quartier VARCHAR(255),
|
||||
r_commune VARCHAR(255),
|
||||
r_impot VARCHAR(255),
|
||||
r_quartier VARCHAR(255),
|
||||
superficie_parcelle REAL,
|
||||
superficie_sol_bat REAL,
|
||||
superficie_sol_ulo REAL,
|
||||
usage VARCHAR(255),
|
||||
valeur_batiment BIGINT
|
||||
);
|
||||
|
||||
GET DIAGNOSTICS v_inserted_count = ROW_COUNT;
|
||||
----------------------------------------------------------------------
|
||||
-- Table temporaire des identifiants réellement importés
|
||||
----------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS tmp_ids_importes;
|
||||
|
||||
RAISE NOTICE 'Intégration terminée. Nombre de lignes insérées : %', v_inserted_count;
|
||||
CREATE TEMP TABLE tmp_ids_importes
|
||||
(
|
||||
id BIGINT
|
||||
) ON COMMIT DROP;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Insertion + récupération des id_impot réellement insérés
|
||||
----------------------------------------------------------------------
|
||||
WITH inserted AS
|
||||
(
|
||||
INSERT INTO edeclaration_propriete
|
||||
(
|
||||
created_at,
|
||||
created_by,
|
||||
deleted,
|
||||
source,
|
||||
updated_at,
|
||||
updated_by,
|
||||
bati,
|
||||
commentaire,
|
||||
date_construction,
|
||||
date_information,
|
||||
date_validation,
|
||||
gps_latitude,
|
||||
gps_longitude,
|
||||
id_impot,
|
||||
ifu,
|
||||
montant_locatif_annuel,
|
||||
nub,
|
||||
nul,
|
||||
nup,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
qip_quartier,
|
||||
r_commune,
|
||||
r_impot,
|
||||
r_quartier,
|
||||
superficie_parcelle,
|
||||
superficie_sol_bat,
|
||||
superficie_sol_ulo,
|
||||
usage,
|
||||
valeur_batiment,
|
||||
personne_id,
|
||||
quartier_id,
|
||||
statut_edeclaration_propriete
|
||||
)
|
||||
SELECT
|
||||
clock_timestamp(),
|
||||
NULL,
|
||||
FALSE,
|
||||
'SIGIBE',
|
||||
clock_timestamp(),
|
||||
NULL,
|
||||
t.bati,
|
||||
t.commentaire,
|
||||
t.date_construction,
|
||||
t.date_information,
|
||||
t.date_validation,
|
||||
t.gps_latitude,
|
||||
t.gps_longitude,
|
||||
t.id_impot,
|
||||
t.ifu,
|
||||
t.montant_locatif_annuel,
|
||||
t.nub,
|
||||
t.nul,
|
||||
t.nup,
|
||||
t.qip_ilot,
|
||||
t.qip_parcelle,
|
||||
t.qip_quartier,
|
||||
t.r_commune,
|
||||
t.r_impot,
|
||||
t.r_quartier,
|
||||
t.superficie_parcelle,
|
||||
t.superficie_sol_bat,
|
||||
t.superficie_sol_ulo,
|
||||
t.usage,
|
||||
t.valeur_batiment,
|
||||
p.id,
|
||||
q.id,
|
||||
'EN_ATTENTE'
|
||||
FROM tmp_declaration_propriete t
|
||||
LEFT JOIN personne p
|
||||
ON p.ifu = t.ifu
|
||||
LEFT JOIN quartier q
|
||||
ON q.code = t.r_quartier
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM edeclaration_propriete d
|
||||
WHERE d.id_impot = t.id_impot
|
||||
)
|
||||
RETURNING id_impot
|
||||
)
|
||||
INSERT INTO tmp_ids_importes(id)
|
||||
SELECT id_impot
|
||||
FROM inserted;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Nombre réellement importé
|
||||
----------------------------------------------------------------------
|
||||
SELECT COUNT(*)
|
||||
INTO v_nb_importe
|
||||
FROM tmp_ids_importes;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Construction de la liste des id_impot
|
||||
----------------------------------------------------------------------
|
||||
SELECT string_agg(id::text, ',')
|
||||
INTO v_ids
|
||||
FROM tmp_ids_importes;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Mise à jour de la base distante
|
||||
----------------------------------------------------------------------
|
||||
IF v_ids IS NOT NULL THEN
|
||||
|
||||
PERFORM dblink_exec
|
||||
(
|
||||
v_conn,
|
||||
format(
|
||||
'UPDATE e_declaration_propriete
|
||||
SET integre = 1
|
||||
WHERE id_impot IN (%s)',
|
||||
v_ids
|
||||
)
|
||||
);
|
||||
|
||||
END IF;
|
||||
|
||||
RAISE NOTICE '% déclaration(s) intégrée(s).', v_nb_importe;
|
||||
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
RAISE EXCEPTION
|
||||
'Erreur dans integrer_edeclaration_propriete_depuis_sigibe : %',
|
||||
SQLERRM;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
@@ -3,75 +3,24 @@ CREATE OR REPLACE PROCEDURE public.integrer_epaiement_acompte_depuis_sigibe()
|
||||
AS
|
||||
$$
|
||||
DECLARE
|
||||
v_nb_importe INTEGER;
|
||||
v_conn TEXT;
|
||||
v_nb_importe INTEGER;
|
||||
v_ids TEXT;
|
||||
BEGIN
|
||||
|
||||
v_conn := get_dblink_connection();
|
||||
|
||||
INSERT INTO public.epaiement_acompte
|
||||
(
|
||||
created_at,
|
||||
created_by,
|
||||
deleted,
|
||||
enquete_external_key,
|
||||
external_key,
|
||||
source,
|
||||
updated_at,
|
||||
updated_by,
|
||||
date_avis_credit,
|
||||
date_information,
|
||||
date_rapprochement,
|
||||
date_validation,
|
||||
id_exercice,
|
||||
id_impot_nature,
|
||||
id_impot_type,
|
||||
id_paiement_acompte,
|
||||
id_paiement_impot,
|
||||
ifu,
|
||||
montant_paye,
|
||||
nup,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
qip_quartier,
|
||||
r_commune,
|
||||
r_doc,
|
||||
r_impot,
|
||||
r_quartier,
|
||||
exercice,
|
||||
montant_payer
|
||||
)
|
||||
SELECT
|
||||
now(),
|
||||
NULL,
|
||||
false,
|
||||
NULL,
|
||||
src.id_paiement_acompte,
|
||||
'SIGIBE',
|
||||
now(),
|
||||
NULL,
|
||||
src.date_avis_credit,
|
||||
src.date_information,
|
||||
src.date_rapprochement,
|
||||
src.date_validation,
|
||||
src.id_exercice,
|
||||
src.id_impot_nature,
|
||||
src.id_impot_type,
|
||||
src.id_paiement_acompte,
|
||||
src.id_paiement_impot,
|
||||
src.ifu,
|
||||
src.montant_paye,
|
||||
src.nup,
|
||||
src.qip_ilot,
|
||||
src.qip_parcelle,
|
||||
src.qip_quartier,
|
||||
src.r_commune,
|
||||
src.r_doc,
|
||||
src.r_impot,
|
||||
src.r_quartier,
|
||||
src.id_exercice,
|
||||
src.montant_paye
|
||||
FROM dblink(
|
||||
----------------------------------------------------------------------
|
||||
-- Chargement des données distantes
|
||||
----------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS tmp_epaiement_acompte;
|
||||
|
||||
CREATE TEMP TABLE tmp_epaiement_acompte
|
||||
ON COMMIT DROP
|
||||
AS
|
||||
SELECT *
|
||||
FROM dblink
|
||||
(
|
||||
v_conn,
|
||||
'
|
||||
SELECT
|
||||
@@ -94,9 +43,12 @@ BEGIN
|
||||
r_doc,
|
||||
r_impot,
|
||||
r_quartier
|
||||
FROM public.e_paiement_acompte
|
||||
FROM e_paiement_acompte
|
||||
WHERE COALESCE(integre,0)=0
|
||||
ORDER BY id_paiement_acompte
|
||||
'
|
||||
) AS src
|
||||
)
|
||||
AS src
|
||||
(
|
||||
date_avis_credit DATE,
|
||||
date_information DATE,
|
||||
@@ -117,14 +69,130 @@ BEGIN
|
||||
r_doc VARCHAR,
|
||||
r_impot VARCHAR,
|
||||
r_quartier VARCHAR
|
||||
)
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM epaiement_acompte d
|
||||
WHERE d.id_paiement_acompte = src.id_paiement_acompte
|
||||
);
|
||||
);
|
||||
|
||||
GET DIAGNOSTICS v_nb_importe = ROW_COUNT;
|
||||
----------------------------------------------------------------------
|
||||
-- Table temporaire des identifiants réellement importés
|
||||
----------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS tmp_ids_importes;
|
||||
|
||||
CREATE TEMP TABLE tmp_ids_importes
|
||||
(
|
||||
id BIGINT
|
||||
) ON COMMIT DROP;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Insertion + récupération des identifiants insérés
|
||||
----------------------------------------------------------------------
|
||||
WITH inserted AS
|
||||
(
|
||||
INSERT INTO epaiement_acompte
|
||||
(
|
||||
created_at,
|
||||
created_by,
|
||||
deleted,
|
||||
enquete_external_key,
|
||||
external_key,
|
||||
source,
|
||||
updated_at,
|
||||
updated_by,
|
||||
date_avis_credit,
|
||||
date_information,
|
||||
date_rapprochement,
|
||||
date_validation,
|
||||
id_exercice,
|
||||
id_impot_nature,
|
||||
id_impot_type,
|
||||
id_paiement_acompte,
|
||||
id_paiement_impot,
|
||||
ifu,
|
||||
montant_paye,
|
||||
nup,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
qip_quartier,
|
||||
r_commune,
|
||||
r_doc,
|
||||
r_impot,
|
||||
r_quartier,
|
||||
exercice,
|
||||
montant_payer
|
||||
)
|
||||
SELECT
|
||||
now(),
|
||||
NULL,
|
||||
false,
|
||||
NULL,
|
||||
t.id_paiement_acompte,
|
||||
'SIGIBE',
|
||||
now(),
|
||||
NULL,
|
||||
t.date_avis_credit,
|
||||
t.date_information,
|
||||
t.date_rapprochement,
|
||||
t.date_validation,
|
||||
t.id_exercice,
|
||||
t.id_impot_nature,
|
||||
t.id_impot_type,
|
||||
t.id_paiement_acompte,
|
||||
t.id_paiement_impot,
|
||||
t.ifu,
|
||||
t.montant_paye,
|
||||
t.nup,
|
||||
t.qip_ilot,
|
||||
t.qip_parcelle,
|
||||
t.qip_quartier,
|
||||
t.r_commune,
|
||||
t.r_doc,
|
||||
t.r_impot,
|
||||
t.r_quartier,
|
||||
t.id_exercice,
|
||||
t.montant_paye
|
||||
FROM tmp_epaiement_acompte t
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM epaiement_acompte d
|
||||
WHERE d.id_paiement_acompte = t.id_paiement_acompte
|
||||
AND d.source = 'SIGIBE'
|
||||
)
|
||||
RETURNING id_paiement_acompte
|
||||
)
|
||||
INSERT INTO tmp_ids_importes(id)
|
||||
SELECT id_paiement_acompte
|
||||
FROM inserted;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Nombre réellement importé
|
||||
----------------------------------------------------------------------
|
||||
SELECT COUNT(*)
|
||||
INTO v_nb_importe
|
||||
FROM tmp_ids_importes;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Construction de la liste des identifiants
|
||||
----------------------------------------------------------------------
|
||||
SELECT string_agg(id::text, ',')
|
||||
INTO v_ids
|
||||
FROM tmp_ids_importes;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Mise à jour de la base distante
|
||||
----------------------------------------------------------------------
|
||||
IF v_ids IS NOT NULL THEN
|
||||
|
||||
PERFORM dblink_exec
|
||||
(
|
||||
v_conn,
|
||||
format(
|
||||
'UPDATE e_paiement_acompte
|
||||
SET integre = 1
|
||||
WHERE id_paiement_acompte IN (%s)',
|
||||
v_ids
|
||||
)
|
||||
);
|
||||
|
||||
END IF;
|
||||
|
||||
RAISE NOTICE '% enregistrement(s) importé(s) dans epaiement_acompte.', v_nb_importe;
|
||||
|
||||
|
||||
@@ -5,70 +5,20 @@ $$
|
||||
DECLARE
|
||||
v_conn TEXT;
|
||||
v_nb_importe INTEGER;
|
||||
v_ids TEXT;
|
||||
BEGIN
|
||||
|
||||
v_conn := get_dblink_connection();
|
||||
|
||||
INSERT INTO public.epaiement_avis
|
||||
(
|
||||
created_at,
|
||||
created_by,
|
||||
deleted,
|
||||
enquete_external_key,
|
||||
external_key,
|
||||
source,
|
||||
updated_at,
|
||||
updated_by,
|
||||
date_avis_credit,
|
||||
date_information,
|
||||
date_rapprochement,
|
||||
date_validation,
|
||||
id_avis,
|
||||
id_contribuable_foncier,
|
||||
id_impot_nature,
|
||||
id_impot_type,
|
||||
id_paiement_impot,
|
||||
id_unite_foncier,
|
||||
ifu,
|
||||
montant_payer,
|
||||
r_commune,
|
||||
r_doc,
|
||||
r_impot,
|
||||
nup,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
qip_quartier,
|
||||
r_quartier
|
||||
)
|
||||
SELECT
|
||||
now(),
|
||||
NULL,
|
||||
false,
|
||||
NULL,
|
||||
src.id_paiement_impot,
|
||||
'SIGIBE',
|
||||
now(),
|
||||
NULL,
|
||||
src.date_avis_credit,
|
||||
src.date_information,
|
||||
src.date_rapprochement,
|
||||
src.date_validation,
|
||||
src.id_avis,
|
||||
src.id_contribuable_foncier,
|
||||
src.id_impot_nature,
|
||||
src.id_impot_type,
|
||||
src.id_paiement_impot,
|
||||
src.id_unite_foncier,
|
||||
src.ifu,
|
||||
src.montant_paye,
|
||||
src.r_commune,
|
||||
src.r_doc,
|
||||
src.r_impot,
|
||||
src.nup,
|
||||
src.qip_ilot,
|
||||
src.qip_parcelle,
|
||||
src.qip_quartier,
|
||||
src.r_quartier
|
||||
----------------------------------------------------------------------
|
||||
-- Chargement des données distantes
|
||||
----------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS tmp_epaiement_avis;
|
||||
|
||||
CREATE TEMP TABLE tmp_epaiement_avis
|
||||
ON COMMIT DROP
|
||||
AS
|
||||
SELECT *
|
||||
FROM dblink
|
||||
(
|
||||
v_conn,
|
||||
@@ -94,7 +44,9 @@ BEGIN
|
||||
qip_parcelle,
|
||||
qip_quartier,
|
||||
r_quartier
|
||||
FROM public.e_paiement_avis
|
||||
FROM e_paiement_avis
|
||||
WHERE COALESCE(integre,0)=0
|
||||
ORDER BY id_paiement_impot
|
||||
'
|
||||
)
|
||||
AS src
|
||||
@@ -119,15 +71,128 @@ BEGIN
|
||||
qip_parcelle VARCHAR,
|
||||
qip_quartier VARCHAR,
|
||||
r_quartier VARCHAR
|
||||
)
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM public.epaiement_avis d
|
||||
WHERE d.id_paiement_impot = src.id_paiement_impot
|
||||
);
|
||||
);
|
||||
|
||||
GET DIAGNOSTICS v_nb_importe = ROW_COUNT;
|
||||
----------------------------------------------------------------------
|
||||
-- Table temporaire des identifiants réellement importés
|
||||
----------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS tmp_ids_importes;
|
||||
|
||||
CREATE TEMP TABLE tmp_ids_importes
|
||||
(
|
||||
id BIGINT
|
||||
) ON COMMIT DROP;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Insertion + récupération des identifiants insérés
|
||||
----------------------------------------------------------------------
|
||||
WITH inserted AS
|
||||
(
|
||||
INSERT INTO epaiement_avis
|
||||
(
|
||||
created_at,
|
||||
created_by,
|
||||
deleted,
|
||||
enquete_external_key,
|
||||
external_key,
|
||||
source,
|
||||
updated_at,
|
||||
updated_by,
|
||||
date_avis_credit,
|
||||
date_information,
|
||||
date_rapprochement,
|
||||
date_validation,
|
||||
id_avis,
|
||||
id_contribuable_foncier,
|
||||
id_impot_nature,
|
||||
id_impot_type,
|
||||
id_paiement_impot,
|
||||
id_unite_foncier,
|
||||
ifu,
|
||||
montant_paye,
|
||||
r_commune,
|
||||
r_doc,
|
||||
r_impot,
|
||||
nup,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
qip_quartier,
|
||||
r_quartier
|
||||
)
|
||||
SELECT
|
||||
now(),
|
||||
NULL,
|
||||
false,
|
||||
NULL,
|
||||
t.id_paiement_impot,
|
||||
'SIGIBE',
|
||||
now(),
|
||||
NULL,
|
||||
t.date_avis_credit,
|
||||
t.date_information,
|
||||
t.date_rapprochement,
|
||||
t.date_validation,
|
||||
t.id_avis,
|
||||
t.id_contribuable_foncier,
|
||||
t.id_impot_nature,
|
||||
t.id_impot_type,
|
||||
t.id_paiement_impot,
|
||||
t.id_unite_foncier,
|
||||
t.ifu,
|
||||
t.montant_paye,
|
||||
t.r_commune,
|
||||
t.r_doc,
|
||||
t.r_impot,
|
||||
t.nup,
|
||||
t.qip_ilot,
|
||||
t.qip_parcelle,
|
||||
t.qip_quartier,
|
||||
t.r_quartier
|
||||
FROM tmp_epaiement_avis t
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM epaiement_avis d
|
||||
WHERE d.id_paiement_impot = t.id_paiement_impot
|
||||
AND d.source = 'SIGIBE'
|
||||
)
|
||||
RETURNING id_paiement_impot
|
||||
)
|
||||
INSERT INTO tmp_ids_importes(id)
|
||||
SELECT id_paiement_impot
|
||||
FROM inserted;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Nombre réellement importé
|
||||
----------------------------------------------------------------------
|
||||
SELECT COUNT(*)
|
||||
INTO v_nb_importe
|
||||
FROM tmp_ids_importes;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Construction de la liste des identifiants
|
||||
----------------------------------------------------------------------
|
||||
SELECT string_agg(id::text, ',')
|
||||
INTO v_ids
|
||||
FROM tmp_ids_importes;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Mise à jour de la base distante
|
||||
----------------------------------------------------------------------
|
||||
IF v_ids IS NOT NULL THEN
|
||||
|
||||
PERFORM dblink_exec
|
||||
(
|
||||
v_conn,
|
||||
format(
|
||||
'UPDATE e_paiement_avis
|
||||
SET integre = 1
|
||||
WHERE id_paiement_impot IN (%s)',
|
||||
v_ids
|
||||
)
|
||||
);
|
||||
|
||||
END IF;
|
||||
|
||||
RAISE NOTICE '% enregistrement(s) importé(s) dans epaiement_avis.', v_nb_importe;
|
||||
|
||||
|
||||
@@ -5,56 +5,20 @@ $$
|
||||
DECLARE
|
||||
v_conn TEXT;
|
||||
v_nb_importe INTEGER;
|
||||
v_ids TEXT;
|
||||
BEGIN
|
||||
|
||||
v_conn := get_dblink_connection();
|
||||
|
||||
INSERT INTO public.epaiement_retenue
|
||||
(
|
||||
date_avis_credit,
|
||||
date_information,
|
||||
date_rapprochement,
|
||||
date_validation,
|
||||
id_exercice,
|
||||
id_edi_generique,
|
||||
id_impot_nature,
|
||||
id_impot_type,
|
||||
id_paiement_impot,
|
||||
id_paiement_retenue,
|
||||
ifu_payeur,
|
||||
ifu_retenue,
|
||||
montant_paye,
|
||||
nup,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
qip_quartier,
|
||||
r_commune,
|
||||
r_doc,
|
||||
r_impot,
|
||||
r_quartier
|
||||
)
|
||||
SELECT
|
||||
src.date_avis_credit,
|
||||
src.date_information,
|
||||
src.date_rapprochement,
|
||||
src.date_validation,
|
||||
src.id_exercice,
|
||||
src.id_edi_generique,
|
||||
src.id_impot_nature,
|
||||
src.id_impot_type,
|
||||
src.id_paiement_impot,
|
||||
src.id_paiement_retenue,
|
||||
src.ifu_payeur,
|
||||
src.ifu_retenue,
|
||||
src.montant_paye,
|
||||
src.nup,
|
||||
src.qip_ilot,
|
||||
src.qip_parcelle,
|
||||
src.qip_quartier,
|
||||
src.r_commune,
|
||||
src.r_doc,
|
||||
src.r_impot,
|
||||
src.r_quartier
|
||||
----------------------------------------------------------------------
|
||||
-- Chargement des données distantes
|
||||
----------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS tmp_epaiement_retenue;
|
||||
|
||||
CREATE TEMP TABLE tmp_epaiement_retenue
|
||||
ON COMMIT DROP
|
||||
AS
|
||||
SELECT *
|
||||
FROM dblink
|
||||
(
|
||||
v_conn,
|
||||
@@ -81,7 +45,9 @@ BEGIN
|
||||
r_doc,
|
||||
r_impot,
|
||||
r_quartier
|
||||
FROM public.e_paiement_retenue
|
||||
FROM e_paiement_retenue
|
||||
WHERE COALESCE(integre,0)=0
|
||||
ORDER BY id_paiement_retenue
|
||||
'
|
||||
)
|
||||
AS src
|
||||
@@ -107,15 +73,113 @@ BEGIN
|
||||
r_doc VARCHAR,
|
||||
r_impot VARCHAR,
|
||||
r_quartier VARCHAR
|
||||
)
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM public.epaiement_retenue d
|
||||
WHERE d.id_paiement_retenue = src.id_paiement_retenue
|
||||
);
|
||||
);
|
||||
|
||||
GET DIAGNOSTICS v_nb_importe = ROW_COUNT;
|
||||
----------------------------------------------------------------------
|
||||
-- Table temporaire des identifiants réellement importés
|
||||
----------------------------------------------------------------------
|
||||
DROP TABLE IF EXISTS tmp_ids_importes;
|
||||
|
||||
CREATE TEMP TABLE tmp_ids_importes
|
||||
(
|
||||
id BIGINT
|
||||
) ON COMMIT DROP;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Insertion + récupération des identifiants insérés
|
||||
----------------------------------------------------------------------
|
||||
WITH inserted AS
|
||||
(
|
||||
INSERT INTO epaiement_retenue
|
||||
(
|
||||
date_avis_credit,
|
||||
date_information,
|
||||
date_rapprochement,
|
||||
date_validation,
|
||||
id_exercice,
|
||||
id_edi_generique,
|
||||
id_impot_nature,
|
||||
id_impot_type,
|
||||
id_paiement_impot,
|
||||
id_paiement_retenue,
|
||||
ifu_payeur,
|
||||
ifu_retenue,
|
||||
montant_paye,
|
||||
nup,
|
||||
qip_ilot,
|
||||
qip_parcelle,
|
||||
qip_quartier,
|
||||
r_commune,
|
||||
r_doc,
|
||||
r_impot,
|
||||
r_quartier
|
||||
)
|
||||
SELECT
|
||||
t.date_avis_credit,
|
||||
t.date_information,
|
||||
t.date_rapprochement,
|
||||
t.date_validation,
|
||||
t.id_exercice,
|
||||
t.id_edi_generique,
|
||||
t.id_impot_nature,
|
||||
t.id_impot_type,
|
||||
t.id_paiement_impot,
|
||||
t.id_paiement_retenue,
|
||||
t.ifu_payeur,
|
||||
t.ifu_retenue,
|
||||
t.montant_paye,
|
||||
t.nup,
|
||||
t.qip_ilot,
|
||||
t.qip_parcelle,
|
||||
t.qip_quartier,
|
||||
t.r_commune,
|
||||
t.r_doc,
|
||||
t.r_impot,
|
||||
t.r_quartier
|
||||
FROM tmp_epaiement_retenue t
|
||||
WHERE NOT EXISTS
|
||||
(
|
||||
SELECT 1
|
||||
FROM epaiement_retenue d
|
||||
WHERE d.id_paiement_retenue = t.id_paiement_retenue
|
||||
)
|
||||
RETURNING id_paiement_retenue
|
||||
)
|
||||
INSERT INTO tmp_ids_importes(id)
|
||||
SELECT id_paiement_retenue
|
||||
FROM inserted;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Nombre réellement importé
|
||||
----------------------------------------------------------------------
|
||||
SELECT COUNT(*)
|
||||
INTO v_nb_importe
|
||||
FROM tmp_ids_importes;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Construction de la liste des identifiants
|
||||
----------------------------------------------------------------------
|
||||
SELECT string_agg(id::text, ',')
|
||||
INTO v_ids
|
||||
FROM tmp_ids_importes;
|
||||
|
||||
----------------------------------------------------------------------
|
||||
-- Mise à jour de la base distante
|
||||
----------------------------------------------------------------------
|
||||
IF v_ids IS NOT NULL THEN
|
||||
|
||||
PERFORM dblink_exec
|
||||
(
|
||||
v_conn,
|
||||
format(
|
||||
'UPDATE e_paiement_retenue
|
||||
SET integre = 1
|
||||
WHERE id_paiement_retenue IN (%s)',
|
||||
v_ids
|
||||
)
|
||||
);
|
||||
|
||||
END IF;
|
||||
|
||||
RAISE NOTICE '% enregistrement(s) importé(s) dans epaiement_retenue.', v_nb_importe;
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.gmss.fiscad.persistence.repositories.rfu.metier;
|
||||
|
||||
import io.gmss.fiscad.entities.rfu.metier.Batiment;
|
||||
import io.gmss.fiscad.entities.rfu.metier.SituationFiscaleParcelle;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.BatimentPaylaodWeb;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.SituationFiscaleParcellePayloadWeb;
|
||||
import io.gmss.fiscad.paylaods.response.restoration.BatimentPayloadRestor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public interface SituationFiscaleParcelleRepository extends JpaRepository<SituationFiscaleParcelle, Long> {
|
||||
|
||||
@Query("""
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.SituationFiscaleParcellePayloadWeb(
|
||||
s.id,
|
||||
p.id,
|
||||
p.q,
|
||||
p.i,
|
||||
p.p,
|
||||
q.code,
|
||||
s.dateDernierPaiement,
|
||||
e.id,
|
||||
e.annee,
|
||||
s.montantDu,
|
||||
s.montantPaye,
|
||||
s.montantDegeve,
|
||||
s.resteAPayer,
|
||||
s.dateSync,
|
||||
s.natureImpot
|
||||
)
|
||||
FROM SituationFiscaleParcelle s
|
||||
JOIN s.parcelle p
|
||||
JOIN p.quartier q
|
||||
JOIN s.exercice e
|
||||
WHERE s.deleted = false
|
||||
AND p.id = :parcelleId
|
||||
order by e.annee desc
|
||||
""")
|
||||
List<SituationFiscaleParcellePayloadWeb> findAllPayloadByParcelleId(
|
||||
@Param("parcelleId") Long parcelleId
|
||||
);
|
||||
}
|
||||
@@ -1071,6 +1071,7 @@ public class EntityFromPayLoadService {
|
||||
moduleApp.setCode(modulePayloadWeb.getCode());
|
||||
moduleApp.setNom(modulePayloadWeb.getNom());
|
||||
moduleApp.setActif(modulePayloadWeb.getActif());
|
||||
moduleApp.setLien(modulePayloadWeb.getLien());
|
||||
return moduleApp ;
|
||||
}
|
||||
|
||||
@@ -1116,6 +1117,8 @@ public class EntityFromPayLoadService {
|
||||
profileModuleFonctionnalite.setFonctionnalite(fonctionnalite);
|
||||
}
|
||||
profileModuleFonctionnalite.setActif(profileModuleFonctionnalitePayloadWeb.getActif());
|
||||
//profileModuleFonctionnalite.setL(profileModuleFonctionnalitePayloadWeb.getActif());
|
||||
|
||||
return profileModuleFonctionnalite ;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user