This commit is contained in:
2025-11-02 07:35:49 +01:00
parent 77340d2cf6
commit 46939c265c
9 changed files with 183 additions and 145 deletions

View File

@@ -284,26 +284,26 @@ services:
networks: networks:
- caddy_net - caddy_net
rabbitmq: #rabbitmq:
image: rabbitmq:4.1.4-management # image: rabbitmq:4.1.4-management
ports: # ports:
- "5672:5672" # AMQP # - "5672:5672" # AMQP
- "1883:1883" # MQTT # - "1883:1883" # MQTT
networks: # networks:
- caddy_net # - caddy_net
environment: # environment:
RABBITMQ_DEFAULT_USER: admin # RABBITMQ_DEFAULT_USER: admin
RABBITMQ_DEFAULT_PASS: admin # RABBITMQ_DEFAULT_PASS: admin
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: "-rabbitmq_mqtt tcp_listeners [1883]" # RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS: "-rabbitmq_mqtt tcp_listeners [1883]"
volumes: # volumes:
- rabbitmq_data:/var/lib/rabbitmq # - rabbitmq_data:/var/lib/rabbitmq
command: > # command: >
sh -c "rabbitmq-plugins enable --offline rabbitmq_mqtt rabbitmq_management && # sh -c "rabbitmq-plugins enable --offline rabbitmq_mqtt rabbitmq_management &&
rabbitmq-server" # rabbitmq-server"
labels: # labels:
caddy: rabbitmq.localhost # caddy: rabbitmq.localhost
caddy.reverse_proxy: "{{upstreams 15672}}" # caddy.reverse_proxy: "{{upstreams 15672}}"
caddy.tls: internal # caddy.tls: internal
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# Observabilité - Télémétrie # Observabilité - Télémétrie

8
data/banque/devises.csv Normal file
View File

@@ -0,0 +1,8 @@
devise_code,num4217,symbole,nom,division,minor,minors
EUR,978,,Euro,100,centime,centimes
CHF,756,CHf,Franc suisse,100,centime,centimes
GBP,826,£,Livre sterling,100,penny,pence
JPY,392,¥,Yen japonais,1,,
TRY,949,,Nouvelle livre turque,100,kuruş,kuruş
USD,840,$,Dollar des Etats-Unis,100,cent,cents
ZAR,710,R,Rand sud-africain,100,cent,cents
1 devise_code num4217 symbole nom division minor minors
2 EUR 978 Euro 100 centime centimes
3 CHF 756 CHf Franc suisse 100 centime centimes
4 GBP 826 £ Livre sterling 100 penny pence
5 JPY 392 ¥ Yen japonais 1
6 TRY 949 Nouvelle livre turque 100 kuruş kuruş
7 USD 840 $ Dollar des Etats-Unis 100 cent cents
8 ZAR 710 R Rand sud-africain 100 cent cents

View File

@@ -0,0 +1,8 @@
pays_code,devise,valide
FR,EUR,"[1999-01-01,)"
CH,CHF,"(,)"
JP,JPY,"(,)"
GB,GBP,"(,)"
US,USD,"(,)"
TR,TRY,"[2005-01-01,)"
ZA,ZAR,"(,)"
1 pays_code devise valide
2 FR EUR [1999-01-01,)
3 CH CHF (,)
4 JP JPY (,)
5 GB GBP (,)
6 US USD (,)
7 TR TRY [2005-01-01,)
8 ZA ZAR (,)

View File

