--------------------------------------------------------------------------
-- Play this script in PRUEBAS@VISANY to make it look like DESA@VISMAR
--                                                                      --
-- Please review the script before using it to make sure it won't       --
-- cause any unacceptable data loss.                                    --
--                                                                      --
-- PRUEBAS@VISANY Schema Extracted by User PRUEBAS 
-- DESA@VISMAR Schema Extracted by User DESA 

CREATE SEQUENCE CXC_SEQ_AUTORIZA
  START WITH 241
  MAXVALUE 999999999999999999999999999
  MINVALUE 1
  NOCYCLE
  CACHE 20
  NOORDER;

--
-- CXC_DET_PAGO_NOTATMP  (Table) 
--
CREATE TABLE CXC_DET_PAGO_NOTATMP
(
  COD_CIA        CHAR(3 BYTE)                   NOT NULL,
  SUCURSAL       CHAR(3 BYTE)                   NOT NULL,
  TIP_DOC        CHAR(3 BYTE)                   NOT NULL,
  NUM_DOC        NUMBER(10)                     NOT NULL,
  SUCURSAL_REF   CHAR(3 BYTE)                   NOT NULL,
  TIP_DOC_REF    CHAR(3 BYTE)                   NOT NULL,
  NUM_DOC_REF    NUMBER(10)                     NOT NULL,
  NUM_PARTE      NUMBER(4),
  FEC_VENCE      DATE                           NOT NULL,
  MON_DESCUENTO  NUMBER(14,2)                   NOT NULL,
  MON_PAGO       NUMBER(14,2)                   NOT NULL,
  INTERES        NUMBER(14,2)                   NOT NULL,
  INT_MORA       NUMBER(14,2)                   NOT NULL
)
LOGGING 
NOCACHE
PARALLEL ( DEGREE DEFAULT INSTANCES 1 )
NOMONITORING;

ALTER TABLE CXC_ENCAGECXCTMP
 ADD (CLIENTE  VARCHAR2(25 BYTE));

ALTER TABLE CXC_ENC_MOVIMIENTO_HIST DROP COLUMN FEC_REG;

ALTER TABLE CXC_ENC_PAGO_NOTA_HIST DROP COLUMN FEC_REG;

ALTER TABLE CXC_MOVIMIENTOTMP
MODIFY(FEC_REG  NULL);

ALTER TABLE CXC_PARAMETRO
MODIFY(TIP_DOC_SALDO  NOT NULL);

--
-- CXC_RECAGTMP  (Table) 
--
CREATE TABLE CXC_RECAGTMP
(
  COD_CIA     CHAR(3 BYTE)                      NOT NULL,
  SUCURSAL    CHAR(3 BYTE)                      NOT NULL,
  TIP_DOC     CHAR(3 BYTE)                      NOT NULL,
  COD_AGENTE  VARCHAR2(3 BYTE)                  NOT NULL,
  INICIAL     NUMBER(10)                        NOT NULL,
  DOCUMENTO   NUMBER(10)                        NOT NULL
)
LOGGING 
NOCACHE
NOPARALLEL
NOMONITORING;

ALTER TABLE CXC_RECAGTMP
 ADD CONSTRAINT CXC_RECAGETMP_PK
 PRIMARY KEY
 (COD_CIA, SUCURSAL, TIP_DOC, COD_AGENTE, INICIAL, DOCUMENTO);

--
-- CXC_VISDETAGECXC  (View) 
--
CREATE OR REPLACE FORCE VIEW CXC_VISDETAGECXC
(COD_CIA, COD_AGENTE, FECHA, SUCURSAL, TIP_DOC, 
 NUM_DOC, DOC_REF, COD_CLIENTE, FEC_VENCE, MON_SALDO)
AS 
select dt.COD_CIA, dt.COD_AGENTE, dt.FECHA, dt.SUCURSAL,
          dt.TIP_DOC, dt.NUM_DOC,
          em.doc_ref, em.cod_cliente, em.fec_vence, em.mon_saldo
   from   cxc_enc_movimiento em,  cxc_detagecxctmp dt
   where  em.cod_cia  = dt.cod_cia
   and    em.sucursal = dt.sucursal
   and    em.tip_doc  = dt.tip_doc
   and    em.num_doc  = dt.num_doc;

--
-- CXC_DET_MOV_PAGO  (View) 
--
CREATE OR REPLACE FORCE VIEW CXC_DET_MOV_PAGO
(COD_CIA, SUCURSAL, TIP_DOC, NUM_DOC, FEC_DOC, 
 TIPOREF, DOC_REF, SUCURSAL_REF, TIP_DOC_REF, NUM_DOC_REF, 
 MON_DESCUENTO, MON_PAGO, INTERES, INT_MORA)
AS 
select a.cod_cia, a.sucursal, a.tip_doc, a.num_doc, a.fec_doc,
a.tip_doc_ref tiporef, a.doc_ref, b.sucursal_ref, b.tip_doc_ref, b.num_doc_ref,
b.mon_descuento, b.mon_pago, b.interes, b.int_mora
from CXC_ENC_PAGO_NOTA a, CXC_DET_PAGO_NOTA b
where a.cod_cia = b.cod_cia and a.sucursal = b.sucursal
and a.tip_doc = b.tip_doc and a.num_doc = b.num_doc;

ALTER TABLE CXC_ENC_MOVIMIENTO
 DROP CONSTRAINT CXC_ENC_MOVIMIENTO_DOCREF_AK;
ALTER TABLE CXC_ENC_MOVIMIENTO
 ADD CONSTRAINT CXC_ENC_MOVIMIENTO_DOCREF_AK
 UNIQUE (COD_CIA, COD_CLIENTE, TIP_DOC, DOC_REF, ESTADO);

_ ALTER TABLE CXC_AUTORIZACION
MODIFY(MONTO  NULL);
Ok hacerlos

ALTER TABLE CXC_AUTORIZACION
MODIFY(SALDO  NULL);