x_hst_bulletin.date_debut
where x_hst_bulletin.cnt_code_original is null
group by 1
)
UPDATE temp.x_hst_bulletin set
cnt_code_original = toto.cnt_code_original,
est_hors_periode = 1
from toto
where x_hst_bulletin.row_id = toto.row_id
;
-- ICI : Tous les bulletins doivent avoir un contrat de renseigné.
-- A remonter plus tard dans une table spéciale avant suppression pour controle expert.
delete from temp.x_hst_bulletin
where cnt_code_original is null
;
-- HISTORIQUE ETP Théorique contrat.
DROP TABLE IF EXISTS temp.x_hst_etp_contrat
;
CREATE TABLE temp.x_hst_etp_contrat AS
select
dossier||'-'||dossier as ety_code_original,
id1 as sal_code_original,
id1||'-'||lpad(no, 3, '0') as cnt_code_original,
to_date(datapp, 'DD/MM/YYYY') as date_effet,
opa::numeric / 151.67 as etp_contrat
from prod_aliciarh.a_cont
join w_ets on w_ets.ets_id1 = a_cont.dossier
join temp.x_ref_salarie on x_ref_salarie.code_original = a_cont.id1
where rub = 'A079'
group by 1,2,3,4,5
;
-- HISTORIQUE CSP.
DROP TABLE IF EXISTS temp.x_hst_categorie_socio_professionnelle
;
CREATE TABLE temp.x_hst_categorie_socio_professionnelle AS
select
dossier||'-'||dossier as ety_code_original,
id1 as sal_code_original,
id1||'-'||lpad(no, 3, '0') as cnt_code_original,
to_date(datapp, 'DD/MM/YYYY') as date_effet,
opf::text as categorie_socio_professionnelle_code_original
from prod_aliciarh.a_cont
join w_ets on w_ets.ets_id1 = a_cont.dossier
join temp.x_ref_salarie on x_ref_salarie.code_original = a_cont.id1
where rub = 'AZ02'
group by 1,2,3,4,5
;
-- HISTORIQUE Motif de début.
DROP TABLE IF EXISTS temp.x_hst_motif_debut_contrat
;
CREATE TABLE temp.x_hst_motif_debut_contrat AS
SELECT
null::text as ety_code_original,
null::text as sal_code_original,
null::text as cnt_code_original,
null::date as date_effet,
null::text as motif_debut_code_original
limit 0
;
-- HISTORIQUE Motif de fin.
DROP TABLE IF EXISTS temp.x_hst_motif_fin_contrat
;
CREATE TABLE temp.x_hst_motif_fin_contrat AS
SELECT
null::text as ety_code_original,
null::text as sal_code_original,
null::text as cnt_code_original,
null::date as date_effet,
null::text as motif_fin_code_original
limit 0
;
-- HISTORIQUE Types de contrat.
DROP TABLE IF EXISTS temp.x_hst_type_contrat
;
CREATE TABLE temp.x_hst_type_contrat AS
select
dossier||'-'||dossier as ety_code_original,
id1 as sal_code_original,
id1||'-'||lpad(no, 3, '0') as cnt_code_original,
to_date(datapp, 'DD/MM/YYYY') as date_effet,
opf::text as type_contrat_code_original
from prod_aliciarh.a_cont
join w_ets on w_ets.ets_id1 = a_cont.dossier
join temp.x_ref_salarie on x_ref_salarie.code_original = a_cont.id1
where rub = 'A070'
group by 1,2,3,4,5
;
-- HISTORIQUE CSP.
DROP TABLE IF EXISTS temp.x_hst_qualification
;
CREATE TABLE temp.x_hst_qualification AS
select
dossier||'-'||dossier as ety_code_original,
id1 as sal_code_original,
id1||'-'||lpad(no, 3, '0') as cnt_code_original,
to_date(datapp, 'DD/MM/YYYY') as date_effet,
replace(opf::text,' ','_') as qualification_code_original
from prod_aliciarh.a_cont
join w_ets on w_ets.ets_id1 = a_cont.dossier
join temp.x_ref_salarie on x_ref_salarie.code_original = a_cont.id1
where rub = 'AVF1'
or rub = 'AV10' --qualifications non référencées issues d'un champ libre
group by 1,2,3,4,5
;
-- HISTORIQUE Status.
DROP TABLE IF EXISTS temp.x_hst_statut
;
CREATE TABLE temp.x_hst_statut AS
select
dossier||'-'||dossier as ety_code_original,
id1 as sal_code_original,
id1||'-'||lpad(no, 3, '0') as cnt_code_original,
to_date(datapp, 'DD/MM/YYYY') as date_effet,
opf::text as statut_code_original
from prod_aliciarh.a_cont
join w_ets on w_ets.ets_id1 = a_cont.dossier
join temp.x_ref_salarie on x_ref_salarie.code_original = a_cont.id1
where rub = 'A072'
group by 1,2,3,4,5
;
-- HISTORIQUE CSP.
DROP TABLE IF EXISTS temp.x_hst_type_temps_travail
;
CREATE TABLE temp.x_hst_type_temps_travail AS
select
dossier||'-'||dossier as ety_code_original,
id1 as sal_code_original,
id1||'-'||lpad(no, 3, '0') as cnt_code_original,
to_date(datapp, 'DD/MM/YYYY') as date_effet,
case when opa = '151.67' then 'C' else 'P'||opa end as type_temps_travail_code_original
from prod_aliciarh.a_cont
join w_ets on w_ets.ets_id1 = a_cont.dossier
join temp.x_ref_salarie on x_ref_salarie.code_original = a_cont.id1
where rub = 'A079'
group by 1,2,3,4,5
;
-- HISTORIQUE CSP.
DROP TABLE IF EXISTS temp.x_hst_service
;
CREATE TABLE temp.x_hst_service AS
select
dossier||'-'||dossier as ety_code_original,
id1 as sal_code_original,
id1||'-'||lpad(no, 3, '0') as cnt_code_original,
to_date(datapp, 'DD/MM/YYYY') as date_effet,
opf::text as service_code_original
from prod_aliciarh.a_cont
join w_ets on w_ets.ets_id1 = a_cont.dossier
join temp.x_ref_salarie on x_ref_salarie.code_original = a_cont.id1
where rub = 'A948'
group by 1,2,3,4,5
;
-- HISTORIQUE CSP.
DROP TABLE IF EXISTS temp.x_hst_code_emploi
;
CREATE TABLE temp.x_hst_code_emploi AS
SELECT
null::text as ety_code_original,
null::text as sal_code_original,
null::text as cnt_code_original,
null::date as date_effet,
null::text as code_emploi_code_original
limit 0
;
-- HISTORIQUE GRILLE.
DROP TABLE IF EXISTS temp.x_hst_grille
;
CREATE TABLE temp.x_hst_grille AS
SELECT
null::text as ety_code_original,
null::text as sal_code_original,
null::text as cnt_code_original,
null::date as date_effet,
null::text as grille_code_original
limit 0
;
]]>
= to_char(rhp('rhprovider_start')::date, 'YYYYMM')
;
]]>