|
1
|
-- m?dulo pr?stamos
|
|
2
|
|
|
3
|
create table tipo_archivo(
|
|
4
|
id int not null,
|
|
5
|
nombre character varying(100) not null,
|
|
6
|
constraint pk_tipo_archivo primary key(id),
|
|
7
|
constraint uq_tipo_archivo_nombre unique(nombre)
|
|
8
|
);
|
|
9
|
|
|
10
|
create table estado(
|
|
11
|
id int not null,
|
|
12
|
nombre character varying(100) not null,
|
|
13
|
constraint pk_estado primary key(id),
|
|
14
|
constraint uq_estado_nombre unique(nombre)
|
|
15
|
);
|
|
16
|
|
|
17
|
create table destino(
|
|
18
|
id int not null,
|
|
19
|
nombre character varying(100) not null,
|
|
20
|
constraint pk_destino primary key(id),
|
|
21
|
constraint uq_destino_nombre unique(nombre)
|
|
22
|
);
|
|
23
|
|
|
24
|
create table tipo_garantia(
|
|
25
|
id int not null,
|
|
26
|
nombre character varying(100) not null,
|
|
27
|
constraint pk_tipo_garantia primary key(id),
|
|
28
|
constraint uq_tipo_garantia_nombre unique(nombre)
|
|
29
|
);
|
|
30
|
|
|
31
|
create table tipo_plazo(
|
|
32
|
id int not null,
|
|
33
|
nombre character varying(100) not null,
|
|
34
|
constraint pk_tipo_plazo primary key(id),
|
|
35
|
constraint uq_tipo_plazo_nombre unique(nombre)
|
|
36
|
);
|
|
37
|
|
|
38
|
create table archivo_solicitud(
|
|
39
|
id int not null,
|
|
40
|
archivo_id int not null,
|
|
41
|
solicitud_id int not null,
|
|
42
|
constraint pk_archivo_solicitud primary key(id),
|
|
43
|
constraint fk_archivo_solicitud_archivo_id foreign key(archivo_id) references archivo(id),
|
|
44
|
constraint fk_archivo_solicitud_solicitud_id foreign key(solicitud_id) references solicitud(id)
|
|
45
|
);
|
|
46
|
|
|
47
|
create table archivo(
|
|
48
|
id int not null,
|
|
49
|
fecha_subida date not null,
|
|
50
|
tipo_archivo_id int not null,
|
|
51
|
ruta character varying(200) not null,
|
|
52
|
nombre_archivo character varying(100) not null,
|
|
53
|
tipo_extension character varying(30) not null,
|
|
54
|
solicitud_id int,
|
|
55
|
constraint pk_archivo primary key(id),
|
|
56
|
constraint fk_archivo_tipo_archivo_id foreign key(tipo_archivo_id) references tipo_archivo(id),
|
|
57
|
constraint fk_archivo_solicitud_id foreign key(solicitud_id) references solicitud(id)
|
|
58
|
);
|
|
59
|
|
|
60
|
create table cuenta(
|
|
61
|
id int not null,
|
|
62
|
socio_id int not null, --titular de cuenta
|
|
63
|
fecha_apertura date not null,
|
|
64
|
fecha_expiracion date,
|
|
65
|
solicitud_id int,
|
|
66
|
saldo numeric,
|
|
67
|
saldo_promedio numeric,
|
|
68
|
saldo_contable numeric,
|
|
69
|
saldo_bloqueado numeric,
|
|
70
|
saldo_retenido numeric,
|
|
71
|
dias_atraso int,
|
|
72
|
maximo_atraso int,
|
|
73
|
monto_atraso numeric,
|
|
74
|
motivo_cancelacion character varying(100) not null,
|
|
75
|
fecha_cancelacion date,
|
|
76
|
fecha_ultimo_movimiento date,
|
|
77
|
estado_cuenta_id int not null,
|
|
78
|
tipo_cuenta_id int not null,
|
|
79
|
constraint pk_cuenta primary key(id),
|
|
80
|
constraint fk_cuenta_socio_id foreign key(socio_id) references socio(id),
|
|
81
|
constraint fk_cuenta_solicitud_id foreign key(solicitud_id) references solicitud(id),
|
|
82
|
constraint fk_cuenta_estado_cuenta_id foreign key(estado_cuenta_id) references estado_cuenta(id),
|
|
83
|
constraint fk_cuenta_tipo_cuenta_id foreign key(tipo_cuenta_id) references tipo_cuenta(id)
|
|
84
|
);
|
|
85
|
|
|
86
|
create table cuenta_socio(
|
|
87
|
id int not null,
|
|
88
|
persona_id int not null,
|
|
89
|
cuenta_id int not null,
|
|
90
|
es_titular boolean not null,
|
|
91
|
constraint pk_cuenta_socio primary key(id),
|
|
92
|
constraint fk_cuenta_estado_persona_id foreign key(persona_id) references persona(id),
|
|
93
|
constraint fk_cuenta_estado_cuenta_id foreign key(cuenta_id) references cuenta(id)
|
|
94
|
);
|
|
95
|
|
|
96
|
create table perfil_economico(
|
|
97
|
id int not null,
|
|
98
|
fecha date not null,
|
|
99
|
persona_id int not null,
|
|
100
|
inmueble_id int not null,
|
|
101
|
rodado_id int not null,
|
|
102
|
cuentas_externas_id int not null,
|
|
103
|
otros_bienes_id int not null,
|
|
104
|
deudas_externas_id int not null,
|
|
105
|
deudas_hipotecarias_id int not null,
|
|
106
|
renta_mensual_id int not null,
|
|
107
|
constraint pk_perfil_economico primary key(id),
|
|
108
|
constraint fk_perfil_economico_persona_id foreign key(persona_id) references persona(id),
|
|
109
|
constraint fk_perfil_economico_inmueble_id foreign key(inmueble_id) references inmueble(id),
|
|
110
|
constraint fk_perfil_economico_rodado_id foreign key(rodado_id) references rodado(id),
|
|
111
|
constraint fk_perfil_economico_cuentas_externas_id foreign key(cuentas_externas_id) references cuentas_externas(id),
|
|
112
|
constraint fk_perfil_economico_otros_bienes_id foreign key(otros_bienes_id) references otros_bienes(id),
|
|
113
|
constraint fk_perfil_economico_deudas_externas_id foreign key(deudas_externas_id) references deudas_externas(id),
|
|
114
|
constraint fk_perfil_economico_deudas_hipotecarias_id foreign key(deudas_hipotecarias_id) references deudas_hipotecarias(id),
|
|
115
|
constraint fk_perfil_economico_renta_mensual_id foreign key(renta_mensual_id) references renta_mensual(id)
|
|
116
|
);
|
|
117
|
|
|
118
|
-- individual, intercooperativo, empleados
|
|
119
|
create table tipo_sujeto_credito(
|
|
120
|
id int not null,
|
|
121
|
nombre character varying(100) not null,
|
|
122
|
constraint pk_tipo_sujeto_credito primary key(id),
|
|
123
|
constraint uq_tipo_sujeto_credito_nombre unique(nombre)
|
|
124
|
);
|
|
125
|
|
|
126
|
-- normal, tarjeta cr?dito, vivienda
|
|
127
|
create table tipo_credito(
|
|
128
|
id int not null,
|
|
129
|
nombre character varying(100) not null,
|
|
130
|
constraint pk_tipo_credito primary key(id),
|
|
131
|
constraint uq_tipo_credito_nombre unique(nombre)
|
|
132
|
);
|
|
133
|
|
|
134
|
create table tipo_credito(
|
|
135
|
id int not null,
|
|
136
|
nombre character varying(100) not null,
|
|
137
|
constraint pk_tipo_credito primary key(id),
|
|
138
|
constraint uq_tipo_credito_nombre unique(nombre)
|
|
139
|
);
|
|
140
|
|
|
141
|
create table calificacion_socio(
|
|
142
|
id int not null,
|
|
143
|
socio_id int not null,
|
|
144
|
fecha date not null,
|
|
145
|
calificacion character varying(10) not null,
|
|
146
|
constraint pk_calificacion_socio primary key(id),
|
|
147
|
constraint fk_calificacion_socio_socio_id foreign key(socio_id) references socio(id)
|
|
148
|
);
|
|
149
|
|
|
150
|
create table solicitud_prorroga(
|
|
151
|
id int not null,
|
|
152
|
cuota_id int not null,
|
|
153
|
fecha_solicitud date not null,
|
|
154
|
motivo character varying(100) not null,
|
|
155
|
estado_solicitud_id int not null,
|
|
156
|
constraint pk_solicitud_prorroga primary key(id),
|
|
157
|
constraint fk_solicitud_prorroga_cuota_id foreign key(cuota_id) references cuota(id),
|
|
158
|
constraint fk_solicitud_prorroga_estado_id foreign key(estado_id) references estado(id)
|
|
159
|
);
|
|
160
|
|
|
161
|
create table solicitud_amplicacion(
|
|
162
|
id int not null,
|
|
163
|
prestamo_id int not null,
|
|
164
|
fecha_solicitud date not null,
|
|
165
|
motivo character varying(100) not null,
|
|
166
|
estado_solicitud_id int not null,
|
|
167
|
constraint pk_solicitud_amplicacion primary key(id),
|
|
168
|
constraint fk_solicitud_amplicacion_prestamo_id foreign key(prestamo_id) references prestamo(id),
|
|
169
|
constraint fk_solicitud_amplicacion_estado_id foreign key(estado_id) references estado(id)
|
|
170
|
);
|
|
171
|
|
|
172
|
create table solicitud_refinanciacion(
|
|
173
|
id int not null,
|
|
174
|
prestamo_id int not null,
|
|
175
|
fecha_solicitud date not null,
|
|
176
|
motivo character varying(100) not null,
|
|
177
|
estado_solicitud_id int not null,
|
|
178
|
constraint pk_solicitud_amplicacion primary key(id),
|
|
179
|
constraint fk_solicitud_prorroga_prestamo_id foreign key(prestamo_id) references prestamo(id),
|
|
180
|
constraint fk_solicitud_prorroga_estado_id foreign key(estado_id) references estado(id)
|
|
181
|
);
|
|
182
|
|
|
183
|
create table solicitud_consolidacion(
|
|
184
|
id int not null,
|
|
185
|
fecha_solicitud date not null,
|
|
186
|
motivo character varying(100) not null,
|
|
187
|
estado_solicitud_id int not null,
|
|
188
|
constraint pk_solicitud_amplicacion primary key(id),
|
|
189
|
constraint fk_solicitud_prorroga_estado_id foreign key(estado_id) references estado(id)
|
|
190
|
);
|
|
191
|
|
|
192
|
create table prestamo_consolidacion(
|
|
193
|
id int not null,
|
|
194
|
prestamo_id int not null,
|
|
195
|
solicitud_id int not null,
|
|
196
|
constraint pk_prestamo_consolidacion primary key(id),
|
|
197
|
constraint fk_prestamo_consolidacion_prestamo_id foreign key(prestamo_id) references prestamo(id),
|
|
198
|
constraint fk_prestamo_consolidacion_solicitud_id foreign key(solicitud_id) references solicitud_consolidacion(id)
|
|
199
|
);
|
|
200
|
|
|
201
|
create table solicitud_prestamo(
|
|
202
|
id int not null,
|
|
203
|
socio_id int not null,
|
|
204
|
fecha_solicitud date not null,
|
|
205
|
nro_solicitud character varying(20) not null,
|
|
206
|
monto_solicitado numeric not null,
|
|
207
|
cant_cuotas int not null,
|
|
208
|
observacion character varying(200),
|
|
209
|
perfil_economico_id int not null,
|
|
210
|
destino_id int not null,
|
|
211
|
tipo_credito_id int not null,
|
|
212
|
tipo_garantia_id int not null,
|
|
213
|
tipo_plazo_id int not null,
|
|
214
|
producto_credito_id int not null,
|
|
215
|
constraint pk_solicitud primary key(id),
|
|
216
|
constraint fk_solicitud_persona_id foreign key(persona_id) references persona(id)
|
|
217
|
);
|
|
218
|
|
|
219
|
create table analisis_credito(
|
|
220
|
id int not null,
|
|
221
|
solicitud_prestamo_id int not null,
|
|
222
|
analizado_por int not null,
|
|
223
|
fecha_analisis date,
|
|
224
|
recomendacion_analista character varying(100),
|
|
225
|
jefe_por int not null,
|
|
226
|
fecha_analisis_jefe date,
|
|
227
|
recomendacion_jefe character varying(100),
|
|
228
|
gerente_por int not null,
|
|
229
|
fecha_analisis_gerente date,
|
|
230
|
recomendacion_gerente character varying(100),
|
|
231
|
comite_por int not null,
|
|
232
|
fecha_analisis_comite date,
|
|
233
|
recomendacion_comite character varying(100),
|
|
234
|
consejo_por int not null,
|
|
235
|
fecha_analisis_consejo date,
|
|
236
|
recomendacion_consejo character varying(100),
|
|
237
|
estado_id int not null,
|
|
238
|
fecha_estado date not null,
|
|
239
|
constraint pk_analisis_credito primary key(id)
|
|
240
|
-- falta agregar los fks
|
|
241
|
);
|
|
242
|
|
|
243
|
create table prestamo(
|
|
244
|
id int not null,
|
|
245
|
cuenta_id int not null,
|
|
246
|
fecha_aprobacion date not null,
|
|
247
|
saldo numeric,
|
|
248
|
saldo_capital numeric,
|
|
249
|
saldo_interes numeric,
|
|
250
|
capital_pagado numeric,
|
|
251
|
interes_pagado numeric,
|
|
252
|
prevision numeric,
|
|
253
|
prevision_heredada numeric,
|
|
254
|
cantidad_cuotas int,
|
|
255
|
monto_aprobado numeric,
|
|
256
|
cantidad_cuotas_pagadas int,
|
|
257
|
producto_credito_id int not null,
|
|
258
|
constraint pk_prestamo primary key(id),
|
|
259
|
constraint fk_prestamo_cuenta_id foreign key(cuenta_id) references cuenta(id),
|
|
260
|
-- falta agregar los mismo
|
|
261
|
);
|
|
262
|
|
|
263
|
create table codeudor(
|
|
264
|
id int not null,
|
|
265
|
persona_id int not null,
|
|
266
|
prestamo_id int not null,
|
|
267
|
es_socio boolean not null,
|
|
268
|
es_conyuge boolean not null,
|
|
269
|
constraint pk_deudor primary key(id),
|
|
270
|
constraint fk_deudor_persona_id foreign key(persona_id) references persona(id),
|
|
271
|
constraint fk_deudor_prestamo_id foreign key(prestamo_id) references prestamo(id)
|
|
272
|
);
|
|
273
|
|
|
274
|
create table tipo_accion(
|
|
275
|
id int not null,
|
|
276
|
nombre character varying(100) not null,
|
|
277
|
constraint pk_tipo_accion primary key(id),
|
|
278
|
constraint uq_tipo_accion_nombre unique(nombre)
|
|
279
|
);
|
|
280
|
|
|
281
|
create table recuperacion(
|
|
282
|
id int not null,
|
|
283
|
prestamo_id int not null,
|
|
284
|
etapa int not null,
|
|
285
|
tipo_accion_id int not null,
|
|
286
|
tratamiento character varying(200) not null,
|
|
287
|
constraint pk_tipo_archivo primary key(id),
|
|
288
|
constraint fk_recuperacion_prestamo_id foreign key(prestamo_id) references prestamo(id),
|
|
289
|
constraint fk_recuperacion_tipo_accion_id foreign key(tipo_accion_id) references tipo_accion(id)
|
|
290
|
);
|
|
291
|
|
|
292
|
-- cheque, deposito ahorro
|
|
293
|
create table tipo_desembolso(
|
|
294
|
id int not null,
|
|
295
|
nombre character varying(100) not null,
|
|
296
|
constraint pk_tipo_desembolso primary key(id),
|
|
297
|
constraint uq_tipo_desembolso_nombre unique(nombre)
|
|
298
|
);
|
|
299
|
|
|
300
|
create table descuento_desembolso(
|
|
301
|
id int not null,
|
|
302
|
nombre character varying(100) not null,
|
|
303
|
constraint pk_descuento_desembolso primary key(id),
|
|
304
|
constraint uq_descuento_desembolso_nombre unique(nombre)
|
|
305
|
);
|
|
306
|
|
|
307
|
create table desembolso(
|
|
308
|
id int not null,
|
|
309
|
prestamo_id int not null,
|
|
310
|
fecha date not null,
|
|
311
|
constraint pk_desembolso primary key(id),
|
|
312
|
constraint fk_desembolso_prestamo_id foreign key(prestamo_id) references prestamo(id)
|
|
313
|
);
|
|
314
|
|
|
315
|
create table detalle_desembolso(
|
|
316
|
id int not null,
|
|
317
|
desembolso_id int not null,
|
|
318
|
tipo_desembolso_id int not null,
|
|
319
|
monto numeric not null,
|
|
320
|
ahorro_id int,
|
|
321
|
cheque_id int,
|
|
322
|
constraint pk_detalle_desembolso primary key(id),
|
|
323
|
constraint fk_detalle_desembolso_tipo_desembolso_id foreign key(tipo_desembolso_id) references tipo_desembolso(id)
|
|
324
|
);
|
|
325
|
|
|
326
|
create table detalle_descuento(
|
|
327
|
id int not null,
|
|
328
|
desembolso_id int not null,
|
|
329
|
descuento_id int not null,
|
|
330
|
monto numeric not null,
|
|
331
|
constraint pk_detalle_descuento primary key(id),
|
|
332
|
constraint fk_detalle_descuento_desembolso_id foreign key(desembolso_id) references desembolso(id),
|
|
333
|
constraint fk_detalle_descuento_descuento_id foreign key(descuento_id) references descuento(id)
|
|
334
|
);
|
|
335
|
|
|
336
|
-- plan de pago (ideal)
|
|
337
|
create table plan_pago(
|
|
338
|
id int not null,
|
|
339
|
cuenta_id int not null, -- 12548
|
|
340
|
monto_capital numeric not null, -- 100
|
|
341
|
interes numeric not null, -- 10
|
|
342
|
saldo numeric,
|
|
343
|
nro_cuota int,
|
|
344
|
fecha_vencimiento date not null,
|
|
345
|
constraint pk_cuota primary key(id),
|
|
346
|
constraint fk_cuota_cuenta_id foreign key(cuenta_id) references cuenta(id)
|
|
347
|
);
|
|
348
|
|
|
349
|
create table cuota(
|
|
350
|
id int not null,
|
|
351
|
cuenta_id int not null, -- 12548
|
|
352
|
monto_capital numeric not null, -- 100
|
|
353
|
interes numeric not null, -- 10
|
|
354
|
interes_moratorio numeric,
|
|
355
|
interes_punitorio numeric,
|
|
356
|
saldo numeric,
|
|
357
|
nro_cuota int,
|
|
358
|
fecha_vencimiento date not null,
|
|
359
|
constraint pk_cuota primary key(id),
|
|
360
|
constraint fk_cuota_cuenta_id foreign key(cuenta_id) references cuenta(id)
|
|
361
|
);
|
|
362
|
|
|
363
|
create table producto_credito(
|
|
364
|
id int not null,
|
|
365
|
nombre character varying(100) not null,
|
|
366
|
tipo_credito_id int not null, -- consumo
|
|
367
|
sub_tipo_id int not null, -- compra anteojos
|
|
368
|
monto_hasta numeric not null, -- 5.000.000
|
|
369
|
relacion_aporte character varying(20) not null, -- 1/15
|
|
370
|
plazo_minimo int not null, -- 6
|
|
371
|
plazo_maximo int not null, -- 36
|
|
372
|
constraint pk_producto_credito primary key(id),
|
|
373
|
constraint fk_producto_credito_tipo_credito_id foreign key(tipo_credito_id) references tipo_credito(id),
|
|
374
|
constraint fk_producto_credito_sub_tipo_id foreign key(sub_tipo_id) references sub_tipo_credito(id)
|
|
375
|
);
|
|
376
|
|
|
377
|
create table producto_detalle(
|
|
378
|
id int not null,
|
|
379
|
producto_credito_id int not null,
|
|
380
|
cuota_desde int not null, -- 13
|
|
381
|
cuota_hasta int not null, -- 16
|
|
382
|
tasa numeric not null, -- 18
|
|
383
|
constraint pk_producto_detalle primary key(id),
|
|
384
|
constraint fk_producto_detalle_producto_credito_id foreign key(tipo_credito_id) references tipo_credito(id),
|
|
385
|
);
|
|
386
|
|
|
387
|
|