Emanuel Calvo Franco escribió:
El día 22 de enero de 2009 16:42, Linos <[email protected]> escribió:
Emanuel Calvo Franco escribió:

Podés pasar el código ddl de las tablas?
De ultima recreo una simulación y las pruebo.
Debería funcionar... es raro.

Claro, estas son las tablas implicadas.


CREATE TABLE articulo (
    articulo_id integer NOT NULL,
    talla character varying(3) NOT NULL,
    fecha_creacion date DEFAULT ('now'::text)::date,
    id_modelo integer NOT NULL,
    id_usuario integer NOT NULL,
    codigo_barras character(13) NOT NULL,
    codigo_barras_proveedor character(13)
);
ALTER TABLE ONLY articulo
    ADD CONSTRAINT articulo_pkey PRIMARY KEY (articulo_id);
CREATE INDEX id_modelo_index_art ON articulo USING btree (id_modelo);
CREATE UNIQUE INDEX uq_referencia_art ON articulo USING btree (codigo_barras_schema); CREATE UNIQUE INDEX uq_codigo_proveedor_art ON articulo USING btree (codigo_barras_proveedor);
CREATE UNIQUE INDEX uq_modelo_talla_art ON articulo USING btree (id_modelo, 
talla);

CREATE TABLE modelo (
    modelo_id integer NOT NULL,
    nombre character varying(40) NOT NULL,
    tipo_iva integer NOT NULL,
    rango_tallas character varying(32),
    color character varying(16),
    foto bytea,
    id_marca character(2) NOT NULL,
    id_subfamilia character(4) NOT NULL,
    id_temporada character(2) NOT NULL,
    lineal character varying(64),
    actividad integer,
    unidad_de_venta integer,
    virtual boolean,
    abreviatura character varying(21),
    precio_costo numeric(7,2) NOT NULL,
    impresion_etiqueta_auto boolean DEFAULT false,
    codigo_proveedor character varying(20) NOT NULL,
    fecha_creacion date NOT NULL,
    estado integer NOT NULL,
    comentario text,
    referencia character(8) NOT NULL,
    numero_etiquetas integer NOT NULL,
    id_usuario integer NOT NULL,
    id_seccion integer NOT NULL
);
ALTER TABLE ONLY modelo
    ADD CONSTRAINT modelo_pkey PRIMARY KEY (modelo_id);
CREATE INDEX codigo_proveedor_index_mod ON modelo USING btree 
(codigo_proveedor);
CREATE INDEX color_index_mod ON modelo USING btree (color);
CREATE INDEX marca_index_mod ON modelo USING btree (id_marca);
CREATE INDEX nombre_index_mod ON modelo USING btree (nombre);
CREATE INDEX pattern_referencia_mod ON modelo USING btree (referencia bpchar_pattern_ops); CREATE INDEX pattern_codigo_proveedor_mod ON modelo USING btree (codigo_proveedor varchar_pattern_ops); CREATE INDEX pattern_id_subfamilia_mod ON modelo USING btree (id_subfamilia bpchar_pattern_ops);
CREATE INDEX pattern_nombre_mod ON modelo USING btree (nombre 
varchar_pattern_ops);
CREATE INDEX subfamilia_index_mod ON modelo USING btree (id_subfamilia);
CREATE INDEX temporada_index_mod ON modelo USING btree (id_temporada);
CREATE UNIQUE INDEX uq_referencia_index_mod ON modelo USING btree (referencia);


CREATE TABLE oferta (
    oferta_id integer NOT NULL,
    tipo_oferta character varying(64) NOT NULL,
    nombre character varying(64) NOT NULL,
    id_redondeo integer,
    fecha_creacion date DEFAULT ('now'::text)::date,
    fecha_inicio date NOT NULL,
    fecha_fin date NOT NULL,
    descripcion text,
    id_usuario integer NOT NULL,
    dto integer DEFAULT 0,
    dto_adicional integer DEFAULT 0,
    precio_fijo numeric(7,2),
    cheque_regalo_karhu integer DEFAULT 0,
    cheque_regalo integer DEFAULT 0,
    prioridad integer NOT NULL,
    dosxuno boolean DEFAULT false,
    dto_residual integer DEFAULT 0,
    un_euro_mas boolean DEFAULT false,
    tarifa integer,
    minimo_acumulativo numeric(7,2) DEFAULT 0.00
);
ALTER TABLE ONLY oferta
    ADD CONSTRAINT oferta_pkey PRIMARY KEY (oferta_id);
CREATE INDEX fecha_fin_index_ofe ON oferta USING btree (fecha_fin);
CREATE INDEX fecha_inicio_index_ofe ON oferta USING btree (fecha_inicio);
CREATE INDEX prioridad_index_ofe ON oferta USING btree (prioridad);

CREATE TABLE modelo_oferta (
    id_oferta integer NOT NULL,
    id_nivel_aplicacion integer,
    id_modelo integer NOT NULL
);
ALTER TABLE ONLY modelo_oferta
    ADD CONSTRAINT modelo_oferta_pkey PRIMARY KEY (id_modelo, id_oferta);
CREATE INDEX id_oferta_index_ofe ON modelo_oferta USING btree (id_oferta);
CREATE INDEX id_modelo_index_ofe ON modelo_oferta USING btree (id_modelo);

CREATE TABLE ticket_cabecera (
    ticket_id integer NOT NULL,
    numero_ticket integer,
    serie character varying(16) NOT NULL,
    fecha date DEFAULT ('now'::text)::date,
    hora time without time zone DEFAULT ('now'::text)::time with time zone,
    cerrado boolean NOT NULL,
    caja integer NOT NULL,
    id_cliente integer NOT NULL,
    id_usuario integer NOT NULL,
    id_vendedor integer NOT NULL,
    total_base numeric(7,2),
    total_valorado numeric(7,2) NOT NULL,
    total_impuesto numeric(7,2)
);
ALTER TABLE ONLY ticket_cabecera
    ADD CONSTRAINT ticket_cabecera_pkey PRIMARY KEY (ticket_id);
CREATE INDEX caja_index_tic ON ticket_cabecera USING btree (caja);
CREATE INDEX fecha_index_tic ON ticket_cabecera USING btree (fecha);
CREATE INDEX hora_index_tic ON ticket_cabecera USING btree (hora);
CREATE INDEX id_cliente_index_tic ON ticket_cabecera USING btree (id_cliente);
CREATE UNIQUE INDEX uq_numero_ticket_tic ON ticket_cabecera USING btree (numero_ticket);

CREATE TABLE ticket_linea (
    id_ticket integer NOT NULL,
    linea_id integer NOT NULL,
    id_articulo integer NOT NULL,
    dto_linea numeric(5,2) DEFAULT 0.00,
    pvp_teorico numeric(7,2) NOT NULL,
    pvp_real numeric(7,2) NOT NULL,
    iva integer NOT NULL,
    unidades integer NOT NULL,
    precio_costo numeric(7,2) NOT NULL,
    id_oferta integer,
    total_linea numeric(7,2) NOT NULL,
    modificado_manual boolean DEFAULT false,
    id_tarifa integer
);
ALTER TABLE ONLY ticket_linea
    ADD CONSTRAINT ticket_linea_pkey PRIMARY KEY (id_ticket, linea_id);
CREATE INDEX articulo_index_ticlin ON ticket_linea USING btree (id_articulo);
--
TIP 5: ¿Has leído nuestro extenso FAQ?
        http://www.postgresql.org/docs/faqs.FAQ.html

Responder a