@@ -0,0 +1,46 @@
devise_code,num4217,symbole,nom,division,minor,minors
ATS,40,,Schilling autrichien,100,Groschen,
AUD,36,,Dollar australien,100,cent,cents
BEF,56,,Franc belge,100,centime,centimes
BGN,975,Лв.,Lev bulgare,100,stotinki,
CAD,124,,Dollar canadien,100,cent,cents
CYP,196,,Livre chypriote,100,cent,cents
CZK,203,,Couronne tchèque,100,haléřů,
DEM,276,,Mark allemand,100,Pfennig,
DKK,208,,Couronne danoise,100,øre,
EEK,233,,Couronne estonienne,100,sents,
ESP,724,,Peseta espagnole,100,céntimos,
FIM,246,,Mark finlandais,100,penni,
FRF,250,,Franc français,100,centimes,centime
GRD,300,,Drachme grecque,100,leptae,
HUF,348,Ft,Forint hongrois,100,fillér,
IEP,372,,Livre irlandaise,100,penny,pence
ILS,376,,Nouveau sheqel israélien,100,agorots,
INR,356,,Roupie indienne,100,paise,
ISK,352,,Couronne islandaise,100,eyrir,aurar
ITL,380,,Lire italienne,100,centesimi,
KRW,410,,Won coréen,100,jeon,
LTL,440,,Litas lituanien,,,
LUF,442,,Franc luxembourgeois,100,centime,centimes
LVL,428,,Lats letton,100,santimes,
MTL,470,,Livre maltaise,100,cents / 1000 mils,
NLG,528,,Florin néerlandais,100,cents,
NOK,578,kr,Couronne norvégienne,100,øre,
NZD,554,,Dollar néo-zélandais,100,cents,
PLN,985,,Zloty,,,
PTE,620,,Escudo portugais,100,centavo,centavos
ROL,642,leu,Leu roumain,100,ban,bani
RON,946,leu,Leu roumain,100,ban,bani
SEK,752,kr,Couronne suédoise,100,öre,
SIT,705,,Tolar slovène,100,haliers,
SKK,703,,Couronne slovaque,100,haliers,
THB,764,฿,Baht thaïlandais,100,satang,
TRL,792,,Livre turque,100,kuruş,
TWD,901,,Nouveau dollar de Taïwan,,,
UAH,980,,Hryvnia ukrainien,100,kopiykas,
XOF,952,F.CFA,Franc CFA Ouest BCEAO,,,
HKD,344,,Dollar de Hong Kong,,,
SGD,702,,Dollar de Singapour,100,cent,cents
MXN,484,,Peso mexicain,100,centavo,centavos
MAD,504,,Dirham marocain,100,centime,centimes
BRL,986,,Real brésilien,100,centavo,centavos
1 devise_code num4217 symbole nom division minor minors
2 ATS 40 Schilling autrichien 100 Groschen
3 AUD 36 Dollar australien 100 cent cents
4 BEF 56 Franc belge 100 centime centimes
5 BGN 975 Лв. Lev bulgare 100 stotinki
6 CAD 124 Dollar canadien 100 cent cents
7 CYP 196 Livre chypriote 100 cent cents
8 CZK 203 Couronne tchèque 100 haléřů
9 DEM 276 Mark allemand 100 Pfennig
10 DKK 208 Couronne danoise 100 øre
11 EEK 233 Couronne estonienne 100 sents
12 ESP 724 Peseta espagnole 100 céntimos
13 FIM 246 Mark finlandais 100 penni
14 FRF 250 Franc français 100 centimes centime
15 GRD 300 Drachme grecque 100 leptae
16 HUF 348 Ft Forint hongrois 100 fillér
17 IEP 372 Livre irlandaise 100 penny pence
18 ILS 376 Nouveau sheqel israélien 100 agorots
19 INR 356 Roupie indienne 100 paise
20 ISK 352 Couronne islandaise 100 eyrir aurar
21 ITL 380 Lire italienne 100 centesimi
22 KRW 410 Won coréen 100 jeon
23 LTL 440 Litas lituanien
24 LUF 442 Franc luxembourgeois 100 centime centimes
25 LVL 428 Lats letton 100 santimes
26 MTL 470 Livre maltaise 100 cents / 1000 mils
27 NLG 528 Florin néerlandais 100 cents
28 NOK 578 kr Couronne norvégienne 100 øre
29 NZD 554 Dollar néo-zélandais 100 cents
30 PLN 985 Zloty
31 PTE 620 Escudo portugais 100 centavo centavos
32 ROL 642 leu Leu roumain 100 ban bani
33 RON 946 leu Leu roumain 100 ban bani
34 SEK 752 kr Couronne suédoise 100 öre
35 SIT 705 Tolar slovène 100 haliers
36 SKK 703 Couronne slovaque 100 haliers
37 THB 764 ฿ Baht thaïlandais 100 satang
38 TRL 792 Livre turque 100 kuruş
39 TWD 901 Nouveau dollar de Taïwan
40 UAH 980 Hryvnia ukrainien 100 kopiykas
41 XOF 952 F.CFA Franc CFA Ouest BCEAO
42 HKD 344 Dollar de Hong Kong
43 SGD 702 Dollar de Singapour 100 cent cents
44 MXN 484 Peso mexicain 100 centavo centavos
45 MAD 504 Dirham marocain 100 centime centimes
46 BRL 986 Real brésilien 100 centavo centavos

