You are on page 1of 29

--- PostgreSQL database dump

--- Dumped from database version 9.2.3


-- Dumped by pg_dump version 9.2.3
-- Started on 2013-03-20 19:36:38
SET
SET
SET
SET
SET

statement_timeout = 0;
client_encoding = 'UTF8';
standard_conforming_strings = on;
check_function_bodies = false;
client_min_messages = warning;

--- TOC entry 1981 (class 1262 OID 12002)


-- Dependencies: 1980
-- Name: postgres; Type: COMMENT; Schema: -; Owner: postgres
-COMMENT ON DATABASE postgres IS 'default administrative connection
database';

--- TOC entry 178 (class 3079 OID 11727)


-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
-CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;

--- TOC entry 1984 (class 0 OID 0)


-- Dependencies: 178
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
-COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';

--- TOC entry 177 (class 3079 OID 16384)


-- Name: adminpack; Type: EXTENSION; Schema: -; Owner:
-CREATE EXTENSION IF NOT EXISTS adminpack WITH SCHEMA pg_catalog;

--

-- TOC entry 1985 (class 0 OID 0)


-- Dependencies: 177
-- Name: EXTENSION adminpack; Type: COMMENT; Schema: -; Owner:
-COMMENT ON EXTENSION adminpack IS 'administrative functions for
PostgreSQL';

SET search_path = public, pg_catalog;


--- TOC entry 191 (class 1255 OID 16609)
-- Name: aumento(); Type: FUNCTION; Schema: public; Owner:
postgres
-CREATE FUNCTION aumento() RETURNS trigger
LANGUAGE plpgsql
AS $$Declare

_salario_anterior real;
_salario_nuevo real;
_salario_max real;

BEGIN
_salario_anterior = OLD.salario from empleado;
_salario_nuevo=NEW.salario from empleado;
_salario_max= _salario_anterior + (_salario_anterior *
0.5);

NEW.id_emp := id_emp from empleado ;


IF (_salario_nuevo >= _salario_max) then
update empleado set salario = _salario_anterior;
RAISE EXCEPTION 'Salario incorrecto';
end if;
Return

NEW;

END;
$$;

ALTER FUNCTION public.aumento() OWNER TO postgres;


--

-- TOC entry 192 (class 1255 OID 16610)


-- Name: emp(); Type: FUNCTION; Schema: public; Owner: postgres
-CREATE FUNCTION emp() RETURNS trigger
LANGUAGE plpgsql
AS $$Declare
_id_empleado integer;
_salario_anterior integer;
_salario_nuevo integer;
_nombre text;
_apellido text;

BEGIN
_id_empleado = id_emp from empleado;
_salario_anterior = OLD.salario from empleado;
_salario_nuevo=NEW.salario from empleado;
_nombre = nombre from empleado;
_apellido = apellido from empleado;
NEW.id_emp := id_emp from empleado ;
Insert into registro (id_empleado, salario_anterior,
salario_actual, nombre, apellido)
values (_id_empleado, _salario_anterior,_salario_nuevo,
_nombre, _apellido);
Return
NEW;
END;
$$;

ALTER FUNCTION public.emp() OWNER TO postgres;


SET default_tablespace = '';
SET default_with_oids = false;
--- TOC entry 169 (class 1259 OID 16540)
-- Name: bodega; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE bodega (
id integer NOT NULL,
nombre text,
ubicacion text,

id_responsable integer
);

ALTER TABLE public.bodega OWNER TO postgres;


--- TOC entry 173 (class 1259 OID 16561)
-- Name: cliente; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE cliente (
id integer NOT NULL,
nombre text,
apellido text
);

ALTER TABLE public.cliente OWNER TO postgres;


--- TOC entry 172 (class 1259 OID 16552)
-- Name: detalle_factura; Type: TABLE; Schema: public; Owner:
postgres; Tablespace:
-CREATE TABLE detalle_factura (
id_factura integer,
id_producto integer,
cantidad integer,
valor_unitario real,
valor_total real,
valor_iva real
);

