· 8 years ago · Aug 18, 2018, 01:44 AM
1-- Database: "SistemaProduccion"
2
3-- DROP DATABASE "SistemaProduccion";
4drop database if exists SistemaProduccion;
5
6drop table if exists Productos
7drop table if exists Insumos
8drop table if exists Areas
9drop table if exists Empleados
10drop table if exists ValoresIniciales
11drop table if exists InicioSesion
12drop table if exists CompraXInsumo
13drop table if exists Nomina
14drop table if exists VentaXProducto
15
16CREATE DATABASE "SistemaProduccion"
17 WITH OWNER = postgres
18 ENCODING = 'UTF8'
19 TABLESPACE = pg_default
20 LC_COLLATE = 'es_CR.UTF-8'
21 LC_CTYPE = 'es_CR.UTF-8'
22 CONNECTION LIMIT = -1;
23
24create table Insumos (
25 Id serial not null,
26 Nombre char(25) not null,
27 CONSTRAINT PK_INSUMOS PRIMARY KEY (Id),
28 unique(Nombre)
29);
30
31create table Productos(
32 Id serial not null,
33 Nombre char(25) not null,
34 Precio int not null,
35 ImpuestoAplicado float not null,
36 CONSTRAINT PK_PRODUCTOS PRIMARY KEY (Id),
37 UNIQUE (Nombre)
38);
39
40create table Areas(
41 Id serial not null,
42 Nombre char(25) not null,
43 Dimension float not null,
44 ProductoProducido int not null REFERENCES Productos(Id),
45 Estado boolean not null,
46 CONSTRAINT PK_AREAS PRIMARY KEY (Id),
47 UNIQUE(Nombre)
48);
49
50create table Empleados(
51 Cedula char(25) not null,
52 Nombre char(25) not null,
53 Apellidos char(30) not null,
54 Labor char(25) not null,
55 SalarioMensual int not null,
56 SalarioCarga int not null,
57 Estado boolean not null,
58 CONSTRAINT PK_EMPLEADOS PRIMARY KEY (Cedula)
59);
60
61create table ValoresIniciales(
62 Nombre char(25) not null,
63 Telefono char(10) not null,
64 CedulaJuridica char(15) not null,
65 NumeroSecuencial int not null
66);
67
68create table InicioSesion(
69 Usuario char(25) not null,
70 Contrasenia char(25) not null
71);
72
73create table Compra(
74 Id serial not null,
75 NumFactura char(25) not null,
76 NombreProveedor char(25) not null,
77 Fecha date not null,
78 CONSTRAINT PK_COMPRA PRIMARY KEY (Id)
79);
80
81
82create table CompraXInsumo(
83 IdInsumo int not null REFERENCES Insumos(Id),
84 IdFactura int not null REFERENCES Compra(Id),
85 Cantidad int not null,
86 PrecioUnitario int not null,
87 ImpuestoUnitario float not null
88
89);
90
91create table Nomina(
92 Id int not null,
93 Mes int not null,
94 Anio int not null,
95 CedulaEmpleado char(25) not null references Empleados(Cedula),
96 NombreEmpleado char(25) not null,
97 LaborEmpleado char(25) not null,
98 SalarioMensual int not null,
99 SalarioCarga float not null
100);
101
102create table Venta(
103 Id serial not null,
104 NombreCliente char(25) not null,
105 Fecha date not null,
106 LocalComercial char(25) not null,
107 CedJuridica char(15) not null,
108 Telefono char(10) not null,
109 CONSTRAINT PK_PRODUCTO PRIMARY KEY(Id)
110);
111create table VentaXProducto(
112 IdVenta int not null REFERENCES Venta(Id),
113 IdProducto int not null REFERENCES Productos(Id),
114 Cantidad int not null,
115 Area char(25) not null,
116 PrecioUnitario int not null,
117 ImpuestoUnitario float not null
118);
119
120
121
122insert into Insumos (Nombre) values ('Clavo');
123insert into Insumos (nombre) values ('Pegamento');
124select * from Insumos;
125
126insert into Productos (Nombre,Precio,ImpuestoAplicado) values('Atun',2000,0.13);
127insert into Productos (Nombre,Precio,ImpuestoAplicado) values('Garbanzos',2000,0.13);
128insert into Productos (Nombre,Precio,ImpuestoAplicado) values('Aceite',2000,0.13);
129select * from Productos;
130
131insert into Areas (Nombre,Dimension,ProductoProducido,Estado) values ('Las Mantas',500,2,'1');
132insert into Areas (Nombre,Dimension,ProductoProducido,Estado) values ('Las Catalinas',500,1,'1');
133select * from Areas;
134
135insert into Empleados values('702550708','Luis','Araya Aragon','Cargador',10000,10000*(1.50),'1');
136insert into Empleados values('602210128','Mario','Altamirano Aragon','Inspector',20000,20000*(1.50),'1');
137select * from Empleados;
138
139insert into ValoresIniciales values('Megasuper','27184576','3024150012',2);
140select * from ValoresIniciales;
141
142Insert into InicioSesion values('operativo','operativo');
143Insert into InicioSesion values('administrador','administrador');
144select * from InicioSesion;
145
146
147insert into Compra (NumFactura,NombreProveedor,Fecha) values('123456','wallmart','14/8/2018')
148select * from Compra
149
150insert into CompraXInsumo values(1,1,5,5000,0.13);
151insert into CompraXInsumo values(2,1,5,5000,0.13);
152select * from CompraXInsumo
153
154Insert into Nomina values(1,8,2018,'702550708','Luis','Cargador',10000,15000);
155Insert into Nomina values(1,8,2018,'602210128','Mario','Inspector',20000,35000);
156select * from Nomina
157
158insert into VentaXProducto (IdProducto,Cantidad,Area,PrecioUnitario,ImpuestoUnitario,NombreCliente,Fecha,NombreLocal,CedJuridica,Telefono)
159values(1,10,'Las Mantas',2000,0.13,'Carlos','14/8/2018','PalÃ','3024150021','27189556');
160select * from VentaXProducto
161
162
163insert into Venta(NombreCliente,Fecha,LocalComercial,CedJuridica,Telefono) values('Marcos','14/8/2018','Megasuper','3024150012','27184576')
164select * from Venta
165
166insert into VentaXProducto values(1,2,5,'Las Mantas',2000,0.13);
167insert into VentaXProducto values(1,1,10,'Las Catalinas',2000,0.13);
168select * from VentaXproducto