CREATE TABLE atributocancelacion
(
  id character varying(40) NOT NULL,
  descripcion character varying(200),
  nombre character varying(80),
  attributoclassid character varying(40),
  tipo integer DEFAULT 0,
  iscompound boolean DEFAULT false,
  listaatributos_id character varying(40),
  lista character varying(50),
  listaitemclassid character varying(50),
  relacionar boolean DEFAULT false,
  readonly boolean DEFAULT false,
  atributoauxiliar boolean DEFAULT false,
  bo_place_id character varying(40),
  bo_owner_id character varying(40),
  atributoscancelacion_id character varying(40),
  CONSTRAINT atributocancelacion_pkey PRIMARY KEY (id)
);
CREATE INDEX a ON atributocancelacion(bo_place_id);
CREATE INDEX b ON atributocancelacion(bo_owner_id);
CREATE INDEX c ON atributocancelacion(nombre);
CREATE INDEX d ON atributocancelacion(lista);

CREATE TABLE atributos
(
  id character varying(40) NOT NULL,
  bo_place_id character varying(40),
  bo_owner_id character varying(40),
  descripcion character varying(200),
  nombre character varying(80),
  attributoclassid character varying(40),
  tipo integer DEFAULT 0,
  iscompound boolean DEFAULT false,
  listaatributos_id character varying(40),
  lista character varying(50),
  listaitemclassid character varying(50),
  relacionar boolean DEFAULT false,
  readonly boolean DEFAULT false,
  atributoauxiliar boolean DEFAULT false,
  CONSTRAINT atributos_pkey PRIMARY KEY (id)
);
CREATE INDEX e ON atributos(bo_place_id);
CREATE INDEX f ON atributos(bo_owner_id);
CREATE INDEX g ON atributos(nombre);
CREATE INDEX h ON atributos(lista);

CREATE TABLE relacionatributocont
(
  id character varying(40) NOT NULL,
  bo_place_id character varying(40),
  bo_owner_id character varying(40),
  descripcion character varying(40),
  atributo_id character varying(40),
  descripcioncontable_id character varying(40),
  cuentacontable_id character varying(40),
  evaluascriptctacontable boolean DEFAULT false,
  scriptcuentacontable_id character varying(40),
  atributoimporte_id character varying(40),
  comportamiento_id character varying(40),
  CONSTRAINT relacionatributocont_pkey PRIMARY KEY (id)
);
CREATE INDEX i ON relacionatributocont(bo_place_id);
CREATE INDEX j ON relacionatributocont(bo_owner_id);

CREATE OR REPLACE VIEW v_atributos AS 
 SELECT atributos.id, atributos.bo_place_id, atributos.bo_owner_id, atributos.descripcion, atributos.nombre, atributos.attributoclassid, atributos.tipo, atributos.iscompound, atributos.listaatributos_id, atributos.lista, atributos.listaitemclassid, atributos.relacionar, atributos.readonly, atributos.atributoauxiliar
   FROM atributos
UNION ALL 
 SELECT atributocancelacion.id, atributocancelacion.bo_place_id, atributocancelacion.bo_owner_id, atributocancelacion.descripcion, atributocancelacion.nombre, atributocancelacion.attributoclassid, atributocancelacion.tipo, atributocancelacion.iscompound, atributocancelacion.listaatributos_id, atributocancelacion.lista, atributocancelacion.listaitemclassid, atributocancelacion.relacionar, atributocancelacion.readonly, atributocancelacion.atributoauxiliar
   FROM atributocancelacion;
   
CREATE OR REPLACE VIEW v_relacionatributocont AS 
 SELECT relacionatributocont.id, relacionatributocont.bo_place_id, relacionatributocont.bo_owner_id, relacionatributocont.descripcion, relacionatributocont.atributo_id, relacionatributocont.descripcioncontable_id, relacionatributocont.cuentacontable_id, relacionatributocont.evaluascriptctacontable, relacionatributocont.scriptcuentacontable_id, relacionatributocont.atributoimporte_id, relacionatributocont.comportamiento_id
   FROM relacionatributocont;

insert into RELACIONATRIBUTOCONT values
('{BF0EFA2D-A615-11D5-B09D-004854841C8A}','{BF0EFA28-A615-11D5-B09D-004854841C8A}',null,'Cliente','{92D3E2DD-3D9D-11D5-B059-004854841C8A}','{BF0EFA09-A615-11D5-B09D-004854841C8A}',null,'t','{BF0EFA2E-A615-11D5-B09D-004854841C8A}','{BF0EFA2F-A615-11D5-B09D-004854841C8A}','{92D3F5FD-3D9D-11D5-B059-004854841C8A}'),
('{BF0EFA38-A615-11D5-B09D-004854841C8A}','{BF0EFA28-A615-11D5-B09D-004854841C8A}',null,'Venta','{92D3E270-3D9D-11D5-B059-004854841C8A}','{89C2371D-3F01-11D5-86AD-0080AD403F5F}',null,'t','{BF0EFA39-A615-11D5-B09D-004854841C8A}','{BF0EFA3A-A615-11D5-B09D-004854841C8A}','{92D3F604-3D9D-11D5-B059-004854841C8A}'),
('{082FDDE6-C954-489B-BE69-A1FEAE233D51}','{BF0EFA28-A615-11D5-B09D-004854841C8A}',null,'Descuento Total',null,null,null,'t','{7E7F8669-5E5D-4111-B872-02C7FA2C2D81}','{153A0367-70DA-4F71-8B00-A672AACDBF91}','{92D3F5FD-3D9D-11D5-B059-004854841C8A}'),
('{1F40BD50-3D27-4BA1-AAEF-3EF7FCC18226}','{BF0EFA28-A615-11D5-B09D-004854841C8A}',null,'Bonificaciones item','{92D3E270-3D9D-11D5-B059-004854841C8A}','{BF0EFA09-A615-11D5-B09D-004854841C8A}',null,'t','{67A66814-2B45-4B4C-A54B-1E6762B7F099}','{4D1BD659-1CAC-4BDA-9150-99B39B401A34}','{92D3F5FD-3D9D-11D5-B059-004854841C8A}');

insert into atributos values 
('{92D3E2DD-3D9D-11D5-B059-004854841C8A}','{92D3E26E-3D9D-11D5-B059-004854841C8A}',null,'Destinatario','DESTINATARIO','{F87C09C1-77CB-11D1-8668-0000C0162096}',7,'f','{05FAC491-1998-11D6-B2A0-0048548404E5}',null,null,'t','f','f'),
('{92D3E270-3D9D-11D5-B059-004854841C8A}','{92D3E26E-3D9D-11D5-B059-004854841C8A}',null,'Items de transacción.Referencia','REFERENCIA','{F87C09C1-77CB-11D1-8668-0000C0162096}',7,'f','{24DF7DF6-569C-11D5-B613-0050DAC017BE}','ITEMSTRANSACCION','{6F724B45-FADE-11D1-9E49-0000214166F2}','t','f','f');