View File

@@ -7,7 +7,6 @@ NL,EUR,"[1999-01-01,)"
NL,NLG,"(,1999-01-01)" NL,NLG,"(,1999-01-01)"
FI,EUR,"[1999-01-01,)" FI,EUR,"[1999-01-01,)"
FI,FIM,"(,1999-01-01)" FI,FIM,"(,1999-01-01)"
FR,EUR,"[1999-01-01,)"
FR,FRF,"[1960-01-01,1999-01-01)" FR,FRF,"[1960-01-01,1999-01-01)"
DE,EUR,"[1999-01-01,)" DE,EUR,"[1999-01-01,)"
DE,DEM,"(,1999-01-01)" DE,DEM,"(,1999-01-01)"
@@ -40,7 +39,8 @@ LT,LTL,"(,2015-01-01)"
HR,EUR,"[2023-01-01,)" HR,EUR,"[2023-01-01,)"
AD,EUR,"[1999-01-01,)" AD,EUR,"[1999-01-01,)"
MC,EUR,"[1999-01-01,)" MC,EUR,"[1999-01-01,)"
US,USD,"(,)" SG,SGD,"(,)"
HK,HKD,"(,)"
EC,USD,"(,)" EC,USD,"(,)"
SV,USD,"(,)" SV,USD,"(,)"
HT,USD,"(,)" HT,USD,"(,)"
@@ -54,8 +54,6 @@ ML,XOF,"(,)"
NE,XOF,"(,)" NE,XOF,"(,)"
SN,XOF,"(,)" SN,XOF,"(,)"
TG,XOF,"(,)" TG,XOF,"(,)"
JP,JPY,"(,)"
CH,CHF,"(,)"
LI,CHF,"(,)" LI,CHF,"(,)"
SE,SEK,"(,)" SE,SEK,"(,)"
NO,NOK,"(,)" NO,NOK,"(,)"
@@ -68,15 +66,11 @@ NZ,NZD,"(,)"
UA,UAH,"(,)" UA,UAH,"(,)"
BG,BGN,"(,)" BG,BGN,"(,)"
CZ,CZK,"(,)" CZ,CZK,"(,)"
GB,GBP,"(,)"
TR,TRL,"(,2005-01-01)" TR,TRL,"(,2005-01-01)"
TR,TRY,"[2005-01-01,)"
DK,DKK,"(,)" DK,DKK,"(,)"
HU,HUF,"(,)" HU,HUF,"(,)"
IS,ISK,"(,)" IS,ISK,"(,)"
TW,TWD,"(,)" TW,TWD,"(,)"
MX,MXN,"(,)" MX,MXN,"(,)"
SG,SGD,"(,)"
HK,HKD,"(,)"
UA,UAH,"(,)" UA,UAH,"(,)"
BR,BRL,"(,)" BR,BRL,"(,)"
1 pays_code devise valide
7 NL NLG (,1999-01-01)
8 FI EUR [1999-01-01,)
9 FI FIM (,1999-01-01)
FR EUR [1999-01-01,)
10 FR FRF [1960-01-01,1999-01-01)
11 DE EUR [1999-01-01,)
12 DE DEM (,1999-01-01)
39 HR EUR [2023-01-01,)
40 AD EUR [1999-01-01,)
41 MC EUR [1999-01-01,)
42 US SG USD SGD (,)
43 HK HKD (,)
44 EC USD (,)
45 SV USD (,)
46 HT USD (,)
54 NE XOF (,)
55 SN XOF (,)
56 TG XOF (,)
JP JPY (,)
CH CHF (,)
57 LI CHF (,)
58 SE SEK (,)
59 NO NOK (,)
66 UA UAH (,)
67 BG BGN (,)
68 CZ CZK (,)
GB GBP (,)
69 TR TRL (,2005-01-01)
TR TRY [2005-01-01,)
70 DK DKK (,)
71 HU HUF (,)
72 IS ISK (,)
73 TW TWD (,)
74 MX MXN (,)
SG SGD (,)
HK HKD (,)
75 UA UAH (,)
76 BR BRL (,)

View File

