@flowselections/layout-maker 1.63.5 → 1.66.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -4
- package/dist-lib/components/BedrijfsgegevensKaart.d.ts +3 -0
- package/dist-lib/components/BedrijfsgegevensKaart.d.ts.map +1 -0
- package/dist-lib/components/BedrijfsgegevensKaart.js +58 -0
- package/dist-lib/components/KlaarOmTePrintenBlok.d.ts +3 -0
- package/dist-lib/components/KlaarOmTePrintenBlok.d.ts.map +1 -0
- package/dist-lib/components/KlaarOmTePrintenBlok.js +69 -0
- package/dist-lib/components/LayoutsPage.d.ts.map +1 -1
- package/dist-lib/components/LayoutsPage.js +23 -3
- package/dist-lib/components/PakbonPreview.d.ts.map +1 -1
- package/dist-lib/components/PakbonPreview.js +10 -7
- package/dist-lib/components/PrintenPage.d.ts.map +1 -1
- package/dist-lib/components/PrintenPage.js +8 -2
- package/dist-lib/components/StandaardLayoutActies.d.ts +19 -0
- package/dist-lib/components/StandaardLayoutActies.d.ts.map +1 -0
- package/dist-lib/components/StandaardLayoutActies.js +105 -0
- package/dist-lib/index.d.ts +9 -2
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/index.js +10 -3
- package/dist-lib/integrations/supabase/types.d.ts +1078 -0
- package/dist-lib/integrations/supabase/types.d.ts.map +1 -1
- package/dist-lib/lib/bedrijfsgegevens.d.ts +41 -0
- package/dist-lib/lib/bedrijfsgegevens.d.ts.map +1 -0
- package/dist-lib/lib/bedrijfsgegevens.functions.d.ts +41 -0
- package/dist-lib/lib/bedrijfsgegevens.functions.d.ts.map +1 -0
- package/dist-lib/lib/bedrijfsgegevens.functions.js +75 -0
- package/dist-lib/lib/bedrijfsgegevens.js +126 -0
- package/dist-lib/lib/documentTypes.d.ts +10 -0
- package/dist-lib/lib/documentTypes.d.ts.map +1 -1
- package/dist-lib/lib/documentTypes.js +8 -0
- package/dist-lib/lib/klaarOmTePrinten.d.ts +39 -0
- package/dist-lib/lib/klaarOmTePrinten.d.ts.map +1 -0
- package/dist-lib/lib/klaarOmTePrinten.js +65 -0
- package/dist-lib/lib/layoutStandaarden.d.ts +19 -0
- package/dist-lib/lib/layoutStandaarden.d.ts.map +1 -0
- package/dist-lib/lib/layoutStandaarden.js +23 -0
- package/dist-lib/lib/orderData.server.d.ts.map +1 -1
- package/dist-lib/lib/orderData.server.js +163 -0
- package/dist-lib/lib/pakbonBuilder.d.ts +30 -0
- package/dist-lib/lib/pakbonBuilder.d.ts.map +1 -1
- package/dist-lib/lib/pakbonBuilder.js +90 -2
- package/dist-lib/lib/pakbonContent.d.ts.map +1 -1
- package/dist-lib/lib/pakbonContent.js +15 -8
- package/dist-lib/lib/pakbonHtml.d.ts.map +1 -1
- package/dist-lib/lib/pakbonHtml.js +24 -7
- package/dist-lib/lib/printQueue.server.d.ts.map +1 -1
- package/dist-lib/lib/printQueue.server.js +33 -2
- package/dist-lib/lib/printService.functions.d.ts +1 -1
- package/dist-lib/lib/printnodeWebhookBeheer.server.d.ts +1 -1
- package/dist-lib/lib/shellPoort.d.ts +2 -2
- package/dist-lib/lib/shellPoort.d.ts.map +1 -1
- package/dist-lib/lib/shellPoort.js +3 -2
- package/dist-lib/lib/standaardLayouts.server.d.ts +7 -1
- package/dist-lib/lib/standaardLayouts.server.d.ts.map +1 -1
- package/dist-lib/lib/standaardLayouts.server.js +52 -54
- package/dist-lib/lib/useDocumentData.d.ts.map +1 -1
- package/dist-lib/lib/useDocumentData.js +9 -5
- package/dist-lib/lib/versie.generated.d.ts +2 -0
- package/dist-lib/lib/versie.generated.d.ts.map +1 -0
- package/dist-lib/lib/versie.generated.js +2 -0
- package/package.json +9 -4
- package/sql/print-schema.sql +3205 -0
|
@@ -0,0 +1,3205 @@
|
|
|
1
|
+
-- ============================================================================
|
|
2
|
+
set check_function_bodies = off;
|
|
3
|
+
-- layout-maker 1.65.1 — volledig database-schema (idempotent)
|
|
4
|
+
-- Gegenereerd door scripts/bouw-schema.py. Mag zo vaak worden gedraaid als je
|
|
5
|
+
-- wilt. Bevat alleen structuur: geen adressen, sleutels of klantgegevens.
|
|
6
|
+
-- Vereiste extensies: pgcrypto, pg_net, pg_cron (en vault voor het tickgeheim).
|
|
7
|
+
-- ============================================================================
|
|
8
|
+
create extension if not exists pgcrypto;
|
|
9
|
+
create extension if not exists pg_net;
|
|
10
|
+
create extension if not exists pg_cron;
|
|
11
|
+
-- Functies mogen naar elkaar verwijzen ongeacht de volgorde.
|
|
12
|
+
set check_function_bodies = off;
|
|
13
|
+
|
|
14
|
+
-- 1. Keuzelijsten
|
|
15
|
+
do $$ begin if not exists (select 1 from pg_type where typname='ai_import_status') then create type public.ai_import_status as enum ('nieuw', 'verwerken', 'bevestigen', 'klaar', 'mislukt'); end if; end $$;
|
|
16
|
+
alter type public.ai_import_status add value if not exists 'nieuw';
|
|
17
|
+
alter type public.ai_import_status add value if not exists 'verwerken';
|
|
18
|
+
alter type public.ai_import_status add value if not exists 'bevestigen';
|
|
19
|
+
alter type public.ai_import_status add value if not exists 'klaar';
|
|
20
|
+
alter type public.ai_import_status add value if not exists 'mislukt';
|
|
21
|
+
do $$ begin if not exists (select 1 from pg_type where typname='doc_layout_type') then create type public.doc_layout_type as enum ('pakbon', 'factuur', 'offerte', 'orderbevestiging', 'etiket', 'verzendlabel', 'productlabel', 'barcode_label', 'magazijnlijst', 'controlelijst', 'transportdocument', 'vrij', 'sticker', 'productiebon', 'veilingbon', 'afleverbrief', 'veilingbrief', 'traysticker'); end if; end $$;
|
|
22
|
+
alter type public.doc_layout_type add value if not exists 'pakbon';
|
|
23
|
+
alter type public.doc_layout_type add value if not exists 'factuur';
|
|
24
|
+
alter type public.doc_layout_type add value if not exists 'offerte';
|
|
25
|
+
alter type public.doc_layout_type add value if not exists 'orderbevestiging';
|
|
26
|
+
alter type public.doc_layout_type add value if not exists 'etiket';
|
|
27
|
+
alter type public.doc_layout_type add value if not exists 'verzendlabel';
|
|
28
|
+
alter type public.doc_layout_type add value if not exists 'productlabel';
|
|
29
|
+
alter type public.doc_layout_type add value if not exists 'barcode_label';
|
|
30
|
+
alter type public.doc_layout_type add value if not exists 'magazijnlijst';
|
|
31
|
+
alter type public.doc_layout_type add value if not exists 'controlelijst';
|
|
32
|
+
alter type public.doc_layout_type add value if not exists 'transportdocument';
|
|
33
|
+
alter type public.doc_layout_type add value if not exists 'vrij';
|
|
34
|
+
alter type public.doc_layout_type add value if not exists 'sticker';
|
|
35
|
+
alter type public.doc_layout_type add value if not exists 'productiebon';
|
|
36
|
+
alter type public.doc_layout_type add value if not exists 'veilingbon';
|
|
37
|
+
alter type public.doc_layout_type add value if not exists 'afleverbrief';
|
|
38
|
+
alter type public.doc_layout_type add value if not exists 'veilingbrief';
|
|
39
|
+
alter type public.doc_layout_type add value if not exists 'traysticker';
|
|
40
|
+
do $$ begin if not exists (select 1 from pg_type where typname='doc_orientation') then create type public.doc_orientation as enum ('portrait', 'landscape'); end if; end $$;
|
|
41
|
+
alter type public.doc_orientation add value if not exists 'portrait';
|
|
42
|
+
alter type public.doc_orientation add value if not exists 'landscape';
|
|
43
|
+
do $$ begin if not exists (select 1 from pg_type where typname='print_job_status') then create type public.print_job_status as enum ('wachtend', 'bezig', 'voltooid', 'mislukt', 'geannuleerd'); end if; end $$;
|
|
44
|
+
alter type public.print_job_status add value if not exists 'wachtend';
|
|
45
|
+
alter type public.print_job_status add value if not exists 'bezig';
|
|
46
|
+
alter type public.print_job_status add value if not exists 'voltooid';
|
|
47
|
+
alter type public.print_job_status add value if not exists 'mislukt';
|
|
48
|
+
alter type public.print_job_status add value if not exists 'geannuleerd';
|
|
49
|
+
do $$ begin if not exists (select 1 from pg_type where typname='printer_connection') then create type public.printer_connection as enum ('ipp', 'raw9100', 'printnode', 'cups', 'usb', 'windows', 'airprint', 'cloud'); end if; end $$;
|
|
50
|
+
alter type public.printer_connection add value if not exists 'ipp';
|
|
51
|
+
alter type public.printer_connection add value if not exists 'raw9100';
|
|
52
|
+
alter type public.printer_connection add value if not exists 'printnode';
|
|
53
|
+
alter type public.printer_connection add value if not exists 'cups';
|
|
54
|
+
alter type public.printer_connection add value if not exists 'usb';
|
|
55
|
+
alter type public.printer_connection add value if not exists 'windows';
|
|
56
|
+
alter type public.printer_connection add value if not exists 'airprint';
|
|
57
|
+
alter type public.printer_connection add value if not exists 'cloud';
|
|
58
|
+
do $$ begin if not exists (select 1 from pg_type where typname='printer_kind') then create type public.printer_kind as enum ('labelprinter', 'laserprinter', 'inkjet', 'thermal', 'kantoorprinter', 'overig'); end if; end $$;
|
|
59
|
+
alter type public.printer_kind add value if not exists 'labelprinter';
|
|
60
|
+
alter type public.printer_kind add value if not exists 'laserprinter';
|
|
61
|
+
alter type public.printer_kind add value if not exists 'inkjet';
|
|
62
|
+
alter type public.printer_kind add value if not exists 'thermal';
|
|
63
|
+
alter type public.printer_kind add value if not exists 'kantoorprinter';
|
|
64
|
+
alter type public.printer_kind add value if not exists 'overig';
|
|
65
|
+
|
|
66
|
+
-- 2. Tabellen
|
|
67
|
+
create table if not exists public.ai_layout_imports ();
|
|
68
|
+
alter table public.ai_layout_imports add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
69
|
+
alter table public.ai_layout_imports add column if not exists "bestandsnaam" text default ''::text not null;
|
|
70
|
+
alter table public.ai_layout_imports add column if not exists "mime_type" text default ''::text not null;
|
|
71
|
+
alter table public.ai_layout_imports add column if not exists "bestand_url" text;
|
|
72
|
+
alter table public.ai_layout_imports add column if not exists "status" ai_import_status default 'nieuw'::ai_import_status not null;
|
|
73
|
+
alter table public.ai_layout_imports add column if not exists "analyse_json" jsonb default '{}'::jsonb not null;
|
|
74
|
+
alter table public.ai_layout_imports add column if not exists "voorstel" jsonb default '{}'::jsonb not null;
|
|
75
|
+
alter table public.ai_layout_imports add column if not exists "onzekere_velden" jsonb default '[]'::jsonb not null;
|
|
76
|
+
alter table public.ai_layout_imports add column if not exists "bevestigd" boolean default false not null;
|
|
77
|
+
alter table public.ai_layout_imports add column if not exists "layout_id" uuid;
|
|
78
|
+
alter table public.ai_layout_imports add column if not exists "foutmelding" text;
|
|
79
|
+
alter table public.ai_layout_imports add column if not exists "created_by" uuid;
|
|
80
|
+
alter table public.ai_layout_imports add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
81
|
+
alter table public.ai_layout_imports add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
82
|
+
create table if not exists public.document_bronregels ();
|
|
83
|
+
alter table public.document_bronregels add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
84
|
+
alter table public.document_bronregels add column if not exists "documenttype" text not null;
|
|
85
|
+
alter table public.document_bronregels add column if not exists "herkomst" text not null;
|
|
86
|
+
alter table public.document_bronregels add column if not exists "bron" text default 'auto'::text not null;
|
|
87
|
+
alter table public.document_bronregels add column if not exists "layout_id" uuid;
|
|
88
|
+
alter table public.document_bronregels add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
89
|
+
alter table public.document_bronregels add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
90
|
+
create table if not exists public.document_formaat_printers ();
|
|
91
|
+
alter table public.document_formaat_printers add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
92
|
+
alter table public.document_formaat_printers add column if not exists "documenttype" text not null;
|
|
93
|
+
alter table public.document_formaat_printers add column if not exists "formaat_code" text not null;
|
|
94
|
+
alter table public.document_formaat_printers add column if not exists "printer_id" uuid;
|
|
95
|
+
alter table public.document_formaat_printers add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
96
|
+
alter table public.document_formaat_printers add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
97
|
+
alter table public.document_formaat_printers add column if not exists "printer_ontbreekt_sinds" timestamp with time zone;
|
|
98
|
+
create table if not exists public.document_layout_conditions ();
|
|
99
|
+
alter table public.document_layout_conditions add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
100
|
+
alter table public.document_layout_conditions add column if not exists "layout_id" uuid not null;
|
|
101
|
+
alter table public.document_layout_conditions add column if not exists "element_key" text not null;
|
|
102
|
+
alter table public.document_layout_conditions add column if not exists "veld" text not null;
|
|
103
|
+
alter table public.document_layout_conditions add column if not exists "operator" text default '='::text not null;
|
|
104
|
+
alter table public.document_layout_conditions add column if not exists "waarde" text default ''::text not null;
|
|
105
|
+
alter table public.document_layout_conditions add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
106
|
+
alter table public.document_layout_conditions add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
107
|
+
create table if not exists public.document_layout_datasources ();
|
|
108
|
+
alter table public.document_layout_datasources add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
109
|
+
alter table public.document_layout_datasources add column if not exists "layout_id" uuid not null;
|
|
110
|
+
alter table public.document_layout_datasources add column if not exists "module_id" text not null;
|
|
111
|
+
alter table public.document_layout_datasources add column if not exists "entiteit" text not null;
|
|
112
|
+
alter table public.document_layout_datasources add column if not exists "alias" text default ''::text not null;
|
|
113
|
+
alter table public.document_layout_datasources add column if not exists "filter" jsonb default '{}'::jsonb not null;
|
|
114
|
+
alter table public.document_layout_datasources add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
115
|
+
alter table public.document_layout_datasources add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
116
|
+
create table if not exists public.document_layout_elements ();
|
|
117
|
+
alter table public.document_layout_elements add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
118
|
+
alter table public.document_layout_elements add column if not exists "layout_id" uuid not null;
|
|
119
|
+
alter table public.document_layout_elements add column if not exists "element_key" text not null;
|
|
120
|
+
alter table public.document_layout_elements add column if not exists "type" text not null;
|
|
121
|
+
alter table public.document_layout_elements add column if not exists "parent_key" text;
|
|
122
|
+
alter table public.document_layout_elements add column if not exists "volgorde" integer default 0 not null;
|
|
123
|
+
alter table public.document_layout_elements add column if not exists "x" numeric default 10 not null;
|
|
124
|
+
alter table public.document_layout_elements add column if not exists "y" numeric default 10 not null;
|
|
125
|
+
alter table public.document_layout_elements add column if not exists "breedte" numeric default 60 not null;
|
|
126
|
+
alter table public.document_layout_elements add column if not exists "hoogte" numeric default 10 not null;
|
|
127
|
+
alter table public.document_layout_elements add column if not exists "rotatie" numeric default 0 not null;
|
|
128
|
+
alter table public.document_layout_elements add column if not exists "z_index" integer default 0 not null;
|
|
129
|
+
alter table public.document_layout_elements add column if not exists "content" text default ''::text not null;
|
|
130
|
+
alter table public.document_layout_elements add column if not exists "veldpad" text;
|
|
131
|
+
alter table public.document_layout_elements add column if not exists "stijl" jsonb default '{}'::jsonb not null;
|
|
132
|
+
alter table public.document_layout_elements add column if not exists "config" jsonb default '{}'::jsonb not null;
|
|
133
|
+
alter table public.document_layout_elements add column if not exists "vergrendeld" boolean default false not null;
|
|
134
|
+
alter table public.document_layout_elements add column if not exists "verborgen" boolean default false not null;
|
|
135
|
+
alter table public.document_layout_elements add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
136
|
+
alter table public.document_layout_elements add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
137
|
+
alter table public.document_layout_elements add column if not exists "logo_id" uuid;
|
|
138
|
+
create table if not exists public.document_layout_variables ();
|
|
139
|
+
alter table public.document_layout_variables add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
140
|
+
alter table public.document_layout_variables add column if not exists "layout_id" uuid not null;
|
|
141
|
+
alter table public.document_layout_variables add column if not exists "naam" text not null;
|
|
142
|
+
alter table public.document_layout_variables add column if not exists "expressie" text default ''::text not null;
|
|
143
|
+
alter table public.document_layout_variables add column if not exists "omschrijving" text default ''::text not null;
|
|
144
|
+
alter table public.document_layout_variables add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
145
|
+
alter table public.document_layout_variables add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
146
|
+
create table if not exists public.document_layout_versions ();
|
|
147
|
+
alter table public.document_layout_versions add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
148
|
+
alter table public.document_layout_versions add column if not exists "layout_id" uuid not null;
|
|
149
|
+
alter table public.document_layout_versions add column if not exists "versienummer" integer not null;
|
|
150
|
+
alter table public.document_layout_versions add column if not exists "elements" jsonb default '[]'::jsonb not null;
|
|
151
|
+
alter table public.document_layout_versions add column if not exists "page_settings" jsonb default '{}'::jsonb not null;
|
|
152
|
+
alter table public.document_layout_versions add column if not exists "commentaar" text default ''::text not null;
|
|
153
|
+
alter table public.document_layout_versions add column if not exists "created_by" uuid;
|
|
154
|
+
alter table public.document_layout_versions add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
155
|
+
alter table public.document_layout_versions add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
156
|
+
create table if not exists public.document_layouts ();
|
|
157
|
+
alter table public.document_layouts add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
158
|
+
alter table public.document_layouts add column if not exists "naam" text not null;
|
|
159
|
+
alter table public.document_layouts add column if not exists "documenttype" doc_layout_type default 'vrij'::doc_layout_type not null;
|
|
160
|
+
alter table public.document_layouts add column if not exists "omschrijving" text default ''::text not null;
|
|
161
|
+
alter table public.document_layouts add column if not exists "papierformaat" text default 'A4'::text not null;
|
|
162
|
+
alter table public.document_layouts add column if not exists "breedte_mm" numeric default 210 not null;
|
|
163
|
+
alter table public.document_layouts add column if not exists "hoogte_mm" numeric default 297 not null;
|
|
164
|
+
alter table public.document_layouts add column if not exists "marge_boven" numeric default 10 not null;
|
|
165
|
+
alter table public.document_layouts add column if not exists "marge_onder" numeric default 10 not null;
|
|
166
|
+
alter table public.document_layouts add column if not exists "marge_links" numeric default 10 not null;
|
|
167
|
+
alter table public.document_layouts add column if not exists "marge_rechts" numeric default 10 not null;
|
|
168
|
+
alter table public.document_layouts add column if not exists "orientatie" doc_orientation default 'portrait'::doc_orientation not null;
|
|
169
|
+
alter table public.document_layouts add column if not exists "actief" boolean default true not null;
|
|
170
|
+
alter table public.document_layouts add column if not exists "is_standaard" boolean default false not null;
|
|
171
|
+
alter table public.document_layouts add column if not exists "thumbnail_url" text;
|
|
172
|
+
alter table public.document_layouts add column if not exists "huidige_versie" integer default 1 not null;
|
|
173
|
+
alter table public.document_layouts add column if not exists "page_settings" jsonb default '{}'::jsonb not null;
|
|
174
|
+
alter table public.document_layouts add column if not exists "created_by" uuid;
|
|
175
|
+
alter table public.document_layouts add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
176
|
+
alter table public.document_layouts add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
177
|
+
alter table public.document_layouts add column if not exists "config" jsonb default '{}'::jsonb not null;
|
|
178
|
+
alter table public.document_layouts add column if not exists "bron" text default 'eigen'::text not null;
|
|
179
|
+
alter table public.document_layouts add column if not exists "systeem" boolean default false not null;
|
|
180
|
+
create table if not exists public.document_printplek_printers ();
|
|
181
|
+
alter table public.document_printplek_printers add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
182
|
+
alter table public.document_printplek_printers add column if not exists "print_plek_id" uuid not null;
|
|
183
|
+
alter table public.document_printplek_printers add column if not exists "documenttype" text not null;
|
|
184
|
+
alter table public.document_printplek_printers add column if not exists "printer_id" uuid;
|
|
185
|
+
alter table public.document_printplek_printers add column if not exists "papierformaat" text;
|
|
186
|
+
alter table public.document_printplek_printers add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
187
|
+
alter table public.document_printplek_printers add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
188
|
+
alter table public.document_printplek_printers add column if not exists "printer_ontbreekt_sinds" timestamp with time zone;
|
|
189
|
+
create table if not exists public.document_werkplek_printers ();
|
|
190
|
+
alter table public.document_werkplek_printers add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
191
|
+
alter table public.document_werkplek_printers add column if not exists "documenttype" text not null;
|
|
192
|
+
alter table public.document_werkplek_printers add column if not exists "werkplek" text not null;
|
|
193
|
+
alter table public.document_werkplek_printers add column if not exists "printer_id" uuid;
|
|
194
|
+
alter table public.document_werkplek_printers add column if not exists "papierformaat" text;
|
|
195
|
+
alter table public.document_werkplek_printers add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
196
|
+
alter table public.document_werkplek_printers add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
197
|
+
alter table public.document_werkplek_printers add column if not exists "printer_ontbreekt_sinds" timestamp with time zone;
|
|
198
|
+
create table if not exists public.layout_logos ();
|
|
199
|
+
alter table public.layout_logos add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
200
|
+
alter table public.layout_logos add column if not exists "naam" text not null;
|
|
201
|
+
alter table public.layout_logos add column if not exists "omschrijving" text default ''::text not null;
|
|
202
|
+
alter table public.layout_logos add column if not exists "categorie" text default 'overig'::text not null;
|
|
203
|
+
alter table public.layout_logos add column if not exists "bestand_url" text not null;
|
|
204
|
+
alter table public.layout_logos add column if not exists "bestandspad" text;
|
|
205
|
+
alter table public.layout_logos add column if not exists "bestandstype" text default 'png'::text not null;
|
|
206
|
+
alter table public.layout_logos add column if not exists "breedte" integer default 0 not null;
|
|
207
|
+
alter table public.layout_logos add column if not exists "hoogte" integer default 0 not null;
|
|
208
|
+
alter table public.layout_logos add column if not exists "bestandsgrootte" integer default 0 not null;
|
|
209
|
+
alter table public.layout_logos add column if not exists "transparant" boolean default false not null;
|
|
210
|
+
alter table public.layout_logos add column if not exists "is_standaard" boolean default false not null;
|
|
211
|
+
alter table public.layout_logos add column if not exists "hash" text;
|
|
212
|
+
alter table public.layout_logos add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
213
|
+
alter table public.layout_logos add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
214
|
+
alter table public.layout_logos add column if not exists "origineel_pad" text;
|
|
215
|
+
create table if not exists public.pakbon_barcode_inhoud ();
|
|
216
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "barcode" text not null;
|
|
217
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "order_ref" text;
|
|
218
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "order_nummer" text;
|
|
219
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "klant_naam" text;
|
|
220
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "klant_nummer" text;
|
|
221
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "cart_id" text;
|
|
222
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "cart_label" text;
|
|
223
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "cart_index" integer;
|
|
224
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "cart_total" integer;
|
|
225
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "layout_variant" text;
|
|
226
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "layout_id" uuid;
|
|
227
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "print_job_id" uuid;
|
|
228
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "is_herprint" boolean default false not null;
|
|
229
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "regels" jsonb default '[]'::jsonb not null;
|
|
230
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
231
|
+
alter table public.pakbon_barcode_inhoud add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
232
|
+
create table if not exists public.pakbon_barcode_verzoeken ();
|
|
233
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
234
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "print_job_id" uuid not null;
|
|
235
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "documentnaam" text;
|
|
236
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "order_nummer" text;
|
|
237
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "order_ref" text;
|
|
238
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "klant_naam" text;
|
|
239
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "klant_nummer" text;
|
|
240
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "cart_id" text;
|
|
241
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "cart_label" text;
|
|
242
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "cart_index" integer;
|
|
243
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "cart_total" integer;
|
|
244
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "layout_variant" text;
|
|
245
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "layout_id" text;
|
|
246
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "is_herprint" boolean default false not null;
|
|
247
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "status" text default 'open'::text not null;
|
|
248
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "barcode" text;
|
|
249
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "aangevraagd_op" timestamp with time zone default now() not null;
|
|
250
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "laatst_gevraagd_op" timestamp with time zone default now() not null;
|
|
251
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "geleverd_op" timestamp with time zone;
|
|
252
|
+
alter table public.pakbon_barcode_verzoeken add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
253
|
+
create table if not exists public.print_agents ();
|
|
254
|
+
alter table public.print_agents add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
255
|
+
alter table public.print_agents add column if not exists "naam" text not null;
|
|
256
|
+
alter table public.print_agents add column if not exists "locatie" text default ''::text not null;
|
|
257
|
+
alter table public.print_agents add column if not exists "token_hash" text not null;
|
|
258
|
+
alter table public.print_agents add column if not exists "actief" boolean default true not null;
|
|
259
|
+
alter table public.print_agents add column if not exists "laatst_gezien" timestamp with time zone;
|
|
260
|
+
alter table public.print_agents add column if not exists "versie" text default ''::text not null;
|
|
261
|
+
alter table public.print_agents add column if not exists "gemelde_printers" jsonb default '[]'::jsonb not null;
|
|
262
|
+
alter table public.print_agents add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
263
|
+
alter table public.print_agents add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
264
|
+
alter table public.print_agents add column if not exists "pairing_code_hash" text;
|
|
265
|
+
alter table public.print_agents add column if not exists "pairing_expires_at" timestamp with time zone;
|
|
266
|
+
alter table public.print_agents add column if not exists "pairing_used_at" timestamp with time zone;
|
|
267
|
+
create table if not exists public.print_computer_status ();
|
|
268
|
+
alter table public.print_computer_status add column if not exists "extern_computer_id" text not null;
|
|
269
|
+
alter table public.print_computer_status add column if not exists "naam" text;
|
|
270
|
+
alter table public.print_computer_status add column if not exists "verbonden" boolean default false not null;
|
|
271
|
+
alter table public.print_computer_status add column if not exists "status" text;
|
|
272
|
+
alter table public.print_computer_status add column if not exists "bijgewerkt_op" timestamp with time zone default now() not null;
|
|
273
|
+
alter table public.print_computer_status add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
274
|
+
alter table public.print_computer_status add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
275
|
+
create table if not exists public.print_dedupe_events ();
|
|
276
|
+
alter table public.print_dedupe_events add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
277
|
+
alter table public.print_dedupe_events add column if not exists "idempotentie_sleutel" text not null;
|
|
278
|
+
alter table public.print_dedupe_events add column if not exists "reden" text not null;
|
|
279
|
+
alter table public.print_dedupe_events add column if not exists "documentnaam" text;
|
|
280
|
+
alter table public.print_dedupe_events add column if not exists "documenttype" text;
|
|
281
|
+
alter table public.print_dedupe_events add column if not exists "bestaande_job_id" uuid;
|
|
282
|
+
alter table public.print_dedupe_events add column if not exists "detail" text;
|
|
283
|
+
alter table public.print_dedupe_events add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
284
|
+
create table if not exists public.print_gebruiker_werkplek ();
|
|
285
|
+
alter table public.print_gebruiker_werkplek add column if not exists "user_id" uuid not null;
|
|
286
|
+
alter table public.print_gebruiker_werkplek add column if not exists "werkplek_id" uuid not null;
|
|
287
|
+
alter table public.print_gebruiker_werkplek add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
288
|
+
alter table public.print_gebruiker_werkplek add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
289
|
+
create table if not exists public.print_genegeerde_computers ();
|
|
290
|
+
alter table public.print_genegeerde_computers add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
291
|
+
alter table public.print_genegeerde_computers add column if not exists "computer_naam" text not null;
|
|
292
|
+
alter table public.print_genegeerde_computers add column if not exists "genegeerd_op" timestamp with time zone default now() not null;
|
|
293
|
+
alter table public.print_genegeerde_computers add column if not exists "genegeerd_door" uuid default auth.uid();
|
|
294
|
+
alter table public.print_genegeerde_computers add column if not exists "printnode_computer_id" bigint;
|
|
295
|
+
create table if not exists public.print_job_logs ();
|
|
296
|
+
alter table public.print_job_logs add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
297
|
+
alter table public.print_job_logs add column if not exists "job_id" uuid not null;
|
|
298
|
+
alter table public.print_job_logs add column if not exists "gebeurtenis" text not null;
|
|
299
|
+
alter table public.print_job_logs add column if not exists "detail" text default ''::text not null;
|
|
300
|
+
alter table public.print_job_logs add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
301
|
+
create table if not exists public.print_jobs ();
|
|
302
|
+
alter table public.print_jobs add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
303
|
+
alter table public.print_jobs add column if not exists "layout_id" uuid;
|
|
304
|
+
alter table public.print_jobs add column if not exists "printer_id" uuid;
|
|
305
|
+
alter table public.print_jobs add column if not exists "documenttype" doc_layout_type default 'vrij'::doc_layout_type not null;
|
|
306
|
+
alter table public.print_jobs add column if not exists "documentnaam" text default ''::text not null;
|
|
307
|
+
alter table public.print_jobs add column if not exists "status" print_job_status default 'wachtend'::print_job_status not null;
|
|
308
|
+
alter table public.print_jobs add column if not exists "payload" jsonb default '{}'::jsonb not null;
|
|
309
|
+
alter table public.print_jobs add column if not exists "paginas" integer default 1 not null;
|
|
310
|
+
alter table public.print_jobs add column if not exists "kopieen" integer default 1 not null;
|
|
311
|
+
alter table public.print_jobs add column if not exists "foutmelding" text;
|
|
312
|
+
alter table public.print_jobs add column if not exists "is_herprint" boolean default false not null;
|
|
313
|
+
alter table public.print_jobs add column if not exists "bron_job_id" uuid;
|
|
314
|
+
alter table public.print_jobs add column if not exists "gebruiker_id" uuid;
|
|
315
|
+
alter table public.print_jobs add column if not exists "gebruiker_naam" text default ''::text not null;
|
|
316
|
+
alter table public.print_jobs add column if not exists "gestart_op" timestamp with time zone;
|
|
317
|
+
alter table public.print_jobs add column if not exists "voltooid_op" timestamp with time zone;
|
|
318
|
+
alter table public.print_jobs add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
319
|
+
alter table public.print_jobs add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
320
|
+
alter table public.print_jobs add column if not exists "agent_id" uuid;
|
|
321
|
+
alter table public.print_jobs add column if not exists "opgepakt_op" timestamp with time zone;
|
|
322
|
+
alter table public.print_jobs add column if not exists "pogingen" integer default 0 not null;
|
|
323
|
+
alter table public.print_jobs add column if not exists "render_html" text;
|
|
324
|
+
alter table public.print_jobs add column if not exists "extern_job_id" text;
|
|
325
|
+
alter table public.print_jobs add column if not exists "volgende_poging" timestamp with time zone;
|
|
326
|
+
alter table public.print_jobs add column if not exists "idempotentie_sleutel" text;
|
|
327
|
+
alter table public.print_jobs add column if not exists "pdf_url" text;
|
|
328
|
+
alter table public.print_jobs add column if not exists "pdf_base64" text;
|
|
329
|
+
alter table public.print_jobs add column if not exists "herkomst" text;
|
|
330
|
+
alter table public.print_jobs add column if not exists "gebruikte_layout_id" uuid;
|
|
331
|
+
alter table public.print_jobs add column if not exists "gebruikte_bron" text;
|
|
332
|
+
alter table public.print_jobs add column if not exists "resultaat_pdf_base64" text;
|
|
333
|
+
alter table public.print_jobs add column if not exists "lokale_pdf_status" text;
|
|
334
|
+
alter table public.print_jobs add column if not exists "lokaal_opgeslagen_op" timestamp with time zone;
|
|
335
|
+
alter table public.print_jobs add column if not exists "lokale_pdf_fout" text;
|
|
336
|
+
alter table public.print_jobs add column if not exists "lokale_pdf_print_plek_id" uuid;
|
|
337
|
+
alter table public.print_jobs add column if not exists "lokale_pdf_claim_id" text;
|
|
338
|
+
alter table public.print_jobs add column if not exists "lokale_pdf_claim_tot" timestamp with time zone;
|
|
339
|
+
alter table public.print_jobs add column if not exists "verwerkingsfase" text default 'wachtend'::text not null;
|
|
340
|
+
alter table public.print_jobs add column if not exists "fase_gestart_op" timestamp with time zone;
|
|
341
|
+
alter table public.print_jobs add column if not exists "fase_voltooid_op" timestamp with time zone;
|
|
342
|
+
alter table public.print_jobs add column if not exists "foutcode" text;
|
|
343
|
+
alter table public.print_jobs add column if not exists "batch_id" uuid;
|
|
344
|
+
alter table public.print_jobs add column if not exists "artefact_pad" text;
|
|
345
|
+
alter table public.print_jobs add column if not exists "artefact_sha256" text;
|
|
346
|
+
alter table public.print_jobs add column if not exists "artefact_bytes" bigint;
|
|
347
|
+
alter table public.print_jobs add column if not exists "artefact_gereed_op" timestamp with time zone;
|
|
348
|
+
alter table public.print_jobs add column if not exists "aflever_pogingen" integer default 0 not null;
|
|
349
|
+
alter table public.print_jobs add column if not exists "printnode_status" text;
|
|
350
|
+
alter table public.print_jobs add column if not exists "printnode_bericht" text;
|
|
351
|
+
alter table public.print_jobs add column if not exists "printnode_status_op" timestamp with time zone;
|
|
352
|
+
alter table public.print_jobs add column if not exists "verloopt_na_s" integer;
|
|
353
|
+
alter table public.print_jobs add column if not exists "origineel_sleutel" text;
|
|
354
|
+
alter table public.print_jobs add column if not exists "verwerkt_door_runner" text;
|
|
355
|
+
alter table public.print_jobs add column if not exists "verwerkt_met_versie" text;
|
|
356
|
+
create table if not exists public.print_plek_computers ();
|
|
357
|
+
alter table public.print_plek_computers add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
358
|
+
alter table public.print_plek_computers add column if not exists "print_plek_id" uuid not null;
|
|
359
|
+
alter table public.print_plek_computers add column if not exists "computer_naam" text not null;
|
|
360
|
+
alter table public.print_plek_computers add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
361
|
+
alter table public.print_plek_computers add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
362
|
+
alter table public.print_plek_computers add column if not exists "printnode_computer_id" bigint;
|
|
363
|
+
create table if not exists public.print_plek_koppelingen ();
|
|
364
|
+
alter table public.print_plek_koppelingen add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
365
|
+
alter table public.print_plek_koppelingen add column if not exists "print_plek_id" uuid not null;
|
|
366
|
+
alter table public.print_plek_koppelingen add column if not exists "bron" text not null;
|
|
367
|
+
alter table public.print_plek_koppelingen add column if not exists "bron_id" text not null;
|
|
368
|
+
alter table public.print_plek_koppelingen add column if not exists "label" text;
|
|
369
|
+
alter table public.print_plek_koppelingen add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
370
|
+
alter table public.print_plek_koppelingen add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
371
|
+
create table if not exists public.print_plek_printers ();
|
|
372
|
+
alter table public.print_plek_printers add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
373
|
+
alter table public.print_plek_printers add column if not exists "print_plek_id" uuid not null;
|
|
374
|
+
alter table public.print_plek_printers add column if not exists "printer_id" uuid not null;
|
|
375
|
+
alter table public.print_plek_printers add column if not exists "toegevoegd_op" timestamp with time zone default now() not null;
|
|
376
|
+
create table if not exists public.print_plekken ();
|
|
377
|
+
alter table public.print_plekken add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
378
|
+
alter table public.print_plekken add column if not exists "naam" text not null;
|
|
379
|
+
alter table public.print_plekken add column if not exists "omschrijving" text;
|
|
380
|
+
alter table public.print_plekken add column if not exists "actief" boolean default true not null;
|
|
381
|
+
alter table public.print_plekken add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
382
|
+
alter table public.print_plekken add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
383
|
+
create table if not exists public.print_preview_events ();
|
|
384
|
+
alter table public.print_preview_events add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
385
|
+
alter table public.print_preview_events add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
386
|
+
alter table public.print_preview_events add column if not exists "station_slug" text;
|
|
387
|
+
alter table public.print_preview_events add column if not exists "queue_item_id" uuid;
|
|
388
|
+
alter table public.print_preview_events add column if not exists "uitkomst" text default 'toegestaan'::text not null;
|
|
389
|
+
alter table public.print_preview_events add column if not exists "code" text;
|
|
390
|
+
alter table public.print_preview_events add column if not exists "reden" text;
|
|
391
|
+
alter table public.print_preview_events add column if not exists "detail" jsonb default '{}'::jsonb not null;
|
|
392
|
+
create table if not exists public.print_printer_verwijder_herstel ();
|
|
393
|
+
alter table public.print_printer_verwijder_herstel add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
394
|
+
alter table public.print_printer_verwijder_herstel add column if not exists "print_plek_id" uuid not null;
|
|
395
|
+
alter table public.print_printer_verwijder_herstel add column if not exists "printer_id" uuid not null;
|
|
396
|
+
alter table public.print_printer_verwijder_herstel add column if not exists "extern_printer_id" text;
|
|
397
|
+
alter table public.print_printer_verwijder_herstel add column if not exists "printer_naam" text;
|
|
398
|
+
alter table public.print_printer_verwijder_herstel add column if not exists "regels" jsonb default '[]'::jsonb not null;
|
|
399
|
+
alter table public.print_printer_verwijder_herstel add column if not exists "verwijderd_op" timestamp with time zone default now() not null;
|
|
400
|
+
alter table public.print_printer_verwijder_herstel add column if not exists "hersteld_op" timestamp with time zone;
|
|
401
|
+
alter table public.print_printer_verwijder_herstel add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
402
|
+
create table if not exists public.print_queue_leases ();
|
|
403
|
+
alter table public.print_queue_leases add column if not exists "naam" text not null;
|
|
404
|
+
alter table public.print_queue_leases add column if not exists "houder" uuid not null;
|
|
405
|
+
alter table public.print_queue_leases add column if not exists "verloopt_op" timestamp with time zone not null;
|
|
406
|
+
alter table public.print_queue_leases add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
407
|
+
alter table public.print_queue_leases add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
408
|
+
create table if not exists public.print_queue_runners ();
|
|
409
|
+
alter table public.print_queue_runners add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
410
|
+
alter table public.print_queue_runners add column if not exists "basis_url" text not null;
|
|
411
|
+
alter table public.print_queue_runners add column if not exists "tick_sleutel" text default encode(extensions.gen_random_bytes(24), 'hex'::text) not null;
|
|
412
|
+
alter table public.print_queue_runners add column if not exists "laatst_gezien" timestamp with time zone default now() not null;
|
|
413
|
+
alter table public.print_queue_runners add column if not exists "actief" boolean default true not null;
|
|
414
|
+
alter table public.print_queue_runners add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
415
|
+
alter table public.print_queue_runners add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
416
|
+
alter table public.print_queue_runners add column if not exists "mislukte_posts" integer default 0 not null;
|
|
417
|
+
alter table public.print_queue_runners add column if not exists "laatste_fout" text;
|
|
418
|
+
alter table public.print_queue_runners add column if not exists "laatste_request_id" bigint;
|
|
419
|
+
alter table public.print_queue_runners add column if not exists "laatste_wakeup" timestamp with time zone;
|
|
420
|
+
alter table public.print_queue_runners add column if not exists "mislukte_wakeups" integer default 0 not null;
|
|
421
|
+
alter table public.print_queue_runners add column if not exists "module_versie" text;
|
|
422
|
+
alter table public.print_queue_runners add column if not exists "laatste_ok" timestamp with time zone;
|
|
423
|
+
create table if not exists public.print_queue_settings ();
|
|
424
|
+
alter table public.print_queue_settings add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
425
|
+
alter table public.print_queue_settings add column if not exists "dubbel_venster_minuten" integer default 10 not null;
|
|
426
|
+
alter table public.print_queue_settings add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
427
|
+
alter table public.print_queue_settings add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
428
|
+
alter table public.print_queue_settings add column if not exists "bewaar_bestanden_dagen" integer default 7 not null;
|
|
429
|
+
alter table public.print_queue_settings add column if not exists "bewaar_opdrachten_dagen" integer default 90 not null;
|
|
430
|
+
create table if not exists public.print_rules ();
|
|
431
|
+
alter table public.print_rules add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
432
|
+
alter table public.print_rules add column if not exists "layout_id" uuid not null;
|
|
433
|
+
alter table public.print_rules add column if not exists "printer_id" uuid;
|
|
434
|
+
alter table public.print_rules add column if not exists "naam" text default 'Regel'::text not null;
|
|
435
|
+
alter table public.print_rules add column if not exists "conditie" jsonb default '[]'::jsonb not null;
|
|
436
|
+
alter table public.print_rules add column if not exists "kopieen" integer default 1 not null;
|
|
437
|
+
alter table public.print_rules add column if not exists "alleen_eerste_keer" boolean default false not null;
|
|
438
|
+
alter table public.print_rules add column if not exists "actief" boolean default true not null;
|
|
439
|
+
alter table public.print_rules add column if not exists "volgorde" integer default 0 not null;
|
|
440
|
+
alter table public.print_rules add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
441
|
+
alter table public.print_rules add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
442
|
+
create table if not exists public.print_shell_stilstand ();
|
|
443
|
+
alter table public.print_shell_stilstand add column if not exists "id" bigserial not null;
|
|
444
|
+
alter table public.print_shell_stilstand add column if not exists "reden" text not null;
|
|
445
|
+
alter table public.print_shell_stilstand add column if not exists "sinds" timestamp with time zone;
|
|
446
|
+
alter table public.print_shell_stilstand add column if not exists "gemeld_op" timestamp with time zone default now() not null;
|
|
447
|
+
alter table public.print_shell_stilstand add column if not exists "opgelost_op" timestamp with time zone;
|
|
448
|
+
create table if not exists public.print_werkplek_afwijkingen ();
|
|
449
|
+
alter table public.print_werkplek_afwijkingen add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
450
|
+
alter table public.print_werkplek_afwijkingen add column if not exists "werkplek_id" uuid not null;
|
|
451
|
+
alter table public.print_werkplek_afwijkingen add column if not exists "documenttype" text not null;
|
|
452
|
+
alter table public.print_werkplek_afwijkingen add column if not exists "printer_id" uuid;
|
|
453
|
+
alter table public.print_werkplek_afwijkingen add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
454
|
+
alter table public.print_werkplek_afwijkingen add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
455
|
+
create table if not exists public.print_werkplekken ();
|
|
456
|
+
alter table public.print_werkplekken add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
457
|
+
alter table public.print_werkplekken add column if not exists "naam" text not null;
|
|
458
|
+
alter table public.print_werkplekken add column if not exists "print_plek_id" uuid;
|
|
459
|
+
alter table public.print_werkplekken add column if not exists "a4_printer_id" uuid;
|
|
460
|
+
alter table public.print_werkplekken add column if not exists "label_printer_id" uuid;
|
|
461
|
+
alter table public.print_werkplekken add column if not exists "actief" boolean default true not null;
|
|
462
|
+
alter table public.print_werkplekken add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
463
|
+
alter table public.print_werkplekken add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
464
|
+
create table if not exists public.printer_mappings ();
|
|
465
|
+
alter table public.printer_mappings add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
466
|
+
alter table public.printer_mappings add column if not exists "layout_id" uuid not null;
|
|
467
|
+
alter table public.printer_mappings add column if not exists "printer_id" uuid;
|
|
468
|
+
alter table public.printer_mappings add column if not exists "prioriteit" integer default 1 not null;
|
|
469
|
+
alter table public.printer_mappings add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
470
|
+
alter table public.printer_mappings add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
471
|
+
alter table public.printer_mappings add column if not exists "printer_ontbreekt_sinds" timestamp with time zone;
|
|
472
|
+
create table if not exists public.printer_profiles ();
|
|
473
|
+
alter table public.printer_profiles add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
474
|
+
alter table public.printer_profiles add column if not exists "printer_id" uuid not null;
|
|
475
|
+
alter table public.printer_profiles add column if not exists "naam" text default 'Standaard'::text not null;
|
|
476
|
+
alter table public.printer_profiles add column if not exists "papierlade" text default ''::text not null;
|
|
477
|
+
alter table public.printer_profiles add column if not exists "resolutie" integer default 203 not null;
|
|
478
|
+
alter table public.printer_profiles add column if not exists "kopieen" integer default 1 not null;
|
|
479
|
+
alter table public.printer_profiles add column if not exists "duplex" boolean default false not null;
|
|
480
|
+
alter table public.printer_profiles add column if not exists "kleur" boolean default false not null;
|
|
481
|
+
alter table public.printer_profiles add column if not exists "orientatie" doc_orientation default 'portrait'::doc_orientation not null;
|
|
482
|
+
alter table public.printer_profiles add column if not exists "auto_schalen" boolean default true not null;
|
|
483
|
+
alter table public.printer_profiles add column if not exists "snijden" boolean default false not null;
|
|
484
|
+
alter table public.printer_profiles add column if not exists "label_gap" numeric default 3 not null;
|
|
485
|
+
alter table public.printer_profiles add column if not exists "is_standaard" boolean default true not null;
|
|
486
|
+
alter table public.printer_profiles add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
487
|
+
alter table public.printer_profiles add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
488
|
+
create table if not exists public.printer_routes ();
|
|
489
|
+
alter table public.printer_routes add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
490
|
+
alter table public.printer_routes add column if not exists "printer_id" uuid not null;
|
|
491
|
+
alter table public.printer_routes add column if not exists "extern_printer_id" text not null;
|
|
492
|
+
alter table public.printer_routes add column if not exists "computer_naam" text;
|
|
493
|
+
alter table public.printer_routes add column if not exists "prioriteit" integer default 0 not null;
|
|
494
|
+
alter table public.printer_routes add column if not exists "geladen_etiket" jsonb;
|
|
495
|
+
alter table public.printer_routes add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
496
|
+
alter table public.printer_routes add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
497
|
+
create table if not exists public.printers ();
|
|
498
|
+
alter table public.printers add column if not exists "id" uuid default gen_random_uuid() not null;
|
|
499
|
+
alter table public.printers add column if not exists "naam" text not null;
|
|
500
|
+
alter table public.printers add column if not exists "omschrijving" text default ''::text not null;
|
|
501
|
+
alter table public.printers add column if not exists "soort" printer_kind default 'kantoorprinter'::printer_kind not null;
|
|
502
|
+
alter table public.printers add column if not exists "verbinding" printer_connection default 'ipp'::printer_connection not null;
|
|
503
|
+
alter table public.printers add column if not exists "merk" text default ''::text not null;
|
|
504
|
+
alter table public.printers add column if not exists "ip_adres" text;
|
|
505
|
+
alter table public.printers add column if not exists "poort" integer;
|
|
506
|
+
alter table public.printers add column if not exists "driver" text default ''::text not null;
|
|
507
|
+
alter table public.printers add column if not exists "papierformaat" text default 'A4'::text not null;
|
|
508
|
+
alter table public.printers add column if not exists "locatie" text default ''::text not null;
|
|
509
|
+
alter table public.printers add column if not exists "online" boolean default false not null;
|
|
510
|
+
alter table public.printers add column if not exists "actief" boolean default true not null;
|
|
511
|
+
alter table public.printers add column if not exists "laatst_gezien" timestamp with time zone;
|
|
512
|
+
alter table public.printers add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
513
|
+
alter table public.printers add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
514
|
+
alter table public.printers add column if not exists "agent_id" uuid;
|
|
515
|
+
alter table public.printers add column if not exists "systeemnaam" text default ''::text not null;
|
|
516
|
+
alter table public.printers add column if not exists "afdrukmethode" text default 'systeem'::text not null;
|
|
517
|
+
alter table public.printers add column if not exists "extern_printer_id" text;
|
|
518
|
+
alter table public.printers add column if not exists "ondersteunde_formaten" jsonb;
|
|
519
|
+
alter table public.printers add column if not exists "ondersteunde_laden" jsonb;
|
|
520
|
+
alter table public.printers add column if not exists "formaten_bijgewerkt_op" timestamp with time zone;
|
|
521
|
+
alter table public.printers add column if not exists "pdf_map" text;
|
|
522
|
+
alter table public.printers add column if not exists "weergavenaam" text;
|
|
523
|
+
alter table public.printers add column if not exists "verborgen" boolean default false not null;
|
|
524
|
+
alter table public.printers add column if not exists "is_virtueel" boolean default false not null;
|
|
525
|
+
alter table public.printers add column if not exists "geladen_etiket" jsonb;
|
|
526
|
+
create table if not exists public.printnode_webhook_koppeling ();
|
|
527
|
+
alter table public.printnode_webhook_koppeling add column if not exists "id" smallint default 1 not null;
|
|
528
|
+
alter table public.printnode_webhook_koppeling add column if not exists "geheim" text;
|
|
529
|
+
alter table public.printnode_webhook_koppeling add column if not exists "secret_veld" text;
|
|
530
|
+
alter table public.printnode_webhook_koppeling add column if not exists "webhook_id" bigint;
|
|
531
|
+
alter table public.printnode_webhook_koppeling add column if not exists "url" text;
|
|
532
|
+
alter table public.printnode_webhook_koppeling add column if not exists "status" text default 'uit'::text not null;
|
|
533
|
+
alter table public.printnode_webhook_koppeling add column if not exists "fout" text;
|
|
534
|
+
alter table public.printnode_webhook_koppeling add column if not exists "melding" text;
|
|
535
|
+
alter table public.printnode_webhook_koppeling add column if not exists "gekoppeld_op" timestamp with time zone;
|
|
536
|
+
alter table public.printnode_webhook_koppeling add column if not exists "laatste_poging_op" timestamp with time zone;
|
|
537
|
+
alter table public.printnode_webhook_koppeling add column if not exists "laatst_ontvangen_op" timestamp with time zone;
|
|
538
|
+
alter table public.printnode_webhook_koppeling add column if not exists "created_at" timestamp with time zone default now() not null;
|
|
539
|
+
alter table public.printnode_webhook_koppeling add column if not exists "updated_at" timestamp with time zone default now() not null;
|
|
540
|
+
alter table public.printnode_webhook_koppeling add column if not exists "bereikbaar" text;
|
|
541
|
+
alter table public.printnode_webhook_koppeling add column if not exists "zelftest_op" timestamp with time zone;
|
|
542
|
+
alter table public.printnode_webhook_koppeling add column if not exists "zelftest_fout" text;
|
|
543
|
+
alter table public.printnode_webhook_koppeling add column if not exists "pn_url" text;
|
|
544
|
+
alter table public.printnode_webhook_koppeling add column if not exists "pn_geslaagd" integer;
|
|
545
|
+
alter table public.printnode_webhook_koppeling add column if not exists "pn_mislukt" integer;
|
|
546
|
+
alter table public.printnode_webhook_koppeling add column if not exists "pn_geslaagd_vorig" integer;
|
|
547
|
+
alter table public.printnode_webhook_koppeling add column if not exists "pn_opgehaald_op" timestamp with time zone;
|
|
548
|
+
alter table public.printnode_webhook_koppeling add column if not exists "pn_ontvangen" integer;
|
|
549
|
+
alter table public.printnode_webhook_koppeling add column if not exists "pn_weggegooid" integer;
|
|
550
|
+
create table if not exists public.printnode_webhook_meldingen ();
|
|
551
|
+
alter table public.printnode_webhook_meldingen add column if not exists "id" bigint not null generated by default as identity;
|
|
552
|
+
alter table public.printnode_webhook_meldingen add column if not exists "ontvangen_op" timestamp with time zone default now() not null;
|
|
553
|
+
alter table public.printnode_webhook_meldingen add column if not exists "http_status" integer not null;
|
|
554
|
+
alter table public.printnode_webhook_meldingen add column if not exists "soorten" text[] default '{}'::text[] not null;
|
|
555
|
+
alter table public.printnode_webhook_meldingen add column if not exists "printnode_ids" text[] default '{}'::text[] not null;
|
|
556
|
+
alter table public.printnode_webhook_meldingen add column if not exists "gematcht" integer default 0 not null;
|
|
557
|
+
alter table public.printnode_webhook_meldingen add column if not exists "niet_gematcht" text[] default '{}'::text[] not null;
|
|
558
|
+
alter table public.printnode_webhook_meldingen add column if not exists "antwoord" jsonb;
|
|
559
|
+
|
|
560
|
+
-- 3. Sleutels en controles
|
|
561
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='ai_layout_imports_pkey' and conrelid='ai_layout_imports'::regclass) then alter table ai_layout_imports add constraint "ai_layout_imports_pkey" PRIMARY KEY (id); end if; end $$;
|
|
562
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_bronregels_documenttype_herkomst_key' and conrelid='document_bronregels'::regclass) then alter table document_bronregels add constraint "document_bronregels_documenttype_herkomst_key" UNIQUE (documenttype, herkomst); end if; end $$;
|
|
563
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_bronregels_pkey' and conrelid='document_bronregels'::regclass) then alter table document_bronregels add constraint "document_bronregels_pkey" PRIMARY KEY (id); end if; end $$;
|
|
564
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_formaat_printers_documenttype_formaat_code_key' and conrelid='document_formaat_printers'::regclass) then alter table document_formaat_printers add constraint "document_formaat_printers_documenttype_formaat_code_key" UNIQUE (documenttype, formaat_code); end if; end $$;
|
|
565
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_formaat_printers_pkey' and conrelid='document_formaat_printers'::regclass) then alter table document_formaat_printers add constraint "document_formaat_printers_pkey" PRIMARY KEY (id); end if; end $$;
|
|
566
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_conditions_pkey' and conrelid='document_layout_conditions'::regclass) then alter table document_layout_conditions add constraint "document_layout_conditions_pkey" PRIMARY KEY (id); end if; end $$;
|
|
567
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_datasources_pkey' and conrelid='document_layout_datasources'::regclass) then alter table document_layout_datasources add constraint "document_layout_datasources_pkey" PRIMARY KEY (id); end if; end $$;
|
|
568
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_elements_layout_id_element_key_key' and conrelid='document_layout_elements'::regclass) then alter table document_layout_elements add constraint "document_layout_elements_layout_id_element_key_key" UNIQUE (layout_id, element_key); end if; end $$;
|
|
569
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_elements_pkey' and conrelid='document_layout_elements'::regclass) then alter table document_layout_elements add constraint "document_layout_elements_pkey" PRIMARY KEY (id); end if; end $$;
|
|
570
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_variables_layout_id_naam_key' and conrelid='document_layout_variables'::regclass) then alter table document_layout_variables add constraint "document_layout_variables_layout_id_naam_key" UNIQUE (layout_id, naam); end if; end $$;
|
|
571
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_variables_pkey' and conrelid='document_layout_variables'::regclass) then alter table document_layout_variables add constraint "document_layout_variables_pkey" PRIMARY KEY (id); end if; end $$;
|
|
572
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_versions_layout_id_versienummer_key' and conrelid='document_layout_versions'::regclass) then alter table document_layout_versions add constraint "document_layout_versions_layout_id_versienummer_key" UNIQUE (layout_id, versienummer); end if; end $$;
|
|
573
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_versions_pkey' and conrelid='document_layout_versions'::regclass) then alter table document_layout_versions add constraint "document_layout_versions_pkey" PRIMARY KEY (id); end if; end $$;
|
|
574
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layouts_pkey' and conrelid='document_layouts'::regclass) then alter table document_layouts add constraint "document_layouts_pkey" PRIMARY KEY (id); end if; end $$;
|
|
575
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_printplek_printers_pkey' and conrelid='document_printplek_printers'::regclass) then alter table document_printplek_printers add constraint "document_printplek_printers_pkey" PRIMARY KEY (id); end if; end $$;
|
|
576
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_printplek_printers_print_plek_id_documenttype_key' and conrelid='document_printplek_printers'::regclass) then alter table document_printplek_printers add constraint "document_printplek_printers_print_plek_id_documenttype_key" UNIQUE (print_plek_id, documenttype); end if; end $$;
|
|
577
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_werkplek_printers_documenttype_werkplek_key' and conrelid='document_werkplek_printers'::regclass) then alter table document_werkplek_printers add constraint "document_werkplek_printers_documenttype_werkplek_key" UNIQUE (documenttype, werkplek); end if; end $$;
|
|
578
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_werkplek_printers_pkey' and conrelid='document_werkplek_printers'::regclass) then alter table document_werkplek_printers add constraint "document_werkplek_printers_pkey" PRIMARY KEY (id); end if; end $$;
|
|
579
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='layout_logos_pkey' and conrelid='layout_logos'::regclass) then alter table layout_logos add constraint "layout_logos_pkey" PRIMARY KEY (id); end if; end $$;
|
|
580
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='pakbon_barcode_inhoud_pkey' and conrelid='pakbon_barcode_inhoud'::regclass) then alter table pakbon_barcode_inhoud add constraint "pakbon_barcode_inhoud_pkey" PRIMARY KEY (barcode); end if; end $$;
|
|
581
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='pakbon_barcode_verzoeken_pkey' and conrelid='pakbon_barcode_verzoeken'::regclass) then alter table pakbon_barcode_verzoeken add constraint "pakbon_barcode_verzoeken_pkey" PRIMARY KEY (id); end if; end $$;
|
|
582
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='pakbon_barcode_verzoeken_print_job_id_key' and conrelid='pakbon_barcode_verzoeken'::regclass) then alter table pakbon_barcode_verzoeken add constraint "pakbon_barcode_verzoeken_print_job_id_key" UNIQUE (print_job_id); end if; end $$;
|
|
583
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='pakbon_barcode_verzoeken_status_check' and conrelid='pakbon_barcode_verzoeken'::regclass) then alter table pakbon_barcode_verzoeken add constraint "pakbon_barcode_verzoeken_status_check" CHECK ((status = ANY (ARRAY['open'::text, 'geleverd'::text, 'geannuleerd'::text]))); end if; end $$;
|
|
584
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_agents_pkey' and conrelid='print_agents'::regclass) then alter table print_agents add constraint "print_agents_pkey" PRIMARY KEY (id); end if; end $$;
|
|
585
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_computer_status_pkey' and conrelid='print_computer_status'::regclass) then alter table print_computer_status add constraint "print_computer_status_pkey" PRIMARY KEY (extern_computer_id); end if; end $$;
|
|
586
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_dedupe_events_pkey' and conrelid='print_dedupe_events'::regclass) then alter table print_dedupe_events add constraint "print_dedupe_events_pkey" PRIMARY KEY (id); end if; end $$;
|
|
587
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_gebruiker_werkplek_pkey' and conrelid='print_gebruiker_werkplek'::regclass) then alter table print_gebruiker_werkplek add constraint "print_gebruiker_werkplek_pkey" PRIMARY KEY (user_id); end if; end $$;
|
|
588
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_genegeerde_computers_computer_naam_key' and conrelid='print_genegeerde_computers'::regclass) then alter table print_genegeerde_computers add constraint "print_genegeerde_computers_computer_naam_key" UNIQUE (computer_naam); end if; end $$;
|
|
589
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_genegeerde_computers_pkey' and conrelid='print_genegeerde_computers'::regclass) then alter table print_genegeerde_computers add constraint "print_genegeerde_computers_pkey" PRIMARY KEY (id); end if; end $$;
|
|
590
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_job_logs_pkey' and conrelid='print_job_logs'::regclass) then alter table print_job_logs add constraint "print_job_logs_pkey" PRIMARY KEY (id); end if; end $$;
|
|
591
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_jobs_pkey' and conrelid='print_jobs'::regclass) then alter table print_jobs add constraint "print_jobs_pkey" PRIMARY KEY (id); end if; end $$;
|
|
592
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_computers_computer_naam_key' and conrelid='print_plek_computers'::regclass) then alter table print_plek_computers add constraint "print_plek_computers_computer_naam_key" UNIQUE (computer_naam); end if; end $$;
|
|
593
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_computers_pkey' and conrelid='print_plek_computers'::regclass) then alter table print_plek_computers add constraint "print_plek_computers_pkey" PRIMARY KEY (id); end if; end $$;
|
|
594
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_koppelingen_bron_bron_id_key' and conrelid='print_plek_koppelingen'::regclass) then alter table print_plek_koppelingen add constraint "print_plek_koppelingen_bron_bron_id_key" UNIQUE (bron, bron_id); end if; end $$;
|
|
595
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_koppelingen_pkey' and conrelid='print_plek_koppelingen'::regclass) then alter table print_plek_koppelingen add constraint "print_plek_koppelingen_pkey" PRIMARY KEY (id); end if; end $$;
|
|
596
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_printers_pkey' and conrelid='print_plek_printers'::regclass) then alter table print_plek_printers add constraint "print_plek_printers_pkey" PRIMARY KEY (id); end if; end $$;
|
|
597
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_printers_print_plek_id_printer_id_key' and conrelid='print_plek_printers'::regclass) then alter table print_plek_printers add constraint "print_plek_printers_print_plek_id_printer_id_key" UNIQUE (print_plek_id, printer_id); end if; end $$;
|
|
598
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plekken_naam_key' and conrelid='print_plekken'::regclass) then alter table print_plekken add constraint "print_plekken_naam_key" UNIQUE (naam); end if; end $$;
|
|
599
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plekken_pkey' and conrelid='print_plekken'::regclass) then alter table print_plekken add constraint "print_plekken_pkey" PRIMARY KEY (id); end if; end $$;
|
|
600
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_preview_events_pkey' and conrelid='print_preview_events'::regclass) then alter table print_preview_events add constraint "print_preview_events_pkey" PRIMARY KEY (id); end if; end $$;
|
|
601
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_printer_verwijder_herstel_pkey' and conrelid='print_printer_verwijder_herstel'::regclass) then alter table print_printer_verwijder_herstel add constraint "print_printer_verwijder_herstel_pkey" PRIMARY KEY (id); end if; end $$;
|
|
602
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_queue_leases_pkey' and conrelid='print_queue_leases'::regclass) then alter table print_queue_leases add constraint "print_queue_leases_pkey" PRIMARY KEY (naam); end if; end $$;
|
|
603
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_queue_runners_basis_url_key' and conrelid='print_queue_runners'::regclass) then alter table print_queue_runners add constraint "print_queue_runners_basis_url_key" UNIQUE (basis_url); end if; end $$;
|
|
604
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_queue_runners_pkey' and conrelid='print_queue_runners'::regclass) then alter table print_queue_runners add constraint "print_queue_runners_pkey" PRIMARY KEY (id); end if; end $$;
|
|
605
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_queue_settings_pkey' and conrelid='print_queue_settings'::regclass) then alter table print_queue_settings add constraint "print_queue_settings_pkey" PRIMARY KEY (id); end if; end $$;
|
|
606
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_rules_pkey' and conrelid='print_rules'::regclass) then alter table print_rules add constraint "print_rules_pkey" PRIMARY KEY (id); end if; end $$;
|
|
607
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_shell_stilstand_pkey' and conrelid='print_shell_stilstand'::regclass) then alter table print_shell_stilstand add constraint "print_shell_stilstand_pkey" PRIMARY KEY (id); end if; end $$;
|
|
608
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_werkplek_afwijkingen_pkey' and conrelid='print_werkplek_afwijkingen'::regclass) then alter table print_werkplek_afwijkingen add constraint "print_werkplek_afwijkingen_pkey" PRIMARY KEY (id); end if; end $$;
|
|
609
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_werkplek_afwijkingen_werkplek_id_documenttype_key' and conrelid='print_werkplek_afwijkingen'::regclass) then alter table print_werkplek_afwijkingen add constraint "print_werkplek_afwijkingen_werkplek_id_documenttype_key" UNIQUE (werkplek_id, documenttype); end if; end $$;
|
|
610
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_werkplekken_pkey' and conrelid='print_werkplekken'::regclass) then alter table print_werkplekken add constraint "print_werkplekken_pkey" PRIMARY KEY (id); end if; end $$;
|
|
611
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printer_mappings_layout_id_printer_id_key' and conrelid='printer_mappings'::regclass) then alter table printer_mappings add constraint "printer_mappings_layout_id_printer_id_key" UNIQUE (layout_id, printer_id); end if; end $$;
|
|
612
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printer_mappings_pkey' and conrelid='printer_mappings'::regclass) then alter table printer_mappings add constraint "printer_mappings_pkey" PRIMARY KEY (id); end if; end $$;
|
|
613
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printer_profiles_pkey' and conrelid='printer_profiles'::regclass) then alter table printer_profiles add constraint "printer_profiles_pkey" PRIMARY KEY (id); end if; end $$;
|
|
614
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printer_routes_extern_printer_id_key' and conrelid='printer_routes'::regclass) then alter table printer_routes add constraint "printer_routes_extern_printer_id_key" UNIQUE (extern_printer_id); end if; end $$;
|
|
615
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printer_routes_pkey' and conrelid='printer_routes'::regclass) then alter table printer_routes add constraint "printer_routes_pkey" PRIMARY KEY (id); end if; end $$;
|
|
616
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printers_pkey' and conrelid='printers'::regclass) then alter table printers add constraint "printers_pkey" PRIMARY KEY (id); end if; end $$;
|
|
617
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printnode_webhook_koppeling_id_check' and conrelid='printnode_webhook_koppeling'::regclass) then alter table printnode_webhook_koppeling add constraint "printnode_webhook_koppeling_id_check" CHECK ((id = 1)); end if; end $$;
|
|
618
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printnode_webhook_koppeling_pkey' and conrelid='printnode_webhook_koppeling'::regclass) then alter table printnode_webhook_koppeling add constraint "printnode_webhook_koppeling_pkey" PRIMARY KEY (id); end if; end $$;
|
|
619
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printnode_webhook_meldingen_pkey' and conrelid='printnode_webhook_meldingen'::regclass) then alter table printnode_webhook_meldingen add constraint "printnode_webhook_meldingen_pkey" PRIMARY KEY (id); end if; end $$;
|
|
620
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='ai_layout_imports_layout_id_fkey' and conrelid='ai_layout_imports'::regclass) then alter table ai_layout_imports add constraint "ai_layout_imports_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE SET NULL; end if; end $$;
|
|
621
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_bronregels_layout_id_fkey' and conrelid='document_bronregels'::regclass) then alter table document_bronregels add constraint "document_bronregels_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE SET NULL; end if; end $$;
|
|
622
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_formaat_printers_printer_id_fkey' and conrelid='document_formaat_printers'::regclass) then alter table document_formaat_printers add constraint "document_formaat_printers_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE SET NULL; end if; end $$;
|
|
623
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_conditions_layout_id_fkey' and conrelid='document_layout_conditions'::regclass) then alter table document_layout_conditions add constraint "document_layout_conditions_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE CASCADE; end if; end $$;
|
|
624
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_datasources_layout_id_fkey' and conrelid='document_layout_datasources'::regclass) then alter table document_layout_datasources add constraint "document_layout_datasources_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE CASCADE; end if; end $$;
|
|
625
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_elements_layout_id_fkey' and conrelid='document_layout_elements'::regclass) then alter table document_layout_elements add constraint "document_layout_elements_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE CASCADE; end if; end $$;
|
|
626
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_elements_logo_id_fkey' and conrelid='document_layout_elements'::regclass) then alter table document_layout_elements add constraint "document_layout_elements_logo_id_fkey" FOREIGN KEY (logo_id) REFERENCES layout_logos(id) ON DELETE SET NULL; end if; end $$;
|
|
627
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_variables_layout_id_fkey' and conrelid='document_layout_variables'::regclass) then alter table document_layout_variables add constraint "document_layout_variables_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE CASCADE; end if; end $$;
|
|
628
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_layout_versions_layout_id_fkey' and conrelid='document_layout_versions'::regclass) then alter table document_layout_versions add constraint "document_layout_versions_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE CASCADE; end if; end $$;
|
|
629
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_printplek_printers_print_plek_id_fkey' and conrelid='document_printplek_printers'::regclass) then alter table document_printplek_printers add constraint "document_printplek_printers_print_plek_id_fkey" FOREIGN KEY (print_plek_id) REFERENCES print_plekken(id) ON DELETE CASCADE; end if; end $$;
|
|
630
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_printplek_printers_printer_id_fkey' and conrelid='document_printplek_printers'::regclass) then alter table document_printplek_printers add constraint "document_printplek_printers_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE SET NULL; end if; end $$;
|
|
631
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='document_werkplek_printers_printer_id_fkey' and conrelid='document_werkplek_printers'::regclass) then alter table document_werkplek_printers add constraint "document_werkplek_printers_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE SET NULL; end if; end $$;
|
|
632
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_gebruiker_werkplek_werkplek_id_fkey' and conrelid='print_gebruiker_werkplek'::regclass) then alter table print_gebruiker_werkplek add constraint "print_gebruiker_werkplek_werkplek_id_fkey" FOREIGN KEY (werkplek_id) REFERENCES print_werkplekken(id) ON DELETE CASCADE; end if; end $$;
|
|
633
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_job_logs_job_id_fkey' and conrelid='print_job_logs'::regclass) then alter table print_job_logs add constraint "print_job_logs_job_id_fkey" FOREIGN KEY (job_id) REFERENCES print_jobs(id) ON DELETE CASCADE; end if; end $$;
|
|
634
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_jobs_agent_id_fkey' and conrelid='print_jobs'::regclass) then alter table print_jobs add constraint "print_jobs_agent_id_fkey" FOREIGN KEY (agent_id) REFERENCES print_agents(id) ON DELETE SET NULL; end if; end $$;
|
|
635
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_jobs_layout_id_fkey' and conrelid='print_jobs'::regclass) then alter table print_jobs add constraint "print_jobs_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE SET NULL; end if; end $$;
|
|
636
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_jobs_lokale_pdf_print_plek_id_fkey' and conrelid='print_jobs'::regclass) then alter table print_jobs add constraint "print_jobs_lokale_pdf_print_plek_id_fkey" FOREIGN KEY (lokale_pdf_print_plek_id) REFERENCES print_plekken(id) ON DELETE SET NULL; end if; end $$;
|
|
637
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_jobs_printer_id_fkey' and conrelid='print_jobs'::regclass) then alter table print_jobs add constraint "print_jobs_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE SET NULL; end if; end $$;
|
|
638
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_computers_print_plek_id_fkey' and conrelid='print_plek_computers'::regclass) then alter table print_plek_computers add constraint "print_plek_computers_print_plek_id_fkey" FOREIGN KEY (print_plek_id) REFERENCES print_plekken(id) ON DELETE CASCADE; end if; end $$;
|
|
639
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_koppelingen_print_plek_id_fkey' and conrelid='print_plek_koppelingen'::regclass) then alter table print_plek_koppelingen add constraint "print_plek_koppelingen_print_plek_id_fkey" FOREIGN KEY (print_plek_id) REFERENCES print_plekken(id) ON DELETE CASCADE; end if; end $$;
|
|
640
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_printers_print_plek_id_fkey' and conrelid='print_plek_printers'::regclass) then alter table print_plek_printers add constraint "print_plek_printers_print_plek_id_fkey" FOREIGN KEY (print_plek_id) REFERENCES print_plekken(id) ON DELETE CASCADE; end if; end $$;
|
|
641
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_plek_printers_printer_id_fkey' and conrelid='print_plek_printers'::regclass) then alter table print_plek_printers add constraint "print_plek_printers_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE CASCADE; end if; end $$;
|
|
642
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_rules_layout_id_fkey' and conrelid='print_rules'::regclass) then alter table print_rules add constraint "print_rules_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE CASCADE; end if; end $$;
|
|
643
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_rules_printer_id_fkey' and conrelid='print_rules'::regclass) then alter table print_rules add constraint "print_rules_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE SET NULL; end if; end $$;
|
|
644
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_werkplek_afwijkingen_printer_id_fkey' and conrelid='print_werkplek_afwijkingen'::regclass) then alter table print_werkplek_afwijkingen add constraint "print_werkplek_afwijkingen_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE SET NULL; end if; end $$;
|
|
645
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_werkplek_afwijkingen_werkplek_id_fkey' and conrelid='print_werkplek_afwijkingen'::regclass) then alter table print_werkplek_afwijkingen add constraint "print_werkplek_afwijkingen_werkplek_id_fkey" FOREIGN KEY (werkplek_id) REFERENCES print_werkplekken(id) ON DELETE CASCADE; end if; end $$;
|
|
646
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_werkplekken_a4_printer_id_fkey' and conrelid='print_werkplekken'::regclass) then alter table print_werkplekken add constraint "print_werkplekken_a4_printer_id_fkey" FOREIGN KEY (a4_printer_id) REFERENCES printers(id) ON DELETE SET NULL; end if; end $$;
|
|
647
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_werkplekken_label_printer_id_fkey' and conrelid='print_werkplekken'::regclass) then alter table print_werkplekken add constraint "print_werkplekken_label_printer_id_fkey" FOREIGN KEY (label_printer_id) REFERENCES printers(id) ON DELETE SET NULL; end if; end $$;
|
|
648
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='print_werkplekken_print_plek_id_fkey' and conrelid='print_werkplekken'::regclass) then alter table print_werkplekken add constraint "print_werkplekken_print_plek_id_fkey" FOREIGN KEY (print_plek_id) REFERENCES print_plekken(id) ON DELETE SET NULL; end if; end $$;
|
|
649
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printer_mappings_layout_id_fkey' and conrelid='printer_mappings'::regclass) then alter table printer_mappings add constraint "printer_mappings_layout_id_fkey" FOREIGN KEY (layout_id) REFERENCES document_layouts(id) ON DELETE CASCADE; end if; end $$;
|
|
650
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printer_mappings_printer_id_fkey' and conrelid='printer_mappings'::regclass) then alter table printer_mappings add constraint "printer_mappings_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE SET NULL; end if; end $$;
|
|
651
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printer_profiles_printer_id_fkey' and conrelid='printer_profiles'::regclass) then alter table printer_profiles add constraint "printer_profiles_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE CASCADE; end if; end $$;
|
|
652
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printer_routes_printer_id_fkey' and conrelid='printer_routes'::regclass) then alter table printer_routes add constraint "printer_routes_printer_id_fkey" FOREIGN KEY (printer_id) REFERENCES printers(id) ON DELETE CASCADE; end if; end $$;
|
|
653
|
+
do $$ begin if not exists (select 1 from pg_constraint where conname='printers_agent_id_fkey' and conrelid='printers'::regclass) then alter table printers add constraint "printers_agent_id_fkey" FOREIGN KEY (agent_id) REFERENCES print_agents(id) ON DELETE SET NULL; end if; end $$;
|
|
654
|
+
|
|
655
|
+
-- 4. Functies
|
|
656
|
+
CREATE OR REPLACE FUNCTION public._jsonb_paden_met_waarde(_j jsonb, _w text, _pad text[] DEFAULT '{}'::text[])
|
|
657
|
+
RETURNS SETOF text[]
|
|
658
|
+
LANGUAGE plpgsql
|
|
659
|
+
IMMUTABLE
|
|
660
|
+
SET search_path TO 'public'
|
|
661
|
+
AS $function$
|
|
662
|
+
DECLARE k text; v jsonb; i int;
|
|
663
|
+
BEGIN
|
|
664
|
+
IF _j IS NULL THEN RETURN; END IF;
|
|
665
|
+
CASE jsonb_typeof(_j)
|
|
666
|
+
WHEN 'string' THEN IF _j #>> '{}' = _w THEN RETURN NEXT _pad; END IF;
|
|
667
|
+
WHEN 'object' THEN
|
|
668
|
+
FOR k, v IN SELECT * FROM jsonb_each(_j) LOOP
|
|
669
|
+
RETURN QUERY SELECT * FROM public._jsonb_paden_met_waarde(v, _w, _pad || k);
|
|
670
|
+
END LOOP;
|
|
671
|
+
WHEN 'array' THEN
|
|
672
|
+
FOR i IN 0 .. jsonb_array_length(_j) - 1 LOOP
|
|
673
|
+
RETURN QUERY SELECT * FROM public._jsonb_paden_met_waarde(_j -> i, _w, _pad || i::text);
|
|
674
|
+
END LOOP;
|
|
675
|
+
ELSE NULL;
|
|
676
|
+
END CASE;
|
|
677
|
+
END $function$;
|
|
678
|
+
|
|
679
|
+
CREATE OR REPLACE FUNCTION public._print_meld_stilstand(_reden text, _sinds timestamp with time zone)
|
|
680
|
+
RETURNS void
|
|
681
|
+
LANGUAGE plpgsql
|
|
682
|
+
SECURITY DEFINER
|
|
683
|
+
SET search_path TO 'public'
|
|
684
|
+
AS $function$
|
|
685
|
+
begin
|
|
686
|
+
if not exists (select 1 from public.print_shell_stilstand where opgelost_op is null and reden = _reden) then
|
|
687
|
+
insert into public.print_shell_stilstand(reden, sinds) values (_reden, _sinds);
|
|
688
|
+
end if;
|
|
689
|
+
end $function$;
|
|
690
|
+
|
|
691
|
+
CREATE OR REPLACE FUNCTION public.beveilig_systeem_layouts()
|
|
692
|
+
RETURNS trigger
|
|
693
|
+
LANGUAGE plpgsql
|
|
694
|
+
SECURITY DEFINER
|
|
695
|
+
SET search_path TO 'public'
|
|
696
|
+
AS $function$
|
|
697
|
+
begin
|
|
698
|
+
if tg_op = 'DELETE' then
|
|
699
|
+
if old.systeem then
|
|
700
|
+
raise exception 'Systeemlayout kan niet worden verwijderd';
|
|
701
|
+
end if;
|
|
702
|
+
return old;
|
|
703
|
+
end if;
|
|
704
|
+
|
|
705
|
+
if old.systeem then
|
|
706
|
+
new.id := old.id;
|
|
707
|
+
new.naam := old.naam;
|
|
708
|
+
new.documenttype := old.documenttype;
|
|
709
|
+
new.omschrijving := old.omschrijving;
|
|
710
|
+
new.papierformaat := old.papierformaat;
|
|
711
|
+
new.breedte_mm := old.breedte_mm;
|
|
712
|
+
new.hoogte_mm := old.hoogte_mm;
|
|
713
|
+
new.orientatie := old.orientatie;
|
|
714
|
+
new.config := old.config;
|
|
715
|
+
new.page_settings := old.page_settings;
|
|
716
|
+
new.bron := old.bron;
|
|
717
|
+
new.systeem := old.systeem;
|
|
718
|
+
end if;
|
|
719
|
+
return new;
|
|
720
|
+
end;
|
|
721
|
+
$function$;
|
|
722
|
+
|
|
723
|
+
CREATE OR REPLACE FUNCTION public.cancel_open_print_jobs(_cutoff timestamp with time zone)
|
|
724
|
+
RETURNS TABLE(id uuid, extern_job_id text)
|
|
725
|
+
LANGUAGE plpgsql
|
|
726
|
+
SET search_path TO 'public'
|
|
727
|
+
AS $function$
|
|
728
|
+
BEGIN
|
|
729
|
+
IF auth.uid() IS NULL THEN
|
|
730
|
+
RAISE EXCEPTION 'Niet ingelogd';
|
|
731
|
+
END IF;
|
|
732
|
+
|
|
733
|
+
IF _cutoff IS NULL THEN
|
|
734
|
+
RAISE EXCEPTION 'Annuleermoment is verplicht';
|
|
735
|
+
END IF;
|
|
736
|
+
|
|
737
|
+
RETURN QUERY
|
|
738
|
+
UPDATE public.print_jobs AS j
|
|
739
|
+
SET status = 'geannuleerd'::public.print_job_status,
|
|
740
|
+
verwerkingsfase = 'geannuleerd',
|
|
741
|
+
fase_voltooid_op = now(),
|
|
742
|
+
lokale_pdf_status = 'geannuleerd',
|
|
743
|
+
lokale_pdf_fout = NULL,
|
|
744
|
+
lokale_pdf_claim_id = NULL,
|
|
745
|
+
lokale_pdf_claim_tot = NULL,
|
|
746
|
+
volgende_poging = NULL,
|
|
747
|
+
voltooid_op = now(),
|
|
748
|
+
updated_at = now()
|
|
749
|
+
WHERE j.status IN ('wachtend'::public.print_job_status, 'bezig'::public.print_job_status)
|
|
750
|
+
AND j.created_at <= _cutoff
|
|
751
|
+
RETURNING j.id, j.extern_job_id;
|
|
752
|
+
END;
|
|
753
|
+
$function$;
|
|
754
|
+
|
|
755
|
+
CREATE OR REPLACE FUNCTION public.claim_cloud_print_jobs(_max integer DEFAULT 5)
|
|
756
|
+
RETURNS SETOF print_jobs
|
|
757
|
+
LANGUAGE plpgsql
|
|
758
|
+
SECURITY DEFINER
|
|
759
|
+
SET search_path TO 'public'
|
|
760
|
+
AS $function$
|
|
761
|
+
begin
|
|
762
|
+
update public.print_jobs j
|
|
763
|
+
set status = 'wachtend', opgepakt_op = null, verwerkingsfase = 'wachtend', updated_at = now()
|
|
764
|
+
where j.status = 'bezig'
|
|
765
|
+
and j.extern_job_id is null
|
|
766
|
+
and j.lokale_pdf_status is distinct from 'gereed'
|
|
767
|
+
and coalesce(j.opgepakt_op, j.updated_at) < now() - interval '10 minutes';
|
|
768
|
+
|
|
769
|
+
return query
|
|
770
|
+
with kandidaten as (
|
|
771
|
+
select j.id, public.resolve_print_job_printer_id(j) as resolved_printer_id
|
|
772
|
+
from public.print_jobs j
|
|
773
|
+
left join public.printers p on p.id = public.resolve_print_job_printer_id(j)
|
|
774
|
+
where j.status = 'wachtend'
|
|
775
|
+
and (j.volgende_poging is null or j.volgende_poging <= now())
|
|
776
|
+
and coalesce(p.afdrukmethode, 'systeem') <> 'pdf'
|
|
777
|
+
order by j.created_at
|
|
778
|
+
limit greatest(_max, 1)
|
|
779
|
+
for update of j skip locked
|
|
780
|
+
)
|
|
781
|
+
update public.print_jobs j
|
|
782
|
+
set printer_id = coalesce(k.resolved_printer_id, j.printer_id),
|
|
783
|
+
status = 'bezig',
|
|
784
|
+
verwerkingsfase = case when j.artefact_pad is not null or j.resultaat_pdf_base64 is not null then 'pdf_gereed' else 'renderen' end,
|
|
785
|
+
fase_gestart_op = now(),
|
|
786
|
+
fase_voltooid_op = null,
|
|
787
|
+
foutcode = null,
|
|
788
|
+
opgepakt_op = now(),
|
|
789
|
+
gestart_op = coalesce(j.gestart_op, now()),
|
|
790
|
+
pogingen = j.pogingen + 1,
|
|
791
|
+
updated_at = now()
|
|
792
|
+
from kandidaten k
|
|
793
|
+
where j.id = k.id
|
|
794
|
+
returning j.*;
|
|
795
|
+
end;
|
|
796
|
+
$function$;
|
|
797
|
+
|
|
798
|
+
CREATE OR REPLACE FUNCTION public.claim_local_pdf_jobs(_print_plek_id uuid, _writer_id text, _max integer DEFAULT 20)
|
|
799
|
+
RETURNS TABLE(id uuid, status text, printer_id uuid, documentnaam text, lokale_pdf_status text, lokale_pdf_print_plek_id uuid, artefact_pad text, artefact_sha256 text, artefact_bytes bigint, resultaat_pdf_base64 text)
|
|
800
|
+
LANGUAGE plpgsql
|
|
801
|
+
SET search_path TO 'public'
|
|
802
|
+
AS $function$
|
|
803
|
+
begin
|
|
804
|
+
if auth.uid() is null then raise exception 'Niet ingelogd'; end if;
|
|
805
|
+
if _print_plek_id is null or nullif(trim(_writer_id), '') is null then
|
|
806
|
+
raise exception 'Printplek en schrijver zijn verplicht';
|
|
807
|
+
end if;
|
|
808
|
+
return query
|
|
809
|
+
with kandidaten as (
|
|
810
|
+
select j.id
|
|
811
|
+
from public.print_jobs j
|
|
812
|
+
join public.printers p on p.id = j.printer_id
|
|
813
|
+
where p.afdrukmethode = 'pdf'
|
|
814
|
+
and j.status <> 'geannuleerd'
|
|
815
|
+
and (j.artefact_pad is not null or j.resultaat_pdf_base64 is not null)
|
|
816
|
+
and coalesce(j.lokale_pdf_print_plek_id,
|
|
817
|
+
nullif(j.payload->>'print_plek_id', '')::uuid,
|
|
818
|
+
nullif(j.payload->'data'->>'print_plek_id', '')::uuid) = _print_plek_id
|
|
819
|
+
and coalesce(j.lokale_pdf_status, '') in ('gereed','bezig')
|
|
820
|
+
and (j.lokale_pdf_claim_id is null or j.lokale_pdf_claim_tot is null
|
|
821
|
+
or j.lokale_pdf_claim_tot < now() or j.lokale_pdf_claim_id = _writer_id)
|
|
822
|
+
order by j.created_at
|
|
823
|
+
limit greatest(1, least(coalesce(_max, 20), 100))
|
|
824
|
+
for update of j skip locked
|
|
825
|
+
), geclaimd as (
|
|
826
|
+
update public.print_jobs j
|
|
827
|
+
set lokale_pdf_print_plek_id = _print_plek_id,
|
|
828
|
+
lokale_pdf_claim_id = _writer_id,
|
|
829
|
+
lokale_pdf_claim_tot = now() + interval '2 minutes',
|
|
830
|
+
lokale_pdf_status = 'bezig',
|
|
831
|
+
verwerkingsfase = 'afleveren',
|
|
832
|
+
fase_gestart_op = now(),
|
|
833
|
+
fase_voltooid_op = null,
|
|
834
|
+
aflever_pogingen = j.aflever_pogingen + 1,
|
|
835
|
+
lokale_pdf_fout = null,
|
|
836
|
+
updated_at = now()
|
|
837
|
+
from kandidaten k
|
|
838
|
+
where j.id = k.id
|
|
839
|
+
and j.status <> 'geannuleerd'
|
|
840
|
+
returning j.*
|
|
841
|
+
)
|
|
842
|
+
select g.id, g.status::text, g.printer_id, g.documentnaam, g.lokale_pdf_status,
|
|
843
|
+
g.lokale_pdf_print_plek_id, g.artefact_pad, g.artefact_sha256,
|
|
844
|
+
g.artefact_bytes,
|
|
845
|
+
case when g.artefact_pad is null then g.resultaat_pdf_base64 else null end
|
|
846
|
+
from geclaimd g;
|
|
847
|
+
end;
|
|
848
|
+
$function$;
|
|
849
|
+
|
|
850
|
+
CREATE OR REPLACE FUNCTION public.claim_pdf_print_jobs(_max integer DEFAULT 5)
|
|
851
|
+
RETURNS SETOF print_jobs
|
|
852
|
+
LANGUAGE plpgsql
|
|
853
|
+
SECURITY DEFINER
|
|
854
|
+
SET search_path TO 'public'
|
|
855
|
+
AS $function$
|
|
856
|
+
begin
|
|
857
|
+
return query
|
|
858
|
+
with kandidaten as (
|
|
859
|
+
select j.id, public.resolve_print_job_printer_id(j) as resolved_printer_id
|
|
860
|
+
from public.print_jobs j
|
|
861
|
+
join public.printers p on p.id = public.resolve_print_job_printer_id(j)
|
|
862
|
+
where j.status = 'wachtend'
|
|
863
|
+
and (j.volgende_poging is null or j.volgende_poging <= now())
|
|
864
|
+
and p.actief is distinct from false
|
|
865
|
+
and p.afdrukmethode = 'pdf'
|
|
866
|
+
order by j.created_at
|
|
867
|
+
limit greatest(_max, 1)
|
|
868
|
+
for update of j skip locked
|
|
869
|
+
)
|
|
870
|
+
update public.print_jobs j
|
|
871
|
+
set printer_id = k.resolved_printer_id,
|
|
872
|
+
status = 'bezig',
|
|
873
|
+
verwerkingsfase = case when j.artefact_pad is not null or j.resultaat_pdf_base64 is not null then 'pdf_gereed' else 'renderen' end,
|
|
874
|
+
fase_gestart_op = now(),
|
|
875
|
+
fase_voltooid_op = null,
|
|
876
|
+
foutcode = null,
|
|
877
|
+
lokale_pdf_status = case when j.artefact_pad is not null or j.resultaat_pdf_base64 is not null then 'gereed' else 'genereren' end,
|
|
878
|
+
lokale_pdf_fout = null,
|
|
879
|
+
opgepakt_op = now(),
|
|
880
|
+
gestart_op = coalesce(j.gestart_op, now()),
|
|
881
|
+
pogingen = j.pogingen + 1,
|
|
882
|
+
updated_at = now()
|
|
883
|
+
from kandidaten k
|
|
884
|
+
where j.id = k.id
|
|
885
|
+
returning j.*;
|
|
886
|
+
end;
|
|
887
|
+
$function$;
|
|
888
|
+
|
|
889
|
+
CREATE OR REPLACE FUNCTION public.claim_print_jobs(_agent_id uuid, _max integer DEFAULT 5)
|
|
890
|
+
RETURNS SETOF print_jobs
|
|
891
|
+
LANGUAGE plpgsql
|
|
892
|
+
SECURITY DEFINER
|
|
893
|
+
SET search_path TO 'public'
|
|
894
|
+
AS $function$
|
|
895
|
+
BEGIN
|
|
896
|
+
RETURN QUERY
|
|
897
|
+
WITH kandidaten AS (
|
|
898
|
+
SELECT j.id
|
|
899
|
+
FROM public.print_jobs j
|
|
900
|
+
JOIN public.printers p ON p.id = j.printer_id
|
|
901
|
+
WHERE j.status = 'wachtend'
|
|
902
|
+
AND p.agent_id = _agent_id
|
|
903
|
+
AND p.actief = true
|
|
904
|
+
ORDER BY j.created_at
|
|
905
|
+
LIMIT GREATEST(_max, 1)
|
|
906
|
+
FOR UPDATE SKIP LOCKED
|
|
907
|
+
)
|
|
908
|
+
UPDATE public.print_jobs j
|
|
909
|
+
SET status = 'bezig',
|
|
910
|
+
agent_id = _agent_id,
|
|
911
|
+
opgepakt_op = now(),
|
|
912
|
+
gestart_op = COALESCE(j.gestart_op, now()),
|
|
913
|
+
pogingen = j.pogingen + 1,
|
|
914
|
+
updated_at = now()
|
|
915
|
+
FROM kandidaten k
|
|
916
|
+
WHERE j.id = k.id
|
|
917
|
+
RETURNING j.*;
|
|
918
|
+
END;
|
|
919
|
+
$function$;
|
|
920
|
+
|
|
921
|
+
CREATE OR REPLACE FUNCTION public.claim_print_queue_lease(_naam text, _houder uuid, _seconden integer DEFAULT 120)
|
|
922
|
+
RETURNS boolean
|
|
923
|
+
LANGUAGE plpgsql
|
|
924
|
+
SECURITY DEFINER
|
|
925
|
+
SET search_path TO 'public'
|
|
926
|
+
AS $function$
|
|
927
|
+
declare
|
|
928
|
+
v_ok boolean := false;
|
|
929
|
+
begin
|
|
930
|
+
insert into public.print_queue_leases (naam, houder, verloopt_op)
|
|
931
|
+
values (_naam, _houder, now() + make_interval(secs => greatest(5, _seconden)))
|
|
932
|
+
on conflict (naam) do update
|
|
933
|
+
set houder = excluded.houder,
|
|
934
|
+
verloopt_op = excluded.verloopt_op,
|
|
935
|
+
updated_at = now()
|
|
936
|
+
where public.print_queue_leases.verloopt_op < now()
|
|
937
|
+
or public.print_queue_leases.houder = excluded.houder
|
|
938
|
+
returning true into v_ok;
|
|
939
|
+
return coalesce(v_ok, false);
|
|
940
|
+
end;
|
|
941
|
+
$function$;
|
|
942
|
+
|
|
943
|
+
CREATE OR REPLACE FUNCTION public.controleer_printplek_printer()
|
|
944
|
+
RETURNS trigger
|
|
945
|
+
LANGUAGE plpgsql
|
|
946
|
+
SET search_path TO 'public'
|
|
947
|
+
AS $function$
|
|
948
|
+
BEGIN
|
|
949
|
+
IF NEW.printer_id IS NOT NULL AND NOT EXISTS (
|
|
950
|
+
SELECT 1 FROM print_plek_printers WHERE print_plek_id = NEW.print_plek_id AND printer_id = NEW.printer_id
|
|
951
|
+
) THEN
|
|
952
|
+
RAISE EXCEPTION 'PRINTER_NIET_OP_PLEK: deze printer is niet aan deze printplek gekoppeld.';
|
|
953
|
+
END IF;
|
|
954
|
+
RETURN NEW;
|
|
955
|
+
END $function$;
|
|
956
|
+
|
|
957
|
+
CREATE OR REPLACE FUNCTION public.controleer_werkplek_printer()
|
|
958
|
+
RETURNS trigger
|
|
959
|
+
LANGUAGE plpgsql
|
|
960
|
+
SET search_path TO 'public'
|
|
961
|
+
AS $function$
|
|
962
|
+
DECLARE v_plek uuid;
|
|
963
|
+
BEGIN
|
|
964
|
+
IF NEW.printer_id IS NULL THEN RETURN NEW; END IF;
|
|
965
|
+
SELECT print_plek_id INTO v_plek FROM print_plek_computers WHERE computer_naam = NEW.werkplek LIMIT 1;
|
|
966
|
+
IF v_plek IS NOT NULL AND NOT EXISTS (
|
|
967
|
+
SELECT 1 FROM print_plek_printers WHERE print_plek_id = v_plek AND printer_id = NEW.printer_id
|
|
968
|
+
) THEN
|
|
969
|
+
RAISE EXCEPTION 'PRINTER_NIET_OP_PLEK: deze printer is niet gekoppeld aan de printplek van werkplek %.', NEW.werkplek;
|
|
970
|
+
END IF;
|
|
971
|
+
RETURN NEW;
|
|
972
|
+
END $function$;
|
|
973
|
+
|
|
974
|
+
CREATE OR REPLACE FUNCTION public.document_layout_een_standaard()
|
|
975
|
+
RETURNS trigger
|
|
976
|
+
LANGUAGE plpgsql
|
|
977
|
+
SET search_path TO 'public'
|
|
978
|
+
AS $function$
|
|
979
|
+
BEGIN
|
|
980
|
+
IF NEW.is_standaard AND NEW.actief THEN
|
|
981
|
+
UPDATE document_layouts SET is_standaard = false
|
|
982
|
+
WHERE id <> NEW.id AND is_standaard
|
|
983
|
+
AND documenttype = NEW.documenttype
|
|
984
|
+
AND coalesce(bron,'eigen') = coalesce(NEW.bron,'eigen');
|
|
985
|
+
END IF;
|
|
986
|
+
RETURN NEW;
|
|
987
|
+
END $function$;
|
|
988
|
+
|
|
989
|
+
CREATE OR REPLACE FUNCTION public.finish_local_pdf_job(_job_id uuid, _writer_id text, _status text, _fout text DEFAULT NULL::text)
|
|
990
|
+
RETURNS boolean
|
|
991
|
+
LANGUAGE plpgsql
|
|
992
|
+
SET search_path TO 'public'
|
|
993
|
+
AS $function$
|
|
994
|
+
declare v_gelukt boolean := _status = 'opgeslagen';
|
|
995
|
+
begin
|
|
996
|
+
if auth.uid() is null then raise exception 'Niet ingelogd'; end if;
|
|
997
|
+
if _status not in ('opgeslagen','map_ontbreekt','geen_rechten','schrijffout','timeout') then
|
|
998
|
+
raise exception 'Ongeldige lokale PDF-status';
|
|
999
|
+
end if;
|
|
1000
|
+
-- Een geannuleerde opdracht wordt nooit meer voltooid of mislukt; de
|
|
1001
|
+
-- annulering wint altijd, zelfs als het bestand al geschreven was.
|
|
1002
|
+
update public.print_jobs
|
|
1003
|
+
set lokale_pdf_status = _status,
|
|
1004
|
+
lokale_pdf_fout = case when v_gelukt then null else nullif(trim(_fout), '') end,
|
|
1005
|
+
lokaal_opgeslagen_op = case when v_gelukt then now() else null end,
|
|
1006
|
+
status = case when v_gelukt then 'voltooid'::public.print_job_status else 'mislukt'::public.print_job_status end,
|
|
1007
|
+
verwerkingsfase = case when v_gelukt then 'voltooid' else 'mislukt' end,
|
|
1008
|
+
fase_voltooid_op = now(),
|
|
1009
|
+
foutcode = case when v_gelukt then null else _status end,
|
|
1010
|
+
foutmelding = case when v_gelukt then null else nullif(trim(_fout), '') end,
|
|
1011
|
+
voltooid_op = now(), lokale_pdf_claim_id = null, lokale_pdf_claim_tot = null, updated_at = now()
|
|
1012
|
+
where id = _job_id
|
|
1013
|
+
and lokale_pdf_claim_id = _writer_id
|
|
1014
|
+
and lokale_pdf_claim_tot >= now()
|
|
1015
|
+
and status <> 'geannuleerd';
|
|
1016
|
+
return found;
|
|
1017
|
+
end;
|
|
1018
|
+
$function$;
|
|
1019
|
+
|
|
1020
|
+
CREATE OR REPLACE FUNCTION public.geladen_etiketten(_werkplek_id uuid DEFAULT NULL::uuid, _print_plek_id uuid DEFAULT NULL::uuid)
|
|
1021
|
+
RETURNS jsonb
|
|
1022
|
+
LANGUAGE sql
|
|
1023
|
+
STABLE
|
|
1024
|
+
SET search_path TO 'public'
|
|
1025
|
+
AS $function$
|
|
1026
|
+
SELECT coalesce(jsonb_agg(jsonb_build_object(
|
|
1027
|
+
'werkplek_id', w.id, 'werkplek_naam', w.naam, 'print_plek_id', w.print_plek_id,
|
|
1028
|
+
'printer_id', p.id, 'printer_naam', coalesce(p.weergavenaam, p.naam),
|
|
1029
|
+
'naam', coalesce(p.weergavenaam, p.naam),
|
|
1030
|
+
'geladen_etiket', p.geladen_etiket,
|
|
1031
|
+
'breedte_mm', nullif(p.geladen_etiket->>'breedte_mm','')::numeric,
|
|
1032
|
+
'hoogte_mm', nullif(p.geladen_etiket->>'hoogte_mm','')::numeric,
|
|
1033
|
+
'routes', (SELECT coalesce(jsonb_agg(jsonb_build_object('route_id', r.id, 'computer', r.computer_naam,
|
|
1034
|
+
'geladen_etiket', coalesce(r.geladen_etiket, p.geladen_etiket),
|
|
1035
|
+
'breedte_mm', nullif(coalesce(r.geladen_etiket, p.geladen_etiket)->>'breedte_mm','')::numeric,
|
|
1036
|
+
'hoogte_mm', nullif(coalesce(r.geladen_etiket, p.geladen_etiket)->>'hoogte_mm','')::numeric)), '[]'::jsonb)
|
|
1037
|
+
FROM printer_routes r WHERE r.printer_id = p.id)
|
|
1038
|
+
)), '[]'::jsonb)
|
|
1039
|
+
FROM print_werkplekken w JOIN printers p ON p.id = w.label_printer_id
|
|
1040
|
+
WHERE w.actief
|
|
1041
|
+
AND (_werkplek_id IS NULL OR w.id = _werkplek_id)
|
|
1042
|
+
AND (_print_plek_id IS NULL OR w.print_plek_id = _print_plek_id)
|
|
1043
|
+
$function$;
|
|
1044
|
+
|
|
1045
|
+
CREATE OR REPLACE FUNCTION public.layout_print_document(_documenttype text, _documentnaam text, _pdf_base64 text DEFAULT NULL::text, _pdf_url text DEFAULT NULL::text, _layout_id uuid DEFAULT NULL::uuid, _print_plek_id uuid DEFAULT NULL::uuid, _werkplek text DEFAULT NULL::text, _kopieen integer DEFAULT 1, _herkomst text DEFAULT NULL::text, _is_herprint boolean DEFAULT false, _payload jsonb DEFAULT '{}'::jsonb, _idempotentie_sleutel text DEFAULT NULL::text, _mislukt_reden text DEFAULT NULL::text)
|
|
1046
|
+
RETURNS TABLE(job_id uuid, printer_id uuid, bestaand boolean, status text, mislukt boolean, fout_code text, fout_bericht text)
|
|
1047
|
+
LANGUAGE plpgsql
|
|
1048
|
+
SECURITY DEFINER
|
|
1049
|
+
SET search_path TO 'public'
|
|
1050
|
+
AS $function$
|
|
1051
|
+
DECLARE
|
|
1052
|
+
v_type text := btrim(coalesce(_documenttype, ''));
|
|
1053
|
+
v_herkomst text := nullif(btrim(coalesce(_herkomst, '')), '');
|
|
1054
|
+
v_werkplek text := nullif(btrim(coalesce(_werkplek, '')), '');
|
|
1055
|
+
v_sleutel text := nullif(btrim(coalesce(_idempotentie_sleutel, '')), '');
|
|
1056
|
+
v_pdf text := nullif(btrim(regexp_replace(coalesce(_pdf_base64, ''), '^data:application/pdf;base64,', '', 'i')), '');
|
|
1057
|
+
v_url text := nullif(btrim(coalesce(_pdf_url, '')), '');
|
|
1058
|
+
v_reden text := nullif(btrim(coalesce(_mislukt_reden, '')), '');
|
|
1059
|
+
v_payload jsonb := coalesce(_payload, '{}'::jsonb);
|
|
1060
|
+
v_opslag boolean := coalesce(jsonb_typeof(_payload->'pdf_opslag') = 'object', false);
|
|
1061
|
+
v_bron text; v_regel_layout uuid; v_gebruik_pdf boolean;
|
|
1062
|
+
v_layout uuid; v_route_layout uuid; v_formaat text;
|
|
1063
|
+
v_plek uuid; v_printer uuid; v_route jsonb;
|
|
1064
|
+
v_job uuid; v_bestaand_job uuid; v_bestaand_printer uuid;
|
|
1065
|
+
v_constraint text;
|
|
1066
|
+
BEGIN
|
|
1067
|
+
IF v_type = '' THEN RAISE EXCEPTION 'GEEN_DOCUMENTTYPE: geef een documenttype mee.'; END IF;
|
|
1068
|
+
IF v_sleutel IS NOT NULL THEN
|
|
1069
|
+
SELECT j.id, j.printer_id INTO v_bestaand_job, v_bestaand_printer FROM print_jobs j
|
|
1070
|
+
WHERE j.idempotentie_sleutel = v_sleutel AND j.status NOT IN ('mislukt','geannuleerd')
|
|
1071
|
+
ORDER BY j.created_at DESC LIMIT 1;
|
|
1072
|
+
IF v_bestaand_job IS NOT NULL THEN
|
|
1073
|
+
RETURN QUERY SELECT v_bestaand_job, v_bestaand_printer, true, s.status, s.mislukt, s.fout_code, s.fout_bericht
|
|
1074
|
+
FROM public.print_job_status_uitgebreid(v_bestaand_job) s;
|
|
1075
|
+
RETURN;
|
|
1076
|
+
END IF;
|
|
1077
|
+
END IF;
|
|
1078
|
+
|
|
1079
|
+
v_plek := coalesce(_print_plek_id, nullif(v_payload->>'print_plek_id', '')::uuid);
|
|
1080
|
+
|
|
1081
|
+
IF v_reden IS NOT NULL THEN
|
|
1082
|
+
v_route := public.printer_routering(v_type, v_plek, v_werkplek, _layout_id, NULL);
|
|
1083
|
+
v_printer := nullif(v_route->>'printer_id', '')::uuid;
|
|
1084
|
+
v_payload := v_payload
|
|
1085
|
+
|| CASE WHEN v_werkplek IS NOT NULL THEN jsonb_build_object('werkplek', v_werkplek) ELSE '{}'::jsonb END
|
|
1086
|
+
|| CASE WHEN v_plek IS NOT NULL THEN jsonb_build_object('print_plek_id', v_plek) ELSE '{}'::jsonb END
|
|
1087
|
+
|| CASE WHEN v_herkomst IS NOT NULL THEN jsonb_build_object('herkomst', v_herkomst) ELSE '{}'::jsonb END;
|
|
1088
|
+
INSERT INTO print_jobs (status, layout_id, printer_id, documenttype, documentnaam, kopieen, payload,
|
|
1089
|
+
herkomst, is_herprint, idempotentie_sleutel, foutcode, foutmelding, voltooid_op)
|
|
1090
|
+
VALUES ('mislukt', _layout_id, v_printer, v_type::doc_layout_type,
|
|
1091
|
+
left(coalesce(nullif(btrim(_documentnaam), ''), v_type), 200),
|
|
1092
|
+
public.print_kopieen_aantal(v_type, _kopieen, _payload), v_payload, v_herkomst, coalesce(_is_herprint, false),
|
|
1093
|
+
v_sleutel, 'AANLEVERING_MISLUKT', left(v_reden, 500), now())
|
|
1094
|
+
RETURNING id INTO v_job;
|
|
1095
|
+
RETURN QUERY SELECT v_job, v_printer, false, 'mislukt'::text, true, 'AANLEVERING_MISLUKT'::text, left(v_reden, 500);
|
|
1096
|
+
RETURN;
|
|
1097
|
+
END IF;
|
|
1098
|
+
|
|
1099
|
+
IF v_herkomst IS NOT NULL THEN
|
|
1100
|
+
SELECT b.bron, b.layout_id INTO v_bron, v_regel_layout FROM document_bronregels b WHERE b.documenttype = v_type AND b.herkomst = v_herkomst LIMIT 1;
|
|
1101
|
+
END IF;
|
|
1102
|
+
IF v_bron = 'eigen_layout' THEN v_gebruik_pdf := false;
|
|
1103
|
+
ELSIF v_bron = 'extern_pdf' THEN
|
|
1104
|
+
IF v_pdf IS NULL AND v_url IS NULL AND NOT v_opslag THEN
|
|
1105
|
+
RAISE EXCEPTION 'GEEN_EXTERN_DOCUMENT: voor % (herkomst %) is het meegestuurde document verplicht; er wordt geen eigen layout gemaakt.', v_type, v_herkomst;
|
|
1106
|
+
END IF;
|
|
1107
|
+
v_gebruik_pdf := true;
|
|
1108
|
+
ELSE v_gebruik_pdf := (v_pdf IS NOT NULL OR v_url IS NOT NULL OR v_opslag);
|
|
1109
|
+
END IF;
|
|
1110
|
+
|
|
1111
|
+
IF v_type IN ('sticker','traysticker') AND NOT v_gebruik_pdf THEN
|
|
1112
|
+
RAISE EXCEPTION 'GEEN_EXTERN_DOCUMENT: een % wordt 1-op-1 geprint; geef pdf_opslag of pdf_url mee.', v_type;
|
|
1113
|
+
END IF;
|
|
1114
|
+
|
|
1115
|
+
IF NOT v_gebruik_pdf THEN
|
|
1116
|
+
v_layout := coalesce(_layout_id, CASE WHEN v_bron = 'eigen_layout' THEN v_regel_layout END);
|
|
1117
|
+
IF v_layout IS NOT NULL THEN
|
|
1118
|
+
SELECT l.id, l.papierformaat INTO v_route_layout, v_formaat FROM document_layouts l WHERE l.id = v_layout;
|
|
1119
|
+
ELSE
|
|
1120
|
+
SELECT l.id, l.papierformaat INTO v_route_layout, v_formaat FROM document_layouts l
|
|
1121
|
+
WHERE l.documenttype::text = v_type AND l.actief ORDER BY l.is_standaard DESC, l.updated_at DESC LIMIT 1;
|
|
1122
|
+
END IF;
|
|
1123
|
+
IF v_route_layout IS NULL THEN RAISE EXCEPTION 'GEEN_LAYOUT: geen layout gevonden voor documenttype %.', v_type; END IF;
|
|
1124
|
+
v_layout := v_route_layout;
|
|
1125
|
+
ELSIF v_type IN ('sticker','traysticker') THEN
|
|
1126
|
+
IF _layout_id IS NULL THEN
|
|
1127
|
+
RAISE EXCEPTION 'GEEN_LAYOUT: geef layout_id mee voor %.', v_type;
|
|
1128
|
+
END IF;
|
|
1129
|
+
SELECT l.id INTO v_route_layout FROM document_layouts l
|
|
1130
|
+
WHERE l.id = _layout_id AND l.documenttype::text = v_type AND l.actief;
|
|
1131
|
+
IF v_route_layout IS NULL THEN
|
|
1132
|
+
RAISE EXCEPTION 'GEEN_LAYOUT: layout % is geen actieve %-layout.', _layout_id, v_type;
|
|
1133
|
+
END IF;
|
|
1134
|
+
v_layout := v_route_layout;
|
|
1135
|
+
ELSE
|
|
1136
|
+
v_layout := NULL;
|
|
1137
|
+
END IF;
|
|
1138
|
+
|
|
1139
|
+
v_route := public.printer_routering(v_type, v_plek, v_werkplek, v_route_layout, v_formaat);
|
|
1140
|
+
v_printer := nullif(v_route->>'printer_id', '')::uuid;
|
|
1141
|
+
v_plek := nullif(v_route->>'print_plek_id', '')::uuid;
|
|
1142
|
+
IF v_printer IS NULL THEN
|
|
1143
|
+
RAISE EXCEPTION 'GEEN_PRINTER: geen printer voor % (printplek %, werkplek %) — stel dit in bij Printplekken of Routering.',
|
|
1144
|
+
v_type, coalesce(v_plek::text, '-'), coalesce(v_werkplek, '-');
|
|
1145
|
+
END IF;
|
|
1146
|
+
|
|
1147
|
+
v_payload := v_payload
|
|
1148
|
+
|| CASE WHEN v_werkplek IS NOT NULL THEN jsonb_build_object('werkplek', v_werkplek) ELSE '{}'::jsonb END
|
|
1149
|
+
|| CASE WHEN v_plek IS NOT NULL THEN jsonb_build_object('print_plek_id', v_plek) ELSE '{}'::jsonb END
|
|
1150
|
+
|| CASE WHEN v_herkomst IS NOT NULL THEN jsonb_build_object('herkomst', v_herkomst) ELSE '{}'::jsonb END;
|
|
1151
|
+
BEGIN
|
|
1152
|
+
INSERT INTO print_jobs (status, layout_id, printer_id, documenttype, documentnaam, kopieen, payload,
|
|
1153
|
+
herkomst, is_herprint, pdf_base64, pdf_url, idempotentie_sleutel)
|
|
1154
|
+
VALUES ('wachtend', v_layout, v_printer, v_type::doc_layout_type,
|
|
1155
|
+
left(coalesce(nullif(btrim(_documentnaam), ''), v_type), 200),
|
|
1156
|
+
public.print_kopieen_aantal(v_type, _kopieen, _payload), v_payload, v_herkomst, coalesce(_is_herprint, false),
|
|
1157
|
+
CASE WHEN v_gebruik_pdf THEN v_pdf END, CASE WHEN v_gebruik_pdf THEN v_url END, v_sleutel)
|
|
1158
|
+
RETURNING id INTO v_job;
|
|
1159
|
+
EXCEPTION WHEN unique_violation THEN
|
|
1160
|
+
GET STACKED DIAGNOSTICS v_constraint = CONSTRAINT_NAME;
|
|
1161
|
+
IF v_constraint = 'print_jobs_een_origineel_per_kar' THEN
|
|
1162
|
+
DECLARE v_b record; BEGIN
|
|
1163
|
+
SELECT j.id, j.printer_id, j.created_at, j.status::text AS status INTO v_b FROM print_jobs j
|
|
1164
|
+
WHERE j.origineel_sleutel LIKE (v_payload->>'cart_id') || ':' || v_type || '%' AND j.status NOT IN ('mislukt','geannuleerd') LIMIT 1;
|
|
1165
|
+
RAISE EXCEPTION 'DUBBEL_ORIGINEEL: voor deze kar is al een origineel % aangemaakt.', v_type
|
|
1166
|
+
USING DETAIL = jsonb_build_object('job_id', v_b.id, 'printer_id', v_b.printer_id, 'created_at', v_b.created_at, 'status', v_b.status)::text;
|
|
1167
|
+
END;
|
|
1168
|
+
END IF;
|
|
1169
|
+
SELECT j.id, j.printer_id INTO v_bestaand_job, v_bestaand_printer FROM print_jobs j
|
|
1170
|
+
WHERE j.idempotentie_sleutel = v_sleutel AND j.status NOT IN ('mislukt','geannuleerd') LIMIT 1;
|
|
1171
|
+
IF v_bestaand_job IS NOT NULL THEN
|
|
1172
|
+
RETURN QUERY SELECT v_bestaand_job, v_bestaand_printer, true, s.status, s.mislukt, s.fout_code, s.fout_bericht
|
|
1173
|
+
FROM public.print_job_status_uitgebreid(v_bestaand_job) s;
|
|
1174
|
+
RETURN;
|
|
1175
|
+
END IF;
|
|
1176
|
+
RAISE;
|
|
1177
|
+
END;
|
|
1178
|
+
IF v_job IS NULL THEN
|
|
1179
|
+
RAISE EXCEPTION 'DUBBELE_AANVRAAG: dit document stond al in de printwachtrij; de dubbele aanvraag is genegeerd.';
|
|
1180
|
+
END IF;
|
|
1181
|
+
RETURN QUERY SELECT v_job, v_printer, false, 'wachtend'::text, false, NULL::text, NULL::text;
|
|
1182
|
+
END;
|
|
1183
|
+
$function$;
|
|
1184
|
+
|
|
1185
|
+
CREATE OR REPLACE FUNCTION public.layout_verwijzing_omzetten(_tabel text, _rij_id uuid, _oud uuid, _nieuw uuid)
|
|
1186
|
+
RETURNS void
|
|
1187
|
+
LANGUAGE plpgsql
|
|
1188
|
+
SECURITY DEFINER
|
|
1189
|
+
SET search_path TO 'public'
|
|
1190
|
+
AS $function$
|
|
1191
|
+
DECLARE v_oud text; v_nieuw text; v_huidig uuid;
|
|
1192
|
+
BEGIN
|
|
1193
|
+
IF NOT (public.has_role(auth.uid(),'admin') OR public.has_role(auth.uid(),'superadmin')) THEN
|
|
1194
|
+
RAISE EXCEPTION 'ALLEEN_BEHEERDER: alleen beheerders kunnen verwijzingen omzetten';
|
|
1195
|
+
END IF;
|
|
1196
|
+
IF _tabel NOT IN ('print_rules','printer_mappings','document_bronregels') THEN
|
|
1197
|
+
RAISE EXCEPTION 'ANDERE_MODULE: deze instelling hoort bij een andere module en wordt hier niet gewijzigd';
|
|
1198
|
+
END IF;
|
|
1199
|
+
SELECT documenttype::text INTO v_oud FROM document_layouts WHERE id = _oud;
|
|
1200
|
+
SELECT documenttype::text INTO v_nieuw FROM document_layouts WHERE id = _nieuw AND actief;
|
|
1201
|
+
IF v_nieuw IS NULL THEN RAISE EXCEPTION 'LAYOUT_ONBEKEND: de nieuwe layout bestaat niet of is niet actief'; END IF;
|
|
1202
|
+
IF v_oud IS DISTINCT FROM v_nieuw THEN RAISE EXCEPTION 'ANDERE_SOORT: de nieuwe layout is van een andere documentsoort'; END IF;
|
|
1203
|
+
EXECUTE format('SELECT layout_id FROM public.%I WHERE id = $1 FOR UPDATE', _tabel) INTO v_huidig USING _rij_id;
|
|
1204
|
+
IF v_huidig IS DISTINCT FROM _oud THEN RAISE EXCEPTION 'GEWIJZIGD: deze instelling wijst niet meer naar de oude layout'; END IF;
|
|
1205
|
+
EXECUTE format('UPDATE public.%I SET layout_id = $1 WHERE id = $2', _tabel) USING _nieuw, _rij_id;
|
|
1206
|
+
END $function$;
|
|
1207
|
+
|
|
1208
|
+
CREATE OR REPLACE FUNCTION public.layout_verwijzingen()
|
|
1209
|
+
RETURNS jsonb
|
|
1210
|
+
LANGUAGE plpgsql
|
|
1211
|
+
STABLE SECURITY DEFINER
|
|
1212
|
+
SET search_path TO 'public'
|
|
1213
|
+
AS $function$
|
|
1214
|
+
DECLARE
|
|
1215
|
+
c record; rij jsonb; lid text; pad text[];
|
|
1216
|
+
v_ids text[]; v_pat text[];
|
|
1217
|
+
v_ref jsonb := '[]'::jsonb;
|
|
1218
|
+
v_layouts jsonb;
|
|
1219
|
+
BEGIN
|
|
1220
|
+
IF auth.uid() IS NULL AND coalesce(auth.role(), '') <> 'service_role' THEN RAISE EXCEPTION 'NIET_INGELOGD'; END IF;
|
|
1221
|
+
SELECT array_agg(id::text) INTO v_ids FROM document_layouts;
|
|
1222
|
+
IF v_ids IS NULL THEN RETURN jsonb_build_object('layouts','[]'::jsonb,'verwijzingen','[]'::jsonb); END IF;
|
|
1223
|
+
SELECT array_agg('%' || x || '%') INTO v_pat FROM unnest(v_ids) x;
|
|
1224
|
+
|
|
1225
|
+
-- jsonb-instellingen van modules (geen historie, logs of caches)
|
|
1226
|
+
FOR c IN
|
|
1227
|
+
SELECT col.table_name t, col.column_name k FROM information_schema.columns col
|
|
1228
|
+
JOIN information_schema.tables tb ON tb.table_schema = col.table_schema AND tb.table_name = col.table_name AND tb.table_type = 'BASE TABLE'
|
|
1229
|
+
WHERE col.table_schema = 'public' AND col.data_type = 'jsonb'
|
|
1230
|
+
AND col.column_name IN ('settings','config','instellingen','configuratie')
|
|
1231
|
+
AND col.table_name !~ '(^|_)(versions?|logs?|historie)($|_)'
|
|
1232
|
+
AND col.table_name !~ '(^|_)cache($|_)'
|
|
1233
|
+
AND col.table_name NOT LIKE 'document_layout%'
|
|
1234
|
+
AND EXISTS (SELECT 1 FROM information_schema.columns i WHERE i.table_schema='public' AND i.table_name=col.table_name AND i.column_name='id')
|
|
1235
|
+
LOOP
|
|
1236
|
+
FOR rij IN EXECUTE format('SELECT to_jsonb(x) FROM public.%I x WHERE x.%I::text LIKE ANY ($1)', c.t, c.k) USING v_pat LOOP
|
|
1237
|
+
FOREACH lid IN ARRAY v_ids LOOP
|
|
1238
|
+
IF (rij -> c.k)::text LIKE '%' || lid || '%' THEN
|
|
1239
|
+
FOR pad IN SELECT * FROM public._jsonb_paden_met_waarde(rij -> c.k, lid) LOOP
|
|
1240
|
+
v_ref := v_ref || jsonb_build_object('tabel',c.t,'kolom',c.k,'pad',to_jsonb(pad),'rij_id',rij->>'id',
|
|
1241
|
+
'rij_naam',coalesce(rij->>'name',rij->>'naam',rij->>'label'),
|
|
1242
|
+
'rij_actief',coalesce(rij->'is_active',rij->'actief'),'layout_id',lid);
|
|
1243
|
+
END LOOP;
|
|
1244
|
+
END IF;
|
|
1245
|
+
END LOOP;
|
|
1246
|
+
END LOOP;
|
|
1247
|
+
END LOOP;
|
|
1248
|
+
|
|
1249
|
+
-- losse layout-kolommen (uuid)
|
|
1250
|
+
FOR c IN
|
|
1251
|
+
SELECT col.table_name t, col.column_name k FROM information_schema.columns col
|
|
1252
|
+
JOIN information_schema.tables tb ON tb.table_schema = col.table_schema AND tb.table_name = col.table_name AND tb.table_type = 'BASE TABLE'
|
|
1253
|
+
WHERE col.table_schema = 'public' AND col.data_type = 'uuid'
|
|
1254
|
+
AND (col.column_name = 'layout_id' OR col.column_name LIKE '%\_layout\_id')
|
|
1255
|
+
AND col.table_name NOT IN ('print_jobs','ai_layout_imports','pakbon_barcode_inhoud')
|
|
1256
|
+
AND col.table_name NOT LIKE 'document_layout%'
|
|
1257
|
+
AND col.table_name !~ '(^|_)(logs?|cache)($|_)'
|
|
1258
|
+
AND EXISTS (SELECT 1 FROM information_schema.columns i WHERE i.table_schema='public' AND i.table_name=col.table_name AND i.column_name='id')
|
|
1259
|
+
LOOP
|
|
1260
|
+
FOR rij IN EXECUTE format('SELECT to_jsonb(x) FROM public.%I x WHERE x.%I IS NOT NULL', c.t, c.k) LOOP
|
|
1261
|
+
v_ref := v_ref || jsonb_build_object('tabel',c.t,'kolom',c.k,'pad','[]'::jsonb,'rij_id',rij->>'id',
|
|
1262
|
+
'rij_naam',coalesce(rij->>'name',rij->>'naam',rij->>'label'),
|
|
1263
|
+
'rij_actief',coalesce(rij->'is_active',rij->'actief'),'layout_id',rij->>c.k);
|
|
1264
|
+
END LOOP;
|
|
1265
|
+
END LOOP;
|
|
1266
|
+
|
|
1267
|
+
SELECT coalesce(jsonb_agg(jsonb_build_object(
|
|
1268
|
+
'id',l.id,'naam',l.naam,'documenttype',l.documenttype,'bron',coalesce(l.bron,'eigen'),
|
|
1269
|
+
'actief',l.actief,'is_standaard',l.is_standaard,
|
|
1270
|
+
'gebruik',(SELECT coalesce(jsonb_object_agg(b, n),'{}'::jsonb) FROM (
|
|
1271
|
+
SELECT coalesce(j.gebruikte_bron,'onbekend') b, count(*) n FROM print_jobs j
|
|
1272
|
+
WHERE coalesce(j.gebruikte_layout_id, j.layout_id) = l.id AND j.created_at > now() - interval '30 days'
|
|
1273
|
+
GROUP BY 1) s))), '[]'::jsonb)
|
|
1274
|
+
INTO v_layouts FROM document_layouts l;
|
|
1275
|
+
|
|
1276
|
+
RETURN jsonb_build_object('layouts', v_layouts, 'verwijzingen', v_ref);
|
|
1277
|
+
END $function$;
|
|
1278
|
+
|
|
1279
|
+
-- layout_zorg_systeemlayouts(): zie sectie 11 (1.65.0).
|
|
1280
|
+
|
|
1281
|
+
CREATE OR REPLACE FUNCTION public.markeer_ontbrekende_printer()
|
|
1282
|
+
RETURNS trigger
|
|
1283
|
+
LANGUAGE plpgsql
|
|
1284
|
+
SET search_path TO 'public'
|
|
1285
|
+
AS $function$
|
|
1286
|
+
BEGIN
|
|
1287
|
+
IF NEW.printer_id IS NULL AND OLD.printer_id IS NOT NULL THEN
|
|
1288
|
+
NEW.printer_ontbreekt_sinds := now();
|
|
1289
|
+
ELSIF NEW.printer_id IS NOT NULL THEN
|
|
1290
|
+
NEW.printer_ontbreekt_sinds := NULL;
|
|
1291
|
+
END IF;
|
|
1292
|
+
RETURN NEW;
|
|
1293
|
+
END $function$;
|
|
1294
|
+
|
|
1295
|
+
CREATE OR REPLACE FUNCTION public.opruim_print_historie()
|
|
1296
|
+
RETURNS TABLE(ontdaan integer, verwijderd integer)
|
|
1297
|
+
LANGUAGE plpgsql
|
|
1298
|
+
SECURITY DEFINER
|
|
1299
|
+
SET search_path TO 'public'
|
|
1300
|
+
AS $function$
|
|
1301
|
+
DECLARE
|
|
1302
|
+
dagen_bestanden integer;
|
|
1303
|
+
dagen_opdrachten integer;
|
|
1304
|
+
n1 integer := 0;
|
|
1305
|
+
n2 integer := 0;
|
|
1306
|
+
BEGIN
|
|
1307
|
+
SELECT COALESCE(bewaar_bestanden_dagen, 7), COALESCE(bewaar_opdrachten_dagen, 90)
|
|
1308
|
+
INTO dagen_bestanden, dagen_opdrachten
|
|
1309
|
+
FROM public.print_queue_settings ORDER BY created_at LIMIT 1;
|
|
1310
|
+
|
|
1311
|
+
dagen_bestanden := COALESCE(dagen_bestanden, 7);
|
|
1312
|
+
dagen_opdrachten := COALESCE(dagen_opdrachten, 90);
|
|
1313
|
+
|
|
1314
|
+
IF dagen_bestanden > 0 THEN
|
|
1315
|
+
WITH opgeschoond AS (
|
|
1316
|
+
UPDATE public.print_jobs
|
|
1317
|
+
SET pdf_base64 = NULL, render_html = NULL
|
|
1318
|
+
WHERE status IN ('voltooid', 'mislukt', 'geannuleerd')
|
|
1319
|
+
AND created_at < now() - make_interval(days => dagen_bestanden)
|
|
1320
|
+
AND (pdf_base64 IS NOT NULL OR render_html IS NOT NULL)
|
|
1321
|
+
RETURNING 1
|
|
1322
|
+
)
|
|
1323
|
+
SELECT count(*)::int INTO n1 FROM opgeschoond;
|
|
1324
|
+
END IF;
|
|
1325
|
+
|
|
1326
|
+
IF dagen_opdrachten > 0 THEN
|
|
1327
|
+
WITH gewist AS (
|
|
1328
|
+
DELETE FROM public.print_jobs
|
|
1329
|
+
WHERE status IN ('voltooid', 'mislukt', 'geannuleerd')
|
|
1330
|
+
AND created_at < now() - make_interval(days => dagen_opdrachten)
|
|
1331
|
+
RETURNING 1
|
|
1332
|
+
)
|
|
1333
|
+
SELECT count(*)::int INTO n2 FROM gewist;
|
|
1334
|
+
END IF;
|
|
1335
|
+
|
|
1336
|
+
RETURN QUERY SELECT n1, n2;
|
|
1337
|
+
END;
|
|
1338
|
+
$function$;
|
|
1339
|
+
|
|
1340
|
+
CREATE OR REPLACE FUNCTION public.print_formaat_klasse(_code text)
|
|
1341
|
+
RETURNS text
|
|
1342
|
+
LANGUAGE sql
|
|
1343
|
+
IMMUTABLE
|
|
1344
|
+
SET search_path TO 'public'
|
|
1345
|
+
AS $function$
|
|
1346
|
+
SELECT CASE
|
|
1347
|
+
WHEN upper(coalesce(_code,'A4')) IN ('A4','A5','A3','LETTER','LEGAL','VRIJ') THEN 'a4'
|
|
1348
|
+
ELSE 'label' END
|
|
1349
|
+
$function$;
|
|
1350
|
+
|
|
1351
|
+
CREATE OR REPLACE FUNCTION public.print_is_etiketsoort(_t text)
|
|
1352
|
+
RETURNS boolean
|
|
1353
|
+
LANGUAGE sql
|
|
1354
|
+
IMMUTABLE
|
|
1355
|
+
SET search_path TO 'public'
|
|
1356
|
+
AS $function$
|
|
1357
|
+
SELECT coalesce(_t, '') IN ('sticker','traysticker','etiket','verzendlabel','productlabel','barcode_label')
|
|
1358
|
+
$function$;
|
|
1359
|
+
|
|
1360
|
+
CREATE OR REPLACE FUNCTION public.print_is_labelprinter(_printer_id uuid)
|
|
1361
|
+
RETURNS boolean
|
|
1362
|
+
LANGUAGE sql
|
|
1363
|
+
STABLE
|
|
1364
|
+
SET search_path TO 'public'
|
|
1365
|
+
AS $function$
|
|
1366
|
+
SELECT EXISTS (
|
|
1367
|
+
SELECT 1 FROM printers p
|
|
1368
|
+
WHERE p.id = _printer_id AND p.actief IS DISTINCT FROM false
|
|
1369
|
+
AND (p.geladen_etiket IS NOT NULL OR p.soort::text IN ('labelprinter','thermal')
|
|
1370
|
+
OR EXISTS (SELECT 1 FROM print_werkplekken w WHERE w.actief AND w.label_printer_id = p.id))
|
|
1371
|
+
AND NOT EXISTS (SELECT 1 FROM print_werkplekken w WHERE w.actief AND w.a4_printer_id = p.id)
|
|
1372
|
+
)
|
|
1373
|
+
$function$;
|
|
1374
|
+
|
|
1375
|
+
CREATE OR REPLACE FUNCTION public.print_job_status_uitgebreid(_job_id uuid)
|
|
1376
|
+
RETURNS TABLE(status text, mislukt boolean, fout_code text, fout_bericht text)
|
|
1377
|
+
LANGUAGE sql
|
|
1378
|
+
STABLE SECURITY DEFINER
|
|
1379
|
+
SET search_path TO 'public'
|
|
1380
|
+
AS $function$
|
|
1381
|
+
SELECT CASE WHEN j.status::text = 'mislukt' AND (j.foutcode = 'VERLOPEN' OR j.printnode_status = 'expired') THEN 'verlopen' ELSE j.status::text END,
|
|
1382
|
+
j.status::text IN ('mislukt','geannuleerd'),
|
|
1383
|
+
CASE WHEN j.status::text IN ('mislukt','geannuleerd') THEN coalesce(j.foutcode, upper(j.status::text)) END,
|
|
1384
|
+
CASE WHEN j.status::text IN ('mislukt','geannuleerd') THEN j.foutmelding END
|
|
1385
|
+
FROM print_jobs j WHERE j.id = _job_id
|
|
1386
|
+
$function$;
|
|
1387
|
+
|
|
1388
|
+
CREATE OR REPLACE FUNCTION public.print_jobs_dedupe()
|
|
1389
|
+
RETURNS trigger
|
|
1390
|
+
LANGUAGE plpgsql
|
|
1391
|
+
SET search_path TO 'public'
|
|
1392
|
+
AS $function$
|
|
1393
|
+
declare
|
|
1394
|
+
venster integer;
|
|
1395
|
+
bucket bigint;
|
|
1396
|
+
basis text;
|
|
1397
|
+
kenmerk text;
|
|
1398
|
+
bestaande uuid;
|
|
1399
|
+
al_gebruikt boolean;
|
|
1400
|
+
begin
|
|
1401
|
+
if coalesce(new.is_herprint, false) then
|
|
1402
|
+
if new.idempotentie_sleutel is null then
|
|
1403
|
+
new.idempotentie_sleutel := 'herprint:' || new.id::text;
|
|
1404
|
+
end if;
|
|
1405
|
+
return new;
|
|
1406
|
+
end if;
|
|
1407
|
+
|
|
1408
|
+
select coalesce(dubbel_venster_minuten, 10) into venster
|
|
1409
|
+
from public.print_queue_settings order by created_at limit 1;
|
|
1410
|
+
venster := coalesce(venster, 10);
|
|
1411
|
+
|
|
1412
|
+
if venster <= 0 then
|
|
1413
|
+
if new.idempotentie_sleutel is null then
|
|
1414
|
+
new.idempotentie_sleutel := 'vrij:' || new.id::text;
|
|
1415
|
+
end if;
|
|
1416
|
+
return new;
|
|
1417
|
+
end if;
|
|
1418
|
+
|
|
1419
|
+
if new.idempotentie_sleutel is null then
|
|
1420
|
+
kenmerk := coalesce(
|
|
1421
|
+
nullif(new.payload->>'queue_item_id', ''),
|
|
1422
|
+
nullif(new.payload->>'order_id', ''),
|
|
1423
|
+
nullif(new.payload->>'ordernummer', ''),
|
|
1424
|
+
nullif(new.payload->>'order_number', ''),
|
|
1425
|
+
nullif(new.payload->>'orderId', ''),
|
|
1426
|
+
case when coalesce(new.pdf_base64, '') <> '' then md5(left(new.pdf_base64, 4000)) end,
|
|
1427
|
+
nullif(new.pdf_url, ''),
|
|
1428
|
+
case when coalesce(new.render_html, '') <> '' then md5(left(new.render_html, 4000)) end,
|
|
1429
|
+
coalesce(new.documentnaam, '')
|
|
1430
|
+
);
|
|
1431
|
+
bucket := floor(extract(epoch from now()) / (venster * 60))::bigint;
|
|
1432
|
+
new.idempotentie_sleutel := md5(
|
|
1433
|
+
coalesce(new.payload->>'source', '') || ':' ||
|
|
1434
|
+
kenmerk || ':' ||
|
|
1435
|
+
coalesce(new.documenttype::text, '') || ':' ||
|
|
1436
|
+
coalesce(new.layout_id::text, '') || ':' ||
|
|
1437
|
+
coalesce(new.printer_id::text, '') || ':' ||
|
|
1438
|
+
bucket::text
|
|
1439
|
+
);
|
|
1440
|
+
end if;
|
|
1441
|
+
|
|
1442
|
+
basis := new.idempotentie_sleutel;
|
|
1443
|
+
perform pg_advisory_xact_lock(hashtext('print_jobs_dedupe:' || basis));
|
|
1444
|
+
|
|
1445
|
+
select id into bestaande
|
|
1446
|
+
from public.print_jobs
|
|
1447
|
+
where idempotentie_sleutel = basis
|
|
1448
|
+
and created_at > now() - make_interval(mins => venster)
|
|
1449
|
+
and status in ('wachtend','bezig','voltooid')
|
|
1450
|
+
order by created_at desc
|
|
1451
|
+
limit 1;
|
|
1452
|
+
|
|
1453
|
+
if bestaande is not null then
|
|
1454
|
+
insert into public.print_job_logs (job_id, gebeurtenis, detail)
|
|
1455
|
+
values (bestaande, 'overgeslagen',
|
|
1456
|
+
'Dubbele aanvraag genegeerd: dit document stond al in de wachtrij.');
|
|
1457
|
+
insert into public.print_dedupe_events
|
|
1458
|
+
(idempotentie_sleutel, reden, documentnaam, documenttype, bestaande_job_id, detail)
|
|
1459
|
+
values (basis, 'overgeslagen', new.documentnaam, new.documenttype::text, bestaande,
|
|
1460
|
+
'Binnen het dubbelvenster van ' || venster || ' minuten.');
|
|
1461
|
+
return null;
|
|
1462
|
+
end if;
|
|
1463
|
+
|
|
1464
|
+
-- Alleen een nog geldige opdracht met deze sleutel dwingt een eigen sleutel af.
|
|
1465
|
+
-- Mislukte/geannuleerde opdrachten vallen buiten de unieke index, dus een
|
|
1466
|
+
-- herstelpoging houdt de oorspronkelijke sleutel en blijft terug te vinden.
|
|
1467
|
+
select exists (
|
|
1468
|
+
select 1 from public.print_jobs
|
|
1469
|
+
where idempotentie_sleutel = basis
|
|
1470
|
+
and status not in ('mislukt','geannuleerd')
|
|
1471
|
+
) into al_gebruikt;
|
|
1472
|
+
|
|
1473
|
+
if al_gebruikt then
|
|
1474
|
+
new.idempotentie_sleutel := basis || ':' || new.id::text;
|
|
1475
|
+
insert into public.print_dedupe_events
|
|
1476
|
+
(idempotentie_sleutel, reden, documentnaam, documenttype, detail)
|
|
1477
|
+
values (basis, 'hergebruik', new.documentnaam, new.documenttype::text,
|
|
1478
|
+
'Sleutel bestond al buiten het venster; opdracht kreeg een eigen sleutel.');
|
|
1479
|
+
end if;
|
|
1480
|
+
|
|
1481
|
+
return new;
|
|
1482
|
+
end;
|
|
1483
|
+
$function$;
|
|
1484
|
+
|
|
1485
|
+
CREATE OR REPLACE FUNCTION public.print_jobs_origineel_controle()
|
|
1486
|
+
RETURNS trigger
|
|
1487
|
+
LANGUAGE plpgsql
|
|
1488
|
+
SET search_path TO 'public'
|
|
1489
|
+
AS $function$
|
|
1490
|
+
DECLARE
|
|
1491
|
+
v_cart text := nullif(btrim(coalesce(NEW.payload->>'cart_id', '')), '');
|
|
1492
|
+
v_stuk text;
|
|
1493
|
+
v_bestaand record;
|
|
1494
|
+
BEGIN
|
|
1495
|
+
IF coalesce(NEW.is_herprint, false) OR v_cart IS NULL OR NEW.status IN ('mislukt', 'geannuleerd') THEN
|
|
1496
|
+
RETURN NEW;
|
|
1497
|
+
END IF;
|
|
1498
|
+
IF NEW.documenttype::text = 'sticker' THEN
|
|
1499
|
+
v_stuk := nullif(btrim(coalesce(NEW.payload->>'sticker_id', '')), '');
|
|
1500
|
+
IF v_stuk IS NULL THEN RETURN NEW; END IF;
|
|
1501
|
+
ELSIF NEW.documenttype::text = 'traysticker' THEN
|
|
1502
|
+
v_stuk := nullif(btrim(coalesce(NEW.payload->>'delivery_order_id', '')), '');
|
|
1503
|
+
IF v_stuk IS NULL THEN RETURN NEW; END IF;
|
|
1504
|
+
END IF;
|
|
1505
|
+
NEW.origineel_sleutel := v_cart || ':' || NEW.documenttype::text || coalesce(':' || v_stuk, '');
|
|
1506
|
+
PERFORM pg_advisory_xact_lock(hashtext('print_jobs_origineel:' || NEW.origineel_sleutel));
|
|
1507
|
+
SELECT j.id, j.printer_id, j.created_at, j.status::text AS status INTO v_bestaand
|
|
1508
|
+
FROM print_jobs j
|
|
1509
|
+
WHERE j.origineel_sleutel = NEW.origineel_sleutel AND j.status NOT IN ('mislukt', 'geannuleerd')
|
|
1510
|
+
LIMIT 1;
|
|
1511
|
+
IF v_bestaand.id IS NOT NULL THEN
|
|
1512
|
+
RAISE EXCEPTION 'DUBBEL_ORIGINEEL: voor deze kar is al een origineel % aangemaakt.', NEW.documenttype
|
|
1513
|
+
USING ERRCODE = 'P0001',
|
|
1514
|
+
DETAIL = jsonb_build_object('job_id', v_bestaand.id, 'printer_id', v_bestaand.printer_id,
|
|
1515
|
+
'created_at', v_bestaand.created_at, 'status', v_bestaand.status)::text;
|
|
1516
|
+
END IF;
|
|
1517
|
+
RETURN NEW;
|
|
1518
|
+
END;
|
|
1519
|
+
$function$;
|
|
1520
|
+
|
|
1521
|
+
CREATE OR REPLACE FUNCTION public.print_jobs_wake_queue()
|
|
1522
|
+
RETURNS trigger
|
|
1523
|
+
LANGUAGE plpgsql
|
|
1524
|
+
SECURITY DEFINER
|
|
1525
|
+
SET search_path TO 'public'
|
|
1526
|
+
AS $function$
|
|
1527
|
+
begin
|
|
1528
|
+
if new.status = 'wachtend'
|
|
1529
|
+
and (new.volgende_poging is null or new.volgende_poging <= now())
|
|
1530
|
+
and (tg_op = 'INSERT' or old.status is distinct from new.status or old.volgende_poging is distinct from new.volgende_poging) then
|
|
1531
|
+
perform public.wake_print_queue(1500);
|
|
1532
|
+
end if;
|
|
1533
|
+
return null;
|
|
1534
|
+
end;
|
|
1535
|
+
$function$;
|
|
1536
|
+
|
|
1537
|
+
CREATE OR REPLACE FUNCTION public.print_kopieen_aantal(_type text, _kopieen integer, _payload jsonb)
|
|
1538
|
+
RETURNS integer
|
|
1539
|
+
LANGUAGE plpgsql
|
|
1540
|
+
IMMUTABLE
|
|
1541
|
+
SET search_path TO 'public'
|
|
1542
|
+
AS $function$
|
|
1543
|
+
DECLARE
|
|
1544
|
+
v_p integer;
|
|
1545
|
+
v_n integer;
|
|
1546
|
+
v_max integer := CASE WHEN btrim(coalesce(_type,'')) IN ('sticker','traysticker') THEN 5000 ELSE 50 END;
|
|
1547
|
+
BEGIN
|
|
1548
|
+
IF jsonb_typeof(_payload->'kopieen') = 'number' AND (_payload->>'kopieen') ~ '^\d+$' THEN
|
|
1549
|
+
v_p := (_payload->>'kopieen')::integer;
|
|
1550
|
+
END IF;
|
|
1551
|
+
-- _kopieen wint; payload.kopieen is alleen het vangnet als _kopieen niet (of als standaard 1) is meegegeven.
|
|
1552
|
+
v_n := CASE WHEN (_kopieen IS NULL OR _kopieen = 1) AND v_p IS NOT NULL AND v_p >= 1 THEN v_p ELSE coalesce(_kopieen, 1) END;
|
|
1553
|
+
IF v_max = 5000 AND v_n > v_max THEN
|
|
1554
|
+
RAISE EXCEPTION 'TE_VEEL_KOPIEEN: % afdrukken gevraagd; het maximum voor een % is %. Er is niets geprint.', v_n, _type, v_max;
|
|
1555
|
+
END IF;
|
|
1556
|
+
RETURN greatest(1, least(v_max, v_n));
|
|
1557
|
+
END $function$;
|
|
1558
|
+
|
|
1559
|
+
CREATE OR REPLACE FUNCTION public.print_preview_toestaan(_station_slug text, _queue_item_id uuid, _max integer DEFAULT 6, _venster_sec integer DEFAULT 60)
|
|
1560
|
+
RETURNS jsonb
|
|
1561
|
+
LANGUAGE plpgsql
|
|
1562
|
+
SECURITY DEFINER
|
|
1563
|
+
SET search_path TO 'public'
|
|
1564
|
+
AS $function$
|
|
1565
|
+
DECLARE
|
|
1566
|
+
v_aantal integer;
|
|
1567
|
+
v_oudste timestamptz;
|
|
1568
|
+
v_max integer := greatest(1, coalesce(_max, 6));
|
|
1569
|
+
v_venster integer := greatest(1, coalesce(_venster_sec, 60));
|
|
1570
|
+
BEGIN
|
|
1571
|
+
PERFORM pg_advisory_xact_lock(hashtext('print_preview:' || coalesce(_station_slug, '')));
|
|
1572
|
+
|
|
1573
|
+
SELECT count(*), min(created_at)
|
|
1574
|
+
INTO v_aantal, v_oudste
|
|
1575
|
+
FROM public.print_preview_events
|
|
1576
|
+
WHERE uitkomst = 'toegestaan'
|
|
1577
|
+
AND station_slug IS NOT DISTINCT FROM _station_slug
|
|
1578
|
+
AND created_at > now() - make_interval(secs => v_venster);
|
|
1579
|
+
|
|
1580
|
+
IF v_aantal >= v_max THEN
|
|
1581
|
+
INSERT INTO public.print_preview_events (station_slug, queue_item_id, uitkomst, code, reden, detail)
|
|
1582
|
+
VALUES (_station_slug, _queue_item_id, 'geweigerd', 'te_snel',
|
|
1583
|
+
format('Te veel voorbeelden: %s binnen %s seconden (maximum %s).', v_aantal, v_venster, v_max),
|
|
1584
|
+
jsonb_build_object('max', v_max, 'venster_sec', v_venster));
|
|
1585
|
+
RETURN jsonb_build_object(
|
|
1586
|
+
'toegestaan', false,
|
|
1587
|
+
'code', 'te_snel',
|
|
1588
|
+
'aantal', v_aantal,
|
|
1589
|
+
'wacht_sec', greatest(1, v_venster - floor(extract(epoch FROM now() - v_oudste))::int)
|
|
1590
|
+
);
|
|
1591
|
+
END IF;
|
|
1592
|
+
|
|
1593
|
+
INSERT INTO public.print_preview_events (station_slug, queue_item_id, uitkomst, code)
|
|
1594
|
+
VALUES (_station_slug, _queue_item_id, 'toegestaan', null);
|
|
1595
|
+
|
|
1596
|
+
RETURN jsonb_build_object('toegestaan', true, 'aantal', v_aantal + 1);
|
|
1597
|
+
END;
|
|
1598
|
+
$function$;
|
|
1599
|
+
|
|
1600
|
+
CREATE OR REPLACE FUNCTION public.print_preview_weiger(_station_slug text, _queue_item_id uuid, _code text, _reden text)
|
|
1601
|
+
RETURNS void
|
|
1602
|
+
LANGUAGE sql
|
|
1603
|
+
SECURITY DEFINER
|
|
1604
|
+
SET search_path TO 'public'
|
|
1605
|
+
AS $function$
|
|
1606
|
+
INSERT INTO public.print_preview_events (station_slug, queue_item_id, uitkomst, code, reden)
|
|
1607
|
+
VALUES (_station_slug, _queue_item_id, 'geweigerd', left(coalesce(_code, 'onbekend'), 60), left(coalesce(_reden, ''), 500));
|
|
1608
|
+
$function$;
|
|
1609
|
+
|
|
1610
|
+
CREATE OR REPLACE FUNCTION public.print_set_updated_at()
|
|
1611
|
+
RETURNS trigger
|
|
1612
|
+
LANGUAGE plpgsql
|
|
1613
|
+
SET search_path TO 'public'
|
|
1614
|
+
AS $function$
|
|
1615
|
+
BEGIN NEW.updated_at := now(); RETURN NEW; END $function$;
|
|
1616
|
+
|
|
1617
|
+
CREATE OR REPLACE FUNCTION public.print_shell_url()
|
|
1618
|
+
RETURNS text
|
|
1619
|
+
LANGUAGE sql
|
|
1620
|
+
STABLE SECURITY DEFINER
|
|
1621
|
+
SET search_path TO 'public'
|
|
1622
|
+
AS $function$ select public.print_url_norm(value::text) from public.module_runtime_config where key = 'shell_base_url' $function$;
|
|
1623
|
+
|
|
1624
|
+
CREATE OR REPLACE FUNCTION public.print_url_norm(_u text)
|
|
1625
|
+
RETURNS text
|
|
1626
|
+
LANGUAGE sql
|
|
1627
|
+
IMMUTABLE
|
|
1628
|
+
SET search_path TO 'public'
|
|
1629
|
+
AS $function$ select nullif(lower(rtrim(btrim(coalesce(_u,'')), '/')), '') $function$;
|
|
1630
|
+
|
|
1631
|
+
CREATE OR REPLACE FUNCTION public.print_werkplek_keuze(_werkplek_id uuid, _documenttype text, _klasse text)
|
|
1632
|
+
RETURNS jsonb
|
|
1633
|
+
LANGUAGE plpgsql
|
|
1634
|
+
STABLE
|
|
1635
|
+
SET search_path TO 'public'
|
|
1636
|
+
AS $function$
|
|
1637
|
+
DECLARE r record; wp record;
|
|
1638
|
+
BEGIN
|
|
1639
|
+
SELECT * INTO wp FROM print_werkplekken WHERE id = _werkplek_id AND actief;
|
|
1640
|
+
IF NOT FOUND THEN RETURN NULL; END IF;
|
|
1641
|
+
SELECT a.id, a.printer_id INTO r FROM print_werkplek_afwijkingen a
|
|
1642
|
+
JOIN printers p ON p.id = a.printer_id AND p.actief IS DISTINCT FROM false
|
|
1643
|
+
WHERE a.werkplek_id = _werkplek_id AND a.documenttype = _documenttype;
|
|
1644
|
+
IF FOUND THEN
|
|
1645
|
+
RETURN jsonb_build_object('bron','werkplek_afwijking','printer_id',r.printer_id,'regel_id',r.id,
|
|
1646
|
+
'werkplek_id',wp.id,'werkplek_naam',wp.naam);
|
|
1647
|
+
END IF;
|
|
1648
|
+
IF _klasse = 'label' AND wp.label_printer_id IS NOT NULL THEN
|
|
1649
|
+
RETURN jsonb_build_object('bron','werkplek_formaat','printer_id',wp.label_printer_id,'regel_id',wp.id,
|
|
1650
|
+
'werkplek_id',wp.id,'werkplek_naam',wp.naam,'printer_rol','label');
|
|
1651
|
+
ELSIF _klasse = 'a4' AND wp.a4_printer_id IS NOT NULL THEN
|
|
1652
|
+
RETURN jsonb_build_object('bron','werkplek_formaat','printer_id',wp.a4_printer_id,'regel_id',wp.id,
|
|
1653
|
+
'werkplek_id',wp.id,'werkplek_naam',wp.naam,'printer_rol','a4');
|
|
1654
|
+
END IF;
|
|
1655
|
+
RETURN NULL;
|
|
1656
|
+
END $function$;
|
|
1657
|
+
|
|
1658
|
+
CREATE OR REPLACE FUNCTION public.printer_gebruik(_printer uuid)
|
|
1659
|
+
RETURNS jsonb
|
|
1660
|
+
LANGUAGE sql
|
|
1661
|
+
STABLE
|
|
1662
|
+
SET search_path TO 'public'
|
|
1663
|
+
AS $function$
|
|
1664
|
+
SELECT jsonb_build_object(
|
|
1665
|
+
'printplek_regels', (SELECT count(*) FROM document_printplek_printers WHERE printer_id = _printer),
|
|
1666
|
+
'werkplek_regels', (SELECT count(*) FROM document_werkplek_printers WHERE printer_id = _printer),
|
|
1667
|
+
'layout_koppelingen', (SELECT count(*) FROM printer_mappings WHERE printer_id = _printer),
|
|
1668
|
+
'standaardregels', (SELECT count(*) FROM document_formaat_printers WHERE printer_id = _printer),
|
|
1669
|
+
'printplekken', (SELECT count(*) FROM print_plek_printers WHERE printer_id = _printer)
|
|
1670
|
+
);
|
|
1671
|
+
$function$;
|
|
1672
|
+
|
|
1673
|
+
CREATE OR REPLACE FUNCTION public.printer_herstel_uitvoeren(_plek uuid, _printer uuid)
|
|
1674
|
+
RETURNS integer
|
|
1675
|
+
LANGUAGE plpgsql
|
|
1676
|
+
SET search_path TO 'public'
|
|
1677
|
+
AS $function$
|
|
1678
|
+
DECLARE
|
|
1679
|
+
_n1 int := 0;
|
|
1680
|
+
_n2 int := 0;
|
|
1681
|
+
_ext text;
|
|
1682
|
+
BEGIN
|
|
1683
|
+
SELECT extern_printer_id INTO _ext FROM printers WHERE id = _printer;
|
|
1684
|
+
IF _ext IS NULL THEN
|
|
1685
|
+
RAISE EXCEPTION 'PRINTER_ZONDER_NUMMER' USING HINT = 'Deze printer heeft geen PrintNode-nummer.';
|
|
1686
|
+
END IF;
|
|
1687
|
+
IF NOT EXISTS (SELECT 1 FROM print_plek_printers WHERE print_plek_id = _plek AND printer_id = _printer) THEN
|
|
1688
|
+
RAISE EXCEPTION 'PRINTER_NIET_OP_PLEK';
|
|
1689
|
+
END IF;
|
|
1690
|
+
WITH h AS (
|
|
1691
|
+
SELECT r->>'tabel' AS tabel, (r->>'id')::uuid AS id
|
|
1692
|
+
FROM print_printer_verwijder_herstel v
|
|
1693
|
+
CROSS JOIN LATERAL jsonb_array_elements(v.regels) r
|
|
1694
|
+
WHERE v.print_plek_id = _plek AND v.hersteld_op IS NULL AND v.extern_printer_id = _ext
|
|
1695
|
+
), u AS (
|
|
1696
|
+
UPDATE document_printplek_printers d SET printer_id = _printer
|
|
1697
|
+
FROM h WHERE h.tabel = 'printplek' AND d.id = h.id AND d.printer_id IS NULL
|
|
1698
|
+
RETURNING d.id
|
|
1699
|
+
) SELECT count(*) INTO _n1 FROM u;
|
|
1700
|
+
WITH h AS (
|
|
1701
|
+
SELECT r->>'tabel' AS tabel, (r->>'id')::uuid AS id
|
|
1702
|
+
FROM print_printer_verwijder_herstel v
|
|
1703
|
+
CROSS JOIN LATERAL jsonb_array_elements(v.regels) r
|
|
1704
|
+
WHERE v.print_plek_id = _plek AND v.hersteld_op IS NULL AND v.extern_printer_id = _ext
|
|
1705
|
+
), u AS (
|
|
1706
|
+
UPDATE document_werkplek_printers d SET printer_id = _printer
|
|
1707
|
+
FROM h WHERE h.tabel = 'werkplek' AND d.id = h.id AND d.printer_id IS NULL
|
|
1708
|
+
RETURNING d.id
|
|
1709
|
+
) SELECT count(*) INTO _n2 FROM u;
|
|
1710
|
+
UPDATE print_printer_verwijder_herstel SET hersteld_op = now()
|
|
1711
|
+
WHERE print_plek_id = _plek AND hersteld_op IS NULL AND extern_printer_id = _ext;
|
|
1712
|
+
RETURN _n1 + _n2;
|
|
1713
|
+
END $function$;
|
|
1714
|
+
|
|
1715
|
+
CREATE OR REPLACE FUNCTION public.printer_herstel_voorstel(_plek uuid, _printer uuid)
|
|
1716
|
+
RETURNS integer
|
|
1717
|
+
LANGUAGE sql
|
|
1718
|
+
STABLE
|
|
1719
|
+
SET search_path TO 'public'
|
|
1720
|
+
AS $function$
|
|
1721
|
+
WITH h AS (
|
|
1722
|
+
SELECT r->>'tabel' AS tabel, (r->>'id')::uuid AS id
|
|
1723
|
+
FROM print_printer_verwijder_herstel v
|
|
1724
|
+
JOIN printers p ON p.id = _printer AND p.extern_printer_id IS NOT NULL AND p.extern_printer_id = v.extern_printer_id
|
|
1725
|
+
CROSS JOIN LATERAL jsonb_array_elements(v.regels) r
|
|
1726
|
+
WHERE v.print_plek_id = _plek AND v.hersteld_op IS NULL
|
|
1727
|
+
)
|
|
1728
|
+
SELECT (SELECT count(*) FROM h JOIN document_printplek_printers d ON d.id = h.id AND h.tabel = 'printplek' AND d.printer_id IS NULL)::int
|
|
1729
|
+
+ (SELECT count(*) FROM h JOIN document_werkplek_printers d ON d.id = h.id AND h.tabel = 'werkplek' AND d.printer_id IS NULL)::int
|
|
1730
|
+
$function$;
|
|
1731
|
+
|
|
1732
|
+
CREATE OR REPLACE FUNCTION public.printer_losgekoppeld_van_plek()
|
|
1733
|
+
RETURNS trigger
|
|
1734
|
+
LANGUAGE plpgsql
|
|
1735
|
+
SET search_path TO 'public'
|
|
1736
|
+
AS $function$
|
|
1737
|
+
DECLARE
|
|
1738
|
+
_plek jsonb;
|
|
1739
|
+
_werk jsonb;
|
|
1740
|
+
BEGIN
|
|
1741
|
+
WITH u AS (
|
|
1742
|
+
UPDATE document_printplek_printers SET printer_id = NULL
|
|
1743
|
+
WHERE print_plek_id = OLD.print_plek_id AND printer_id = OLD.printer_id
|
|
1744
|
+
RETURNING id
|
|
1745
|
+
) SELECT coalesce(jsonb_agg(jsonb_build_object('tabel','printplek','id',id)), '[]'::jsonb) INTO _plek FROM u;
|
|
1746
|
+
WITH u AS (
|
|
1747
|
+
UPDATE document_werkplek_printers w SET printer_id = NULL
|
|
1748
|
+
WHERE w.printer_id = OLD.printer_id
|
|
1749
|
+
AND w.werkplek IN (SELECT computer_naam FROM print_plek_computers WHERE print_plek_id = OLD.print_plek_id)
|
|
1750
|
+
RETURNING id
|
|
1751
|
+
) SELECT coalesce(jsonb_agg(jsonb_build_object('tabel','werkplek','id',id)), '[]'::jsonb) INTO _werk FROM u;
|
|
1752
|
+
IF jsonb_array_length(_plek) + jsonb_array_length(_werk) > 0 THEN
|
|
1753
|
+
INSERT INTO print_printer_verwijder_herstel (print_plek_id, printer_id, extern_printer_id, printer_naam, regels)
|
|
1754
|
+
SELECT OLD.print_plek_id, OLD.printer_id, p.extern_printer_id, p.naam, _plek || _werk
|
|
1755
|
+
FROM (SELECT OLD.printer_id AS id) x LEFT JOIN printers p ON p.id = x.id;
|
|
1756
|
+
END IF;
|
|
1757
|
+
RETURN OLD;
|
|
1758
|
+
END $function$;
|
|
1759
|
+
|
|
1760
|
+
CREATE OR REPLACE FUNCTION public.printer_routering(_documenttype text, _print_plek_id uuid DEFAULT NULL::uuid, _werkplek text DEFAULT NULL::text, _layout_id uuid DEFAULT NULL::uuid, _papierformaat text DEFAULT NULL::text, _werkplek_id uuid DEFAULT NULL::uuid)
|
|
1761
|
+
RETURNS jsonb
|
|
1762
|
+
LANGUAGE plpgsql
|
|
1763
|
+
STABLE
|
|
1764
|
+
SET search_path TO 'public'
|
|
1765
|
+
AS $function$
|
|
1766
|
+
DECLARE
|
|
1767
|
+
v_type text := lower(btrim(coalesce(_documenttype, '')));
|
|
1768
|
+
v_wp text := nullif(btrim(coalesce(_werkplek, '')), '');
|
|
1769
|
+
v_plek uuid := _print_plek_id;
|
|
1770
|
+
v_layout uuid := _layout_id;
|
|
1771
|
+
v_formaat text := nullif(btrim(coalesce(_papierformaat, '')), '');
|
|
1772
|
+
v_lformaat text;
|
|
1773
|
+
v_skip jsonb := '[]'::jsonb;
|
|
1774
|
+
v_wpid uuid := _werkplek_id;
|
|
1775
|
+
v_klasse text;
|
|
1776
|
+
v_etiket boolean;
|
|
1777
|
+
v_label boolean := false; -- etiketsoort: alleen een labelprinter
|
|
1778
|
+
v_melding text := NULL;
|
|
1779
|
+
v_cnt int;
|
|
1780
|
+
v_lp uuid;
|
|
1781
|
+
r record;
|
|
1782
|
+
w record;
|
|
1783
|
+
ok boolean;
|
|
1784
|
+
v_res jsonb;
|
|
1785
|
+
BEGIN
|
|
1786
|
+
IF v_type = 'verzendbrief' THEN v_type := 'afleverbrief'; END IF;
|
|
1787
|
+
v_etiket := v_type = ANY (ARRAY['sticker','traysticker','etiket','verzendlabel','productlabel','barcode_label','barcodelabel']);
|
|
1788
|
+
IF v_plek IS NULL AND v_wp IS NOT NULL THEN
|
|
1789
|
+
SELECT c.print_plek_id INTO v_plek FROM print_plek_computers c WHERE c.computer_naam = v_wp LIMIT 1;
|
|
1790
|
+
END IF;
|
|
1791
|
+
IF v_plek IS NULL AND v_wpid IS NOT NULL THEN
|
|
1792
|
+
SELECT w2.print_plek_id INTO v_plek FROM print_werkplekken w2 WHERE w2.id = v_wpid;
|
|
1793
|
+
END IF;
|
|
1794
|
+
IF v_layout IS NULL THEN
|
|
1795
|
+
SELECT l.id, l.papierformaat INTO v_layout, v_lformaat FROM document_layouts l
|
|
1796
|
+
WHERE l.documenttype::text = v_type AND l.actief ORDER BY l.is_standaard DESC, l.updated_at DESC LIMIT 1;
|
|
1797
|
+
ELSE
|
|
1798
|
+
SELECT l.papierformaat INTO v_lformaat FROM document_layouts l WHERE l.id = v_layout;
|
|
1799
|
+
END IF;
|
|
1800
|
+
|
|
1801
|
+
IF v_etiket THEN
|
|
1802
|
+
IF v_lformaat IS NOT NULL AND public.print_formaat_klasse(v_lformaat) = 'a4' THEN
|
|
1803
|
+
-- Etiketsoort met A4-layout: niet stil naar de labelprinter; huidige route blijft.
|
|
1804
|
+
v_melding := 'geen_etiketlayout';
|
|
1805
|
+
ELSE
|
|
1806
|
+
v_label := true;
|
|
1807
|
+
IF v_formaat IS NULL OR public.print_formaat_klasse(v_formaat) = 'a4' THEN
|
|
1808
|
+
v_formaat := coalesce(v_lformaat, v_formaat);
|
|
1809
|
+
END IF;
|
|
1810
|
+
END IF;
|
|
1811
|
+
END IF;
|
|
1812
|
+
v_formaat := coalesce(v_formaat, v_lformaat, 'A4');
|
|
1813
|
+
v_klasse := CASE WHEN v_label THEN 'label' ELSE public.print_formaat_klasse(v_formaat) END;
|
|
1814
|
+
|
|
1815
|
+
IF v_wpid IS NOT NULL THEN
|
|
1816
|
+
v_res := public.print_werkplek_keuze(v_wpid, v_type, v_klasse);
|
|
1817
|
+
IF v_res IS NOT NULL AND (NOT v_label OR public.print_is_labelprinter((v_res->>'printer_id')::uuid)) THEN
|
|
1818
|
+
RETURN v_res || jsonb_build_object('print_plek_id',v_plek,'werkplek',v_wp,'layout_id',v_layout,
|
|
1819
|
+
'papierformaat',v_formaat,'formaat_klasse',v_klasse,'overgeslagen',v_skip,'melding',v_melding);
|
|
1820
|
+
END IF;
|
|
1821
|
+
END IF;
|
|
1822
|
+
|
|
1823
|
+
IF v_plek IS NOT NULL THEN
|
|
1824
|
+
SELECT d.id, d.printer_id INTO r FROM document_printplek_printers d
|
|
1825
|
+
WHERE d.print_plek_id = v_plek AND d.documenttype::text = v_type LIMIT 1;
|
|
1826
|
+
IF FOUND THEN
|
|
1827
|
+
ok := public.printplek_printer(v_plek, v_type) IS NOT NULL;
|
|
1828
|
+
IF ok AND v_label AND NOT public.print_is_labelprinter(r.printer_id) THEN
|
|
1829
|
+
v_skip := v_skip || jsonb_build_object('bron','printplek','regel_id',r.id,'printer_id',r.printer_id,'reden','geen_labelprinter');
|
|
1830
|
+
ELSIF ok THEN
|
|
1831
|
+
RETURN jsonb_build_object('bron','printplek','printer_id',r.printer_id,'regel_id',r.id,
|
|
1832
|
+
'print_plek_id',v_plek,'werkplek',v_wp,'layout_id',v_layout,'papierformaat',v_formaat,'formaat_klasse',v_klasse,'overgeslagen',v_skip,'melding',v_melding);
|
|
1833
|
+
ELSE
|
|
1834
|
+
v_skip := v_skip || jsonb_build_object('bron','printplek','regel_id',r.id,'printer_id',r.printer_id,
|
|
1835
|
+
'reden', CASE WHEN r.printer_id IS NULL THEN 'ontbreekt' ELSE 'niet_bruikbaar' END);
|
|
1836
|
+
END IF;
|
|
1837
|
+
END IF;
|
|
1838
|
+
END IF;
|
|
1839
|
+
|
|
1840
|
+
IF v_wp IS NOT NULL THEN
|
|
1841
|
+
SELECT w2.id, w2.printer_id INTO r FROM document_werkplek_printers w2
|
|
1842
|
+
WHERE w2.documenttype = v_type AND w2.werkplek = v_wp LIMIT 1;
|
|
1843
|
+
IF FOUND THEN
|
|
1844
|
+
SELECT EXISTS(SELECT 1 FROM printers p WHERE p.id = r.printer_id AND p.actief IS DISTINCT FROM false) INTO ok;
|
|
1845
|
+
IF ok AND v_label AND NOT public.print_is_labelprinter(r.printer_id) THEN
|
|
1846
|
+
v_skip := v_skip || jsonb_build_object('bron','werkplek','regel_id',r.id,'printer_id',r.printer_id,'reden','geen_labelprinter');
|
|
1847
|
+
ELSIF ok THEN
|
|
1848
|
+
RETURN jsonb_build_object('bron','werkplek','printer_id',r.printer_id,'regel_id',r.id,
|
|
1849
|
+
'print_plek_id',v_plek,'werkplek',v_wp,'layout_id',v_layout,'papierformaat',v_formaat,'formaat_klasse',v_klasse,'overgeslagen',v_skip,'melding',v_melding);
|
|
1850
|
+
ELSE
|
|
1851
|
+
v_skip := v_skip || jsonb_build_object('bron','werkplek','regel_id',r.id,'printer_id',r.printer_id,
|
|
1852
|
+
'reden', CASE WHEN r.printer_id IS NULL THEN 'ontbreekt' ELSE 'inactief' END);
|
|
1853
|
+
END IF;
|
|
1854
|
+
END IF;
|
|
1855
|
+
END IF;
|
|
1856
|
+
|
|
1857
|
+
FOR r IN SELECT f.id, f.printer_id, (p.id IS NOT NULL AND p.actief IS DISTINCT FROM false) AS bruikbaar
|
|
1858
|
+
FROM document_formaat_printers f LEFT JOIN printers p ON p.id = f.printer_id
|
|
1859
|
+
WHERE f.documenttype = v_type ORDER BY (f.formaat_code = v_formaat) DESC LOOP
|
|
1860
|
+
IF r.bruikbaar AND v_label AND NOT public.print_is_labelprinter(r.printer_id) THEN
|
|
1861
|
+
v_skip := v_skip || jsonb_build_object('bron','standaard','regel_id',r.id,'printer_id',r.printer_id,'reden','geen_labelprinter');
|
|
1862
|
+
ELSIF r.bruikbaar THEN
|
|
1863
|
+
RETURN jsonb_build_object('bron','standaard','printer_id',r.printer_id,'regel_id',r.id,
|
|
1864
|
+
'print_plek_id',v_plek,'werkplek',v_wp,'layout_id',v_layout,'papierformaat',v_formaat,'formaat_klasse',v_klasse,'overgeslagen',v_skip,'melding',v_melding);
|
|
1865
|
+
ELSE
|
|
1866
|
+
v_skip := v_skip || jsonb_build_object('bron','standaard','regel_id',r.id,'printer_id',r.printer_id,
|
|
1867
|
+
'reden', CASE WHEN r.printer_id IS NULL THEN 'ontbreekt' ELSE 'inactief' END);
|
|
1868
|
+
END IF;
|
|
1869
|
+
END LOOP;
|
|
1870
|
+
|
|
1871
|
+
IF v_plek IS NOT NULL THEN
|
|
1872
|
+
IF v_label THEN
|
|
1873
|
+
-- Etiketsoort zonder werkplek: alleen als de printplek precies één labelprinter heeft.
|
|
1874
|
+
SELECT count(DISTINCT w2.label_printer_id), min(w2.label_printer_id::text)::uuid INTO v_cnt, v_lp
|
|
1875
|
+
FROM print_werkplekken w2 WHERE w2.print_plek_id = v_plek AND w2.actief AND w2.label_printer_id IS NOT NULL
|
|
1876
|
+
AND public.print_is_labelprinter(w2.label_printer_id);
|
|
1877
|
+
IF v_cnt = 1 THEN
|
|
1878
|
+
SELECT w2.id, w2.naam INTO w FROM print_werkplekken w2
|
|
1879
|
+
WHERE w2.print_plek_id = v_plek AND w2.actief AND w2.label_printer_id = v_lp ORDER BY w2.created_at LIMIT 1;
|
|
1880
|
+
RETURN jsonb_build_object('bron','werkplek_formaat','printer_id',v_lp,'regel_id',w.id,
|
|
1881
|
+
'werkplek_id',w.id,'werkplek_naam',w.naam,'printer_rol','label',
|
|
1882
|
+
'print_plek_id',v_plek,'werkplek',v_wp,'layout_id',v_layout,'papierformaat',v_formaat,'formaat_klasse',v_klasse,'overgeslagen',v_skip,'melding',v_melding);
|
|
1883
|
+
ELSIF v_cnt > 1 THEN
|
|
1884
|
+
v_melding := 'meerdere_labelprinters';
|
|
1885
|
+
ELSE
|
|
1886
|
+
v_melding := 'geen_labelprinter';
|
|
1887
|
+
END IF;
|
|
1888
|
+
ELSE
|
|
1889
|
+
FOR w IN SELECT id FROM print_werkplekken WHERE print_plek_id = v_plek AND actief ORDER BY created_at LOOP
|
|
1890
|
+
v_res := public.print_werkplek_keuze(w.id, v_type, v_klasse);
|
|
1891
|
+
IF v_res IS NOT NULL THEN
|
|
1892
|
+
RETURN v_res || jsonb_build_object('print_plek_id',v_plek,'werkplek',v_wp,'layout_id',v_layout,
|
|
1893
|
+
'papierformaat',v_formaat,'formaat_klasse',v_klasse,'overgeslagen',v_skip,'melding',v_melding);
|
|
1894
|
+
END IF;
|
|
1895
|
+
END LOOP;
|
|
1896
|
+
END IF;
|
|
1897
|
+
ELSIF v_label THEN
|
|
1898
|
+
v_melding := coalesce(v_melding, 'geen_labelprinter');
|
|
1899
|
+
END IF;
|
|
1900
|
+
|
|
1901
|
+
RETURN jsonb_build_object('bron','geen','printer_id',NULL,'regel_id',NULL,
|
|
1902
|
+
'print_plek_id',v_plek,'werkplek',v_wp,'layout_id',v_layout,'papierformaat',v_formaat,'formaat_klasse',v_klasse,'overgeslagen',v_skip,'melding',v_melding);
|
|
1903
|
+
END $function$;
|
|
1904
|
+
|
|
1905
|
+
CREATE OR REPLACE FUNCTION public.printer_verwijder_verwijzingen(_plek uuid, _printer uuid)
|
|
1906
|
+
RETURNS jsonb
|
|
1907
|
+
LANGUAGE sql
|
|
1908
|
+
STABLE
|
|
1909
|
+
SET search_path TO 'public'
|
|
1910
|
+
AS $function$
|
|
1911
|
+
SELECT jsonb_build_object(
|
|
1912
|
+
'printplek_regels', (SELECT count(*) FROM document_printplek_printers WHERE print_plek_id = _plek AND printer_id = _printer),
|
|
1913
|
+
'werkplek_regels', (SELECT coalesce(jsonb_agg(jsonb_build_object('werkplek', w.werkplek, 'documenttype', w.documenttype)), '[]'::jsonb)
|
|
1914
|
+
FROM document_werkplek_printers w
|
|
1915
|
+
WHERE w.printer_id = _printer
|
|
1916
|
+
AND w.werkplek IN (SELECT computer_naam FROM print_plek_computers WHERE print_plek_id = _plek)),
|
|
1917
|
+
'werkplekken', (SELECT coalesce(jsonb_agg(jsonb_build_object('naam', k.naam,
|
|
1918
|
+
'rol', CASE WHEN k.a4_printer_id = _printer AND k.label_printer_id = _printer THEN 'A4 en label'
|
|
1919
|
+
WHEN k.a4_printer_id = _printer THEN 'A4' ELSE 'label' END)), '[]'::jsonb)
|
|
1920
|
+
FROM print_werkplekken k WHERE k.a4_printer_id = _printer OR k.label_printer_id = _printer)
|
|
1921
|
+
)
|
|
1922
|
+
$function$;
|
|
1923
|
+
|
|
1924
|
+
CREATE OR REPLACE FUNCTION public.printers_beheer_velden_bewaken()
|
|
1925
|
+
RETURNS trigger
|
|
1926
|
+
LANGUAGE plpgsql
|
|
1927
|
+
SECURITY DEFINER
|
|
1928
|
+
SET search_path TO 'public'
|
|
1929
|
+
AS $function$
|
|
1930
|
+
BEGIN
|
|
1931
|
+
IF auth.uid() IS NULL OR current_user IN ('service_role','postgres','supabase_admin') THEN RETURN NEW; END IF;
|
|
1932
|
+
IF (NEW.weergavenaam IS DISTINCT FROM OLD.weergavenaam OR NEW.verborgen IS DISTINCT FROM OLD.verborgen
|
|
1933
|
+
OR NEW.is_virtueel IS DISTINCT FROM OLD.is_virtueel OR NEW.geladen_etiket IS DISTINCT FROM OLD.geladen_etiket)
|
|
1934
|
+
AND NOT (public.has_role(auth.uid(),'admin') OR public.has_role(auth.uid(),'superadmin')) THEN
|
|
1935
|
+
RAISE EXCEPTION 'ALLEEN_BEHEERDER: alleen beheerders kunnen printernaam, verbergen, virtueel of geladen etiket wijzigen' USING ERRCODE = '42501';
|
|
1936
|
+
END IF;
|
|
1937
|
+
RETURN NEW;
|
|
1938
|
+
END $function$;
|
|
1939
|
+
|
|
1940
|
+
CREATE OR REPLACE FUNCTION public.printplek_printer(_plek uuid, _documenttype text)
|
|
1941
|
+
RETURNS uuid
|
|
1942
|
+
LANGUAGE sql
|
|
1943
|
+
STABLE
|
|
1944
|
+
SET search_path TO 'public'
|
|
1945
|
+
AS $function$
|
|
1946
|
+
SELECT d.printer_id FROM document_printplek_printers d
|
|
1947
|
+
JOIN print_plek_printers pp ON pp.print_plek_id = d.print_plek_id AND pp.printer_id = d.printer_id
|
|
1948
|
+
JOIN printers p ON p.id = d.printer_id AND p.actief IS DISTINCT FROM false
|
|
1949
|
+
WHERE d.print_plek_id = _plek AND d.documenttype::text = _documenttype
|
|
1950
|
+
LIMIT 1;
|
|
1951
|
+
$function$;
|
|
1952
|
+
|
|
1953
|
+
CREATE OR REPLACE FUNCTION public.printplek_verwijder_impact(_id uuid)
|
|
1954
|
+
RETURNS jsonb
|
|
1955
|
+
LANGUAGE sql
|
|
1956
|
+
STABLE
|
|
1957
|
+
SET search_path TO 'public'
|
|
1958
|
+
AS $function$
|
|
1959
|
+
SELECT jsonb_build_object(
|
|
1960
|
+
'computers', coalesce((SELECT jsonb_agg(computer_naam ORDER BY computer_naam) FROM print_plek_computers WHERE print_plek_id=_id),'[]'::jsonb),
|
|
1961
|
+
'regels', (SELECT count(*) FROM document_printplek_printers WHERE print_plek_id=_id),
|
|
1962
|
+
'printers', (SELECT count(*) FROM print_plek_printers WHERE print_plek_id=_id),
|
|
1963
|
+
'koppelingen', coalesce((SELECT jsonb_agg(coalesce(label,bron) ORDER BY label) FROM print_plek_koppelingen WHERE print_plek_id=_id),'[]'::jsonb));
|
|
1964
|
+
$function$;
|
|
1965
|
+
|
|
1966
|
+
CREATE OR REPLACE FUNCTION public.release_local_pdf_job(_job_id uuid, _writer_id text)
|
|
1967
|
+
RETURNS boolean
|
|
1968
|
+
LANGUAGE plpgsql
|
|
1969
|
+
SET search_path TO 'public'
|
|
1970
|
+
AS $function$
|
|
1971
|
+
begin
|
|
1972
|
+
if auth.uid() is null then raise exception 'Niet ingelogd'; end if;
|
|
1973
|
+
update public.print_jobs
|
|
1974
|
+
set lokale_pdf_status = 'gereed',
|
|
1975
|
+
lokale_pdf_claim_id = null,
|
|
1976
|
+
lokale_pdf_claim_tot = null,
|
|
1977
|
+
updated_at = now()
|
|
1978
|
+
where id = _job_id
|
|
1979
|
+
and lokale_pdf_claim_id = _writer_id
|
|
1980
|
+
and lokale_pdf_status = 'bezig'
|
|
1981
|
+
and status <> 'geannuleerd';
|
|
1982
|
+
return found;
|
|
1983
|
+
end;
|
|
1984
|
+
$function$;
|
|
1985
|
+
|
|
1986
|
+
CREATE OR REPLACE FUNCTION public.release_print_queue_lease(_naam text, _houder uuid)
|
|
1987
|
+
RETURNS boolean
|
|
1988
|
+
LANGUAGE plpgsql
|
|
1989
|
+
SECURITY DEFINER
|
|
1990
|
+
SET search_path TO 'public'
|
|
1991
|
+
AS $function$
|
|
1992
|
+
begin
|
|
1993
|
+
delete from public.print_queue_leases where naam = _naam and houder = _houder;
|
|
1994
|
+
return found;
|
|
1995
|
+
end;
|
|
1996
|
+
$function$;
|
|
1997
|
+
|
|
1998
|
+
CREATE OR REPLACE FUNCTION public.resolve_print_job_printer_id(_job print_jobs)
|
|
1999
|
+
RETURNS uuid
|
|
2000
|
+
LANGUAGE sql
|
|
2001
|
+
STABLE SECURITY DEFINER
|
|
2002
|
+
SET search_path TO 'public'
|
|
2003
|
+
AS $function$
|
|
2004
|
+
SELECT COALESCE(
|
|
2005
|
+
_job.printer_id,
|
|
2006
|
+
NULLIF(public.printer_routering(
|
|
2007
|
+
CASE lower(COALESCE(_job.documenttype::text, '')) WHEN 'verzendbrief' THEN 'afleverbrief' ELSE lower(COALESCE(_job.documenttype::text, '')) END,
|
|
2008
|
+
COALESCE(NULLIF(_job.payload->>'print_plek_id', '')::uuid, NULLIF(_job.payload->'data'->>'print_plek_id', '')::uuid),
|
|
2009
|
+
NULLIF(COALESCE(_job.payload->>'werkplek', _job.payload->'data'->>'werkplek'), ''),
|
|
2010
|
+
_job.layout_id,
|
|
2011
|
+
NULL
|
|
2012
|
+
)->>'printer_id', '')::uuid
|
|
2013
|
+
);
|
|
2014
|
+
$function$;
|
|
2015
|
+
|
|
2016
|
+
CREATE OR REPLACE FUNCTION public.ruim_print_jobs_op(_bewaar_dagen integer DEFAULT 90)
|
|
2017
|
+
RETURNS integer
|
|
2018
|
+
LANGUAGE plpgsql
|
|
2019
|
+
SECURITY DEFINER
|
|
2020
|
+
SET search_path TO 'public'
|
|
2021
|
+
AS $function$
|
|
2022
|
+
DECLARE
|
|
2023
|
+
_grens timestamptz := now() - make_interval(days => GREATEST(_bewaar_dagen, 1));
|
|
2024
|
+
_aantal integer := 0;
|
|
2025
|
+
_heeft_log boolean;
|
|
2026
|
+
BEGIN
|
|
2027
|
+
SELECT EXISTS (
|
|
2028
|
+
SELECT 1 FROM information_schema.tables
|
|
2029
|
+
WHERE table_schema = 'public' AND table_name = 'pickstation_print_log'
|
|
2030
|
+
) INTO _heeft_log;
|
|
2031
|
+
|
|
2032
|
+
DELETE FROM public.print_job_logs l
|
|
2033
|
+
USING public.print_jobs j
|
|
2034
|
+
WHERE l.job_id = j.id
|
|
2035
|
+
AND j.status IN ('voltooid', 'geannuleerd')
|
|
2036
|
+
AND COALESCE(j.voltooid_op, j.updated_at) < _grens;
|
|
2037
|
+
|
|
2038
|
+
IF _heeft_log THEN
|
|
2039
|
+
DELETE FROM public.print_jobs j
|
|
2040
|
+
WHERE j.status IN ('voltooid', 'geannuleerd')
|
|
2041
|
+
AND COALESCE(j.voltooid_op, j.updated_at) < _grens
|
|
2042
|
+
AND NOT EXISTS (
|
|
2043
|
+
SELECT 1 FROM public.pickstation_print_log p WHERE p.job_id = j.id
|
|
2044
|
+
);
|
|
2045
|
+
ELSE
|
|
2046
|
+
DELETE FROM public.print_jobs j
|
|
2047
|
+
WHERE j.status IN ('voltooid', 'geannuleerd')
|
|
2048
|
+
AND COALESCE(j.voltooid_op, j.updated_at) < _grens;
|
|
2049
|
+
END IF;
|
|
2050
|
+
|
|
2051
|
+
GET DIAGNOSTICS _aantal = ROW_COUNT;
|
|
2052
|
+
RETURN _aantal;
|
|
2053
|
+
END;
|
|
2054
|
+
$function$;
|
|
2055
|
+
|
|
2056
|
+
CREATE OR REPLACE FUNCTION public.run_print_queue_ticks()
|
|
2057
|
+
RETURNS integer
|
|
2058
|
+
LANGUAGE plpgsql
|
|
2059
|
+
SECURITY DEFINER
|
|
2060
|
+
SET search_path TO 'public'
|
|
2061
|
+
AS $function$
|
|
2062
|
+
declare
|
|
2063
|
+
r record;
|
|
2064
|
+
v_shell text := public.print_shell_url();
|
|
2065
|
+
v_status integer;
|
|
2066
|
+
v_fout text;
|
|
2067
|
+
v_req bigint;
|
|
2068
|
+
begin
|
|
2069
|
+
if v_shell is null then
|
|
2070
|
+
perform public._print_meld_stilstand('Geen Shell-adres ingesteld', null);
|
|
2071
|
+
return 0;
|
|
2072
|
+
end if;
|
|
2073
|
+
|
|
2074
|
+
select id, basis_url, tick_sleutel, laatste_request_id, laatste_ok, created_at
|
|
2075
|
+
into r
|
|
2076
|
+
from public.print_queue_runners
|
|
2077
|
+
where public.print_url_norm(basis_url) = v_shell
|
|
2078
|
+
order by laatst_gezien desc nulls last
|
|
2079
|
+
limit 1;
|
|
2080
|
+
|
|
2081
|
+
if r.id is null then
|
|
2082
|
+
perform public._print_meld_stilstand('De Shell heeft zich nog niet aangemeld', null);
|
|
2083
|
+
return 0;
|
|
2084
|
+
end if;
|
|
2085
|
+
|
|
2086
|
+
if r.laatste_request_id is not null then
|
|
2087
|
+
v_status := null; v_fout := null;
|
|
2088
|
+
begin
|
|
2089
|
+
select status_code, error_msg into v_status, v_fout
|
|
2090
|
+
from net._http_response where id = r.laatste_request_id;
|
|
2091
|
+
exception when others then v_status := null;
|
|
2092
|
+
end;
|
|
2093
|
+
if v_status between 200 and 299 then
|
|
2094
|
+
update public.print_queue_runners
|
|
2095
|
+
set mislukte_posts = 0, laatste_fout = null, laatste_ok = now()
|
|
2096
|
+
where id = r.id;
|
|
2097
|
+
update public.print_shell_stilstand set opgelost_op = now() where opgelost_op is null;
|
|
2098
|
+
r.laatste_ok := now();
|
|
2099
|
+
elsif v_status is not null or v_fout is not null then
|
|
2100
|
+
update public.print_queue_runners
|
|
2101
|
+
set mislukte_posts = mislukte_posts + 1,
|
|
2102
|
+
laatste_fout = coalesce(v_fout, 'HTTP ' || v_status::text)
|
|
2103
|
+
where id = r.id;
|
|
2104
|
+
end if;
|
|
2105
|
+
end if;
|
|
2106
|
+
|
|
2107
|
+
if coalesce(r.laatste_ok, r.created_at) < now() - interval '5 minutes' then
|
|
2108
|
+
perform public._print_meld_stilstand('De Shell reageert niet', coalesce(r.laatste_ok, r.created_at));
|
|
2109
|
+
end if;
|
|
2110
|
+
|
|
2111
|
+
-- Geen stille wissel: alleen de Shell wordt aangeroepen, ook als hij niet reageert.
|
|
2112
|
+
select net.http_post(
|
|
2113
|
+
url := rtrim(r.basis_url, '/') || '/api/public/print/queue-tick',
|
|
2114
|
+
headers := jsonb_build_object('Content-Type','application/json','apikey', r.tick_sleutel),
|
|
2115
|
+
body := '{}'::jsonb
|
|
2116
|
+
) into v_req;
|
|
2117
|
+
update public.print_queue_runners set laatste_request_id = v_req where id = r.id;
|
|
2118
|
+
return 1;
|
|
2119
|
+
end;
|
|
2120
|
+
$function$;
|
|
2121
|
+
|
|
2122
|
+
CREATE OR REPLACE FUNCTION public.set_updated_at_print_queue_runners()
|
|
2123
|
+
RETURNS trigger
|
|
2124
|
+
LANGUAGE plpgsql
|
|
2125
|
+
SET search_path TO 'public'
|
|
2126
|
+
AS $function$
|
|
2127
|
+
BEGIN
|
|
2128
|
+
NEW.updated_at = now();
|
|
2129
|
+
RETURN NEW;
|
|
2130
|
+
END;
|
|
2131
|
+
$function$;
|
|
2132
|
+
|
|
2133
|
+
CREATE OR REPLACE FUNCTION public.sticker_past_controle(_sticker_ids text[], _print_plek_id uuid DEFAULT NULL::uuid)
|
|
2134
|
+
RETURNS jsonb
|
|
2135
|
+
LANGUAGE plpgsql
|
|
2136
|
+
STABLE SECURITY DEFINER
|
|
2137
|
+
SET search_path TO 'public'
|
|
2138
|
+
AS $function$
|
|
2139
|
+
DECLARE
|
|
2140
|
+
sid text; c record; b numeric; h numeric; code text; pid uuid; p record;
|
|
2141
|
+
eb numeric; eh numeric; uit jsonb := '[]'::jsonb; soort text; label text;
|
|
2142
|
+
BEGIN
|
|
2143
|
+
FOREACH sid IN ARRAY coalesce(_sticker_ids, ARRAY[]::text[]) LOOP
|
|
2144
|
+
SELECT * INTO c FROM floriday_customer_stickers_cache
|
|
2145
|
+
WHERE floriday_id = sid AND NOT is_deleted ORDER BY updated_at DESC LIMIT 1;
|
|
2146
|
+
IF NOT FOUND THEN
|
|
2147
|
+
uit := uit || jsonb_build_object('sticker_id', sid, 'uitkomst', 'onbekend',
|
|
2148
|
+
'melding', 'Deze klantsticker is niet gevonden; de maat is onbekend. Er wordt niets geprint.');
|
|
2149
|
+
CONTINUE;
|
|
2150
|
+
END IF;
|
|
2151
|
+
soort := CASE upper(coalesce(c.sticker_type,'')) WHEN 'POT' THEN 'Potsticker' WHEN '' THEN 'Klantsticker' ELSE 'Klantsticker (' || c.sticker_type || ')' END;
|
|
2152
|
+
IF c.should_be_printed IS FALSE THEN
|
|
2153
|
+
uit := uit || jsonb_build_object('sticker_id', sid, 'uitkomst', 'niet_nodig', 'sticker_type', c.sticker_type,
|
|
2154
|
+
'melding', 'De koper heeft aangegeven dat deze sticker niet geprint hoeft te worden.');
|
|
2155
|
+
CONTINUE;
|
|
2156
|
+
END IF;
|
|
2157
|
+
b := c.sticker_width_mm; h := c.sticker_height_mm;
|
|
2158
|
+
IF b IS NULL OR h IS NULL OR b <= 0 OR h <= 0 THEN
|
|
2159
|
+
uit := uit || jsonb_build_object('sticker_id', sid, 'uitkomst', 'onbekend', 'sticker_type', c.sticker_type,
|
|
2160
|
+
'melding', 'De maat van deze klantsticker is onbekend; er wordt niets geprint.');
|
|
2161
|
+
CONTINUE;
|
|
2162
|
+
END IF;
|
|
2163
|
+
label := soort || ' ' || round(b)::text || ' × ' || round(h)::text || ' mm';
|
|
2164
|
+
code := least(round(b), round(h))::text || 'x' || greatest(round(b), round(h))::text;
|
|
2165
|
+
pid := NULL;
|
|
2166
|
+
SELECT f.printer_id INTO pid FROM document_formaat_printers f
|
|
2167
|
+
WHERE f.documenttype = 'sticker' AND f.printer_id IS NOT NULL
|
|
2168
|
+
AND (SELECT least(m[1]::int, m[2]::int)::text || 'x' || greatest(m[1]::int, m[2]::int)::text
|
|
2169
|
+
FROM regexp_match(f.formaat_code, '(\d+)\s*x\s*(\d+)\s*$', 'i') m) = code
|
|
2170
|
+
LIMIT 1;
|
|
2171
|
+
IF pid IS NULL AND _print_plek_id IS NOT NULL THEN
|
|
2172
|
+
SELECT w.label_printer_id INTO pid FROM print_werkplekken w
|
|
2173
|
+
WHERE w.actief AND w.print_plek_id = _print_plek_id AND w.label_printer_id IS NOT NULL
|
|
2174
|
+
ORDER BY w.naam LIMIT 1;
|
|
2175
|
+
END IF;
|
|
2176
|
+
IF pid IS NULL THEN
|
|
2177
|
+
uit := uit || jsonb_build_object('sticker_id', sid, 'uitkomst', 'past_niet', 'sticker_type', c.sticker_type,
|
|
2178
|
+
'breedte_mm', b, 'hoogte_mm', h, 'melding', label || ': er is geen labelprinter voor dit formaat ingesteld. Er wordt niets geprint.');
|
|
2179
|
+
CONTINUE;
|
|
2180
|
+
END IF;
|
|
2181
|
+
SELECT id, coalesce(weergavenaam, naam) AS naam, geladen_etiket INTO p FROM printers WHERE id = pid;
|
|
2182
|
+
eb := nullif(p.geladen_etiket->>'breedte_mm','')::numeric;
|
|
2183
|
+
eh := nullif(p.geladen_etiket->>'hoogte_mm','')::numeric;
|
|
2184
|
+
IF eb IS NULL OR eh IS NULL THEN
|
|
2185
|
+
uit := uit || jsonb_build_object('sticker_id', sid, 'uitkomst', 'past_niet', 'sticker_type', c.sticker_type,
|
|
2186
|
+
'breedte_mm', b, 'hoogte_mm', h, 'printer_id', p.id, 'printer_naam', p.naam,
|
|
2187
|
+
'melding', 'Er is nog niet ingesteld welk etiket in labelprinter ' || p.naam || ' zit.');
|
|
2188
|
+
ELSIF (b <= eb + 2 AND h <= eh + 2) OR (b <= eh + 2 AND h <= eb + 2) THEN
|
|
2189
|
+
uit := uit || jsonb_build_object('sticker_id', sid, 'uitkomst', 'past', 'sticker_type', c.sticker_type,
|
|
2190
|
+
'breedte_mm', b, 'hoogte_mm', h, 'printer_id', p.id, 'printer_naam', p.naam, 'geladen_etiket', p.geladen_etiket,
|
|
2191
|
+
'melding', label || ' past op het etiket in ' || p.naam || '.');
|
|
2192
|
+
ELSE
|
|
2193
|
+
uit := uit || jsonb_build_object('sticker_id', sid, 'uitkomst', 'past_niet', 'sticker_type', c.sticker_type,
|
|
2194
|
+
'breedte_mm', b, 'hoogte_mm', h, 'printer_id', p.id, 'printer_naam', p.naam, 'geladen_etiket', p.geladen_etiket,
|
|
2195
|
+
'melding', label || ' past niet op het etiket in ' || p.naam || ' (' || round(eb) || ' × ' || round(eh) || ' mm). Leg etiketten van minimaal ' || round(b) || ' × ' || round(h) || ' mm in of kies een andere printer.');
|
|
2196
|
+
END IF;
|
|
2197
|
+
END LOOP;
|
|
2198
|
+
RETURN uit;
|
|
2199
|
+
END $function$;
|
|
2200
|
+
|
|
2201
|
+
CREATE OR REPLACE FUNCTION public.update_updated_at_column()
|
|
2202
|
+
RETURNS trigger
|
|
2203
|
+
LANGUAGE plpgsql
|
|
2204
|
+
SET search_path TO 'public'
|
|
2205
|
+
AS $function$ BEGIN NEW.updated_at = now(); RETURN NEW; END; $function$;
|
|
2206
|
+
|
|
2207
|
+
CREATE OR REPLACE FUNCTION public.vervang_printer(_oud uuid, _nieuw uuid)
|
|
2208
|
+
RETURNS jsonb
|
|
2209
|
+
LANGUAGE plpgsql
|
|
2210
|
+
SET search_path TO 'public'
|
|
2211
|
+
AS $function$
|
|
2212
|
+
DECLARE v jsonb; a int; b int; c int; d int;
|
|
2213
|
+
BEGIN
|
|
2214
|
+
IF _oud IS NULL THEN RAISE EXCEPTION 'GEEN_PRINTER: geef de te vervangen printer op.'; END IF;
|
|
2215
|
+
IF _nieuw = _oud THEN RAISE EXCEPTION 'ZELFDE_PRINTER: kies een andere printer.'; END IF;
|
|
2216
|
+
IF _nieuw IS NOT NULL THEN
|
|
2217
|
+
INSERT INTO print_plek_printers (print_plek_id, printer_id)
|
|
2218
|
+
SELECT print_plek_id, _nieuw FROM print_plek_printers WHERE printer_id = _oud
|
|
2219
|
+
ON CONFLICT DO NOTHING;
|
|
2220
|
+
END IF;
|
|
2221
|
+
UPDATE document_printplek_printers SET printer_id = _nieuw WHERE printer_id = _oud; GET DIAGNOSTICS a = ROW_COUNT;
|
|
2222
|
+
UPDATE document_werkplek_printers SET printer_id = _nieuw WHERE printer_id = _oud; GET DIAGNOSTICS b = ROW_COUNT;
|
|
2223
|
+
UPDATE printer_mappings SET printer_id = _nieuw WHERE printer_id = _oud; GET DIAGNOSTICS c = ROW_COUNT;
|
|
2224
|
+
UPDATE document_formaat_printers SET printer_id = _nieuw WHERE printer_id = _oud; GET DIAGNOSTICS d = ROW_COUNT;
|
|
2225
|
+
DELETE FROM print_plek_printers WHERE printer_id = _oud;
|
|
2226
|
+
RETURN jsonb_build_object('printplek_regels', a, 'werkplek_regels', b, 'layout_koppelingen', c, 'standaardregels', d);
|
|
2227
|
+
END $function$;
|
|
2228
|
+
|
|
2229
|
+
CREATE OR REPLACE FUNCTION public.verwijder_printplek(_id uuid)
|
|
2230
|
+
RETURNS jsonb
|
|
2231
|
+
LANGUAGE plpgsql
|
|
2232
|
+
SET search_path TO 'public'
|
|
2233
|
+
AS $function$
|
|
2234
|
+
DECLARE v jsonb;
|
|
2235
|
+
BEGIN
|
|
2236
|
+
IF auth.uid() IS NULL AND coalesce(auth.role(),'') <> 'service_role' THEN
|
|
2237
|
+
RAISE EXCEPTION 'NIET_INGELOGD';
|
|
2238
|
+
END IF;
|
|
2239
|
+
IF NOT EXISTS (SELECT 1 FROM print_plekken WHERE id=_id) THEN
|
|
2240
|
+
RAISE EXCEPTION 'PRINTPLEK_ONBEKEND';
|
|
2241
|
+
END IF;
|
|
2242
|
+
v := public.printplek_verwijder_impact(_id);
|
|
2243
|
+
DELETE FROM document_printplek_printers WHERE print_plek_id=_id;
|
|
2244
|
+
DELETE FROM print_plek_computers WHERE print_plek_id=_id;
|
|
2245
|
+
DELETE FROM print_plek_printers WHERE print_plek_id=_id;
|
|
2246
|
+
DELETE FROM print_plek_koppelingen WHERE print_plek_id=_id;
|
|
2247
|
+
DELETE FROM print_plekken WHERE id=_id;
|
|
2248
|
+
RETURN v;
|
|
2249
|
+
END $function$;
|
|
2250
|
+
|
|
2251
|
+
CREATE OR REPLACE FUNCTION public.wake_print_queue(_min_interval_ms integer DEFAULT 1500)
|
|
2252
|
+
RETURNS integer
|
|
2253
|
+
LANGUAGE plpgsql
|
|
2254
|
+
SECURITY DEFINER
|
|
2255
|
+
SET search_path TO 'public'
|
|
2256
|
+
AS $function$
|
|
2257
|
+
declare
|
|
2258
|
+
r record;
|
|
2259
|
+
v_shell text := public.print_shell_url();
|
|
2260
|
+
v_req bigint;
|
|
2261
|
+
begin
|
|
2262
|
+
if v_shell is null then return 0; end if;
|
|
2263
|
+
select id, basis_url, tick_sleutel into r
|
|
2264
|
+
from public.print_queue_runners
|
|
2265
|
+
where public.print_url_norm(basis_url) = v_shell
|
|
2266
|
+
and (laatste_wakeup is null
|
|
2267
|
+
or laatste_wakeup < now() - make_interval(secs => greatest(0, _min_interval_ms) / 1000.0))
|
|
2268
|
+
order by laatst_gezien desc nulls last
|
|
2269
|
+
limit 1
|
|
2270
|
+
for update skip locked;
|
|
2271
|
+
if r.id is null then return 0; end if;
|
|
2272
|
+
begin
|
|
2273
|
+
select net.http_post(
|
|
2274
|
+
url := rtrim(r.basis_url, '/') || '/api/public/print/queue-tick',
|
|
2275
|
+
headers := jsonb_build_object('Content-Type','application/json','apikey', r.tick_sleutel),
|
|
2276
|
+
body := '{}'::jsonb
|
|
2277
|
+
) into v_req;
|
|
2278
|
+
update public.print_queue_runners set laatste_wakeup = now(), laatste_request_id = v_req where id = r.id;
|
|
2279
|
+
return 1;
|
|
2280
|
+
exception when others then
|
|
2281
|
+
update public.print_queue_runners
|
|
2282
|
+
set laatste_wakeup = now(), mislukte_wakeups = mislukte_wakeups + 1,
|
|
2283
|
+
laatste_fout = left('wake-up mislukt: ' || coalesce(sqlerrm, 'onbekend'), 500)
|
|
2284
|
+
where id = r.id;
|
|
2285
|
+
return 0;
|
|
2286
|
+
end;
|
|
2287
|
+
end;
|
|
2288
|
+
$function$;
|
|
2289
|
+
|
|
2290
|
+
CREATE OR REPLACE FUNCTION public.werkplek_omzetting_toepassen(_werkplekken jsonb)
|
|
2291
|
+
RETURNS jsonb
|
|
2292
|
+
LANGUAGE plpgsql
|
|
2293
|
+
SECURITY DEFINER
|
|
2294
|
+
SET search_path TO 'public'
|
|
2295
|
+
AS $function$
|
|
2296
|
+
DECLARE w jsonb; v_id uuid; v_ids jsonb := '[]'::jsonb; v_plek uuid; v_a4 uuid; v_label uuid;
|
|
2297
|
+
BEGIN
|
|
2298
|
+
IF NOT (public.has_role(auth.uid(),'admin') OR public.has_role(auth.uid(),'superadmin')) THEN
|
|
2299
|
+
RAISE EXCEPTION 'ALLEEN_BEHEERDER: alleen beheerders kunnen werkplekken aanmaken';
|
|
2300
|
+
END IF;
|
|
2301
|
+
IF jsonb_typeof(_werkplekken) IS DISTINCT FROM 'array' OR jsonb_array_length(_werkplekken) = 0 THEN
|
|
2302
|
+
RAISE EXCEPTION 'LEEG: er is niets om aan te maken';
|
|
2303
|
+
END IF;
|
|
2304
|
+
FOR w IN SELECT * FROM jsonb_array_elements(_werkplekken) LOOP
|
|
2305
|
+
IF nullif(btrim(w->>'naam'),'') IS NULL THEN RAISE EXCEPTION 'NAAM_ONTBREEKT: elke werkplek heeft een naam nodig'; END IF;
|
|
2306
|
+
v_plek := nullif(w->>'print_plek_id','')::uuid;
|
|
2307
|
+
v_a4 := nullif(w->>'a4_printer_id','')::uuid;
|
|
2308
|
+
v_label := nullif(w->>'label_printer_id','')::uuid;
|
|
2309
|
+
IF v_a4 IS NULL AND v_label IS NULL THEN RAISE EXCEPTION 'GEEN_PRINTER: werkplek % heeft geen printer', w->>'naam'; END IF;
|
|
2310
|
+
IF v_a4 IS NOT NULL AND NOT EXISTS (SELECT 1 FROM printers WHERE id = v_a4) THEN RAISE EXCEPTION 'PRINTER_ONBEKEND: A4-printer van % bestaat niet', w->>'naam'; END IF;
|
|
2311
|
+
IF v_label IS NOT NULL AND NOT EXISTS (SELECT 1 FROM printers WHERE id = v_label) THEN RAISE EXCEPTION 'PRINTER_ONBEKEND: labelprinter van % bestaat niet', w->>'naam'; END IF;
|
|
2312
|
+
IF v_plek IS NOT NULL AND NOT EXISTS (SELECT 1 FROM print_plekken WHERE id = v_plek) THEN RAISE EXCEPTION 'PRINTPLEK_ONBEKEND: printplek van % bestaat niet', w->>'naam'; END IF;
|
|
2313
|
+
IF v_plek IS NOT NULL AND EXISTS (SELECT 1 FROM print_werkplekken WHERE print_plek_id = v_plek AND actief) THEN
|
|
2314
|
+
RAISE EXCEPTION 'BESTAAT_AL: er is al een werkplek voor de printplek van %', w->>'naam';
|
|
2315
|
+
END IF;
|
|
2316
|
+
INSERT INTO print_werkplekken (naam, print_plek_id, a4_printer_id, label_printer_id, actief)
|
|
2317
|
+
VALUES (btrim(w->>'naam'), v_plek, v_a4, v_label, true) RETURNING id INTO v_id;
|
|
2318
|
+
v_ids := v_ids || to_jsonb(v_id);
|
|
2319
|
+
END LOOP;
|
|
2320
|
+
RETURN v_ids;
|
|
2321
|
+
END $function$;
|
|
2322
|
+
|
|
2323
|
+
CREATE OR REPLACE FUNCTION public.werkplek_omzetting_voorstel()
|
|
2324
|
+
RETURNS jsonb
|
|
2325
|
+
LANGUAGE plpgsql
|
|
2326
|
+
STABLE SECURITY DEFINER
|
|
2327
|
+
SET search_path TO 'public'
|
|
2328
|
+
AS $function$
|
|
2329
|
+
DECLARE
|
|
2330
|
+
pl record; t text; r jsonb; v_rows jsonb; v_a4 uuid; v_label uuid; v_kl text; v_etiket boolean;
|
|
2331
|
+
v_out jsonb := '[]'::jsonb; v_soorten text[];
|
|
2332
|
+
BEGIN
|
|
2333
|
+
IF auth.uid() IS NULL AND coalesce(auth.role(), '') <> 'service_role' THEN RAISE EXCEPTION 'NIET_INGELOGD'; END IF;
|
|
2334
|
+
SELECT array_agg(e::text ORDER BY e) INTO v_soorten FROM unnest(enum_range(NULL::doc_layout_type)) e;
|
|
2335
|
+
FOR pl IN
|
|
2336
|
+
SELECT p.id, p.naam, 1 AS volg FROM print_plekken p WHERE p.actief IS DISTINCT FROM false
|
|
2337
|
+
UNION ALL SELECT NULL::uuid, 'Kantoor', 2
|
|
2338
|
+
ORDER BY volg, naam
|
|
2339
|
+
LOOP
|
|
2340
|
+
v_rows := '[]'::jsonb;
|
|
2341
|
+
FOREACH t IN ARRAY v_soorten LOOP
|
|
2342
|
+
r := public.printer_routering(t, pl.id, NULL, NULL, NULL, NULL);
|
|
2343
|
+
v_kl := coalesce(r->>'formaat_klasse', public.print_formaat_klasse(coalesce(r->>'papierformaat','A4')));
|
|
2344
|
+
v_etiket := public.print_is_etiketsoort(t);
|
|
2345
|
+
v_rows := v_rows || jsonb_build_object('documenttype',t,'bron',r->>'bron','printer_id',r->>'printer_id',
|
|
2346
|
+
'layout_klasse', v_kl,
|
|
2347
|
+
'klasse', CASE WHEN v_etiket THEN 'label' ELSE v_kl END,
|
|
2348
|
+
'geen_etiketlayout', v_etiket AND v_kl IS DISTINCT FROM 'label');
|
|
2349
|
+
END LOOP;
|
|
2350
|
+
SELECT (x->>'printer_id')::uuid INTO v_a4 FROM jsonb_array_elements(v_rows) x
|
|
2351
|
+
WHERE x->>'klasse' = 'a4' AND x->>'printer_id' IS NOT NULL
|
|
2352
|
+
GROUP BY 1 ORDER BY count(*) DESC, 1 LIMIT 1;
|
|
2353
|
+
-- Labelprinter: alleen afgeleid uit soorten die echt een etiketlayout hebben.
|
|
2354
|
+
SELECT (x->>'printer_id')::uuid INTO v_label FROM jsonb_array_elements(v_rows) x
|
|
2355
|
+
WHERE x->>'klasse' = 'label' AND NOT (x->>'geen_etiketlayout')::boolean AND x->>'printer_id' IS NOT NULL
|
|
2356
|
+
GROUP BY 1 ORDER BY count(*) DESC, 1 LIMIT 1;
|
|
2357
|
+
IF v_a4 IS NULL AND v_label IS NULL THEN CONTINUE; END IF;
|
|
2358
|
+
SELECT coalesce(jsonb_agg(x || jsonb_build_object('na_printer_id',
|
|
2359
|
+
CASE WHEN x->>'klasse' = 'label' THEN v_label ELSE v_a4 END,
|
|
2360
|
+
'verschil', (x->>'printer_id') IS DISTINCT FROM (CASE WHEN x->>'klasse' = 'label' THEN v_label ELSE v_a4 END)::text)), '[]'::jsonb)
|
|
2361
|
+
INTO v_rows FROM jsonb_array_elements(v_rows) x;
|
|
2362
|
+
v_out := v_out || jsonb_build_object(
|
|
2363
|
+
'naam', pl.naam, 'print_plek_id', pl.id,
|
|
2364
|
+
'a4_printer_id', v_a4, 'label_printer_id', v_label,
|
|
2365
|
+
'bestaat', CASE WHEN pl.id IS NULL
|
|
2366
|
+
THEN EXISTS (SELECT 1 FROM print_werkplekken w WHERE w.print_plek_id IS NULL AND w.actief)
|
|
2367
|
+
ELSE EXISTS (SELECT 1 FROM print_werkplekken w WHERE w.print_plek_id = pl.id AND w.actief) END,
|
|
2368
|
+
'soorten', v_rows);
|
|
2369
|
+
v_a4 := NULL; v_label := NULL;
|
|
2370
|
+
END LOOP;
|
|
2371
|
+
RETURN v_out;
|
|
2372
|
+
END $function$;
|
|
2373
|
+
|
|
2374
|
+
-- 5. Indexen
|
|
2375
|
+
CREATE INDEX IF NOT EXISTS idx_layout_elements_layout ON public.document_layout_elements USING btree (layout_id);
|
|
2376
|
+
CREATE INDEX IF NOT EXISTS idx_layout_versions_layout ON public.document_layout_versions USING btree (layout_id);
|
|
2377
|
+
CREATE UNIQUE INDEX IF NOT EXISTS uniq_document_layout_standaard ON public.document_layouts USING btree (documenttype, COALESCE(bron, 'eigen'::text)) WHERE (is_standaard AND actief);
|
|
2378
|
+
CREATE INDEX IF NOT EXISTS idx_document_printplek_printers_plek ON public.document_printplek_printers USING btree (print_plek_id);
|
|
2379
|
+
CREATE UNIQUE INDEX IF NOT EXISTS layout_logos_hash_idx ON public.layout_logos USING btree (hash) WHERE (hash IS NOT NULL);
|
|
2380
|
+
CREATE UNIQUE INDEX IF NOT EXISTS layout_logos_standaard_idx ON public.layout_logos USING btree (categorie) WHERE is_standaard;
|
|
2381
|
+
CREATE INDEX IF NOT EXISTS idx_pakbon_barcode_inhoud_upper ON public.pakbon_barcode_inhoud USING btree (upper(barcode));
|
|
2382
|
+
CREATE INDEX IF NOT EXISTS pakbon_barcode_inhoud_cart_idx ON public.pakbon_barcode_inhoud USING btree (cart_id);
|
|
2383
|
+
CREATE INDEX IF NOT EXISTS pakbon_barcode_inhoud_order_idx ON public.pakbon_barcode_inhoud USING btree (order_ref);
|
|
2384
|
+
CREATE INDEX IF NOT EXISTS pakbon_barcode_verzoeken_status_idx ON public.pakbon_barcode_verzoeken USING btree (status, laatst_gevraagd_op DESC);
|
|
2385
|
+
CREATE INDEX IF NOT EXISTS print_agents_pairing_code_hash_idx ON public.print_agents USING btree (pairing_code_hash) WHERE (pairing_code_hash IS NOT NULL);
|
|
2386
|
+
CREATE UNIQUE INDEX IF NOT EXISTS print_agents_token_hash_idx ON public.print_agents USING btree (token_hash);
|
|
2387
|
+
CREATE INDEX IF NOT EXISTS print_dedupe_events_created_idx ON public.print_dedupe_events USING btree (created_at DESC);
|
|
2388
|
+
CREATE INDEX IF NOT EXISTS print_dedupe_events_sleutel_idx ON public.print_dedupe_events USING btree (idempotentie_sleutel);
|
|
2389
|
+
CREATE INDEX IF NOT EXISTS print_job_logs_job_idx ON public.print_job_logs USING btree (job_id, created_at DESC);
|
|
2390
|
+
CREATE INDEX IF NOT EXISTS idx_print_jobs_payload_cart ON public.print_jobs USING btree (((payload ->> 'cart_id'::text)));
|
|
2391
|
+
CREATE INDEX IF NOT EXISTS idx_print_jobs_status ON public.print_jobs USING btree (status, created_at DESC);
|
|
2392
|
+
CREATE UNIQUE INDEX IF NOT EXISTS print_jobs_artefact_pad_key ON public.print_jobs USING btree (artefact_pad) WHERE (artefact_pad IS NOT NULL);
|
|
2393
|
+
CREATE INDEX IF NOT EXISTS print_jobs_batch_idx ON public.print_jobs USING btree (batch_id, created_at) WHERE (batch_id IS NOT NULL);
|
|
2394
|
+
CREATE INDEX IF NOT EXISTS print_jobs_delivery_idx ON public.print_jobs USING btree (lokale_pdf_print_plek_id, lokale_pdf_status, lokale_pdf_claim_tot, created_at) WHERE ((artefact_pad IS NOT NULL) OR (resultaat_pdf_base64 IS NOT NULL));
|
|
2395
|
+
CREATE UNIQUE INDEX IF NOT EXISTS print_jobs_een_origineel_per_kar ON public.print_jobs USING btree (origineel_sleutel) WHERE ((origineel_sleutel IS NOT NULL) AND (status <> ALL (ARRAY['mislukt'::print_job_status, 'geannuleerd'::print_job_status])));
|
|
2396
|
+
CREATE INDEX IF NOT EXISTS print_jobs_extern_job_id_idx ON public.print_jobs USING btree (extern_job_id);
|
|
2397
|
+
CREATE UNIQUE INDEX IF NOT EXISTS print_jobs_idempotentie_sleutel_key ON public.print_jobs USING btree (idempotentie_sleutel) WHERE ((idempotentie_sleutel IS NOT NULL) AND (status <> ALL (ARRAY['mislukt'::print_job_status, 'geannuleerd'::print_job_status])));
|
|
2398
|
+
CREATE INDEX IF NOT EXISTS print_jobs_local_pdf_poll_idx ON public.print_jobs USING btree (lokale_pdf_status, voltooid_op) WHERE ((resultaat_pdf_base64 IS NOT NULL) AND (lokale_pdf_status IS NOT NULL));
|
|
2399
|
+
CREATE INDEX IF NOT EXISTS print_jobs_lokale_pdf_claim_idx ON public.print_jobs USING btree (lokale_pdf_print_plek_id, lokale_pdf_status, lokale_pdf_claim_tot) WHERE (resultaat_pdf_base64 IS NOT NULL);
|
|
2400
|
+
CREATE INDEX IF NOT EXISTS print_jobs_lokale_pdf_status_voltooid_idx ON public.print_jobs USING btree (lokale_pdf_status, voltooid_op) WHERE (resultaat_pdf_base64 IS NOT NULL);
|
|
2401
|
+
CREATE INDEX IF NOT EXISTS print_jobs_payload_cart_idx ON public.print_jobs USING btree (((payload ->> 'cart_id'::text)));
|
|
2402
|
+
CREATE INDEX IF NOT EXISTS print_jobs_pending_claim_idx ON public.print_jobs USING btree (status, created_at) WHERE (status = 'wachtend'::print_job_status);
|
|
2403
|
+
CREATE INDEX IF NOT EXISTS print_jobs_render_claim_idx ON public.print_jobs USING btree (status, volgende_poging, created_at) WHERE ((status = 'wachtend'::print_job_status) AND (artefact_pad IS NULL));
|
|
2404
|
+
CREATE INDEX IF NOT EXISTS print_jobs_status_idx ON public.print_jobs USING btree (status, created_at);
|
|
2405
|
+
CREATE INDEX IF NOT EXISTS print_jobs_status_sync_idx ON public.print_jobs USING btree (created_at) WHERE ((status = 'bezig'::print_job_status) AND (extern_job_id IS NOT NULL));
|
|
2406
|
+
CREATE INDEX IF NOT EXISTS print_jobs_wachtrij_idx ON public.print_jobs USING btree (status, volgende_poging, created_at);
|
|
2407
|
+
CREATE INDEX IF NOT EXISTS idx_print_plek_computers_plek ON public.print_plek_computers USING btree (print_plek_id);
|
|
2408
|
+
CREATE UNIQUE INDEX IF NOT EXISTS print_plek_computers_printnode_id_uniek ON public.print_plek_computers USING btree (printnode_computer_id) WHERE (printnode_computer_id IS NOT NULL);
|
|
2409
|
+
CREATE INDEX IF NOT EXISTS idx_print_plek_koppelingen_plek ON public.print_plek_koppelingen USING btree (print_plek_id);
|
|
2410
|
+
CREATE UNIQUE INDEX IF NOT EXISTS print_plek_koppelingen_pickstation_uniq ON public.print_plek_koppelingen USING btree (bron_id) WHERE (bron = 'pickstation'::text);
|
|
2411
|
+
CREATE INDEX IF NOT EXISTS print_preview_events_created_idx ON public.print_preview_events USING btree (created_at DESC);
|
|
2412
|
+
CREATE INDEX IF NOT EXISTS print_preview_events_station_idx ON public.print_preview_events USING btree (station_slug, created_at DESC);
|
|
2413
|
+
CREATE INDEX IF NOT EXISTS print_printer_verwijder_herstel_plek_idx ON public.print_printer_verwijder_herstel USING btree (print_plek_id, extern_printer_id) WHERE (hersteld_op IS NULL);
|
|
2414
|
+
CREATE UNIQUE INDEX IF NOT EXISTS print_werkplekken_naam_uniek ON public.print_werkplekken USING btree (lower(btrim(naam)));
|
|
2415
|
+
CREATE INDEX IF NOT EXISTS idx_printer_mappings_layout ON public.printer_mappings USING btree (layout_id);
|
|
2416
|
+
CREATE INDEX IF NOT EXISTS printnode_webhook_meldingen_op_idx ON public.printnode_webhook_meldingen USING btree (ontvangen_op DESC);
|
|
2417
|
+
|
|
2418
|
+
-- 6. Triggers
|
|
2419
|
+
drop trigger if exists "trg_ai_layout_imports_updated" on ai_layout_imports;
|
|
2420
|
+
CREATE TRIGGER trg_ai_layout_imports_updated BEFORE UPDATE ON public.ai_layout_imports FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2421
|
+
drop trigger if exists "update_document_bronregels_updated_at" on document_bronregels;
|
|
2422
|
+
CREATE TRIGGER update_document_bronregels_updated_at BEFORE UPDATE ON public.document_bronregels FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2423
|
+
drop trigger if exists "trg_document_formaat_printers_updated" on document_formaat_printers;
|
|
2424
|
+
CREATE TRIGGER trg_document_formaat_printers_updated BEFORE UPDATE ON public.document_formaat_printers FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2425
|
+
drop trigger if exists "trg_markeer_ontbrekende_printer" on document_formaat_printers;
|
|
2426
|
+
CREATE TRIGGER trg_markeer_ontbrekende_printer BEFORE UPDATE OF printer_id ON public.document_formaat_printers FOR EACH ROW EXECUTE FUNCTION markeer_ontbrekende_printer();
|
|
2427
|
+
drop trigger if exists "trg_layout_conditions_updated" on document_layout_conditions;
|
|
2428
|
+
CREATE TRIGGER trg_layout_conditions_updated BEFORE UPDATE ON public.document_layout_conditions FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2429
|
+
drop trigger if exists "trg_layout_datasources_updated" on document_layout_datasources;
|
|
2430
|
+
CREATE TRIGGER trg_layout_datasources_updated BEFORE UPDATE ON public.document_layout_datasources FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2431
|
+
drop trigger if exists "trg_layout_elements_updated" on document_layout_elements;
|
|
2432
|
+
CREATE TRIGGER trg_layout_elements_updated BEFORE UPDATE ON public.document_layout_elements FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2433
|
+
drop trigger if exists "trg_layout_variables_updated" on document_layout_variables;
|
|
2434
|
+
CREATE TRIGGER trg_layout_variables_updated BEFORE UPDATE ON public.document_layout_variables FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2435
|
+
drop trigger if exists "trg_layout_versions_updated" on document_layout_versions;
|
|
2436
|
+
CREATE TRIGGER trg_layout_versions_updated BEFORE UPDATE ON public.document_layout_versions FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2437
|
+
drop trigger if exists "trg_beveilig_systeem_layouts" on document_layouts;
|
|
2438
|
+
CREATE TRIGGER trg_beveilig_systeem_layouts BEFORE DELETE OR UPDATE ON public.document_layouts FOR EACH ROW EXECUTE FUNCTION beveilig_systeem_layouts();
|
|
2439
|
+
drop trigger if exists "trg_document_layout_een_standaard" on document_layouts;
|
|
2440
|
+
CREATE TRIGGER trg_document_layout_een_standaard BEFORE INSERT OR UPDATE OF is_standaard, actief, documenttype, bron ON public.document_layouts FOR EACH ROW EXECUTE FUNCTION document_layout_een_standaard();
|
|
2441
|
+
drop trigger if exists "trg_document_layouts_updated" on document_layouts;
|
|
2442
|
+
CREATE TRIGGER trg_document_layouts_updated BEFORE UPDATE ON public.document_layouts FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2443
|
+
drop trigger if exists "trg_controleer_printplek_printer" on document_printplek_printers;
|
|
2444
|
+
CREATE TRIGGER trg_controleer_printplek_printer BEFORE INSERT OR UPDATE ON public.document_printplek_printers FOR EACH ROW EXECUTE FUNCTION controleer_printplek_printer();
|
|
2445
|
+
drop trigger if exists "trg_document_printplek_printers_updated" on document_printplek_printers;
|
|
2446
|
+
CREATE TRIGGER trg_document_printplek_printers_updated BEFORE UPDATE ON public.document_printplek_printers FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2447
|
+
drop trigger if exists "trg_markeer_ontbrekende_printer" on document_printplek_printers;
|
|
2448
|
+
CREATE TRIGGER trg_markeer_ontbrekende_printer BEFORE UPDATE OF printer_id ON public.document_printplek_printers FOR EACH ROW EXECUTE FUNCTION markeer_ontbrekende_printer();
|
|
2449
|
+
drop trigger if exists "trg_controleer_werkplek_printer" on document_werkplek_printers;
|
|
2450
|
+
CREATE TRIGGER trg_controleer_werkplek_printer BEFORE INSERT OR UPDATE ON public.document_werkplek_printers FOR EACH ROW EXECUTE FUNCTION controleer_werkplek_printer();
|
|
2451
|
+
drop trigger if exists "trg_document_werkplek_printers_updated" on document_werkplek_printers;
|
|
2452
|
+
CREATE TRIGGER trg_document_werkplek_printers_updated BEFORE UPDATE ON public.document_werkplek_printers FOR EACH ROW EXECUTE FUNCTION set_updated_at();
|
|
2453
|
+
drop trigger if exists "trg_markeer_ontbrekende_printer" on document_werkplek_printers;
|
|
2454
|
+
CREATE TRIGGER trg_markeer_ontbrekende_printer BEFORE UPDATE OF printer_id ON public.document_werkplek_printers FOR EACH ROW EXECUTE FUNCTION markeer_ontbrekende_printer();
|
|
2455
|
+
drop trigger if exists "layout_logos_updated_at" on layout_logos;
|
|
2456
|
+
CREATE TRIGGER layout_logos_updated_at BEFORE UPDATE ON public.layout_logos FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2457
|
+
drop trigger if exists "update_pakbon_barcode_inhoud_updated_at" on pakbon_barcode_inhoud;
|
|
2458
|
+
CREATE TRIGGER update_pakbon_barcode_inhoud_updated_at BEFORE UPDATE ON public.pakbon_barcode_inhoud FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2459
|
+
drop trigger if exists "trg_guard_archived_cart" on pakbon_barcode_verzoeken;
|
|
2460
|
+
CREATE TRIGGER trg_guard_archived_cart BEFORE INSERT OR UPDATE ON public.pakbon_barcode_verzoeken FOR EACH ROW EXECUTE FUNCTION logistics_guard_archived_cart();
|
|
2461
|
+
drop trigger if exists "update_print_agents_updated_at" on print_agents;
|
|
2462
|
+
CREATE TRIGGER update_print_agents_updated_at BEFORE UPDATE ON public.print_agents FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2463
|
+
drop trigger if exists "trg_print_computer_status_updated" on print_computer_status;
|
|
2464
|
+
CREATE TRIGGER trg_print_computer_status_updated BEFORE UPDATE ON public.print_computer_status FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2465
|
+
drop trigger if exists "print_gebruiker_werkplek_upd" on print_gebruiker_werkplek;
|
|
2466
|
+
CREATE TRIGGER print_gebruiker_werkplek_upd BEFORE UPDATE ON public.print_gebruiker_werkplek FOR EACH ROW EXECUTE FUNCTION print_set_updated_at();
|
|
2467
|
+
drop trigger if exists "print_jobs_dedupe_trigger" on print_jobs;
|
|
2468
|
+
CREATE TRIGGER print_jobs_dedupe_trigger BEFORE INSERT ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION print_jobs_dedupe();
|
|
2469
|
+
drop trigger if exists "print_jobs_origineel_trigger" on print_jobs;
|
|
2470
|
+
CREATE TRIGGER print_jobs_origineel_trigger BEFORE INSERT ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION print_jobs_origineel_controle();
|
|
2471
|
+
drop trigger if exists "trg_guard_archived_cart" on print_jobs;
|
|
2472
|
+
CREATE TRIGGER trg_guard_archived_cart BEFORE INSERT OR UPDATE ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION logistics_guard_archived_cart();
|
|
2473
|
+
drop trigger if exists "trg_logistics_block_bvo_note_for_floriday" on print_jobs;
|
|
2474
|
+
CREATE TRIGGER trg_logistics_block_bvo_note_for_floriday BEFORE INSERT ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION logistics_block_bvo_note_for_floriday();
|
|
2475
|
+
drop trigger if exists "trg_logistics_require_cart_on_packing_slip" on print_jobs;
|
|
2476
|
+
CREATE TRIGGER trg_logistics_require_cart_on_packing_slip BEFORE INSERT ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION logistics_require_cart_on_packing_slip();
|
|
2477
|
+
drop trigger if exists "trg_logistics_require_pakbon_barcode" on print_jobs;
|
|
2478
|
+
CREATE TRIGGER trg_logistics_require_pakbon_barcode BEFORE INSERT OR UPDATE OF payload, documenttype ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION logistics_require_pakbon_barcode();
|
|
2479
|
+
drop trigger if exists "trg_logistics_shipping_note_after_slip" on print_jobs;
|
|
2480
|
+
CREATE TRIGGER trg_logistics_shipping_note_after_slip AFTER INSERT ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION logistics_shipping_note_after_slip();
|
|
2481
|
+
drop trigger if exists "trg_logistics_shipping_note_follow_printer" on print_jobs;
|
|
2482
|
+
CREATE TRIGGER trg_logistics_shipping_note_follow_printer AFTER UPDATE OF printer_id ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION logistics_shipping_note_follow_printer();
|
|
2483
|
+
drop trigger if exists "trg_logistics_task_status_note" on print_jobs;
|
|
2484
|
+
CREATE TRIGGER trg_logistics_task_status_note AFTER UPDATE OF status ON public.print_jobs FOR EACH ROW WHEN (((new.status = 'voltooid'::print_job_status) AND (old.status IS DISTINCT FROM new.status) AND (new.documenttype = 'afleverbrief'::doc_layout_type))) EXECUTE FUNCTION logistics_task_status_after_signal();
|
|
2485
|
+
drop trigger if exists "trg_print_jobs_updated" on print_jobs;
|
|
2486
|
+
CREATE TRIGGER trg_print_jobs_updated BEFORE UPDATE ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2487
|
+
drop trigger if exists "trg_print_jobs_wake_queue" on print_jobs;
|
|
2488
|
+
CREATE TRIGGER trg_print_jobs_wake_queue AFTER INSERT OR UPDATE OF status, volgende_poging ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION print_jobs_wake_queue();
|
|
2489
|
+
drop trigger if exists "trg_trace_print_jobs" on print_jobs;
|
|
2490
|
+
CREATE TRIGGER trg_trace_print_jobs AFTER INSERT OR UPDATE ON public.print_jobs FOR EACH ROW EXECUTE FUNCTION logistics_trace_row_change();
|
|
2491
|
+
drop trigger if exists "trg_print_plek_computers_updated" on print_plek_computers;
|
|
2492
|
+
CREATE TRIGGER trg_print_plek_computers_updated BEFORE UPDATE ON public.print_plek_computers FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2493
|
+
drop trigger if exists "trg_print_plek_koppelingen_updated" on print_plek_koppelingen;
|
|
2494
|
+
CREATE TRIGGER trg_print_plek_koppelingen_updated BEFORE UPDATE ON public.print_plek_koppelingen FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2495
|
+
drop trigger if exists "trg_printer_losgekoppeld" on print_plek_printers;
|
|
2496
|
+
CREATE TRIGGER trg_printer_losgekoppeld AFTER DELETE ON public.print_plek_printers FOR EACH ROW EXECUTE FUNCTION printer_losgekoppeld_van_plek();
|
|
2497
|
+
drop trigger if exists "trg_print_plekken_updated" on print_plekken;
|
|
2498
|
+
CREATE TRIGGER trg_print_plekken_updated BEFORE UPDATE ON public.print_plekken FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2499
|
+
drop trigger if exists "trg_print_queue_runners_updated_at" on print_queue_runners;
|
|
2500
|
+
CREATE TRIGGER trg_print_queue_runners_updated_at BEFORE UPDATE ON public.print_queue_runners FOR EACH ROW EXECUTE FUNCTION set_updated_at_print_queue_runners();
|
|
2501
|
+
drop trigger if exists "trg_print_rules_updated" on print_rules;
|
|
2502
|
+
CREATE TRIGGER trg_print_rules_updated BEFORE UPDATE ON public.print_rules FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2503
|
+
drop trigger if exists "print_werkplek_afwijkingen_upd" on print_werkplek_afwijkingen;
|
|
2504
|
+
CREATE TRIGGER print_werkplek_afwijkingen_upd BEFORE UPDATE ON public.print_werkplek_afwijkingen FOR EACH ROW EXECUTE FUNCTION print_set_updated_at();
|
|
2505
|
+
drop trigger if exists "print_werkplekken_upd" on print_werkplekken;
|
|
2506
|
+
CREATE TRIGGER print_werkplekken_upd BEFORE UPDATE ON public.print_werkplekken FOR EACH ROW EXECUTE FUNCTION print_set_updated_at();
|
|
2507
|
+
drop trigger if exists "trg_markeer_ontbrekende_printer" on printer_mappings;
|
|
2508
|
+
CREATE TRIGGER trg_markeer_ontbrekende_printer BEFORE UPDATE OF printer_id ON public.printer_mappings FOR EACH ROW EXECUTE FUNCTION markeer_ontbrekende_printer();
|
|
2509
|
+
drop trigger if exists "trg_printer_mappings_updated" on printer_mappings;
|
|
2510
|
+
CREATE TRIGGER trg_printer_mappings_updated BEFORE UPDATE ON public.printer_mappings FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2511
|
+
drop trigger if exists "trg_printer_profiles_updated" on printer_profiles;
|
|
2512
|
+
CREATE TRIGGER trg_printer_profiles_updated BEFORE UPDATE ON public.printer_profiles FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2513
|
+
drop trigger if exists "printer_routes_upd" on printer_routes;
|
|
2514
|
+
CREATE TRIGGER printer_routes_upd BEFORE UPDATE ON public.printer_routes FOR EACH ROW EXECUTE FUNCTION print_set_updated_at();
|
|
2515
|
+
drop trigger if exists "printers_beheer_velden" on printers;
|
|
2516
|
+
CREATE TRIGGER printers_beheer_velden BEFORE UPDATE ON public.printers FOR EACH ROW EXECUTE FUNCTION printers_beheer_velden_bewaken();
|
|
2517
|
+
drop trigger if exists "trg_printers_updated" on printers;
|
|
2518
|
+
CREATE TRIGGER trg_printers_updated BEFORE UPDATE ON public.printers FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
|
2519
|
+
|
|
2520
|
+
-- 7. Rechten en beveiliging
|
|
2521
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.ai_layout_imports to anon;
|
|
2522
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.ai_layout_imports to authenticated;
|
|
2523
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.ai_layout_imports to service_role;
|
|
2524
|
+
alter table public.ai_layout_imports enable row level security;
|
|
2525
|
+
drop policy if exists "ai_layout_imports_auth_all" on public.ai_layout_imports;
|
|
2526
|
+
create policy "ai_layout_imports_auth_all" on public.ai_layout_imports as permissive for all to authenticated using (true) with check (true);
|
|
2527
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_bronregels to anon;
|
|
2528
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_bronregels to authenticated;
|
|
2529
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_bronregels to service_role;
|
|
2530
|
+
alter table public.document_bronregels enable row level security;
|
|
2531
|
+
drop policy if exists "document_bronregels_all" on public.document_bronregels;
|
|
2532
|
+
create policy "document_bronregels_all" on public.document_bronregels as permissive for all to authenticated using (true) with check (true);
|
|
2533
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_formaat_printers to anon;
|
|
2534
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_formaat_printers to authenticated;
|
|
2535
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_formaat_printers to service_role;
|
|
2536
|
+
alter table public.document_formaat_printers enable row level security;
|
|
2537
|
+
drop policy if exists "Ingelogden beheren formaatprinters" on public.document_formaat_printers;
|
|
2538
|
+
create policy "Ingelogden beheren formaatprinters" on public.document_formaat_printers as permissive for all to authenticated using (true) with check (true);
|
|
2539
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_conditions to anon;
|
|
2540
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_conditions to authenticated;
|
|
2541
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_conditions to service_role;
|
|
2542
|
+
alter table public.document_layout_conditions enable row level security;
|
|
2543
|
+
drop policy if exists "layout_conditions_auth_all" on public.document_layout_conditions;
|
|
2544
|
+
create policy "layout_conditions_auth_all" on public.document_layout_conditions as permissive for all to authenticated using (true) with check (true);
|
|
2545
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_datasources to anon;
|
|
2546
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_datasources to authenticated;
|
|
2547
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_datasources to service_role;
|
|
2548
|
+
alter table public.document_layout_datasources enable row level security;
|
|
2549
|
+
drop policy if exists "layout_datasources_auth_all" on public.document_layout_datasources;
|
|
2550
|
+
create policy "layout_datasources_auth_all" on public.document_layout_datasources as permissive for all to authenticated using (true) with check (true);
|
|
2551
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_elements to anon;
|
|
2552
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_elements to authenticated;
|
|
2553
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_elements to service_role;
|
|
2554
|
+
alter table public.document_layout_elements enable row level security;
|
|
2555
|
+
drop policy if exists "layout_elements_auth_all" on public.document_layout_elements;
|
|
2556
|
+
create policy "layout_elements_auth_all" on public.document_layout_elements as permissive for all to authenticated using (true) with check (true);
|
|
2557
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_variables to anon;
|
|
2558
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_variables to authenticated;
|
|
2559
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_variables to service_role;
|
|
2560
|
+
alter table public.document_layout_variables enable row level security;
|
|
2561
|
+
drop policy if exists "layout_variables_auth_all" on public.document_layout_variables;
|
|
2562
|
+
create policy "layout_variables_auth_all" on public.document_layout_variables as permissive for all to authenticated using (true) with check (true);
|
|
2563
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_versions to anon;
|
|
2564
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_versions to authenticated;
|
|
2565
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layout_versions to service_role;
|
|
2566
|
+
alter table public.document_layout_versions enable row level security;
|
|
2567
|
+
drop policy if exists "layout_versions_auth_all" on public.document_layout_versions;
|
|
2568
|
+
create policy "layout_versions_auth_all" on public.document_layout_versions as permissive for all to authenticated using (true) with check (true);
|
|
2569
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layouts to anon;
|
|
2570
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layouts to authenticated;
|
|
2571
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_layouts to service_role;
|
|
2572
|
+
alter table public.document_layouts enable row level security;
|
|
2573
|
+
drop policy if exists "layouts_auth_all" on public.document_layouts;
|
|
2574
|
+
create policy "layouts_auth_all" on public.document_layouts as permissive for all to authenticated using (true) with check (true);
|
|
2575
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_printplek_printers to anon;
|
|
2576
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_printplek_printers to authenticated;
|
|
2577
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_printplek_printers to service_role;
|
|
2578
|
+
alter table public.document_printplek_printers enable row level security;
|
|
2579
|
+
drop policy if exists "document_printplek_printers_auth_all" on public.document_printplek_printers;
|
|
2580
|
+
create policy "document_printplek_printers_auth_all" on public.document_printplek_printers as permissive for all to authenticated using (true) with check (true);
|
|
2581
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_werkplek_printers to anon;
|
|
2582
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_werkplek_printers to authenticated;
|
|
2583
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.document_werkplek_printers to service_role;
|
|
2584
|
+
alter table public.document_werkplek_printers enable row level security;
|
|
2585
|
+
drop policy if exists "document_werkplek_printers_auth_all" on public.document_werkplek_printers;
|
|
2586
|
+
create policy "document_werkplek_printers_auth_all" on public.document_werkplek_printers as permissive for all to authenticated using (true) with check (true);
|
|
2587
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.layout_logos to anon;
|
|
2588
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.layout_logos to authenticated;
|
|
2589
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.layout_logos to service_role;
|
|
2590
|
+
alter table public.layout_logos enable row level security;
|
|
2591
|
+
drop policy if exists "Ingelogden beheren logos" on public.layout_logos;
|
|
2592
|
+
create policy "Ingelogden beheren logos" on public.layout_logos as permissive for all to authenticated using (true) with check (true);
|
|
2593
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.pakbon_barcode_inhoud to anon;
|
|
2594
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.pakbon_barcode_inhoud to authenticated;
|
|
2595
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.pakbon_barcode_inhoud to service_role;
|
|
2596
|
+
alter table public.pakbon_barcode_inhoud enable row level security;
|
|
2597
|
+
drop policy if exists "pakbon_barcode_inhoud_insert" on public.pakbon_barcode_inhoud;
|
|
2598
|
+
create policy "pakbon_barcode_inhoud_insert" on public.pakbon_barcode_inhoud as permissive for insert to authenticated with check (true);
|
|
2599
|
+
drop policy if exists "pakbon_barcode_inhoud_read" on public.pakbon_barcode_inhoud;
|
|
2600
|
+
create policy "pakbon_barcode_inhoud_read" on public.pakbon_barcode_inhoud as permissive for select to authenticated using (true);
|
|
2601
|
+
drop policy if exists "pakbon_barcode_inhoud_update" on public.pakbon_barcode_inhoud;
|
|
2602
|
+
create policy "pakbon_barcode_inhoud_update" on public.pakbon_barcode_inhoud as permissive for update to authenticated using (true) with check (true);
|
|
2603
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.pakbon_barcode_verzoeken to anon;
|
|
2604
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.pakbon_barcode_verzoeken to authenticated;
|
|
2605
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.pakbon_barcode_verzoeken to service_role;
|
|
2606
|
+
alter table public.pakbon_barcode_verzoeken enable row level security;
|
|
2607
|
+
drop policy if exists "Ingelogde gebruikers lezen barcodeverzoeken" on public.pakbon_barcode_verzoeken;
|
|
2608
|
+
create policy "Ingelogde gebruikers lezen barcodeverzoeken" on public.pakbon_barcode_verzoeken as permissive for select to authenticated using (true);
|
|
2609
|
+
drop policy if exists "Ingelogde gebruikers schrijven barcodeverzoeken" on public.pakbon_barcode_verzoeken;
|
|
2610
|
+
create policy "Ingelogde gebruikers schrijven barcodeverzoeken" on public.pakbon_barcode_verzoeken as permissive for insert to authenticated with check (true);
|
|
2611
|
+
drop policy if exists "Ingelogde gebruikers werken barcodeverzoeken bij" on public.pakbon_barcode_verzoeken;
|
|
2612
|
+
create policy "Ingelogde gebruikers werken barcodeverzoeken bij" on public.pakbon_barcode_verzoeken as permissive for update to authenticated using (true) with check (true);
|
|
2613
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_agents to anon;
|
|
2614
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_agents to authenticated;
|
|
2615
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_agents to service_role;
|
|
2616
|
+
alter table public.print_agents enable row level security;
|
|
2617
|
+
drop policy if exists "Ingelogde gebruikers beheren printagents" on public.print_agents;
|
|
2618
|
+
create policy "Ingelogde gebruikers beheren printagents" on public.print_agents as permissive for all to authenticated using (true) with check (true);
|
|
2619
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_computer_status to anon;
|
|
2620
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_computer_status to authenticated;
|
|
2621
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_computer_status to service_role;
|
|
2622
|
+
alter table public.print_computer_status enable row level security;
|
|
2623
|
+
drop policy if exists "Ingelogde gebruikers lezen computerstatus" on public.print_computer_status;
|
|
2624
|
+
create policy "Ingelogde gebruikers lezen computerstatus" on public.print_computer_status as permissive for select to authenticated using (true);
|
|
2625
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_dedupe_events to anon;
|
|
2626
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_dedupe_events to authenticated;
|
|
2627
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_dedupe_events to service_role;
|
|
2628
|
+
alter table public.print_dedupe_events enable row level security;
|
|
2629
|
+
drop policy if exists "print_dedupe_events_read" on public.print_dedupe_events;
|
|
2630
|
+
create policy "print_dedupe_events_read" on public.print_dedupe_events as permissive for select to authenticated using (true);
|
|
2631
|
+
drop policy if exists "print_dedupe_events_write" on public.print_dedupe_events;
|
|
2632
|
+
create policy "print_dedupe_events_write" on public.print_dedupe_events as permissive for insert to authenticated with check (true);
|
|
2633
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_gebruiker_werkplek to anon;
|
|
2634
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_gebruiker_werkplek to authenticated;
|
|
2635
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_gebruiker_werkplek to service_role;
|
|
2636
|
+
alter table public.print_gebruiker_werkplek enable row level security;
|
|
2637
|
+
drop policy if exists "print_gebruiker_werkplek_eigen" on public.print_gebruiker_werkplek;
|
|
2638
|
+
create policy "print_gebruiker_werkplek_eigen" on public.print_gebruiker_werkplek as permissive for all to authenticated using ((user_id = auth.uid())) with check ((user_id = auth.uid()));
|
|
2639
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_genegeerde_computers to anon;
|
|
2640
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_genegeerde_computers to authenticated;
|
|
2641
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_genegeerde_computers to service_role;
|
|
2642
|
+
alter table public.print_genegeerde_computers enable row level security;
|
|
2643
|
+
drop policy if exists "print_genegeerde_computers_auth_all" on public.print_genegeerde_computers;
|
|
2644
|
+
create policy "print_genegeerde_computers_auth_all" on public.print_genegeerde_computers as permissive for all to authenticated using (true) with check (true);
|
|
2645
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_job_logs to anon;
|
|
2646
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_job_logs to authenticated;
|
|
2647
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_job_logs to service_role;
|
|
2648
|
+
alter table public.print_job_logs enable row level security;
|
|
2649
|
+
drop policy if exists "print_job_logs_auth_all" on public.print_job_logs;
|
|
2650
|
+
create policy "print_job_logs_auth_all" on public.print_job_logs as permissive for all to authenticated using (true) with check (true);
|
|
2651
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_jobs to authenticated;
|
|
2652
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_jobs to service_role;
|
|
2653
|
+
alter table public.print_jobs enable row level security;
|
|
2654
|
+
drop policy if exists "print_jobs_auth_all" on public.print_jobs;
|
|
2655
|
+
create policy "print_jobs_auth_all" on public.print_jobs as permissive for all to authenticated using (true) with check (true);
|
|
2656
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plek_computers to anon;
|
|
2657
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plek_computers to authenticated;
|
|
2658
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plek_computers to service_role;
|
|
2659
|
+
alter table public.print_plek_computers enable row level security;
|
|
2660
|
+
drop policy if exists "print_plek_computers_auth_all" on public.print_plek_computers;
|
|
2661
|
+
create policy "print_plek_computers_auth_all" on public.print_plek_computers as permissive for all to authenticated using (true) with check (true);
|
|
2662
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plek_koppelingen to anon;
|
|
2663
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plek_koppelingen to authenticated;
|
|
2664
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plek_koppelingen to service_role;
|
|
2665
|
+
alter table public.print_plek_koppelingen enable row level security;
|
|
2666
|
+
drop policy if exists "print_plek_koppelingen_auth_all" on public.print_plek_koppelingen;
|
|
2667
|
+
create policy "print_plek_koppelingen_auth_all" on public.print_plek_koppelingen as permissive for all to authenticated using (true) with check (true);
|
|
2668
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plek_printers to anon;
|
|
2669
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plek_printers to authenticated;
|
|
2670
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plek_printers to service_role;
|
|
2671
|
+
alter table public.print_plek_printers enable row level security;
|
|
2672
|
+
drop policy if exists "print_plek_printers_auth_all" on public.print_plek_printers;
|
|
2673
|
+
create policy "print_plek_printers_auth_all" on public.print_plek_printers as permissive for all to authenticated using (true) with check (true);
|
|
2674
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plekken to anon;
|
|
2675
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plekken to authenticated;
|
|
2676
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_plekken to service_role;
|
|
2677
|
+
alter table public.print_plekken enable row level security;
|
|
2678
|
+
drop policy if exists "print_plekken_auth_all" on public.print_plekken;
|
|
2679
|
+
create policy "print_plekken_auth_all" on public.print_plekken as permissive for all to authenticated using (true) with check (true);
|
|
2680
|
+
grant SELECT on public.print_preview_events to authenticated;
|
|
2681
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_preview_events to service_role;
|
|
2682
|
+
alter table public.print_preview_events enable row level security;
|
|
2683
|
+
drop policy if exists "print_preview_events_read" on public.print_preview_events;
|
|
2684
|
+
create policy "print_preview_events_read" on public.print_preview_events as permissive for select to authenticated using (true);
|
|
2685
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_printer_verwijder_herstel to anon;
|
|
2686
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_printer_verwijder_herstel to authenticated;
|
|
2687
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_printer_verwijder_herstel to service_role;
|
|
2688
|
+
alter table public.print_printer_verwijder_herstel enable row level security;
|
|
2689
|
+
drop policy if exists "print_printer_verwijder_herstel_auth_all" on public.print_printer_verwijder_herstel;
|
|
2690
|
+
create policy "print_printer_verwijder_herstel_auth_all" on public.print_printer_verwijder_herstel as permissive for all to authenticated using (true) with check (true);
|
|
2691
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_queue_leases to anon;
|
|
2692
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_queue_leases to authenticated;
|
|
2693
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_queue_leases to service_role;
|
|
2694
|
+
alter table public.print_queue_leases enable row level security;
|
|
2695
|
+
drop policy if exists "print_queue_leases_service" on public.print_queue_leases;
|
|
2696
|
+
create policy "print_queue_leases_service" on public.print_queue_leases as permissive for all to service_role using (true) with check (true);
|
|
2697
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_queue_runners to anon;
|
|
2698
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_queue_runners to authenticated;
|
|
2699
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_queue_runners to service_role;
|
|
2700
|
+
alter table public.print_queue_runners enable row level security;
|
|
2701
|
+
drop policy if exists "service role beheert print runners" on public.print_queue_runners;
|
|
2702
|
+
create policy "service role beheert print runners" on public.print_queue_runners as permissive for all to service_role using (true) with check (true);
|
|
2703
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_queue_settings to anon;
|
|
2704
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_queue_settings to authenticated;
|
|
2705
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_queue_settings to service_role;
|
|
2706
|
+
alter table public.print_queue_settings enable row level security;
|
|
2707
|
+
drop policy if exists "Ingelogde gebruikers beheren printwachtrij-instellingen" on public.print_queue_settings;
|
|
2708
|
+
create policy "Ingelogde gebruikers beheren printwachtrij-instellingen" on public.print_queue_settings as permissive for all to authenticated using (true) with check (true);
|
|
2709
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_rules to anon;
|
|
2710
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_rules to authenticated;
|
|
2711
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_rules to service_role;
|
|
2712
|
+
alter table public.print_rules enable row level security;
|
|
2713
|
+
drop policy if exists "print_rules_auth_all" on public.print_rules;
|
|
2714
|
+
create policy "print_rules_auth_all" on public.print_rules as permissive for all to authenticated using (true) with check (true);
|
|
2715
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_shell_stilstand to anon;
|
|
2716
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_shell_stilstand to authenticated;
|
|
2717
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_shell_stilstand to service_role;
|
|
2718
|
+
alter table public.print_shell_stilstand enable row level security;
|
|
2719
|
+
drop policy if exists "Beheer leest stilstandlog" on public.print_shell_stilstand;
|
|
2720
|
+
do $$ begin if to_regtype('public.app_role') is not null and exists (select 1 from pg_proc p join pg_namespace s on s.oid=p.pronamespace where s.nspname='public' and p.proname='has_role') then execute 'create policy "Beheer leest stilstandlog" on public.print_shell_stilstand as permissive for select to authenticated using ((has_role(auth.uid(), ''admin''::app_role) OR has_role(auth.uid(), ''superadmin''::app_role) OR has_role(auth.uid(), ''developer''::app_role)))'; else raise notice 'layout-maker: overgeslagen – rollen (has_role/app_role) ontbreken; beheerpolicy niet aangemaakt'; end if; end $$;
|
|
2721
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_werkplek_afwijkingen to anon;
|
|
2722
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_werkplek_afwijkingen to authenticated;
|
|
2723
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_werkplek_afwijkingen to service_role;
|
|
2724
|
+
alter table public.print_werkplek_afwijkingen enable row level security;
|
|
2725
|
+
drop policy if exists "print_werkplek_afwijkingen_beheer" on public.print_werkplek_afwijkingen;
|
|
2726
|
+
do $$ begin if to_regtype('public.app_role') is not null and exists (select 1 from pg_proc p join pg_namespace s on s.oid=p.pronamespace where s.nspname='public' and p.proname='has_role') then execute 'create policy "print_werkplek_afwijkingen_beheer" on public.print_werkplek_afwijkingen as permissive for all to authenticated using ((has_role(auth.uid(), ''admin''::app_role) OR has_role(auth.uid(), ''superadmin''::app_role))) with check ((has_role(auth.uid(), ''admin''::app_role) OR has_role(auth.uid(), ''superadmin''::app_role)))'; else raise notice 'layout-maker: overgeslagen – rollen (has_role/app_role) ontbreken; beheerpolicy niet aangemaakt'; end if; end $$;
|
|
2727
|
+
drop policy if exists "print_werkplek_afwijkingen_lezen" on public.print_werkplek_afwijkingen;
|
|
2728
|
+
create policy "print_werkplek_afwijkingen_lezen" on public.print_werkplek_afwijkingen as permissive for select to authenticated using (true);
|
|
2729
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_werkplekken to anon;
|
|
2730
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_werkplekken to authenticated;
|
|
2731
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.print_werkplekken to service_role;
|
|
2732
|
+
alter table public.print_werkplekken enable row level security;
|
|
2733
|
+
drop policy if exists "print_werkplekken_beheer" on public.print_werkplekken;
|
|
2734
|
+
do $$ begin if to_regtype('public.app_role') is not null and exists (select 1 from pg_proc p join pg_namespace s on s.oid=p.pronamespace where s.nspname='public' and p.proname='has_role') then execute 'create policy "print_werkplekken_beheer" on public.print_werkplekken as permissive for all to authenticated using ((has_role(auth.uid(), ''admin''::app_role) OR has_role(auth.uid(), ''superadmin''::app_role))) with check ((has_role(auth.uid(), ''admin''::app_role) OR has_role(auth.uid(), ''superadmin''::app_role)))'; else raise notice 'layout-maker: overgeslagen – rollen (has_role/app_role) ontbreken; beheerpolicy niet aangemaakt'; end if; end $$;
|
|
2735
|
+
drop policy if exists "print_werkplekken_lezen" on public.print_werkplekken;
|
|
2736
|
+
create policy "print_werkplekken_lezen" on public.print_werkplekken as permissive for select to authenticated using (true);
|
|
2737
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printer_mappings to anon;
|
|
2738
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printer_mappings to authenticated;
|
|
2739
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printer_mappings to service_role;
|
|
2740
|
+
alter table public.printer_mappings enable row level security;
|
|
2741
|
+
drop policy if exists "printer_mappings_auth_all" on public.printer_mappings;
|
|
2742
|
+
create policy "printer_mappings_auth_all" on public.printer_mappings as permissive for all to authenticated using (true) with check (true);
|
|
2743
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printer_profiles to anon;
|
|
2744
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printer_profiles to authenticated;
|
|
2745
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printer_profiles to service_role;
|
|
2746
|
+
alter table public.printer_profiles enable row level security;
|
|
2747
|
+
drop policy if exists "printer_profiles_auth_all" on public.printer_profiles;
|
|
2748
|
+
create policy "printer_profiles_auth_all" on public.printer_profiles as permissive for all to authenticated using (true) with check (true);
|
|
2749
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printer_routes to anon;
|
|
2750
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printer_routes to authenticated;
|
|
2751
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printer_routes to service_role;
|
|
2752
|
+
alter table public.printer_routes enable row level security;
|
|
2753
|
+
drop policy if exists "printer_routes_beheer" on public.printer_routes;
|
|
2754
|
+
do $$ begin if to_regtype('public.app_role') is not null and exists (select 1 from pg_proc p join pg_namespace s on s.oid=p.pronamespace where s.nspname='public' and p.proname='has_role') then execute 'create policy "printer_routes_beheer" on public.printer_routes as permissive for all to authenticated using ((has_role(auth.uid(), ''admin''::app_role) OR has_role(auth.uid(), ''superadmin''::app_role))) with check ((has_role(auth.uid(), ''admin''::app_role) OR has_role(auth.uid(), ''superadmin''::app_role)))'; else raise notice 'layout-maker: overgeslagen – rollen (has_role/app_role) ontbreken; beheerpolicy niet aangemaakt'; end if; end $$;
|
|
2755
|
+
drop policy if exists "printer_routes_lezen" on public.printer_routes;
|
|
2756
|
+
create policy "printer_routes_lezen" on public.printer_routes as permissive for select to authenticated using (true);
|
|
2757
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printers to authenticated;
|
|
2758
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printers to service_role;
|
|
2759
|
+
alter table public.printers enable row level security;
|
|
2760
|
+
drop policy if exists "printers_auth_all" on public.printers;
|
|
2761
|
+
create policy "printers_auth_all" on public.printers as permissive for all to authenticated using (true) with check (true);
|
|
2762
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printnode_webhook_koppeling to service_role;
|
|
2763
|
+
alter table public.printnode_webhook_koppeling enable row level security;
|
|
2764
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printnode_webhook_meldingen to anon;
|
|
2765
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printnode_webhook_meldingen to authenticated;
|
|
2766
|
+
grant DELETE, INSERT, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE on public.printnode_webhook_meldingen to service_role;
|
|
2767
|
+
alter table public.printnode_webhook_meldingen enable row level security;
|
|
2768
|
+
revoke all on function public._jsonb_paden_met_waarde(jsonb,text,text[]) from public;
|
|
2769
|
+
revoke all on function public._print_meld_stilstand(text,timestamp with time zone) from public;
|
|
2770
|
+
revoke all on function public.beveilig_systeem_layouts() from public;
|
|
2771
|
+
revoke all on function public.cancel_open_print_jobs(timestamp with time zone) from public;
|
|
2772
|
+
revoke all on function public.claim_cloud_print_jobs(integer) from public;
|
|
2773
|
+
revoke all on function public.claim_local_pdf_jobs(uuid,text,integer) from public;
|
|
2774
|
+
revoke all on function public.claim_pdf_print_jobs(integer) from public;
|
|
2775
|
+
revoke all on function public.claim_print_jobs(uuid,integer) from public;
|
|
2776
|
+
revoke all on function public.claim_print_queue_lease(text,uuid,integer) from public;
|
|
2777
|
+
revoke all on function public.controleer_printplek_printer() from public;
|
|
2778
|
+
revoke all on function public.controleer_werkplek_printer() from public;
|
|
2779
|
+
revoke all on function public.document_layout_een_standaard() from public;
|
|
2780
|
+
revoke all on function public.finish_local_pdf_job(uuid,text,text,text) from public;
|
|
2781
|
+
revoke all on function public.geladen_etiketten(uuid,uuid) from public;
|
|
2782
|
+
revoke all on function public.layout_print_document(text,text,text,text,uuid,uuid,text,integer,text,boolean,jsonb,text,text) from public;
|
|
2783
|
+
revoke all on function public.layout_verwijzing_omzetten(text,uuid,uuid,uuid) from public;
|
|
2784
|
+
revoke all on function public.layout_verwijzingen() from public;
|
|
2785
|
+
revoke all on function public.layout_zorg_systeemlayouts() from public;
|
|
2786
|
+
revoke all on function public.markeer_ontbrekende_printer() from public;
|
|
2787
|
+
revoke all on function public.opruim_print_historie() from public;
|
|
2788
|
+
revoke all on function public.print_formaat_klasse(text) from public;
|
|
2789
|
+
revoke all on function public.print_is_etiketsoort(text) from public;
|
|
2790
|
+
revoke all on function public.print_is_labelprinter(uuid) from public;
|
|
2791
|
+
revoke all on function public.print_job_status_uitgebreid(uuid) from public;
|
|
2792
|
+
revoke all on function public.print_jobs_dedupe() from public;
|
|
2793
|
+
revoke all on function public.print_jobs_origineel_controle() from public;
|
|
2794
|
+
revoke all on function public.print_jobs_wake_queue() from public;
|
|
2795
|
+
revoke all on function public.print_kopieen_aantal(text,integer,jsonb) from public;
|
|
2796
|
+
revoke all on function public.print_preview_toestaan(text,uuid,integer,integer) from public;
|
|
2797
|
+
revoke all on function public.print_preview_weiger(text,uuid,text,text) from public;
|
|
2798
|
+
revoke all on function public.print_set_updated_at() from public;
|
|
2799
|
+
revoke all on function public.print_shell_url() from public;
|
|
2800
|
+
revoke all on function public.print_url_norm(text) from public;
|
|
2801
|
+
revoke all on function public.print_werkplek_keuze(uuid,text,text) from public;
|
|
2802
|
+
revoke all on function public.printer_gebruik(uuid) from public;
|
|
2803
|
+
revoke all on function public.printer_herstel_uitvoeren(uuid,uuid) from public;
|
|
2804
|
+
revoke all on function public.printer_herstel_voorstel(uuid,uuid) from public;
|
|
2805
|
+
revoke all on function public.printer_losgekoppeld_van_plek() from public;
|
|
2806
|
+
revoke all on function public.printer_routering(text,uuid,text,uuid,text,uuid) from public;
|
|
2807
|
+
revoke all on function public.printer_verwijder_verwijzingen(uuid,uuid) from public;
|
|
2808
|
+
revoke all on function public.printers_beheer_velden_bewaken() from public;
|
|
2809
|
+
revoke all on function public.printplek_printer(uuid,text) from public;
|
|
2810
|
+
revoke all on function public.printplek_verwijder_impact(uuid) from public;
|
|
2811
|
+
revoke all on function public.release_local_pdf_job(uuid,text) from public;
|
|
2812
|
+
revoke all on function public.release_print_queue_lease(text,uuid) from public;
|
|
2813
|
+
revoke all on function public.resolve_print_job_printer_id(print_jobs) from public;
|
|
2814
|
+
revoke all on function public.ruim_print_jobs_op(integer) from public;
|
|
2815
|
+
revoke all on function public.run_print_queue_ticks() from public;
|
|
2816
|
+
revoke all on function public.set_updated_at_print_queue_runners() from public;
|
|
2817
|
+
revoke all on function public.sticker_past_controle(text[],uuid) from public;
|
|
2818
|
+
revoke all on function public.update_updated_at_column() from public;
|
|
2819
|
+
revoke all on function public.vervang_printer(uuid,uuid) from public;
|
|
2820
|
+
revoke all on function public.verwijder_printplek(uuid) from public;
|
|
2821
|
+
revoke all on function public.wake_print_queue(integer) from public;
|
|
2822
|
+
revoke all on function public.werkplek_omzetting_toepassen(jsonb) from public;
|
|
2823
|
+
revoke all on function public.werkplek_omzetting_voorstel() from public;
|
|
2824
|
+
grant execute on function _jsonb_paden_met_waarde(jsonb,text,text[]) to authenticated;
|
|
2825
|
+
grant execute on function _jsonb_paden_met_waarde(jsonb,text,text[]) to service_role;
|
|
2826
|
+
grant execute on function _print_meld_stilstand(text,timestamp with time zone) to service_role;
|
|
2827
|
+
grant execute on function beveilig_systeem_layouts() to anon;
|
|
2828
|
+
grant execute on function beveilig_systeem_layouts() to authenticated;
|
|
2829
|
+
grant execute on function beveilig_systeem_layouts() to service_role;
|
|
2830
|
+
grant execute on function cancel_open_print_jobs(timestamp with time zone) to authenticated;
|
|
2831
|
+
grant execute on function cancel_open_print_jobs(timestamp with time zone) to service_role;
|
|
2832
|
+
grant execute on function claim_cloud_print_jobs(integer) to service_role;
|
|
2833
|
+
grant execute on function claim_local_pdf_jobs(uuid,text,integer) to authenticated;
|
|
2834
|
+
grant execute on function claim_local_pdf_jobs(uuid,text,integer) to service_role;
|
|
2835
|
+
grant execute on function claim_pdf_print_jobs(integer) to service_role;
|
|
2836
|
+
grant execute on function claim_print_jobs(uuid,integer) to anon;
|
|
2837
|
+
grant execute on function claim_print_jobs(uuid,integer) to authenticated;
|
|
2838
|
+
grant execute on function claim_print_jobs(uuid,integer) to service_role;
|
|
2839
|
+
grant execute on function claim_print_queue_lease(text,uuid,integer) to service_role;
|
|
2840
|
+
grant execute on function controleer_printplek_printer() to anon;
|
|
2841
|
+
grant execute on function controleer_printplek_printer() to authenticated;
|
|
2842
|
+
grant execute on function controleer_printplek_printer() to service_role;
|
|
2843
|
+
grant execute on function controleer_werkplek_printer() to anon;
|
|
2844
|
+
grant execute on function controleer_werkplek_printer() to authenticated;
|
|
2845
|
+
grant execute on function controleer_werkplek_printer() to service_role;
|
|
2846
|
+
grant execute on function document_layout_een_standaard() to anon;
|
|
2847
|
+
grant execute on function document_layout_een_standaard() to authenticated;
|
|
2848
|
+
grant execute on function document_layout_een_standaard() to service_role;
|
|
2849
|
+
grant execute on function finish_local_pdf_job(uuid,text,text,text) to authenticated;
|
|
2850
|
+
grant execute on function finish_local_pdf_job(uuid,text,text,text) to service_role;
|
|
2851
|
+
grant execute on function geladen_etiketten(uuid,uuid) to authenticated;
|
|
2852
|
+
grant execute on function geladen_etiketten(uuid,uuid) to service_role;
|
|
2853
|
+
grant execute on function layout_print_document(text,text,text,text,uuid,uuid,text,integer,text,boolean,jsonb,text,text) to authenticated;
|
|
2854
|
+
grant execute on function layout_print_document(text,text,text,text,uuid,uuid,text,integer,text,boolean,jsonb,text,text) to service_role;
|
|
2855
|
+
grant execute on function layout_verwijzing_omzetten(text,uuid,uuid,uuid) to authenticated;
|
|
2856
|
+
grant execute on function layout_verwijzing_omzetten(text,uuid,uuid,uuid) to service_role;
|
|
2857
|
+
grant execute on function layout_verwijzingen() to authenticated;
|
|
2858
|
+
grant execute on function layout_verwijzingen() to service_role;
|
|
2859
|
+
grant execute on function layout_zorg_systeemlayouts() to service_role;
|
|
2860
|
+
grant execute on function markeer_ontbrekende_printer() to anon;
|
|
2861
|
+
grant execute on function markeer_ontbrekende_printer() to authenticated;
|
|
2862
|
+
grant execute on function markeer_ontbrekende_printer() to service_role;
|
|
2863
|
+
grant execute on function opruim_print_historie() to service_role;
|
|
2864
|
+
grant execute on function print_formaat_klasse(text) to anon;
|
|
2865
|
+
grant execute on function print_formaat_klasse(text) to authenticated;
|
|
2866
|
+
grant execute on function print_formaat_klasse(text) to service_role;
|
|
2867
|
+
grant execute on function print_is_etiketsoort(text) to anon;
|
|
2868
|
+
grant execute on function print_is_etiketsoort(text) to authenticated;
|
|
2869
|
+
grant execute on function print_is_etiketsoort(text) to service_role;
|
|
2870
|
+
grant execute on function print_is_labelprinter(uuid) to authenticated;
|
|
2871
|
+
grant execute on function print_is_labelprinter(uuid) to service_role;
|
|
2872
|
+
grant execute on function print_job_status_uitgebreid(uuid) to service_role;
|
|
2873
|
+
grant execute on function print_jobs_dedupe() to anon;
|
|
2874
|
+
grant execute on function print_jobs_dedupe() to authenticated;
|
|
2875
|
+
grant execute on function print_jobs_dedupe() to service_role;
|
|
2876
|
+
grant execute on function print_jobs_origineel_controle() to anon;
|
|
2877
|
+
grant execute on function print_jobs_origineel_controle() to authenticated;
|
|
2878
|
+
grant execute on function print_jobs_origineel_controle() to service_role;
|
|
2879
|
+
grant execute on function print_jobs_wake_queue() to anon;
|
|
2880
|
+
grant execute on function print_jobs_wake_queue() to authenticated;
|
|
2881
|
+
grant execute on function print_jobs_wake_queue() to service_role;
|
|
2882
|
+
grant execute on function print_kopieen_aantal(text,integer,jsonb) to anon;
|
|
2883
|
+
grant execute on function print_kopieen_aantal(text,integer,jsonb) to authenticated;
|
|
2884
|
+
grant execute on function print_kopieen_aantal(text,integer,jsonb) to service_role;
|
|
2885
|
+
grant execute on function print_preview_toestaan(text,uuid,integer,integer) to service_role;
|
|
2886
|
+
grant execute on function print_preview_weiger(text,uuid,text,text) to service_role;
|
|
2887
|
+
grant execute on function print_set_updated_at() to anon;
|
|
2888
|
+
grant execute on function print_set_updated_at() to authenticated;
|
|
2889
|
+
grant execute on function print_set_updated_at() to service_role;
|
|
2890
|
+
grant execute on function print_shell_url() to service_role;
|
|
2891
|
+
grant execute on function print_url_norm(text) to anon;
|
|
2892
|
+
grant execute on function print_url_norm(text) to authenticated;
|
|
2893
|
+
grant execute on function print_url_norm(text) to service_role;
|
|
2894
|
+
grant execute on function print_werkplek_keuze(uuid,text,text) to authenticated;
|
|
2895
|
+
grant execute on function print_werkplek_keuze(uuid,text,text) to service_role;
|
|
2896
|
+
grant execute on function printer_gebruik(uuid) to authenticated;
|
|
2897
|
+
grant execute on function printer_gebruik(uuid) to service_role;
|
|
2898
|
+
grant execute on function printer_herstel_uitvoeren(uuid,uuid) to authenticated;
|
|
2899
|
+
grant execute on function printer_herstel_uitvoeren(uuid,uuid) to service_role;
|
|
2900
|
+
grant execute on function printer_herstel_voorstel(uuid,uuid) to authenticated;
|
|
2901
|
+
grant execute on function printer_herstel_voorstel(uuid,uuid) to service_role;
|
|
2902
|
+
grant execute on function printer_losgekoppeld_van_plek() to anon;
|
|
2903
|
+
grant execute on function printer_losgekoppeld_van_plek() to authenticated;
|
|
2904
|
+
grant execute on function printer_losgekoppeld_van_plek() to service_role;
|
|
2905
|
+
grant execute on function printer_routering(text,uuid,text,uuid,text,uuid) to authenticated;
|
|
2906
|
+
grant execute on function printer_routering(text,uuid,text,uuid,text,uuid) to service_role;
|
|
2907
|
+
grant execute on function printer_verwijder_verwijzingen(uuid,uuid) to authenticated;
|
|
2908
|
+
grant execute on function printer_verwijder_verwijzingen(uuid,uuid) to service_role;
|
|
2909
|
+
grant execute on function printers_beheer_velden_bewaken() to service_role;
|
|
2910
|
+
grant execute on function printplek_printer(uuid,text) to authenticated;
|
|
2911
|
+
grant execute on function printplek_printer(uuid,text) to service_role;
|
|
2912
|
+
grant execute on function printplek_verwijder_impact(uuid) to authenticated;
|
|
2913
|
+
grant execute on function printplek_verwijder_impact(uuid) to service_role;
|
|
2914
|
+
grant execute on function release_local_pdf_job(uuid,text) to authenticated;
|
|
2915
|
+
grant execute on function release_local_pdf_job(uuid,text) to service_role;
|
|
2916
|
+
grant execute on function release_print_queue_lease(text,uuid) to service_role;
|
|
2917
|
+
grant execute on function resolve_print_job_printer_id(print_jobs) to service_role;
|
|
2918
|
+
grant execute on function ruim_print_jobs_op(integer) to anon;
|
|
2919
|
+
grant execute on function ruim_print_jobs_op(integer) to authenticated;
|
|
2920
|
+
grant execute on function ruim_print_jobs_op(integer) to service_role;
|
|
2921
|
+
grant execute on function run_print_queue_ticks() to service_role;
|
|
2922
|
+
grant execute on function set_updated_at_print_queue_runners() to anon;
|
|
2923
|
+
grant execute on function set_updated_at_print_queue_runners() to authenticated;
|
|
2924
|
+
grant execute on function set_updated_at_print_queue_runners() to service_role;
|
|
2925
|
+
grant execute on function sticker_past_controle(text[],uuid) to authenticated;
|
|
2926
|
+
grant execute on function sticker_past_controle(text[],uuid) to service_role;
|
|
2927
|
+
grant execute on function update_updated_at_column() to anon;
|
|
2928
|
+
grant execute on function update_updated_at_column() to authenticated;
|
|
2929
|
+
grant execute on function update_updated_at_column() to service_role;
|
|
2930
|
+
grant execute on function vervang_printer(uuid,uuid) to authenticated;
|
|
2931
|
+
grant execute on function vervang_printer(uuid,uuid) to service_role;
|
|
2932
|
+
grant execute on function verwijder_printplek(uuid) to authenticated;
|
|
2933
|
+
grant execute on function verwijder_printplek(uuid) to service_role;
|
|
2934
|
+
grant execute on function wake_print_queue(integer) to service_role;
|
|
2935
|
+
grant execute on function werkplek_omzetting_toepassen(jsonb) to authenticated;
|
|
2936
|
+
grant execute on function werkplek_omzetting_toepassen(jsonb) to service_role;
|
|
2937
|
+
grant execute on function werkplek_omzetting_voorstel() to authenticated;
|
|
2938
|
+
grant execute on function werkplek_omzetting_voorstel() to service_role;
|
|
2939
|
+
|
|
2940
|
+
-- 8. Opslag voor de logobibliotheek
|
|
2941
|
+
insert into storage.buckets (id, name, public) values ('layout-logos', 'layout-logos', false) on conflict (id) do nothing;
|
|
2942
|
+
drop policy if exists "Logos lezen" on storage.objects;
|
|
2943
|
+
create policy "Logos lezen" on storage.objects as permissive for select to authenticated using ((bucket_id = 'layout-logos'::text));
|
|
2944
|
+
drop policy if exists "Logos uploaden" on storage.objects;
|
|
2945
|
+
create policy "Logos uploaden" on storage.objects as permissive for insert to authenticated with check ((bucket_id = 'layout-logos'::text));
|
|
2946
|
+
drop policy if exists "Logos verwijderen" on storage.objects;
|
|
2947
|
+
create policy "Logos verwijderen" on storage.objects as permissive for delete to authenticated using ((bucket_id = 'layout-logos'::text));
|
|
2948
|
+
drop policy if exists "Logos wijzigen" on storage.objects;
|
|
2949
|
+
create policy "Logos wijzigen" on storage.objects as permissive for update to authenticated using ((bucket_id = 'layout-logos'::text));
|
|
2950
|
+
drop policy if exists "Pickscherm mag layout-logos lezen" on storage.objects;
|
|
2951
|
+
create policy "Pickscherm mag layout-logos lezen" on storage.objects as permissive for select to anon, authenticated using ((bucket_id = 'layout-logos'::text));
|
|
2952
|
+
|
|
2953
|
+
-- 9. Live meekijken
|
|
2954
|
+
do $$ begin if not exists (select 1 from pg_publication_tables where pubname='supabase_realtime' and schemaname='public' and tablename='print_jobs') then alter publication supabase_realtime add table public.print_jobs; end if; end $$;
|
|
2955
|
+
do $$ begin if not exists (select 1 from pg_publication_tables where pubname='supabase_realtime' and schemaname='public' and tablename='print_job_logs') then alter publication supabase_realtime add table public.print_job_logs; end if; end $$;
|
|
2956
|
+
do $$ begin if not exists (select 1 from pg_publication_tables where pubname='supabase_realtime' and schemaname='public' and tablename='print_computer_status') then alter publication supabase_realtime add table public.print_computer_status; end if; end $$;
|
|
2957
|
+
|
|
2958
|
+
-- 10. Geplande taken (geen adres of sleutel: de functies lezen die uit de eigen database)
|
|
2959
|
+
do $$ begin if exists (select 1 from pg_extension where extname='pg_cron') then execute 'select cron.unschedule(''print-queue-cleanup'') where exists (select 1 from cron.job where jobname=''print-queue-cleanup'')'; else raise notice 'layout-maker: overgeslagen – pg_cron ontbreekt; geplande taak niet aangemaakt'; end if; end $$;
|
|
2960
|
+
do $$ begin if exists (select 1 from pg_extension where extname='pg_cron') then execute 'select cron.schedule(''print-queue-cleanup'', ''20 3 * * *'', '' SELECT public.opruim_print_historie(); '')'; else raise notice 'layout-maker: overgeslagen – pg_cron ontbreekt; geplande taak niet aangemaakt'; end if; end $$;
|
|
2961
|
+
do $$ begin if exists (select 1 from pg_extension where extname='pg_cron') then execute 'select cron.unschedule(''print-queue-tick'') where exists (select 1 from cron.job where jobname=''print-queue-tick'')'; else raise notice 'layout-maker: overgeslagen – pg_cron ontbreekt; geplande taak niet aangemaakt'; end if; end $$;
|
|
2962
|
+
do $$ begin if exists (select 1 from pg_extension where extname='pg_cron') then execute 'select cron.schedule(''print-queue-tick'', ''* * * * *'', '' SELECT public.run_print_queue_ticks(); '')'; else raise notice 'layout-maker: overgeslagen – pg_cron ontbreekt; geplande taak niet aangemaakt'; end if; end $$;
|
|
2963
|
+
|
|
2964
|
+
-- 11. Standaarden van Flow Selections (1.65.0)
|
|
2965
|
+
-- 1.65.0: standaardlayouts per benodigd document, automatisch standaard, automatische printer
|
|
2966
|
+
ALTER TABLE public.document_layouts ADD COLUMN IF NOT EXISTS standaard_sleutel text;
|
|
2967
|
+
ALTER TABLE public.document_layouts ADD COLUMN IF NOT EXISTS standaard_versie integer;
|
|
2968
|
+
CREATE UNIQUE INDEX IF NOT EXISTS uniq_document_layout_standaard_sleutel
|
|
2969
|
+
ON public.document_layouts (standaard_sleutel) WHERE standaard_sleutel IS NOT NULL;
|
|
2970
|
+
|
|
2971
|
+
CREATE TABLE IF NOT EXISTS public.layout_standaarden (
|
|
2972
|
+
sleutel text PRIMARY KEY,
|
|
2973
|
+
versie integer NOT NULL,
|
|
2974
|
+
documenttype public.doc_layout_type NOT NULL,
|
|
2975
|
+
naam text NOT NULL,
|
|
2976
|
+
omschrijving text NOT NULL DEFAULT '',
|
|
2977
|
+
papierformaat text NOT NULL DEFAULT 'A4',
|
|
2978
|
+
breedte_mm numeric NOT NULL DEFAULT 210,
|
|
2979
|
+
hoogte_mm numeric NOT NULL DEFAULT 297,
|
|
2980
|
+
config jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
2981
|
+
page_settings jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
2982
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
2983
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
2984
|
+
);
|
|
2985
|
+
GRANT SELECT ON public.layout_standaarden TO authenticated;
|
|
2986
|
+
GRANT ALL ON public.layout_standaarden TO service_role;
|
|
2987
|
+
ALTER TABLE public.layout_standaarden ENABLE ROW LEVEL SECURITY;
|
|
2988
|
+
DROP POLICY IF EXISTS "Standaarden lezen" ON public.layout_standaarden;
|
|
2989
|
+
CREATE POLICY "Standaarden lezen" ON public.layout_standaarden FOR SELECT TO authenticated USING (true);
|
|
2990
|
+
|
|
2991
|
+
CREATE TABLE IF NOT EXISTS public.layout_auto_acties (
|
|
2992
|
+
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
2993
|
+
actie text NOT NULL,
|
|
2994
|
+
documenttype text,
|
|
2995
|
+
layout_id uuid,
|
|
2996
|
+
printer_id uuid,
|
|
2997
|
+
detail text NOT NULL DEFAULT '',
|
|
2998
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
2999
|
+
);
|
|
3000
|
+
GRANT SELECT ON public.layout_auto_acties TO authenticated;
|
|
3001
|
+
GRANT ALL ON public.layout_auto_acties TO service_role;
|
|
3002
|
+
ALTER TABLE public.layout_auto_acties ENABLE ROW LEVEL SECURITY;
|
|
3003
|
+
DROP POLICY IF EXISTS "Automatische acties lezen" ON public.layout_auto_acties;
|
|
3004
|
+
CREATE POLICY "Automatische acties lezen" ON public.layout_auto_acties FOR SELECT TO authenticated USING (true);
|
|
3005
|
+
|
|
3006
|
+
-- Referentiedata: vaste Flow Selections-standaarden (klant-onafhankelijk). Alleen een hogere versie vervangt.
|
|
3007
|
+
INSERT INTO public.layout_standaarden AS s (sleutel, versie, documenttype, naam, omschrijving, papierformaat, breedte_mm, hoogte_mm, config)
|
|
3008
|
+
VALUES
|
|
3009
|
+
('fs.pakbon', 1, 'pakbon', 'Pakbon', 'Standaarddocument voor eigen orders. Volledig aanpasbaar — aanpassen kan per klant.', 'A4', 210, 297, '{}'::jsonb),
|
|
3010
|
+
('fs.afleverbrief_bvo', 1, 'afleverbrief', 'Afleverbrief (BVO)', 'Verzendbrief voor eigen (niet-Floriday) orders. Volledig aanpasbaar.', 'A4', 210, 297, '{}'::jsonb),
|
|
3011
|
+
('fs.productiebon', 1, 'productiebon', 'Productiebon', 'Standaard productiebon met de vaste blokindeling. Volledig aanpasbaar.', 'A4', 210, 297, '{}'::jsonb)
|
|
3012
|
+
ON CONFLICT (sleutel) DO UPDATE SET
|
|
3013
|
+
versie = EXCLUDED.versie, documenttype = EXCLUDED.documenttype, naam = EXCLUDED.naam,
|
|
3014
|
+
omschrijving = EXCLUDED.omschrijving, papierformaat = EXCLUDED.papierformaat,
|
|
3015
|
+
breedte_mm = EXCLUDED.breedte_mm, hoogte_mm = EXCLUDED.hoogte_mm,
|
|
3016
|
+
config = EXCLUDED.config, page_settings = EXCLUDED.page_settings, updated_at = now()
|
|
3017
|
+
WHERE EXCLUDED.versie > s.versie;
|
|
3018
|
+
|
|
3019
|
+
CREATE OR REPLACE FUNCTION public.layout_zorg_systeemlayouts()
|
|
3020
|
+
RETURNS integer
|
|
3021
|
+
LANGUAGE plpgsql
|
|
3022
|
+
SECURITY DEFINER
|
|
3023
|
+
SET search_path TO 'public'
|
|
3024
|
+
AS $function$
|
|
3025
|
+
DECLARE
|
|
3026
|
+
v_aantal integer := 0;
|
|
3027
|
+
v_n integer;
|
|
3028
|
+
v_id uuid;
|
|
3029
|
+
v_plek uuid;
|
|
3030
|
+
v_formaat text;
|
|
3031
|
+
v_label boolean;
|
|
3032
|
+
v_kand uuid[];
|
|
3033
|
+
r record;
|
|
3034
|
+
BEGIN
|
|
3035
|
+
PERFORM pg_advisory_xact_lock(hashtext('layout_zorg_systeemlayouts'));
|
|
3036
|
+
|
|
3037
|
+
-- 1. Floriday-systeemlayouts: sleutel bron='floriday' + documenttype (ook uitgezet telt).
|
|
3038
|
+
FOR r IN SELECT * FROM (VALUES
|
|
3039
|
+
('Afleverbrief (Floriday)', 'afleverbrief', 'A4', 210::numeric, 297::numeric),
|
|
3040
|
+
('Veilingbrief (Floriday)', 'veilingbrief', 'A4', 210, 297),
|
|
3041
|
+
('Sticker (Floriday)', 'sticker', 'LABEL_100x62', 100, 62),
|
|
3042
|
+
('Traysticker (Floriday)', 'traysticker', 'LABEL_100x62', 100, 62)
|
|
3043
|
+
) AS t(naam, soort, formaat, b, h)
|
|
3044
|
+
LOOP
|
|
3045
|
+
IF NOT EXISTS (SELECT 1 FROM document_layouts WHERE bron = 'floriday' AND documenttype::text = r.soort) THEN
|
|
3046
|
+
INSERT INTO document_layouts
|
|
3047
|
+
(naam, documenttype, omschrijving, papierformaat, breedte_mm, hoogte_mm, orientatie, bron, systeem, actief)
|
|
3048
|
+
VALUES (r.naam, r.soort::doc_layout_type,
|
|
3049
|
+
'Floriday levert dit document kant-en-klaar aan; het wordt 1-op-1 geprint zonder schalen.',
|
|
3050
|
+
r.formaat, r.b, r.h, 'portrait', 'floriday', true, true)
|
|
3051
|
+
RETURNING id INTO v_id;
|
|
3052
|
+
INSERT INTO layout_auto_acties (actie, documenttype, layout_id, detail)
|
|
3053
|
+
VALUES ('layout_aangemaakt', r.soort, v_id, 'Floriday-systeemlayout toegevoegd');
|
|
3054
|
+
v_aantal := v_aantal + 1;
|
|
3055
|
+
END IF;
|
|
3056
|
+
END LOOP;
|
|
3057
|
+
|
|
3058
|
+
-- 2. Flow Selections-standaard per benodigd document: alleen als er geen enkele actieve eigen
|
|
3059
|
+
-- layout van die soort is en deze standaard nooit eerder is aangemaakt (ook niet uitgezet).
|
|
3060
|
+
FOR r IN SELECT * FROM layout_standaarden ORDER BY sleutel LOOP
|
|
3061
|
+
IF NOT EXISTS (SELECT 1 FROM document_layouts WHERE standaard_sleutel = r.sleutel)
|
|
3062
|
+
AND NOT EXISTS (SELECT 1 FROM document_layouts
|
|
3063
|
+
WHERE documenttype = r.documenttype AND actief AND coalesce(bron,'eigen') <> 'floriday') THEN
|
|
3064
|
+
INSERT INTO document_layouts
|
|
3065
|
+
(naam, documenttype, omschrijving, papierformaat, breedte_mm, hoogte_mm, orientatie, bron, systeem, actief,
|
|
3066
|
+
is_standaard, config, page_settings, standaard_sleutel, standaard_versie, huidige_versie)
|
|
3067
|
+
VALUES (r.naam, r.documenttype, r.omschrijving, r.papierformaat, r.breedte_mm, r.hoogte_mm, 'portrait',
|
|
3068
|
+
'eigen', false, true, true, r.config, r.page_settings, r.sleutel, r.versie, 1)
|
|
3069
|
+
RETURNING id INTO v_id;
|
|
3070
|
+
INSERT INTO document_layout_versions (layout_id, versienummer, elements, page_settings, commentaar)
|
|
3071
|
+
VALUES (v_id, 1, '[]'::jsonb,
|
|
3072
|
+
jsonb_build_object('_snapshot', true, 'config', r.config, 'page_settings', r.page_settings),
|
|
3073
|
+
'Standaard van Flow Selections, versie ' || r.versie);
|
|
3074
|
+
INSERT INTO layout_auto_acties (actie, documenttype, layout_id, detail)
|
|
3075
|
+
VALUES ('layout_aangemaakt', r.documenttype::text, v_id, 'Standaard ' || r.sleutel || ' versie ' || r.versie || ' toegevoegd en standaard gemaakt');
|
|
3076
|
+
v_aantal := v_aantal + 1;
|
|
3077
|
+
END IF;
|
|
3078
|
+
END LOOP;
|
|
3079
|
+
|
|
3080
|
+
-- 3. Geen standaard maar precies één actieve layout (per soort en bron): die wordt standaard.
|
|
3081
|
+
FOR r IN SELECT min(l.id::text)::uuid AS id, l.documenttype::text AS soort, coalesce(l.bron,'eigen') AS bron
|
|
3082
|
+
FROM document_layouts l WHERE l.actief
|
|
3083
|
+
GROUP BY l.documenttype, coalesce(l.bron,'eigen')
|
|
3084
|
+
HAVING count(*) = 1 AND NOT bool_or(l.is_standaard) LOOP
|
|
3085
|
+
UPDATE document_layouts SET is_standaard = true WHERE id = r.id;
|
|
3086
|
+
INSERT INTO layout_auto_acties (actie, documenttype, layout_id, detail)
|
|
3087
|
+
VALUES ('standaard_gemaakt', r.soort, r.id, 'Enige actieve layout (bron ' || r.bron || ') automatisch standaard gemaakt');
|
|
3088
|
+
v_aantal := v_aantal + 1;
|
|
3089
|
+
END LOOP;
|
|
3090
|
+
|
|
3091
|
+
-- 4. Standaardprinter: alleen bij precies één actieve printplek, geen bestaande regel voor de soort,
|
|
3092
|
+
-- en precies één passende actieve printer op die plek. Bestaande keuzes nooit overschrijven.
|
|
3093
|
+
SELECT CASE WHEN count(*) = 1 THEN min(id::text)::uuid END INTO v_plek FROM print_plekken WHERE actief;
|
|
3094
|
+
IF v_plek IS NOT NULL THEN
|
|
3095
|
+
FOR r IN SELECT unnest(ARRAY['pakbon','afleverbrief','productiebon','sticker','traysticker','veilingbrief']) AS soort LOOP
|
|
3096
|
+
CONTINUE WHEN EXISTS (SELECT 1 FROM document_formaat_printers WHERE documenttype = r.soort);
|
|
3097
|
+
CONTINUE WHEN EXISTS (SELECT 1 FROM document_printplek_printers WHERE documenttype = r.soort);
|
|
3098
|
+
SELECT l.papierformaat INTO v_formaat FROM document_layouts l
|
|
3099
|
+
WHERE l.documenttype::text = r.soort AND l.actief
|
|
3100
|
+
ORDER BY l.is_standaard DESC, (coalesce(l.bron,'eigen') = 'eigen') DESC, l.updated_at DESC LIMIT 1;
|
|
3101
|
+
v_formaat := coalesce(v_formaat, 'A4');
|
|
3102
|
+
v_label := public.print_is_etiketsoort(r.soort) OR public.print_formaat_klasse(v_formaat) = 'label';
|
|
3103
|
+
SELECT array_agg(p.id) INTO v_kand
|
|
3104
|
+
FROM print_plek_printers pp JOIN printers p ON p.id = pp.printer_id
|
|
3105
|
+
WHERE pp.print_plek_id = v_plek AND p.actief IS DISTINCT FROM false
|
|
3106
|
+
AND NOT coalesce(p.is_virtueel, false) AND NOT coalesce(p.verborgen, false)
|
|
3107
|
+
AND CASE WHEN v_label THEN public.print_is_labelprinter(p.id) AND p.geladen_etiket IS NOT NULL
|
|
3108
|
+
ELSE NOT public.print_is_labelprinter(p.id) END;
|
|
3109
|
+
IF coalesce(array_length(v_kand, 1), 0) = 1 THEN
|
|
3110
|
+
INSERT INTO document_formaat_printers (documenttype, formaat_code, printer_id)
|
|
3111
|
+
VALUES (r.soort, v_formaat, v_kand[1]) ON CONFLICT DO NOTHING;
|
|
3112
|
+
GET DIAGNOSTICS v_n = ROW_COUNT;
|
|
3113
|
+
IF v_n > 0 THEN
|
|
3114
|
+
INSERT INTO layout_auto_acties (actie, documenttype, printer_id, detail)
|
|
3115
|
+
VALUES ('printer_ingesteld', r.soort, v_kand[1], 'Enige passende printer op de printplek als standaard ingesteld (' || v_formaat || ')');
|
|
3116
|
+
v_aantal := v_aantal + 1;
|
|
3117
|
+
END IF;
|
|
3118
|
+
END IF;
|
|
3119
|
+
END LOOP;
|
|
3120
|
+
END IF;
|
|
3121
|
+
|
|
3122
|
+
RETURN v_aantal;
|
|
3123
|
+
END $function$;
|
|
3124
|
+
REVOKE ALL ON FUNCTION public.layout_zorg_systeemlayouts() FROM PUBLIC, anon, authenticated;
|
|
3125
|
+
GRANT EXECUTE ON FUNCTION public.layout_zorg_systeemlayouts() TO service_role;
|
|
3126
|
+
|
|
3127
|
+
CREATE OR REPLACE FUNCTION public._layout_is_beheerder()
|
|
3128
|
+
RETURNS boolean LANGUAGE plpgsql STABLE SECURITY DEFINER SET search_path TO 'public'
|
|
3129
|
+
AS $function$
|
|
3130
|
+
BEGIN
|
|
3131
|
+
IF auth.uid() IS NULL THEN RETURN false; END IF;
|
|
3132
|
+
RETURN public.has_role(auth.uid(), 'admin'::app_role) OR public.has_role(auth.uid(), 'superadmin'::app_role) OR public.has_role(auth.uid(), 'developer'::app_role);
|
|
3133
|
+
END $function$;
|
|
3134
|
+
REVOKE ALL ON FUNCTION public._layout_is_beheerder() FROM PUBLIC, anon;
|
|
3135
|
+
GRANT EXECUTE ON FUNCTION public._layout_is_beheerder() TO authenticated, service_role;
|
|
3136
|
+
|
|
3137
|
+
-- Overnemen / terug naar de standaard: twee nieuwe versies (vóór en na), niets wordt verwijderd.
|
|
3138
|
+
CREATE OR REPLACE FUNCTION public.layout_standaard_overnemen(_layout_id uuid)
|
|
3139
|
+
RETURNS jsonb LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public'
|
|
3140
|
+
AS $function$
|
|
3141
|
+
DECLARE l record; s record; v_n integer; v_el jsonb;
|
|
3142
|
+
BEGIN
|
|
3143
|
+
IF NOT public._layout_is_beheerder() THEN RAISE EXCEPTION 'GEEN_RECHTEN: alleen een beheerder kan dit doen.'; END IF;
|
|
3144
|
+
SELECT * INTO l FROM document_layouts WHERE id = _layout_id FOR UPDATE;
|
|
3145
|
+
IF NOT FOUND THEN RAISE EXCEPTION 'LAYOUT_ONBEKEND'; END IF;
|
|
3146
|
+
IF coalesce(l.bron,'eigen') = 'floriday' THEN RAISE EXCEPTION 'FLORIDAY_LAYOUT: deze layout komt uit Floriday.'; END IF;
|
|
3147
|
+
SELECT * INTO s FROM layout_standaarden
|
|
3148
|
+
WHERE (l.standaard_sleutel IS NOT NULL AND sleutel = l.standaard_sleutel)
|
|
3149
|
+
OR (l.standaard_sleutel IS NULL AND documenttype = l.documenttype)
|
|
3150
|
+
ORDER BY (sleutel = l.standaard_sleutel) DESC NULLS LAST LIMIT 1;
|
|
3151
|
+
IF NOT FOUND THEN RAISE EXCEPTION 'GEEN_STANDAARD: voor deze documentsoort is geen standaard van Flow Selections.'; END IF;
|
|
3152
|
+
SELECT coalesce(max(versienummer), 0) INTO v_n FROM document_layout_versions WHERE layout_id = l.id;
|
|
3153
|
+
SELECT coalesce(jsonb_agg(to_jsonb(e)), '[]'::jsonb) INTO v_el FROM document_layout_elements e WHERE e.layout_id = l.id;
|
|
3154
|
+
INSERT INTO document_layout_versions (layout_id, versienummer, elements, page_settings, commentaar, created_by)
|
|
3155
|
+
VALUES (l.id, v_n + 1, v_el, jsonb_build_object('_snapshot', true, 'config', l.config, 'page_settings', l.page_settings),
|
|
3156
|
+
'Vóór overnemen standaard versie ' || s.versie, auth.uid());
|
|
3157
|
+
UPDATE document_layouts SET config = s.config, page_settings = s.page_settings,
|
|
3158
|
+
standaard_versie = s.versie, huidige_versie = v_n + 2, updated_at = now()
|
|
3159
|
+
WHERE id = l.id;
|
|
3160
|
+
INSERT INTO document_layout_versions (layout_id, versienummer, elements, page_settings, commentaar, created_by)
|
|
3161
|
+
VALUES (l.id, v_n + 2, v_el, jsonb_build_object('_snapshot', true, 'config', s.config, 'page_settings', s.page_settings),
|
|
3162
|
+
'Standaard van Flow Selections, versie ' || s.versie, auth.uid());
|
|
3163
|
+
RETURN jsonb_build_object('versie_voor', v_n + 1, 'versie_na', v_n + 2, 'standaard_versie', s.versie);
|
|
3164
|
+
END $function$;
|
|
3165
|
+
REVOKE ALL ON FUNCTION public.layout_standaard_overnemen(uuid) FROM PUBLIC, anon;
|
|
3166
|
+
GRANT EXECUTE ON FUNCTION public.layout_standaard_overnemen(uuid) TO authenticated, service_role;
|
|
3167
|
+
|
|
3168
|
+
-- Een eerder bewaarde stand (config) terugzetten; maakt zelf een nieuwe versie.
|
|
3169
|
+
CREATE OR REPLACE FUNCTION public.layout_versie_terugzetten(_versie_id uuid)
|
|
3170
|
+
RETURNS integer LANGUAGE plpgsql SECURITY DEFINER SET search_path TO 'public'
|
|
3171
|
+
AS $function$
|
|
3172
|
+
DECLARE v record; l record; v_n integer;
|
|
3173
|
+
BEGIN
|
|
3174
|
+
IF NOT public._layout_is_beheerder() THEN RAISE EXCEPTION 'GEEN_RECHTEN: alleen een beheerder kan dit doen.'; END IF;
|
|
3175
|
+
SELECT * INTO v FROM document_layout_versions WHERE id = _versie_id;
|
|
3176
|
+
IF NOT FOUND OR coalesce((v.page_settings->>'_snapshot')::boolean, false) IS NOT TRUE THEN
|
|
3177
|
+
RAISE EXCEPTION 'GEEN_STAND: deze versie bevat geen bewaarde stand.';
|
|
3178
|
+
END IF;
|
|
3179
|
+
SELECT * INTO l FROM document_layouts WHERE id = v.layout_id FOR UPDATE;
|
|
3180
|
+
SELECT coalesce(max(versienummer), 0) INTO v_n FROM document_layout_versions WHERE layout_id = l.id;
|
|
3181
|
+
UPDATE document_layouts SET config = coalesce(v.page_settings->'config', '{}'::jsonb),
|
|
3182
|
+
page_settings = coalesce(v.page_settings->'page_settings', '{}'::jsonb),
|
|
3183
|
+
huidige_versie = v_n + 1, updated_at = now() WHERE id = l.id;
|
|
3184
|
+
INSERT INTO document_layout_versions (layout_id, versienummer, elements, page_settings, commentaar, created_by)
|
|
3185
|
+
VALUES (l.id, v_n + 1, v.elements, v.page_settings, 'Teruggezet naar versie ' || v.versienummer, auth.uid());
|
|
3186
|
+
RETURN v_n + 1;
|
|
3187
|
+
END $function$;
|
|
3188
|
+
REVOKE ALL ON FUNCTION public.layout_versie_terugzetten(uuid) FROM PUBLIC, anon;
|
|
3189
|
+
GRANT EXECUTE ON FUNCTION public.layout_versie_terugzetten(uuid) TO authenticated, service_role;
|
|
3190
|
+
|
|
3191
|
+
|
|
3192
|
+
-- 12. Aanvulronde: standaardlayouts, standaard maken en standaardprinter (1.65.0)
|
|
3193
|
+
-- Idempotent. Draait hier één keer; mislukt dat (bijv. omdat een nieuwe enumwaarde in dezelfde
|
|
3194
|
+
-- transactie nog niet bruikbaar is), dan doet de module het bij de volgende wachtrijronde of bij het
|
|
3195
|
+
-- openen van Layouts/Printen.
|
|
3196
|
+
do $$ begin perform public.layout_zorg_systeemlayouts();
|
|
3197
|
+
exception when others then raise notice 'layout_zorg_systeemlayouts later via de module: %', sqlerrm; end $$;
|
|
3198
|
+
|
|
3199
|
+
-- 13. Controle op onderdelen van andere modules (alleen meldingen; niets stopt)
|
|
3200
|
+
do $$ begin
|
|
3201
|
+
if to_regclass('public.module_runtime_config') is null then raise notice 'layout-maker: module_runtime_config ontbreekt (Shell); printen blijft dicht tot het Shell-adres er is'; end if;
|
|
3202
|
+
if to_regclass('public.app_settings') is null then raise notice 'layout-maker: app_settings ontbreekt (Shell); bedrijfsgegevens worden niet bewaard'; end if;
|
|
3203
|
+
if to_regclass('public.invoice_branding_settings') is null then raise notice 'layout-maker: invoice_branding_settings ontbreekt; voorinvullen uit factuurgegevens overgeslagen'; end if;
|
|
3204
|
+
if to_regprocedure('public.floriday_eigen_organisatie()') is null then raise notice 'layout-maker: floriday_eigen_organisatie() ontbreekt; voorinvullen uit Floriday overgeslagen'; end if;
|
|
3205
|
+
end $$;
|