CREATE TABLE public.service_fonctiongroupe (
    id serial NOT NULL,
    fk_groupe character varying(50),
    fk_fonction character varying(50),
    can_create character varying(5),
    can_update character varying(5),
    can_update_date character varying(5),
    can_delete character varying(5)
);


CREATE TABLE public.service_fonctionnaliter (
    id character varying(50) NOT NULL,
    nom character varying
);


--
-- Name: service_groupe; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.service_groupe (
    id character varying(50) NOT NULL,
    nom_groupe character varying,
    actif character varying
);






--
-- Name: service_historique_manipulation; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.service_historique_manipulation (
    id bigint NOT NULL,
    nom_table character varying,
    id_ligne character varying,
    type_manipumation character varying,
    date_manipulation date,
    heur_manipulation time without time zone,
    old_valeur real,
    new_valeur real,
    fk_manipulateur character varying(50)
);


--
-- Name: service_historiqueManipulation_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--


--
-- Name: service_incrementation; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.service_incrementation (
    id serial NOT NULL,
    code character varying(50),
    date_mois date,
    incr_telephone integer,
    incr_client integer,
    incr_stage integer,
    incr_groups integer
);



CREATE TABLE public.service_member (
    id serial NOT NULL,
    fk_user character varying(50),
    fk_groupe character varying(50)
);


CREATE TABLE public.service_user (
    userid character varying NOT NULL,
    userpw character varying,
    nom character varying,
    prenom character varying,
    telephone character varying(50),
    mail character varying,
    actif character varying DEFAULT true,
    forcermap character varying(5) DEFAULT true
);



--
-- Name: service_wilaya; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.service_wilaya (
    nom_wilaya character varying,
    id character(2) NOT NULL
);


ALTER TABLE ONLY public.service_fonctiongroupe
    ADD CONSTRAINT service_fonctiongroupe_pkey PRIMARY KEY (id);


--
-- Name: service_fonctionnaliter service_fonctionnaliter_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.service_fonctionnaliter
    ADD CONSTRAINT service_fonctionnaliter_pkey PRIMARY KEY (id);


--
-- Name: service_groupe service_groupe_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.service_groupe
    ADD CONSTRAINT service_groupe_pkey PRIMARY KEY (id);




--
-- Name: service_historique_manipulation service_historiqueManipulation_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.service_historique_manipulation
    ADD CONSTRAINT "service_historiqueManipulation_pkey" PRIMARY KEY (id);


--
-- Name: service_incrementation service_incrementation_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.service_incrementation
    ADD CONSTRAINT service_incrementation_pkey PRIMARY KEY (id);


--
-- Name: service_member service_member_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.service_member
    ADD CONSTRAINT service_member_pkey PRIMARY KEY (id);


--
-- Name: service_user service_user_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.service_user
    ADD CONSTRAINT service_user_pkey PRIMARY KEY (userid);


--
-- Name: service_wilaya service_wilaya_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.service_wilaya
    ADD CONSTRAINT service_wilaya_pkey PRIMARY KEY (id);


ALTER TABLE ONLY public.service_fonctiongroupe
    ADD CONSTRAINT "service_fonctionGroupe_fkFonction_fkey" FOREIGN KEY (fk_fonction) REFERENCES public.service_fonctionnaliter(id);




--
-- Name: service_historique_manipulation service_historiqueManipulation_fkManipulateur_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.service_historique_manipulation
    ADD CONSTRAINT "service_historiqueManipulation_fkManipulateur_fkey" FOREIGN KEY (fk_manipulateur) REFERENCES public.service_user(userid);


--
-- Name: service_member service_member_fkUser_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.service_member
    ADD CONSTRAINT "service_member_fkUser_fkey" FOREIGN KEY (fk_user) REFERENCES public.service_user(userid);

--
-- PostgreSQL database dump complete
--

--Abderrahmane 06/08/2025
--user admin

INSERT INTO public.service_groupe(id, nom_groupe,actif) VALUES ('admin', 'admin','true');
INSERT INTO public.service_user(userid, userpw, nom, prenom, telephone, mail, actif, forcermap) VALUES ('admin', 'admin', 'admin', 'admin', '0560548029', 'contact@hydrotriz.com', 'true', 'true');
INSERT INTO public.service_member(fk_user, fk_groupe) VALUES ('admin', 'admin');
INSERT INTO public.service_fonctionnaliter(id, nom) VALUES ( 'User','User');
INSERT INTO public.service_fonctiongroupe(fk_groupe, fk_fonction, can_create, can_update, can_update_date, can_delete) VALUES ('admin', 'User', 'true', 'true', 'true', 'true');