@@ -1,52 +0,0 @@
devise_code,num4217,symbole,nom,format,division,minor,minors
ATS,40,,Schilling autrichien,"S #.###,##",100,Groschen,
AUD,36,,Dollar australien,$# ###.##,100,cent,cents
BEF,56,,Franc belge,BEF #.###,100,centime,centimes
BGN,975,Лв.,Lev bulgare,#,100,stotinki,
CAD,124,,Dollar canadien,"$#,###.##",100,cent,cents
CHF,756,CHf,Franc suisse,#,100,centime,centimes
CYP,196,,Livre chypriote,"?#.###,##",100,cent,cents
CZK,203,,Couronne tchèque,"#.###,## Kč",100,haléřů,
DEM,276,,Mark allemand,"#.###,##DM",100,Pfennig,
DKK,208,,Couronne danoise,"kr.#.###,##",100,øre,
EEK,233,,Couronne estonienne,"# ###,## EEK",100,sents,
ESP,724,,Peseta espagnole,#,100,céntimos,
EUR,978,,Euro,#,100,centime,centimes
FIM,246,,Mark finlandais,"# ###,## mk",100,penni,
FRF,250,,Franc français,"# ###,## FRF",100,centimes,centime
GBP,826,£,Livre sterling,#,100,penny,pence
GRD,300,,Drachme grecque,#,100,leptae,
HUF,348,Ft,Forint hongrois,#,100,fillér,
IEP,372,,Livre irlandaise,#,100,penny,pence
ILS,376,,Nouveau sheqel israélien,#,100,agorots,
INR,356,,Roupie indienne,#,100,paise,
ISK,352,,Couronne islandaise,#,100,eyrir,aurar
ITL,380,,Lire italienne,₤ #,100,centesimi,
JPY,392,¥,Yen japonais,#,,,
KRW,410,,Won coréen,#,100,jeon,
LTL,440,,Litas lituanien,#,,,
LUF,442,,Franc luxembourgeois,#,100,centime,centimes
LVL,428,,Lats letton,#,100,santimes,
MTL,470,,Livre maltaise,#,100,cents / 1000 mils,
NLG,528,,Florin néerlandais,"f #.###,##",100,cents,
NOK,578,kr,Couronne norvégienne,#,100,øre,
NZD,554,,Dollar néo-zélandais,#,100,cents,
PLN,985,,Zloty,#,,,
PTE,620,,Escudo portugais,##,100,centavo,centavos
ROL,642,leu,Leu roumain,#,100,ban,bani
RON,946,leu,Leu roumain,#,100,ban,bani
SEK,752,kr,Couronne suédoise,#,100,öre,
SIT,705,,Tolar slovène,#,100,haliers,
SKK,703,,Couronne slovaque,#,100,haliers,
THB,764,฿,Baht thaïlandais,#,100,satang,
TRL,792,,Livre turque,#,100,kuruş,
TRY,949,,Nouvelle livre turque,#,100,kuruş,
TWD,901,,Nouveau dollar de Taïwan,#,,,
UAH,980,,Hryvnia ukrainien,#,100,kopiykas,
USD,840,$,Dollar des Etats-Unis,"$#,###.##",100,cent,cents
XOF,952,F.CFA,Franc CFA Ouest BCEAO,#,,,
HKD,344,,Dollar de Hong Kong,#,,,
SGD,702,,Dollar de Singapour,#,100,cent,cents
MXN,484,,Peso mexicain,#,100,centavo,centavos
MAD,504,,Dirham marocain,#,100,centime,centimes
BRL,986,,Real brésilien,"R$ #.###,##",100,centavo,centavos
1 devise_code num4217 symbole nom format division minor minors
2 ATS 40 Schilling autrichien S #.###,## 100 Groschen
3 AUD 36 Dollar australien $# ###.## 100 cent cents
4 BEF 56 Franc belge BEF #.### 100 centime centimes
5 BGN 975 Лв. Lev bulgare # 100 stotinki
6 CAD 124 Dollar canadien $#,###.## 100 cent cents
7 CHF 756 CHf Franc suisse # 100 centime centimes
8 CYP 196 Livre chypriote ?#.###,## 100 cent cents
9 CZK 203 Couronne tchèque #.###,## Kč 100 haléřů
10 DEM 276 Mark allemand #.###,##DM 100 Pfennig
11 DKK 208 Couronne danoise kr.#.###,## 100 øre
12 EEK 233 Couronne estonienne # ###,## EEK 100 sents
13 ESP 724 Peseta espagnole # 100 céntimos
14 EUR 978 Euro # 100 centime centimes
15 FIM 246 Mark finlandais # ###,## mk 100 penni
16 FRF 250 Franc français # ###,## FRF 100 centimes centime
17 GBP 826 £ Livre sterling # 100 penny pence
18 GRD 300 Drachme grecque # 100 leptae
19 HUF 348 Ft Forint hongrois # 100 fillér
20 IEP 372 Livre irlandaise # 100 penny pence
21 ILS 376 Nouveau sheqel israélien # 100 agorots
22 INR 356 Roupie indienne # 100 paise
23 ISK 352 Couronne islandaise # 100 eyrir aurar
24 ITL 380 Lire italienne ₤ # 100 centesimi
25 JPY 392 ¥ Yen japonais #
26 KRW 410 Won coréen # 100 jeon
27 LTL 440 Litas lituanien #
28 LUF 442 Franc luxembourgeois # 100 centime centimes
29 LVL 428 Lats letton # 100 santimes
30 MTL 470 Livre maltaise # 100 cents / 1000 mils
31 NLG 528 Florin néerlandais f #.###,## 100 cents
32 NOK 578 kr Couronne norvégienne # 100 øre
33 NZD 554 Dollar néo-zélandais # 100 cents
34 PLN 985 Zloty #
35 PTE 620 Escudo portugais ## 100 centavo centavos
36 ROL 642 leu Leu roumain # 100 ban bani
37 RON 946 leu Leu roumain # 100 ban bani
38 SEK 752 kr Couronne suédoise # 100 öre
39 SIT 705 Tolar slovène # 100 haliers
40 SKK 703 Couronne slovaque # 100 haliers
41 THB 764 ฿ Baht thaïlandais # 100 satang
42 TRL 792 Livre turque # 100 kuruş
43 TRY 949 Nouvelle livre turque # 100 kuruş
44 TWD 901 Nouveau dollar de Taïwan #
45 UAH 980 Hryvnia ukrainien # 100 kopiykas
46 USD 840 $ Dollar des Etats-Unis $#,###.## 100 cent cents
47 XOF 952 F.CFA Franc CFA Ouest BCEAO #
48 HKD 344 Dollar de Hong Kong #
49 SGD 702 Dollar de Singapour # 100 cent cents
50 MXN 484 Peso mexicain # 100 centavo centavos
51 MAD 504 Dirham marocain # 100 centime centimes
52 BRL 986 Real brésilien R$ #.###,## 100 centavo centavos

