-- Interface Module: Vat_Fnd
-- Interface: Vat_Out

-- Create sequence for bdi_seq_id column

CREATE SEQUENCE vat_out_seq ORDER CACHE 20 MAXVALUE 9999999999999999999;


-- Create BDI Outbound Table: VAT_OUT
-- This table is used to integrate VAT Item information.

CREATE TABLE VAT_OUT (
  -- bdi internal column
  bdi_seq_id NUMBER DEFAULT vat_out_seq.nextval NOT NULL,
  -- bdi internal column
  bdi_app_name VARCHAR2(50) DEFAULT sys_context('userenv', 'current_schema') NOT NULL,
  -- bdi internal column
  bdi_dataset_type VARCHAR2(20) DEFAULT 'FULL',
  -- bdi internal column
  bdi_dataset_action VARCHAR2(20) DEFAULT 'REPLACE',
  -- This field holds the identifying number for the VAT region.
  vat_region NUMBER(4) NOT NULL,
  -- This field holds the name associated with the VAT region.
  vat_region_name VARCHAR2(120) NOT NULL,
  -- This field contains the alphanumeric identification for the VAT code.
  vat_code VARCHAR2(6) NOT NULL,
  -- This field contains the description identifying the VAT code.
  vat_code_desc VARCHAR2(120) NOT NULL,
  -- This field holds the active date on which the VAT rate becomes active.
  active_date TIMESTAMP NOT NULL,
  -- This field contains VAT rate associated with the given VAT code.
  vat_rate NUMBER(20,10) NOT NULL
);

COMMENT ON TABLE VAT_OUT IS 'This table is used to integrate VAT Item information.';
COMMENT ON COLUMN VAT_OUT.bdi_seq_id IS 'bdi internal column';
COMMENT ON COLUMN VAT_OUT.bdi_app_name IS 'bdi internal column';
COMMENT ON COLUMN VAT_OUT.bdi_dataset_type IS 'bdi internal column';
COMMENT ON COLUMN VAT_OUT.bdi_dataset_action IS 'bdi internal column';
COMMENT ON COLUMN VAT_OUT.vat_region IS 'This field holds the identifying number for the VAT region.';
COMMENT ON COLUMN VAT_OUT.vat_region_name IS 'This field holds the name associated with the VAT region.';
COMMENT ON COLUMN VAT_OUT.vat_code IS 'This field contains the alphanumeric identification for the VAT code.';
COMMENT ON COLUMN VAT_OUT.vat_code_desc IS 'This field contains the description identifying the VAT code.';
COMMENT ON COLUMN VAT_OUT.active_date IS 'This field holds the active date on which the VAT rate becomes active.';
COMMENT ON COLUMN VAT_OUT.vat_rate IS 'This field contains VAT rate associated with the given VAT code.';


-- Add BDI primary key constraint

ALTER TABLE VAT_OUT ADD CONSTRAINT pk_vat_out PRIMARY KEY (bdi_app_name, bdi_seq_id);


-- Add check constraint for bdi_dataset_type column

ALTER TABLE VAT_OUT ADD CONSTRAINT chk_type_vat_out CHECK (bdi_dataset_type IN ('FULL', 'PARTIAL'));


-- Add check constraint for bdi_dataset_action column

ALTER TABLE VAT_OUT ADD CONSTRAINT chk_actn_vat_out CHECK (bdi_dataset_action IN ('REPLACE', 'CREATE', 'UPDATE', 'DELETE'));