ALTER TABLE public.detalle_factura OWNER TO postgres;


--- TOC entry 176 (class 1259 OID 16630)
-- Name: empleado; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE empleado (
id_emp integer NOT NULL,
nombre text,
apellido text,
salario real

);

ALTER TABLE public.empleado OWNER TO postgres;


--- TOC entry 171 (class 1259 OID 16549)
-- Name: factura_venta; Type: TABLE; Schema: public; Owner:
postgres; Tablespace:
-CREATE TABLE factura_venta (
numero_factura integer NOT NULL,
fecha date,
id_cliente integer,
id_vendedor integer,
valor_total real,
valor_total_iva real
);

ALTER TABLE public.factura_venta OWNER TO postgres;


--- TOC entry 170 (class 1259 OID 16546)
-- Name: inventario; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE inventario (
id_producto integer,
id_bodega integer,
cantidad integer
);

ALTER TABLE public.inventario OWNER TO postgres;


--- TOC entry 1986 (class 0 OID 0)
-- Dependencies: 170
-- Name: COLUMN inventario.id_producto; Type: COMMENT; Schema:
public; Owner: postgres
-COMMENT ON COLUMN inventario.id_producto IS '
';

--

-- TOC entry 168 (class 1259 OID 16534)


-- Name: producto; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE producto (
id integer NOT NULL,
nombre text,
descripcion text,
existencias integer,
existencia_minima integer,
precio_venta real,
iva real
);

ALTER TABLE public.producto OWNER TO postgres;


--- TOC entry 174 (class 1259 OID 16617)
-- Name: registro; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE registro (
id_empleado integer,
salario_anterior integer,
salario_actual integer,
nombre text,
apellido text,
id_reg integer NOT NULL
);

ALTER TABLE public.registro OWNER TO postgres;


--- TOC entry 175 (class 1259 OID 16623)
-- Name: registro_id_reg_seq; Type: SEQUENCE; Schema: public;
Owner: postgres
-CREATE SEQUENCE registro_id_reg_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER TABLE public.registro_id_reg_seq OWNER TO postgres;

--- TOC entry 1987 (class 0 OID 0)


-- Dependencies: 175
-- Name: registro_id_reg_seq; Type: SEQUENCE OWNED BY; Schema:
public; Owner: postgres
-ALTER SEQUENCE registro_id_reg_seq OWNED BY registro.id_reg;

--- TOC entry 1952 (class 2604 OID 16625)


-- Name: id_reg; Type: DEFAULT; Schema: public; Owner: postgres
-ALTER TABLE ONLY registro ALTER COLUMN id_reg SET DEFAULT
nextval('registro_id_reg_seq'::regclass);

--- TOC entry 1968 (class 0 OID 16540)


-- Dependencies: 169
-- Data for Name: bodega; Type: TABLE DATA; Schema: public; Owner:
postgres
-COPY bodega (id, nombre, ubicacion, id_responsable) FROM stdin;
\.

--- TOC entry 1972 (class 0 OID 16561)


-- Dependencies: 173
-- Data for Name: cliente; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY cliente (id, nombre, apellido) FROM stdin;
\.

--- TOC entry 1971 (class 0 OID 16552)


-- Dependencies: 172
-- Data for Name: detalle_factura; Type: TABLE DATA; Schema:
public; Owner: postgres
-COPY detalle_factura (id_factura, id_producto, cantidad,

valor_unitario, valor_total, valor_iva) FROM stdin;


\.

--- TOC entry 1975 (class 0 OID 16630)


-- Dependencies: 176
-- Data for Name: empleado; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY empleado (id_emp, nombre, apellido, salario) FROM stdin;
100 karl thruman
11000
\.

--- TOC entry 1970 (class 0 OID 16549)


-- Dependencies: 171
-- Data for Name: factura_venta; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY factura_venta (numero_factura, fecha, id_cliente,
id_vendedor, valor_total, valor_total_iva) FROM stdin;
\.