View File

@@ -30,7 +30,7 @@ create extension if not exists pgtap schema pgtap;
-- ---------------------------------------------------------------------- -- ----------------------------------------------------------------------
create schema geo; create schema geo;
select 'Pays -------------------' as msg; select 'Pays --------------------' as msg;
create table geo.pays ( create table geo.pays (
code2 text not null, code2 text not null,
@@ -221,6 +221,12 @@ create table adherent (
codepostal text codepostal text
); );
-- ----------------------------------------------------------------------
-- Marché (Market)
-- ----------------------------------------------------------------------
create schema market;
create table famille ( create table famille (
code text primary key, code text primary key,
famille text, famille text,
@@ -238,14 +244,14 @@ create table article (
suivistock int suivistock int
); );
create table ticket ( create table market.ticket (
id int primary key, id int primary key,
date_ticket timestamp, date_ticket timestamp,
adherent_id int, -- references adherent(id) adherent_id int, -- references adherent(id)
mode_rglt int mode_rglt int
); );
create table ligne ( create table market.ligne (
id int primary key, id int primary key,
ticket_id int, -- references ticket (id), ticket_id int, -- references ticket (id),
article_code text, -- references article (code) article_code text, -- references article (code)
@@ -253,7 +259,7 @@ create table ligne (
quantite decimal quantite decimal
); );
alter table ligne alter table market.ligne
add column total decimal add column total decimal
generated always as (prix_unitaire * quantite) stored; generated always as (prix_unitaire * quantite) stored;
@@ -307,7 +313,7 @@ insert into region values
create table personne ( create table personne (
id bigint primary key generated always as identity, id bigint,
prenom text, prenom text,
nom text, nom text,
telephone text, telephone text,
@@ -315,41 +321,10 @@ create table personne (
); );
create table societe ( create table societe (
id bigint primary key generated always as identity, id bigint,
societe text societe text
); );
insert into societe
OVERRIDING SYSTEM VALUE
values
(1, 'Supérette'),
(2, 'Boulangerie Lagarde'),
(3, 'Pharmacie Martin'),
(4, 'Diminutif'),
(5, 'Vélocité'),
(6, 'Café du Marché'),
(7, 'La Maison Fleurie'),
(8, 'Librairie des Tilleuls'),
(9, 'MétalTech SARL'),
(10, 'BoisDesign'),
(11, 'Les Délices du Terroir'),
(12, 'VitiVerte'),
(13, 'ÉlectroServ'),
(14, 'Ateliers du Moulin'),
(15, 'Comptexpert'),
(16, 'Assur O'' Poil'),
(17, 'Banque Régionale du Centre'),
(18, 'ImmoVilla'),
(19, 'ITLink Solutions'),
(20, 'Studio Graphica '),
(21, 'Mairie de Batz'),
(22, 'Hôtel du rivage'),
(23, 'Collège Marie Curie'),
(24, 'École primaire des Lilas'),
(25, 'Maison de retraite Les Acacias'),
(26, 'Cabinet Médical du Parc'),
(27, 'Banque de l''Étoile'),
(28, 'Pizzeria Geppetto');
/* /*
CREATE TABLE emplois ( CREATE TABLE emplois (
@@ -376,7 +351,7 @@ create schema banque;
CREATE OR REPLACE FUNCTION banque.rand_account(n integer) CREATE OR REPLACE FUNCTION banque.rand_account(n integer)
RETURNS text AS $$ RETURNS text AS $$
DECLARE DECLARE
chars text := '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; chars text := '0123456789ABCDEFGHJKLMNPRSTUWXYZ';
out text := ''; out text := '';
b bytea := gen_random_bytes(n); -- n octets aléatoires b bytea := gen_random_bytes(n); -- n octets aléatoires
i int; i int;
@@ -395,14 +370,13 @@ BEGIN
END; END;
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql;
-- Devises (currencies) -- Devises (Currencies)
-- ---------------------------------------------------------------------- -- ----------------------------------------------------------------------
create table banque.currency ( create table banque.currency (
code text not null, code text not null,
num4217 integer default null, num4217 integer default null,
symbole character varying(5) default null, symbole character varying(5) default null,
nom text default null, nom text default null,
format text default null,
division integer default 0, division integer default 0,
minor text default null, minor text default null,
minors text default null minors text default null
@@ -443,6 +417,8 @@ alter table only pays_devises
add foreign key (devise_code) add foreign key (devise_code)
references banque.currency (code); references banque.currency (code);
-- Taux de change ()
-- ----------------------------------------------------------------------
CREATE TABLE banque.exchange_rate ( CREATE TABLE banque.exchange_rate (
from_currency CHAR(3) references banque.currency(code), from_currency CHAR(3) references banque.currency(code),
to_currency CHAR(3) references banque.currency(code), to_currency CHAR(3) references banque.currency(code),
@@ -457,8 +433,6 @@ create temporary table exchange (
rate decimal(12,6) rate decimal(12,6)
); );
-- CHF
DO $$ DO $$
DECLARE DECLARE
rec RECORD; rec RECORD;
@@ -494,20 +468,80 @@ END $$;
DROP table exchange; DROP table exchange;
-- ----------------------------------------------------------------------
-- Titulaires
-- ---------------------------------------------------------------------- -- ----------------------------------------------------------------------
CREATE TABLE banque.account ( CREATE TABLE banque.titulaire (
id bigint primary key generated always as identity, id bigint primary key generated always as identity,
account_number TEXT UNIQUE NOT NULL, type_titulaire TEXT CHECK (type_titulaire IN ('individu', 'société')) NOT NULL,
balance NUMERIC(18,2) NOT NULL DEFAULT 0, created_at timestamp with time zone not null default now()
currency CHAR(3) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()
); );
CREATE FUNCTION auto_titulaire_physique()
RETURNS TRIGGER AS $$
DECLARE
new_titulaire_id INTEGER;
BEGIN
IF NEW.id IS NULL THEN
INSERT INTO banque.titulaire (type_titulaire) VALUES ('individu')
RETURNING id INTO new_titulaire_id;
NEW.id := new_titulaire_id;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trg_auto_titulaire_physique
BEFORE INSERT ON personne
FOR EACH ROW
EXECUTE FUNCTION auto_titulaire_physique();
CREATE OR REPLACE FUNCTION auto_titulaire_morale()
RETURNS TRIGGER AS $$
DECLARE
new_titulaire_id INTEGER;
BEGIN
IF NEW.id IS NULL THEN
INSERT INTO banque.titulaire (type_titulaire) VALUES ('morale')
RETURNING id INTO new_titulaire_id;
NEW.id := new_titulaire_id;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER trg_auto_titulaire_morale
BEFORE INSERT ON societe
FOR EACH ROW
EXECUTE FUNCTION auto_titulaire_morale();
-- ----------------------------------------------------------------------
-- Comptes (Accounts)
-- ----------------------------------------------------------------------
create table banque.account (
id bigint primary key generated always as identity,
account_number text unique not null,
balance numeric(18,6) not null default 0,
currency char(3) not null,
created_at timestamp with time zone not null default now()
);
create table banque.account_holders (
account_id bigint NOT NULL REFERENCES banque.account(id) ON DELETE CASCADE,
titulaire_id int NOT NULL REFERENCES banque.titulaire(id) ON DELETE CASCADE,
share numeric(5,2) CHECK (share >= 0 AND share <= 100),
role text DEFAULT 'Titulaire',
PRIMARY KEY (account_id, titulaire_id)
);
CREATE TABLE banque."transaction" ( CREATE TABLE banque."transaction" (
id UUID PRIMARY KEY DEFAULT uuidv7(), id UUID PRIMARY KEY DEFAULT uuidv7(),
reference TEXT, reference TEXT,
amount NUMERIC(18,2) NOT NULL, amount NUMERIC(18,6) NOT NULL,
currency CHAR(3) NOT NULL, currency CHAR(3) NOT NULL,
from_account BIGINT NOT NULL REFERENCES banque.account(id), from_account BIGINT NOT NULL REFERENCES banque.account(id),
to_account BIGINT NOT NULL REFERENCES banque.account(id), to_account BIGINT NOT NULL REFERENCES banque.account(id),
@@ -520,7 +554,7 @@ CREATE TABLE banque.ledger_entry (
id bigint primary key generated always as identity, id bigint primary key generated always as identity,
transaction_id UUID NOT NULL REFERENCES banque."transaction"(id), transaction_id UUID NOT NULL REFERENCES banque."transaction"(id),
account_id BIGINT NOT NULL REFERENCES banque.account(id), account_id BIGINT NOT NULL REFERENCES banque.account(id),
amount NUMERIC(18,2) NOT NULL, -- convention: positif = crédit, négatif = débit (ici from = -amount, to = +amount) amount NUMERIC(18,6) NOT NULL, -- convention: positif = crédit, négatif = débit (ici from = -amount, to = +amount)
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
description TEXT description TEXT
); );
@@ -555,16 +589,16 @@ CREATE INDEX idx_block_chain_txid ON banque.block_chain(tx_id);
CREATE OR REPLACE FUNCTION perform_transaction( CREATE OR REPLACE FUNCTION perform_transaction(
from_account_id INT, from_account_id INT,
to_account_id INT, to_account_id INT,
amount DECIMAL(18,2), amount DECIMAL(18,6),
description TEXT description TEXT
) RETURNS VOID AS $$ ) RETURNS VOID AS $$
DECLARE DECLARE
from_currency CHAR(3); from_currency CHAR(3);
to_currency CHAR(3); to_currency CHAR(3);
rate DECIMAL(12,6); rate DECIMAL(12,6);
fee DECIMAL(18,2); fee DECIMAL(18,6);
base_amount DECIMAL(18,2); base_amount DECIMAL(18,6);
converted_amount DECIMAL(18,2); converted_amount DECIMAL(18,6);
tx_id INT; tx_id INT;
prev_hash TEXT; prev_hash TEXT;
new_hash TEXT; new_hash TEXT;

View File

@@ -1,19 +1,19 @@
truncate table adherent; truncate table adherent;
truncate table famille; truncate table famille;
truncate table article; truncate table article;
truncate table ticket; truncate table market.ticket;
truncate table ligne; truncate table market.ligne;
truncate table marque; truncate table marque;
truncate table fournisseur; truncate table fournisseur;
\COPY adherent FROM '/tmp/adherent.csv' (FORMAT CSV, header, ENCODING 'UTF8'); \COPY adherent FROM '/tmp/adherent.csv' (FORMAT CSV, header, ENCODING 'UTF8');
\COPY famille FROM '/tmp/famille.csv' (FORMAT CSV, header, ENCODING 'UTF8'); \COPY famille FROM '/tmp/famille.csv' (FORMAT CSV, header, ENCODING 'UTF8');
\COPY article FROM '/tmp/article.csv' (FORMAT CSV, header, ENCODING 'UTF8'); \COPY article FROM '/tmp/article.csv' (FORMAT CSV, header, ENCODING 'UTF8');
\COPY ticket FROM '/tmp/ticket.csv' (FORMAT CSV, header, ENCODING 'UTF8'); \COPY market.ticket FROM '/tmp/ticket.csv' (FORMAT CSV, header, ENCODING 'UTF8');
\COPY ligne FROM '/tmp/ligne.csv' (FORMAT CSV, header, ENCODING 'UTF8'); \COPY market.ligne FROM '/tmp/ligne.csv' (FORMAT CSV, header, ENCODING 'UTF8');
\COPY marque FROM '/tmp/marque.csv' (FORMAT CSV, header, ENCODING 'UTF8'); \COPY marque FROM '/tmp/marque.csv' (FORMAT CSV, header, ENCODING 'UTF8');
\COPY fournisseur FROM '/tmp/fournisseur.csv' (FORMAT CSV, header, ENCODING 'UTF8'); \COPY fournisseur FROM '/tmp/fournisseur.csv' (FORMAT CSV, header, ENCODING 'UTF8');
\COPY produit FROM '/tmp/produits/cereales_petitdejeuner.csv' (FORMAT CSV, header, ENCODING 'UTF8'); \COPY produit FROM '/tmp/produits/cereales_petitdejeuner.csv' (FORMAT CSV, header, ENCODING 'UTF8');
\COPY personne FROM '/tmp/personne.csv' (FORMAT CSV, header, ENCODING 'UTF8'); \COPY personne FROM '/tmp/personne1.csv' (FORMAT CSV, header, ENCODING 'UTF8');

View File

@@ -5,7 +5,7 @@ create view nb_total_articles as
select count(*) as nb_total_articles from article; select count(*) as nb_total_articles from article;
create view nb_total_tickets as create view nb_total_tickets as
select count(*) as nb_total_tickets from ticket; select count(*) as nb_total_tickets from market.ticket;
create view nb_total_adherents as create view nb_total_adherents as
select count(*) as nb_total_adherents from adherent; select count(*) as nb_total_adherents from adherent;
@@ -14,8 +14,8 @@ create materialized view detail_ticket as
select t.id as ticket_id, t.date_ticket, t.mode_rglt, select t.id as ticket_id, t.date_ticket, t.mode_rglt,
h.id as adherent_id, h.codepostal, h.genre, h.id as adherent_id, h.codepostal, h.genre,
round(sum(l.total), 2) as total round(sum(l.total), 2) as total
from ticket t from market.ticket t
join ligne l on l.ticket_id = t.id join market.ligne l on l.ticket_id = t.id
join adherent h on h.id = t.adherent_id join adherent h on h.id = t.adherent_id
group by t.id, h.id; group by t.id, h.id;
@@ -24,8 +24,8 @@ select t.id as ticket_id, t.date_ticket, t.mode_rglt,
h.id as adherent_id, h.codepostal, h.genre, h.id as adherent_id, h.codepostal, h.genre,
l.article_code, a.famille_code, l.article_code, a.famille_code,
round(sum(l.total), 2) as total round(sum(l.total), 2) as total
from ticket t from market.ticket t
join ligne l on l.ticket_id = t.id join market.ligne l on l.ticket_id = t.id
join adherent h on h.id = t.adherent_id join adherent h on h.id = t.adherent_id
join article a on a.code = l.article_code join article a on a.code = l.article_code
group by t.id, h.id, l.article_code, a.famille_code; group by t.id, h.id, l.article_code, a.famille_code;