-- wilaya
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Adrar', 1);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Chlef', 2);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Laghouat', 3);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Oum El Bouaghi', 4);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Batna', 5);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Béjaïa', 6);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Biskra', 7);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Béchar', 8);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Blida', 9);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Bouira', 10);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Tamanrasset', 11);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Tébessa', 12);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Tlemcen', 13);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Tiaret', 14);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Tizi Ouzou', 15);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Alger', 16);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Djelfa', 17);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Jijel', 18);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Sétif', 19);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Saïda', 20);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Skikda', 21);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Sidi Bel Abbès', 22);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Annaba', 23);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Guelma', 24);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Constantine', 25);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Médéa', 26);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Mostaganem', 27);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('MSila', 28);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Mascara', 29);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Ouargla', 30);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Oran', 31);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('El Bayadh', 32);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Illizi', 33);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Bordj Bou Arréridj', 34);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Boumerdès', 35);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('El Tarf', 36);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Tindouf', 37);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Tissemsilt', 38);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('El Oued', 39);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Khenchela', 40);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Souk Ahras', 41);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Tipaza', 42);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Mila', 43);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Aïn Defla', 44);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Naâma', 45);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Aïn Témouchent', 46);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Ghardaïa', 47);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Relizane', 48);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Timimoun', 49);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Bordj Badji Mokhtar', 50);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Ouled Djellal', 51);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Béni Abbès', 52);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('In Salah', 53);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('In Guezzam', 54);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Touggourt', 55);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('Djanet', 56);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('El MGhair', 57);
INSERT INTO public.service_wilaya(nom_wilaya, id) VALUES ('El Meniaa', 58);

-- Table: public.class

-- DROP TABLE IF EXISTS public.class;