--- TOC entry 1969 (class 0 OID 16546)


-- Dependencies: 170
-- Data for Name: inventario; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY inventario (id_producto, id_bodega, cantidad) FROM stdin;
\.

--- TOC entry 1967 (class 0 OID 16534)


-- Dependencies: 168
-- Data for Name: producto; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY producto (id, nombre, descripcion, existencias,
existencia_minima, precio_venta, iva) FROM stdin;
\.

--- TOC entry 1973 (class 0 OID 16617)


-- Dependencies: 174
-- Data for Name: registro; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY registro (id_empleado, salario_anterior, salario_actual,
nombre, apellido, id_reg) FROM stdin;
100 5000 6000 karl thruman
7
100 6000 7000 karl thruman
12
100 7000 8000 karl thruman
13
100 8000 11000 karl thruman
20
\.

--- TOC entry 1988 (class 0 OID 0)


-- Dependencies: 175
-- Name: registro_id_reg_seq; Type: SEQUENCE SET; Schema: public;
Owner: postgres
-SELECT pg_catalog.setval('registro_id_reg_seq', 20, true);

--- TOC entry 1960 (class 2606 OID 16639)


-- Name: g5; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY registro
ADD CONSTRAINT g5 PRIMARY KEY (id_reg);

--- TOC entry 1962 (class 2606 OID 16637)


-- Name: p1; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY empleado
ADD CONSTRAINT p1 PRIMARY KEY (id_emp);

--- TOC entry 1956 (class 2606 OID 16568)


-- Name: r1; Type: CONSTRAINT; Schema: public; Owner: postgres;

Tablespace:
-ALTER TABLE ONLY bodega
ADD CONSTRAINT r1 PRIMARY KEY (id);

--- TOC entry 1958 (class 2606 OID 16570)


-- Name: r2; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY cliente
ADD CONSTRAINT r2 PRIMARY KEY (id);

--- TOC entry 1954 (class 2606 OID 16576)


-- Name: r5; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY producto
ADD CONSTRAINT r5 PRIMARY KEY (id);

--- TOC entry 1965 (class 2620 OID 16640)


-- Name: emp; Type: TRIGGER; Schema: public; Owner: postgres
-CREATE TRIGGER emp BEFORE INSERT OR UPDATE OF salario ON empleado
FOR EACH ROW EXECUTE PROCEDURE emp();

--- TOC entry 1966 (class 2620 OID 16641)


-- Name: emp2; Type: TRIGGER; Schema: public; Owner: postgres
-CREATE TRIGGER emp2 AFTER INSERT OR UPDATE OF salario ON empleado
FOR EACH ROW EXECUTE PROCEDURE aumento();

--- TOC entry 1963 (class 2606 OID 16577)


-- Name: f1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY inventario


ADD CONSTRAINT f1 FOREIGN KEY (id_bodega) REFERENCES
bodega(id);

--- TOC entry 1964 (class 2606 OID 16582)


-- Name: f2; Type: FK CONSTRAINT; Schema: public; Owner: postgres
-ALTER TABLE ONLY inventario
ADD CONSTRAINT f2 FOREIGN KEY (id_producto) REFERENCES
producto(id);

--- TOC entry 1983 (class 0 OID 0)


-- Dependencies: 6
-- Name: public; Type: ACL; Schema: -; Owner: postgres
-REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;

-- Completed on 2013-03-20 19:36:39


--- PostgreSQL database dump complete
---- PostgreSQL database dump
--- Dumped from database version 9.2.2
-- Dumped by pg_dump version 9.2.2
-- Started on 2013-03-20 19:04:39
SET
SET
SET
SET
SET

statement_timeout = 0;
client_encoding = 'UTF8';
standard_conforming_strings = on;
check_function_bodies = false;
client_min_messages = warning;

--- TOC entry 2007 (class 1262 OID 12002)


-- Dependencies: 2006

-- Name: postgres; Type: COMMENT; Schema: -; Owner: postgres


-COMMENT ON DATABASE postgres IS 'default administrative connection
database';

--- TOC entry 180 (class 3079 OID 11727)


-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
-CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;

--- TOC entry 2010 (class 0 OID 0)


-- Dependencies: 180
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
-COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';

--- TOC entry 179 (class 3079 OID 16384)


-- Name: adminpack; Type: EXTENSION; Schema: -; Owner:
-CREATE EXTENSION IF NOT EXISTS adminpack WITH SCHEMA pg_catalog;

--- TOC entry 2011 (class 0 OID 0)


-- Dependencies: 179
-- Name: EXTENSION adminpack; Type: COMMENT; Schema: -; Owner:
-COMMENT ON EXTENSION adminpack IS 'administrative functions for
PostgreSQL';

SET search_path = public, pg_catalog;


--- TOC entry 194 (class 1255 OID 16618)
-- Name: auditoria_detalle(); Type: FUNCTION; Schema: public;
Owner: postgres
--

CREATE FUNCTION auditoria_detalle() RETURNS trigger


LANGUAGE plpgsql
AS $$Declare

_idfactura integer;
_idproducto integer;
_cantidad integer;
_vu real;
_vt real;
_vi real;
_ip text;
_hora time;
_fecha date;
BEGIN
_ip=inet_client_addr();
_hora= current_time;
_fecha= current_date;
IF (TG_OP='INSERT' or TG_OP='UPDATE') then
_idfactura= NEW.id_factura;
_idproducto= NEW.id_producto;
_cantidad= NEW.cantidad;
_vu= NEW.valor_unitario;
_vt= NEW.valor_total;
_vi= NEW.valor_iva;
insert into
audi_detalle(idfactura,idproducto,cantidadp,valorunitario,valortot
al,valoriva,accion,ip,hora,fecha_actual)
values
(_idfactura,_idproducto,_cantidad,_vu,_vt,_vi,TG_OP,_ip,_hora,_fec
ha);
ELSE IF (TG_OP='DELETE') then
insert into
audi_detalle(idfactura,idproducto,cantidadp,valorunitario,valortot
al,valoriva,accion,ip,hora,fecha_actual)
values
(OLD.id_factura,OLD.id_producto,OLD.cantidad,OLD.valor_unitario,OL
D.valor_total,OLD.valor_iva,TG_OP,_ip,_hora,_fecha);
End IF;
End IF;

Return

OLD;

END;
$$;

ALTER FUNCTION public.auditoria_detalle() OWNER TO postgres;


--- TOC entry 193 (class 1255 OID 16514)
-- Name: auditoria_venta(); Type: FUNCTION; Schema: public; Owner:
postgres
-CREATE FUNCTION auditoria_venta() RETURNS trigger
LANGUAGE plpgsql
AS $$Declare

_numero integer;
_fecha date;
_idc integer;
_idv integer;
_vt real;
_vti real;
_hora time;
_ip text;
BEGIN
_hora= current_time;
_ip=inet_client_addr();
IF (TG_OP='INSERT' or TG_OP='UPDATE') then
_numero= NEW.numero_factura;
_fecha= NEW.fecha;
_idc= NEW.id_cliente;
_idv= NEW.id_vendedor;
_vt= NEW.valor_total;
_vti= NEW.valor_total_iva;
insert into
auditoria_fventa(numerofactura,fecha_accion,idcliente,idvendedor,v
alortotal,valortotal_iva,hora,accion,ip)
values
(_numero,_fecha,_idc,_idv,_vt,_vti,_hora,TG_OP,_ip);
ELSE IF (TG_OP='DELETE') then
insert into
auditoria_fventa(numerofactura,fecha_accion,idcliente,idvendedor,v
alortotal,valortotal_iva,hora,accion,ip)

values
(OLD.numero_factura,OLD.fecha,OLD.id_cliente,OLD.id_vendedor,OLD.v
alor_total,OLD.valor_total_iva,_hora,TG_OP,_ip);
End IF;
End IF;

Return

OLD;

END;
$$;