CREATE TABLE IF NOT EXISTS public.class
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    code character varying(5) COLLATE pg_catalog."default",
    CONSTRAINT class_pkey PRIMARY KEY (id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.class
    OWNER to postgres;


-- Table: public.banque

-- DROP TABLE IF EXISTS public."banque";

CREATE TABLE IF NOT EXISTS public."banque"
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    nom character varying(50) COLLATE pg_catalog."default",
    abreviation character varying(10) COLLATE pg_catalog."default",
    CONSTRAINT "banque_pkey" PRIMARY KEY (id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public."banque"
    OWNER to postgres;

-- Table: public.etablissement

-- DROP TABLE IF EXISTS public."etablissement";

CREATE TABLE IF NOT EXISTS public."etablissement"
(
    id_etab_stock character varying(50) COLLATE pg_catalog."default" NOT NULL,
    nom character varying(50) COLLATE pg_catalog."default",
    actif character(5) COLLATE pg_catalog."default",
    CONSTRAINT "etablissement_pkey" PRIMARY KEY (id_etab_stock)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public."etablissement"
    OWNER to postgres;

--
-- Name: service_historique_connection; Type: TABLE; Schema: public; Owner: postgres
--

-- Table: public.service_historique_connection

-- DROP TABLE IF EXISTS public.service_historique_connection;

CREATE TABLE IF NOT EXISTS public.service_historique_connection
(
    fk_user character varying(50) COLLATE pg_catalog."default",
    date date,
    heur time without time zone,
    adresse_ip character varying COLLATE pg_catalog."default",
    fk_etablissemnt character varying(50) COLLATE pg_catalog."default",
    id bigserial NOT NULL ,
    CONSTRAINT service_historique_connection_pkey PRIMARY KEY (id),
    CONSTRAINT fk_servicehistoriqueconnection_etablissement FOREIGN KEY (fk_etablissemnt)
        REFERENCES public.etablissement (id_etab_stock) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID,
    CONSTRAINT "service_historiqueConnection_fkUser_fkey" FOREIGN KEY (fk_user)
        REFERENCES public.service_user (userid) MATCH SIMPLE
        ON UPDATE CASCADE
        ON DELETE CASCADE
        NOT VALID
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.service_historique_connection
    OWNER to postgres;



-- Table: public.type_tresorie

-- DROP TABLE IF EXISTS public.type_tresorie;

CREATE TABLE IF NOT EXISTS public.type_tresorie
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    type character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT type_tresorie_pkey PRIMARY KEY (id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.type_tresorie
    OWNER to postgres;

-- Table: public.sort

-- DROP TABLE IF EXISTS public.sort;

CREATE TABLE IF NOT EXISTS public.sort
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    sort character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT sort_pkey PRIMARY KEY (id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.sort
    OWNER to postgres;

-- Table: public.type_mouvement

-- DROP TABLE IF EXISTS public.type_mouvement;

CREATE TABLE IF NOT EXISTS public.type_mouvement
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    type character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT type_mouvement_pkey PRIMARY KEY (id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.type_mouvement
    OWNER to postgres;

-- Table: public.annee_fiscale

-- DROP TABLE IF EXISTS public.annee_fiscale;

CREATE TABLE IF NOT EXISTS public.annee_fiscale
(
    annee integer NOT NULL,
    cloture boolean,
    actif boolean,
    code_letterage character varying(255) COLLATE pg_catalog."default",
    fk_etablissement character varying(50) COLLATE pg_catalog."default",
    CONSTRAINT annee_fiscale_pkey PRIMARY KEY (annee),
    CONSTRAINT "fk_etablissement_anneeFiscal" FOREIGN KEY (fk_etablissement)
        REFERENCES public.etablissement (id_etab_stock) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.annee_fiscale
    OWNER to postgres;

-- Table: public.stock_type_destinataire

-- DROP TABLE IF EXISTS public.stock_type_destinataire;

CREATE TABLE IF NOT EXISTS public.stock_type_destinataire
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    designation character varying(50) COLLATE pg_catalog."default",
    stock_type_destinataire character varying(50) COLLATE pg_catalog."default",
    CONSTRAINT stock_type_destinataire_pkey PRIMARY KEY (id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.stock_type_destinataire
    OWNER to postgres;

-- Table: public.agence

-- DROP TABLE IF EXISTS public.agence;

CREATE TABLE IF NOT EXISTS public.agence
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    code character varying(10) COLLATE pg_catalog."default",
    designation character varying(50) COLLATE pg_catalog."default",
    fk_banque integer,
    CONSTRAINT agence_pkey PRIMARY KEY (id),
    CONSTRAINT fk_banque_agence FOREIGN KEY (fk_banque)
        REFERENCES public.banque (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.agence
    OWNER to postgres;



-- Table: public.compte_comptable

-- DROP TABLE IF EXISTS public.compte_comptable;

CREATE TABLE IF NOT EXISTS public.compte_comptable
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    code character varying(255) COLLATE pg_catalog."default",
    num_compte_comptable integer,
    accepter_tier boolean,
    fk_banque integer,
    CONSTRAINT compte_comptable_pkey PRIMARY KEY (id),
    CONSTRAINT "fk_banque_compteComptable" FOREIGN KEY (fk_banque)
        REFERENCES public.banque (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.compte_comptable
    OWNER to postgres;

-- Table: public.tier

-- DROP TABLE IF EXISTS public.tier;

CREATE TABLE IF NOT EXISTS public.tier
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    code character varying(10) COLLATE pg_catalog."default",
    designation character varying(50) COLLATE pg_catalog."default",
    addresse character varying(1000) COLLATE pg_catalog."default",
    num_rc character varying(50) COLLATE pg_catalog."default",
    nif character varying(50) COLLATE pg_catalog."default",
    article_impo character varying(50) COLLATE pg_catalog."default",
    min_liq double precision,
    max_liq double precision,
    sold_initial double precision,
    date_solde_init date,
    duree_max integer,
    num_compte_tier character varying(50) COLLATE pg_catalog."default",
    bp character varying(50) COLLATE pg_catalog."default",
    nis character varying(50) COLLATE pg_catalog."default",
    id_stock_fournisseur character varying(50) COLLATE pg_catalog."default",
    id_stock_client character varying(50) COLLATE pg_catalog."default",
    is_deleted character varying(5) COLLATE pg_catalog."default",
    fk_etablissement character varying(50) COLLATE pg_catalog."default",
    fk_compte_comptable integer,
    CONSTRAINT tier_pkey PRIMARY KEY (id),
    CONSTRAINT "fk_CompteComptable_tier" FOREIGN KEY (fk_compte_comptable)
        REFERENCES public.compte_comptable (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_etablissement_tier FOREIGN KEY (fk_etablissement)
        REFERENCES public.etablissement (id_etab_stock) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.tier
    OWNER to postgres;


-- Table: public.tresorie

-- DROP TABLE IF EXISTS public.tresorie;

CREATE TABLE IF NOT EXISTS public.tresorie
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    numero character varying(10) COLLATE pg_catalog."default",
    code character varying(10) COLLATE pg_catalog."default",
    cle character varying(2) COLLATE pg_catalog."default",
    designation character varying(50) COLLATE pg_catalog."default",
    min_liq double precision,
    max_liq double precision,
    solde_initial double precision,
    date_solde_initial date,
    nbr_cheque integer,
    num_compte_comptable integer,
    is_deleted character varying(5) COLLATE pg_catalog."default",
    stock_id character varying(50) COLLATE pg_catalog."default",
    fk_agence integer,
    fk_etablissement character varying(50) COLLATE pg_catalog."default",
    fk_type_tresorie integer,
    fk_compte_comptable integer,
    CONSTRAINT tresorie_pkey PRIMARY KEY (id),
    CONSTRAINT fk_agence_tresorie FOREIGN KEY (fk_agence)
        REFERENCES public.agence (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "fk_compteComptable_tresori" FOREIGN KEY (fk_compte_comptable)
        REFERENCES public.compte_comptable (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_etablissement_tresori FOREIGN KEY (fk_etablissement)
        REFERENCES public.etablissement (id_etab_stock) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "fk_typeTresori_tresori" FOREIGN KEY (fk_type_tresorie)
        REFERENCES public.type_tresorie (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.tresorie
    OWNER to postgres;

-- Table: public.chequier

-- DROP TABLE IF EXISTS public.chequier;

CREATE TABLE IF NOT EXISTS public.chequier
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    serie character varying(10) COLLATE pg_catalog."default",
    ref_initiale character varying(10) COLLATE pg_catalog."default",
    ref_finale character varying(10) COLLATE pg_catalog."default",
    fk_tresorie integer,
    CONSTRAINT chequier_pkey PRIMARY KEY (id),
    CONSTRAINT fk_chequier_tresorie FOREIGN KEY (fk_tresorie)
        REFERENCES public.tresorie (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.chequier
    OWNER to postgres;

-- Table: public.controle_tresorie

-- DROP TABLE IF EXISTS public.controle_tresorie;

CREATE TABLE IF NOT EXISTS public.controle_tresorie
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    date_controle date,
    heure time without time zone,
    montant double precision,
    fk_tresorie integer,
    CONSTRAINT controle_tresorie_pkey PRIMARY KEY (id),
    CONSTRAINT "fk_controleTresorie_tresorie" FOREIGN KEY (fk_tresorie)
        REFERENCES public.tresorie (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.controle_tresorie
    OWNER to postgres;

-- Table: public.mouvement_tier

-- DROP TABLE IF EXISTS public.mouvement_tier;

CREATE TABLE IF NOT EXISTS public.mouvement_tier
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    reference character varying(50) COLLATE pg_catalog."default",
    montant double precision,
    date date,
    code_letterage character varying(50) COLLATE pg_catalog."default",
    heure time without time zone,
    fk_tier integer,
    fk_type_mouvement integer,
    fk_annee_fiscale integer,
    CONSTRAINT mouvement_tier_pkey PRIMARY KEY (id),
    CONSTRAINT "fk_anneeFiscale_mouvementTier" FOREIGN KEY (fk_annee_fiscale)
        REFERENCES public.annee_fiscale (annee) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "fk_tier_mouvementTier" FOREIGN KEY (fk_tier)
        REFERENCES public.tier (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "fk_typeMouvement_mouvementTier" FOREIGN KEY (fk_type_mouvement)
        REFERENCES public.type_mouvement (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.mouvement_tier
    OWNER to postgres;

-- Table: public.cheque

-- DROP TABLE IF EXISTS public.cheque;

CREATE TABLE IF NOT EXISTS public.cheque
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    reference character varying(50) COLLATE pg_catalog."default",
    montant double precision,
    date_emission date,
    date_remise date,
    fk_chequier integer,
    CONSTRAINT cheque_pkey PRIMARY KEY (id),
    CONSTRAINT fk_chequier_cheque FOREIGN KEY (fk_chequier)
        REFERENCES public.chequier (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.cheque
    OWNER to postgres;


-- Table: public.mouvement

-- DROP TABLE IF EXISTS public.mouvement;

CREATE TABLE IF NOT EXISTS public.mouvement
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    reference character varying(50) COLLATE pg_catalog."default",
    montant double precision,
    date date,
    designation character varying(50) COLLATE pg_catalog."default",
    beneficier character varying(50) COLLATE pg_catalog."default",
    is_deleted character varying(5) COLLATE pg_catalog."default",
    stock_id character varying(50) COLLATE pg_catalog."default",
    heure time without time zone,
    fk_tier integer,
    fk_tresorie_source integer,
    fk_tresorie_destinataire integer,
    fk_type_mouvement integer,
    fk_sort integer,
    fk_annee_fiscale integer,
    fk_type_destinataire integer,
    fk_cheque integer,
    fk_user character varying(50) COLLATE pg_catalog."default",
    CONSTRAINT mouvement_pkey PRIMARY KEY (id),
    CONSTRAINT "fk_anneeFiscale_mouvement" FOREIGN KEY (fk_annee_fiscale)
        REFERENCES public.annee_fiscale (annee) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_cheque_mouvement FOREIGN KEY (fk_cheque)
        REFERENCES public.cheque (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_sort_mouvement FOREIGN KEY (fk_sort)
        REFERENCES public.sort (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_tier_mouvement FOREIGN KEY (fk_tier)
        REFERENCES public.tier (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "fk_tresoriSource_mouvement" FOREIGN KEY (fk_tresorie_source)
        REFERENCES public.tresorie (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "fk_tresorieDestinataire_mouvement" FOREIGN KEY (fk_tresorie_destinataire)
        REFERENCES public.tresorie (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "fk_typeDestinataire_mouvement" FOREIGN KEY (fk_type_destinataire)
        REFERENCES public.stock_type_destinataire (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT "fk_typeMouvement_mouvement" FOREIGN KEY (fk_type_mouvement)
        REFERENCES public.type_mouvement (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_user_mouvement FOREIGN KEY (fk_user)
        REFERENCES public.service_user (userid) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.mouvement
    OWNER to postgres;

-- Table: public.alerte

-- DROP TABLE IF EXISTS public.alerte;

CREATE TABLE IF NOT EXISTS public.alerte
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    reference character varying(50) COLLATE pg_catalog."default",
    montant double precision,
    date date,
    observation character varying(255) COLLATE pg_catalog."default",
    fk_type_mouvement integer,
    fk_mouvement integer,
    CONSTRAINT alerte_pkey PRIMARY KEY (id),
    CONSTRAINT "fk_alerte_stockTypeMouvement" FOREIGN KEY (fk_type_mouvement)
        REFERENCES public.type_mouvement (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_mouvement_alerte FOREIGN KEY (fk_mouvement)
        REFERENCES public.mouvement (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.alerte
    OWNER to postgres;

-- Table: public.service_etablissement_user

-- DROP TABLE IF EXISTS public.service_etablissement_user;

CREATE TABLE IF NOT EXISTS public.service_etablissement_user
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    fk_etablissement character varying(50) COLLATE pg_catalog."default",
    fk_user character varying(50) COLLATE pg_catalog."default",
    CONSTRAINT service_etablissement_user_pkey PRIMARY KEY (id),
    CONSTRAINT fk_etablissement_serviceuseretablissement FOREIGN KEY (fk_etablissement)
        REFERENCES public.etablissement (id_etab_stock) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_serviceuser_serviceetablissementuser FOREIGN KEY (fk_user)
        REFERENCES public.service_user (userid) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.service_etablissement_user
    OWNER to postgres;

-- Table: public.service_user_tresorie

-- DROP TABLE IF EXISTS public.service_user_tresorie;

CREATE TABLE IF NOT EXISTS public.service_user_tresorie
(
    id integer NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    fk_user character varying COLLATE pg_catalog."default",
    fk_tresorie integer,
    CONSTRAINT service_user_tresorie_pkey PRIMARY KEY (id),
    CONSTRAINT fk_serviceusertresorie_tresorie FOREIGN KEY (fk_tresorie)
        REFERENCES public.tresorie (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT fk_serviceusertresorie_user FOREIGN KEY (fk_user)
        REFERENCES public.service_user (userid) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.service_user_tresorie
    OWNER to postgres;


ALTER TABLE public.service_groupe
ADD COLUMN fk_etablissement VARCHAR(50);

ALTER TABLE public.service_groupe
ADD CONSTRAINT fk_servicegroupe_etab
FOREIGN KEY (fk_etablissement) REFERENCES public.etablissement(id_etab_stock);