ALTER FUNCTION public.auditoria_venta() OWNER TO postgres;


--- TOC entry 195 (class 1255 OID 16515)
-- Name: inventario(); Type: FUNCTION; Schema: public; Owner:
postgres
-CREATE FUNCTION inventario() RETURNS trigger
LANGUAGE plpgsql
AS $$Declare

_cant real;
_inv real;
_ncant real;
_id INTEGER;
BEGIN
_cant= NEW.cantidad;
IF (_cant <=100) then
_id= NEW.id_producto;
_inv= cantidad from inventario WHERE id_producto= _id ;
_ncant= _inv - _cant;
update inventario set cantidad = _ncant where
id_producto=_id;
update producto set existencias = _ncant WHERE id=_id;
ELSE
RAISE EXCEPTION 'Cantidad
END IF;

Incorrecta';

Return

OLD;

END;
$$;

ALTER FUNCTION public.inventario() OWNER TO postgres;


SET default_tablespace = '';
SET default_with_oids = false;
--- TOC entry 168 (class 1259 OID 16516)
-- Name: audi_detalle; Type: TABLE; Schema: public; Owner:
postgres; Tablespace:
-CREATE TABLE audi_detalle (
idfactura integer NOT NULL,
idproducto integer NOT NULL,
cantidadp integer,
valorunitario real,
valortotal real,
valoriva real,
id integer NOT NULL,
accion text,
ip text,
hora time without time zone,
fecha_actual date
);

ALTER TABLE public.audi_detalle OWNER TO postgres;


--- TOC entry 169 (class 1259 OID 16522)
-- Name: audi_detalle_id_seq; Type: SEQUENCE; Schema: public;
Owner: postgres
-CREATE SEQUENCE audi_detalle_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER TABLE public.audi_detalle_id_seq OWNER TO postgres;


--- TOC entry 2012 (class 0 OID 0)
-- Dependencies: 169
-- Name: audi_detalle_id_seq; Type: SEQUENCE OWNED BY; Schema:
public; Owner: postgres
-ALTER SEQUENCE audi_detalle_id_seq OWNED BY audi_detalle.id;

--- TOC entry 170 (class 1259 OID 16524)


-- Name: auditoria_fventa; Type: TABLE; Schema: public; Owner:
postgres; Tablespace:
-CREATE TABLE auditoria_fventa (
numerofactura integer NOT NULL,
fecha_accion date,
idcliente integer,
idvendedor integer,
valortotal real,
valortotal_iva real,
hora time without time zone,
id integer NOT NULL,
accion text,
ip text
);

ALTER TABLE public.auditoria_fventa OWNER TO postgres;


--- TOC entry 171 (class 1259 OID 16530)
-- Name: auditoria_fventa_id_seq; Type: SEQUENCE; Schema: public;
Owner: postgres
-CREATE SEQUENCE auditoria_fventa_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER TABLE public.auditoria_fventa_id_seq OWNER TO postgres;

--- TOC entry 2013 (class 0 OID 0)


-- Dependencies: 171
-- Name: auditoria_fventa_id_seq; Type: SEQUENCE OWNED BY; Schema:
public; Owner: postgres
-ALTER SEQUENCE auditoria_fventa_id_seq OWNED BY
auditoria_fventa.id;

--- TOC entry 172 (class 1259 OID 16532)


-- Name: bodega; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE bodega (
id integer NOT NULL,
nombre text,
ubicacion text,
id_responsable integer
);

ALTER TABLE public.bodega OWNER TO postgres;


--- TOC entry 173 (class 1259 OID 16538)
-- Name: cliente; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE cliente (
id integer NOT NULL,
nombre text,
apellido text
);

ALTER TABLE public.cliente OWNER TO postgres;


--- TOC entry 174 (class 1259 OID 16544)
-- Name: detalle_factura; Type: TABLE; Schema: public; Owner:
postgres; Tablespace:
-CREATE TABLE detalle_factura (

);

id_factura integer NOT NULL,


id_producto integer NOT NULL,
cantidad integer,
valor_unitario real,
valor_total real,
valor_iva real

ALTER TABLE public.detalle_factura OWNER TO postgres;


--- TOC entry 175 (class 1259 OID 16547)
-- Name: empleado; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE empleado (
id integer NOT NULL,
nombre text,
apellido text,
usuario text,
"contrasea" "char"
);

ALTER TABLE public.empleado OWNER TO postgres;


--- TOC entry 176 (class 1259 OID 16553)
-- Name: factura_venta; Type: TABLE; Schema: public; Owner:
postgres; Tablespace:
-CREATE TABLE factura_venta (
numero_factura integer NOT NULL,
fecha date,
id_cliente integer,
id_vendedor integer,
valor_total real,
valor_total_iva real
);

ALTER TABLE public.factura_venta OWNER TO postgres;


--- TOC entry 177 (class 1259 OID 16556)
-- Name: inventario; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
--

CREATE TABLE inventario (


id_producto integer NOT NULL,
id_bodega integer NOT NULL,
cantidad integer
);

ALTER TABLE public.inventario OWNER TO postgres;


--- TOC entry 2014 (class 0 OID 0)
-- Dependencies: 177
-- Name: COLUMN inventario.id_producto; Type: COMMENT; Schema:
public; Owner: postgres
-COMMENT ON COLUMN inventario.id_producto IS '
';

--- TOC entry 178 (class 1259 OID 16559)


-- Name: producto; Type: TABLE; Schema: public; Owner: postgres;
Tablespace:
-CREATE TABLE producto (
id integer NOT NULL,
nombre text,
descripcion text,
existencias integer,
existencia_minima integer,
precio_venta real,
iva real
);

ALTER TABLE public.producto OWNER TO postgres;


--- TOC entry 1960 (class 2604 OID 16565)
-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
-ALTER TABLE ONLY audi_detalle ALTER COLUMN id SET DEFAULT
nextval('audi_detalle_id_seq'::regclass);

--

-- TOC entry 1961 (class 2604 OID 16566)


-- Name: id; Type: DEFAULT; Schema: public; Owner: postgres
-ALTER TABLE ONLY auditoria_fventa ALTER COLUMN id SET DEFAULT
nextval('auditoria_fventa_id_seq'::regclass);

--- TOC entry 1991 (class 0 OID 16516)


-- Dependencies: 168
-- Data for Name: audi_detalle; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY audi_detalle (idfactura, idproducto, cantidadp,
valorunitario, valortotal, valoriva, id, accion, ip, hora,
fecha_actual) FROM stdin;
200 100 1
900000
1044000
144000
1
INSERT
::1 18:54:33.807
2013-03-20
201 100 5
900000
5220000
720000
2
INSERT
::1 18:54:55.569
2013-03-20
201 100 5
900000
5220000
720000
3
DELETE
::1 19:01:26.283
2013-03-20
201 100 5
900000
5220000
720000
8
INSERT
::1 19:03:08.995
2013-03-20
\.

--- TOC entry 2015 (class 0 OID 0)


-- Dependencies: 169
-- Name: audi_detalle_id_seq; Type: SEQUENCE SET; Schema: public;
Owner: postgres
-SELECT pg_catalog.setval('audi_detalle_id_seq', 10, true);

--- TOC entry 1993 (class 0 OID 16524)


-- Dependencies: 170
-- Data for Name: auditoria_fventa; Type: TABLE DATA; Schema:
public; Owner: postgres
-COPY auditoria_fventa (numerofactura, fecha_accion, idcliente,
idvendedor, valortotal, valortotal_iva, hora, id, accion, ip) FROM
stdin;
200 2013-03-20 51908701
91221 1044000
144000
18:53:19.691
1
INSERT
::1

201
201
201
\.

2013-03-20 51908701
2
INSERT
::1
2013-03-20 51908701
4
DELETE
::1
2013-03-20 51908701
5
INSERT
::1

91221 5220000

720000

18:53:53.106

91221 5220000

720000

19:01:35.269

91221 5220000

720000

19:01:55.907

--- TOC entry 2016 (class 0 OID 0)


-- Dependencies: 171
-- Name: auditoria_fventa_id_seq; Type: SEQUENCE SET; Schema:
public; Owner: postgres
-SELECT pg_catalog.setval('auditoria_fventa_id_seq', 5, true);

--- TOC entry 1995 (class 0 OID 16532)


-- Dependencies: 172
-- Data for Name: bodega; Type: TABLE DATA; Schema: public; Owner:
postgres
-COPY bodega (id, nombre, ubicacion, id_responsable) FROM stdin;
300 Central
Bucaramanga
91221
\.

--- TOC entry 1996 (class 0 OID 16538)


-- Dependencies: 173
-- Data for Name: cliente; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY cliente (id, nombre, apellido) FROM stdin;
51908701
Mary Guerrero
\.

--- TOC entry 1997 (class 0 OID 16544)


-- Dependencies: 174
-- Data for Name: detalle_factura; Type: TABLE DATA; Schema:
public; Owner: postgres
--

COPY detalle_factura (id_factura, id_producto, cantidad,


valor_unitario, valor_total, valor_iva) FROM stdin;
200 100 1
900000
1044000
144000
201 100 5
900000
5220000
720000
\.

--- TOC entry 1998 (class 0 OID 16547)


-- Dependencies: 175
-- Data for Name: empleado; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY empleado (id, nombre, apellido, usuario, "contrasea") FROM
stdin;
91221 Mark Ferreira
markf 1
\.

--- TOC entry 1999 (class 0 OID 16553)


-- Dependencies: 176
-- Data for Name: factura_venta; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY factura_venta (numero_factura, fecha,
id_vendedor, valor_total, valor_total_iva)
200 2013-03-20 51908701
91221 1044000
201 2013-03-20 51908701
91221 5220000
\.

id_cliente,
FROM stdin;
144000
720000

--- TOC entry 2000 (class 0 OID 16556)


-- Dependencies: 177
-- Data for Name: inventario; Type: TABLE DATA; Schema: public;
Owner: postgres
-COPY inventario (id_producto, id_bodega, cantidad) FROM stdin;
101 300 100
100 300 89
\.

--- TOC entry 2001 (class 0 OID 16559)


-- Dependencies: 178

-- Data for Name: producto; Type: TABLE DATA; Schema: public;


Owner: postgres
-COPY producto (id, nombre, descripcion, existencias,
existencia_minima, precio_venta, iva) FROM stdin;
101 M16 fusil de asalto V2
100 10
900000
144000
100 AK47 fusil de asalto 89
10
900000
144000
\.

--- TOC entry 1963 (class 2606 OID 16568)


-- Name: au4; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY audi_detalle
ADD CONSTRAINT au4 PRIMARY KEY (id);

--- TOC entry 1971 (class 2606 OID 16570)


-- Name: g1; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY detalle_factura
ADD CONSTRAINT g1 PRIMARY KEY (id_factura, id_producto);

--- TOC entry 1965 (class 2606 OID 16572)


-- Name: kid; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY auditoria_fventa
ADD CONSTRAINT kid PRIMARY KEY (id);

--- TOC entry 1967 (class 2606 OID 16574)


-- Name: r1; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY bodega
ADD CONSTRAINT r1 PRIMARY KEY (id);

--- TOC entry 1969 (class 2606 OID 16576)


-- Name: r2; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY cliente
ADD CONSTRAINT r2 PRIMARY KEY (id);

--- TOC entry 1973 (class 2606 OID 16578)


-- Name: r3; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY empleado
ADD CONSTRAINT r3 PRIMARY KEY (id);

--- TOC entry 1975 (class 2606 OID 16580)


-- Name: r4; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY factura_venta
ADD CONSTRAINT r4 PRIMARY KEY (numero_factura);

--- TOC entry 1979 (class 2606 OID 16582)


-- Name: r5; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY producto
ADD CONSTRAINT r5 PRIMARY KEY (id);

--- TOC entry 1977 (class 2606 OID 16584)


-- Name: u8; Type: CONSTRAINT; Schema: public; Owner: postgres;
Tablespace:
-ALTER TABLE ONLY inventario
ADD CONSTRAINT u8 PRIMARY KEY (id_producto, id_bodega);

--- TOC entry 1989 (class 2620 OID 16585)


-- Name: auditoria; Type: TRIGGER; Schema: public; Owner: postgres
-CREATE TRIGGER auditoria AFTER INSERT OR UPDATE ON factura_venta
FOR EACH ROW EXECUTE PROCEDURE auditoria_venta();

--- TOC entry 1987 (class 2620 OID 16619)


-- Name: auditoria; Type: TRIGGER; Schema: public; Owner: postgres
-CREATE TRIGGER auditoria AFTER INSERT OR UPDATE ON detalle_factura
FOR EACH ROW EXECUTE PROCEDURE auditoria_detalle();

--- TOC entry 1990 (class 2620 OID 16586)


-- Name: auditoria2; Type: TRIGGER; Schema: public; Owner:
postgres
-CREATE TRIGGER auditoria2 BEFORE DELETE ON factura_venta FOR EACH
ROW EXECUTE PROCEDURE auditoria_venta();

--- TOC entry 1988 (class 2620 OID 16620)


-- Name: auditoria2; Type: TRIGGER; Schema: public; Owner:
postgres
-CREATE TRIGGER auditoria2 BEFORE DELETE ON detalle_factura FOR
EACH ROW EXECUTE PROCEDURE auditoria_detalle();

--- TOC entry 1986 (class 2620 OID 16587)


-- Name: inv; Type: TRIGGER; Schema: public; Owner: postgres
-CREATE TRIGGER inv AFTER INSERT OR UPDATE OF cantidad ON
detalle_factura FOR EACH ROW EXECUTE PROCEDURE inventario();

--- TOC entry 1982 (class 2606 OID 16588)

-- Name: c1; Type: FK CONSTRAINT; Schema: public; Owner: postgres


-ALTER TABLE ONLY factura_venta
ADD CONSTRAINT c1 FOREIGN KEY (id_vendedor) REFERENCES
empleado(id);

--- TOC entry 1983 (class 2606 OID 16593)


-- Name: c2; Type: FK CONSTRAINT; Schema: public; Owner: postgres
-ALTER TABLE ONLY factura_venta
ADD CONSTRAINT c2 FOREIGN KEY (id_cliente) REFERENCES
cliente(id);

--- TOC entry 1980 (class 2606 OID 16598)


-- Name: d1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
-ALTER TABLE ONLY detalle_factura
ADD CONSTRAINT d1 FOREIGN KEY (id_factura) REFERENCES
factura_venta(numero_factura);

--- TOC entry 1981 (class 2606 OID 16603)


-- Name: d2; Type: FK CONSTRAINT; Schema: public; Owner: postgres
-ALTER TABLE ONLY detalle_factura
ADD CONSTRAINT d2 FOREIGN KEY (id_producto) REFERENCES
producto(id);

--- TOC entry 1984 (class 2606 OID 16608)


-- Name: f1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
-ALTER TABLE ONLY inventario
ADD CONSTRAINT f1 FOREIGN KEY (id_bodega) REFERENCES
bodega(id);

--- TOC entry 1985 (class 2606 OID 16613)

-- Name: f2; Type: FK CONSTRAINT; Schema: public; Owner: postgres


-ALTER TABLE ONLY inventario
ADD CONSTRAINT f2 FOREIGN KEY (id_producto) REFERENCES
producto(id);

--- TOC entry 2009 (class 0 OID 0)


-- Dependencies: 6
-- Name: public; Type: ACL; Schema: -; Owner: postgres
-REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;

-- Completed on 2013-03-20 19:04:40


--- PostgreSQL database dump complete
--

You might also like