-- Name: VIEW todo; Type: COMMENT; Schema: api; Owner: admin
--

COMMENT ON VIEW todo IS 'To-Do List';



--
-- TOC entry 393 (class 1259 OID 146568189)
-- Dependencies: 6264 8
-- Name: vendtype; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE vendtype (
    vendtype_id integer NOT NULL,
    vendtype_code text NOT NULL,
    vendtype_descrip text,
    CONSTRAINT vendtype_vendtype_code_check CHECK ((vendtype_code <> ''::text))
);


ALTER TABLE public.vendtype OWNER TO admin;

--
-- TOC entry 9435 (class 0 OID 0)
-- Dependencies: 393
-- Name: TABLE vendtype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE vendtype IS 'Vendor Type information';



--
-- TOC entry 394 (class 1259 OID 146568196)
-- Dependencies: 8564 6
-- Name: vendor; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW vendor AS
    SELECT (vendinfo.vend_number)::character varying AS vendor_number, vendtype.vendtype_code AS vendor_type, vendinfo.vend_name AS vendor_name, vendinfo.vend_active AS active, vendinfo.vend_accntnum AS account_number, addr.addr_number AS address_number, addr.addr_line1 AS address1, addr.addr_line2 AS address2, addr.addr_line3 AS address3, addr.addr_city AS city, addr.addr_state AS state, addr.addr_postalcode AS postalcode, addr.addr_country AS country, ''::text AS address_change, terms.terms_code AS default_terms, vendinfo.vend_shipvia AS ship_via, curr_symbol.curr_abbr AS default_currency, CASE WHEN (vendinfo.vend_fobsource = 'W'::bpchar) THEN 'Receiving Site'::text ELSE vendinfo.vend_fob END AS default_fob, vendinfo.vend_po AS sells_purchase_order_items, vendinfo.vend_restrictpurch AS may_only_sell_item_source, vendinfo.vend_qualified AS qualified, vendinfo.vend_match AS matching_vo_po_amounts, vendinfo.vend_1099 AS receives_1099, taxzone.taxzone_code AS default_tax_zone, CASE WHEN (accnt.accnt_id IS NULL) THEN 'N/A'::text ELSE public.formatglaccount(accnt.accnt_id) END AS default_dist_gl_account, CASE WHEN (expcat.expcat_id IS NULL) THEN 'N/A'::text ELSE expcat.expcat_code END AS default_dist_expense_category, CASE WHEN (tax.tax_id IS NULL) THEN 'N/A'::text ELSE tax.tax_code END AS default_dist_tax_code, c1.cntct_number AS contact1_number, c1.cntct_honorific AS contact1_honorific, c1.cntct_first_name AS contact1_first, c1.cntct_middle AS contact1_middle, c1.cntct_last_name AS contact1_last, c1.cntct_suffix AS contact1_suffix, c1.cntct_title AS contact1_job_title, c1.cntct_phone AS contact1_voice, c1.cntct_phone2 AS contact1_alternate, c1.cntct_fax AS contact1_fax, c1.cntct_email AS contact1_email, c1.cntct_webaddr AS contact1_web, ''::text AS contact1_change, c2.cntct_number AS contact2_number, c2.cntct_honorific AS contact2_honorific, c2.cntct_first_name AS contact2_first, c2.cntct_middle AS contact2_middle, c2.cntct_last_name AS contact2_last, c2.cntct_suffix AS contact2_suffix, c2.cntct_title AS contact2_job_title, c2.cntct_phone AS contact2_voice, c2.cntct_phone2 AS contact2_alternate, c2.cntct_fax AS contact2_fax, c2.cntct_email AS contact2_email, c2.cntct_webaddr AS contact2_web, ''::text AS contact2_change, vendinfo.vend_comments AS notes, vendinfo.vend_pocomments AS po_comments, vendinfo.vend_emailpodelivery AS allow_email_po_delivery, vendinfo.vend_ediemail AS po_edi_email, vendinfo.vend_edicc AS po_edi_cc, vendinfo.vend_edisubject AS po_edi_subject, vendinfo.vend_edifilename AS po_edi_filename, vendinfo.vend_ediemailbody AS po_edi_emailbody FROM ((((((((((public.vendinfo LEFT JOIN public.addr ON ((vendinfo.vend_addr_id = addr.addr_id))) LEFT JOIN public.cntct c1 ON ((vendinfo.vend_cntct1_id = c1.cntct_id))) LEFT JOIN public.cntct c2 ON ((vendinfo.vend_cntct2_id = c2.cntct_id))) LEFT JOIN public.taxzone ON ((vendinfo.vend_taxzone_id = taxzone.taxzone_id))) LEFT JOIN public.curr_symbol ON ((vendinfo.vend_curr_id = curr_symbol.curr_id))) LEFT JOIN public.terms ON ((vendinfo.vend_terms_id = terms.terms_id))) LEFT JOIN public.vendtype ON ((vendinfo.vend_vendtype_id = vendtype.vendtype_id))) LEFT JOIN public.accnt ON ((vendinfo.vend_accnt_id = accnt.accnt_id))) LEFT JOIN public.expcat ON ((vendinfo.vend_expcat_id = expcat.expcat_id))) LEFT JOIN public.tax ON ((vendinfo.vend_tax_id = tax.tax_id))) ORDER BY vendinfo.vend_number;


ALTER TABLE api.vendor OWNER TO admin;

--
-- TOC entry 9437 (class 0 OID 0)
-- Dependencies: 394
-- Name: VIEW vendor; Type: COMMENT; Schema: api; Owner: admin
--

COMMENT ON VIEW vendor IS 'vendor';


--
-- TOC entry 395 (class 1259 OID 146568201)
-- Dependencies: 8565 6
-- Name: vendoraddress; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW vendoraddress AS
    SELECT (vendinfo.vend_number)::character varying AS vendor_number, vendinfo.vend_name AS vendor_name, (vendaddrinfo.vendaddr_code)::character varying AS vendor_address_number, vendaddrinfo.vendaddr_name AS vendor_address_name, addr.addr_number AS address_number, addr.addr_line1 AS address1, addr.addr_line2 AS address2, addr.addr_line3 AS address3, addr.addr_city AS city, addr.addr_state AS state, addr.addr_postalcode AS postalcode, addr.addr_country AS country, ''::text AS address_change, cntct.cntct_number AS contact_number, cntct.cntct_honorific AS contact_honorific, cntct.cntct_first_name AS contact_first, cntct.cntct_middle AS contact_middle, cntct.cntct_last_name AS contact_last, cntct.cntct_suffix AS contact_suffix, cntct.cntct_title AS contact_job_title, cntct.cntct_phone AS contact_voice, cntct.cntct_phone2 AS contact_alternate, cntct.cntct_fax AS contact_fax, cntct.cntct_email AS contact_email, cntct.cntct_webaddr AS contact_web, ''::text AS contact_change, vendaddrinfo.vendaddr_comments AS notes FROM (((public.vendaddrinfo LEFT JOIN public.vendinfo ON ((vendinfo.vend_id = vendaddrinfo.vendaddr_vend_id))) LEFT JOIN public.addr ON ((vendaddrinfo.vendaddr_addr_id = addr.addr_id))) LEFT JOIN public.cntct ON ((vendaddrinfo.vendaddr_cntct_id = cntct.cntct_id))) ORDER BY vendaddrinfo.vendaddr_code;


ALTER TABLE api.vendoraddress OWNER TO admin;

--
-- TOC entry 9439 (class 0 OID 0)
-- Dependencies: 395
-- Name: VIEW vendoraddress; Type: COMMENT; Schema: api; Owner: admin
--

COMMENT ON VIEW vendoraddress IS 'vendor address';


--
-- TOC entry 396 (class 1259 OID 146568206)
-- Dependencies: 8566 6
-- Name: vendortype; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW vendortype AS
    SELECT (vendtype.vendtype_code)::character varying AS code, vendtype.vendtype_descrip AS description FROM public.vendtype ORDER BY vendtype.vendtype_code;


ALTER TABLE api.vendortype OWNER TO admin;

--
-- TOC entry 9441 (class 0 OID 0)
-- Dependencies: 396
-- Name: VIEW vendortype; Type: COMMENT; Schema: api; Owner: admin
--

COMMENT ON VIEW vendortype IS 'Vendor Type';



--
-- TOC entry 397 (class 1259 OID 146568210)
-- Dependencies: 8
-- Name: cmd; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cmd (
    cmd_id integer NOT NULL,
    cmd_module text NOT NULL,
    cmd_title text NOT NULL,
    cmd_descrip text,
    cmd_privname text,
    cmd_executable text NOT NULL,
    cmd_name text
);


ALTER TABLE public.cmd OWNER TO admin;

--
-- TOC entry 9443 (class 0 OID 0)
-- Dependencies: 397
-- Name: TABLE cmd; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE cmd IS 'Custom menu command table.';


--
-- TOC entry 398 (class 1259 OID 146568216)
-- Dependencies: 397 8
-- Name: cmd_cmd_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cmd_cmd_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cmd_cmd_id_seq OWNER TO admin;

--
-- TOC entry 9445 (class 0 OID 0)
-- Dependencies: 398
-- Name: cmd_cmd_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cmd_cmd_id_seq OWNED BY cmd.cmd_id;



--
-- TOC entry 399 (class 1259 OID 146568219)
-- Dependencies: 6266 397 7
-- Name: pkgcmd; Type: TABLE; Schema: fixcountry; Owner: admin; Tablespace: 
--

CREATE TABLE pkgcmd (
    cmd_id integer DEFAULT nextval('public.cmd_cmd_id_seq'::regclass)
)
INHERITS (public.cmd);


ALTER TABLE fixcountry.pkgcmd OWNER TO admin;


--
-- TOC entry 400 (class 1259 OID 146568226)
-- Dependencies: 8
-- Name: cmdarg; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cmdarg (
    cmdarg_id integer NOT NULL,
    cmdarg_cmd_id integer NOT NULL,
    cmdarg_order integer NOT NULL,
    cmdarg_arg text NOT NULL
);


ALTER TABLE public.cmdarg OWNER TO admin;

--
-- TOC entry 9448 (class 0 OID 0)
-- Dependencies: 400
-- Name: TABLE cmdarg; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE cmdarg IS 'Command argument for custom menu command table.';


--
-- TOC entry 401 (class 1259 OID 146568232)
-- Dependencies: 400 8
-- Name: cmdarg_cmdarg_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cmdarg_cmdarg_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cmdarg_cmdarg_id_seq OWNER TO admin;

--
-- TOC entry 9450 (class 0 OID 0)
-- Dependencies: 401
-- Name: cmdarg_cmdarg_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cmdarg_cmdarg_id_seq OWNED BY cmdarg.cmdarg_id;



--
-- TOC entry 402 (class 1259 OID 146568235)
-- Dependencies: 6268 400 7
-- Name: pkgcmdarg; Type: TABLE; Schema: fixcountry; Owner: admin; Tablespace: 
--

CREATE TABLE pkgcmdarg (
    cmdarg_id integer DEFAULT nextval('public.cmdarg_cmdarg_id_seq'::regclass)
)
INHERITS (public.cmdarg);


ALTER TABLE fixcountry.pkgcmdarg OWNER TO admin;


--
-- TOC entry 403 (class 1259 OID 146568242)
-- Dependencies: 8
-- Name: image_image_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE image_image_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.image_image_id_seq OWNER TO admin;


--
-- TOC entry 404 (class 1259 OID 146568244)
-- Dependencies: 6269 248 7
-- Name: pkgimage; Type: TABLE; Schema: fixcountry; Owner: admin; Tablespace: 
--

CREATE TABLE pkgimage (
    image_id integer DEFAULT nextval('public.image_image_id_seq'::regclass)
)
INHERITS (public.image);


ALTER TABLE fixcountry.pkgimage OWNER TO admin;


--
-- TOC entry 405 (class 1259 OID 146568251)
-- Dependencies: 6271 8
-- Name: metasql; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE metasql (
    metasql_id integer NOT NULL,
    metasql_group text,
    metasql_name text,
    metasql_notes text,
    metasql_query text,
    metasql_lastuser text,
    metasql_lastupdate date,
    metasql_grade integer DEFAULT 0 NOT NULL
);


ALTER TABLE public.metasql OWNER TO admin;

--
-- TOC entry 9455 (class 0 OID 0)
-- Dependencies: 405
-- Name: TABLE metasql; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE metasql IS 'MetaSQL Table';


--
-- TOC entry 406 (class 1259 OID 146568258)
-- Dependencies: 405 8
-- Name: metasql_metasql_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE metasql_metasql_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.metasql_metasql_id_seq OWNER TO admin;

--
-- TOC entry 9457 (class 0 OID 0)
-- Dependencies: 406
-- Name: metasql_metasql_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE metasql_metasql_id_seq OWNED BY metasql.metasql_id;



--
-- TOC entry 407 (class 1259 OID 146568261)
-- Dependencies: 6272 405 7
-- Name: pkgmetasql; Type: TABLE; Schema: fixcountry; Owner: admin; Tablespace: 
--

CREATE TABLE pkgmetasql (
    metasql_id integer DEFAULT nextval('public.metasql_metasql_id_seq'::regclass)
)
INHERITS (public.metasql);


ALTER TABLE fixcountry.pkgmetasql OWNER TO admin;


--
-- TOC entry 408 (class 1259 OID 146568269)
-- Dependencies: 6274 8
-- Name: priv; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE priv (
    priv_id integer DEFAULT nextval(('priv_priv_id_seq'::text)::regclass) NOT NULL,
    priv_module text,
    priv_name text,
    priv_descrip text,
    priv_seq integer
);


ALTER TABLE public.priv OWNER TO admin;

--
-- TOC entry 9460 (class 0 OID 0)
-- Dependencies: 408
-- Name: TABLE priv; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE priv IS 'System Privilege information';


--
-- TOC entry 409 (class 1259 OID 146568276)
-- Dependencies: 8
-- Name: priv_priv_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE priv_priv_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.priv_priv_id_seq OWNER TO admin;


--
-- TOC entry 410 (class 1259 OID 146568278)
-- Dependencies: 6275 408 7
-- Name: pkgpriv; Type: TABLE; Schema: fixcountry; Owner: admin; Tablespace: 
--

CREATE TABLE pkgpriv (
    priv_id integer DEFAULT nextval('public.priv_priv_id_seq'::regclass)
)
INHERITS (public.priv);


ALTER TABLE fixcountry.pkgpriv OWNER TO admin;


--
-- TOC entry 411 (class 1259 OID 146568285)
-- Dependencies: 6276 8
-- Name: report; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE report (
    report_id integer DEFAULT nextval(('report_report_id_seq'::text)::regclass) NOT NULL,
    report_name text,
    report_sys boolean,
    report_source text,
    report_descrip text,
    report_grade integer NOT NULL,
    report_loaddate timestamp without time zone
);


ALTER TABLE public.report OWNER TO admin;

--
-- TOC entry 9464 (class 0 OID 0)
-- Dependencies: 411
-- Name: TABLE report; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE report IS 'Report definition information';


--
-- TOC entry 412 (class 1259 OID 146568292)
-- Dependencies: 8
-- Name: report_report_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE report_report_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.report_report_id_seq OWNER TO admin;


--
-- TOC entry 413 (class 1259 OID 146568294)
-- Dependencies: 6277 411 7
-- Name: pkgreport; Type: TABLE; Schema: fixcountry; Owner: admin; Tablespace: 
--

CREATE TABLE pkgreport (
    report_id integer DEFAULT nextval('public.report_report_id_seq'::regclass)
)
INHERITS (public.report);


ALTER TABLE fixcountry.pkgreport OWNER TO admin;


--
-- TOC entry 414 (class 1259 OID 146568301)
-- Dependencies: 6279 8
-- Name: script; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE script (
    script_id integer NOT NULL,
    script_name text NOT NULL,
    script_order integer NOT NULL,
    script_enabled boolean DEFAULT false NOT NULL,
    script_source text NOT NULL,
    script_notes text
);


ALTER TABLE public.script OWNER TO admin;

--
-- TOC entry 415 (class 1259 OID 146568308)
-- Dependencies: 414 8
-- Name: script_script_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE script_script_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.script_script_id_seq OWNER TO admin;

--
-- TOC entry 9469 (class 0 OID 0)
-- Dependencies: 415
-- Name: script_script_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE script_script_id_seq OWNED BY script.script_id;



--
-- TOC entry 416 (class 1259 OID 146568311)
-- Dependencies: 6280 414 7
-- Name: pkgscript; Type: TABLE; Schema: fixcountry; Owner: admin; Tablespace: 
--

CREATE TABLE pkgscript (
    script_id integer DEFAULT nextval('public.script_script_id_seq'::regclass)
)
INHERITS (public.script);


ALTER TABLE fixcountry.pkgscript OWNER TO admin;


--
-- TOC entry 417 (class 1259 OID 146568319)
-- Dependencies: 6283 8
-- Name: uiform; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE uiform (
    uiform_id integer NOT NULL,
    uiform_name text NOT NULL,
    uiform_order integer NOT NULL,
    uiform_enabled boolean DEFAULT false NOT NULL,
    uiform_source text NOT NULL,
    uiform_notes text
);


ALTER TABLE public.uiform OWNER TO admin;

--
-- TOC entry 418 (class 1259 OID 146568326)
-- Dependencies: 417 8
-- Name: uiform_uiform_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE uiform_uiform_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.uiform_uiform_id_seq OWNER TO admin;

--
-- TOC entry 9473 (class 0 OID 0)
-- Dependencies: 418
-- Name: uiform_uiform_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE uiform_uiform_id_seq OWNED BY uiform.uiform_id;



--
-- TOC entry 419 (class 1259 OID 146568329)
-- Dependencies: 6284 417 7
-- Name: pkguiform; Type: TABLE; Schema: fixcountry; Owner: admin; Tablespace: 
--

CREATE TABLE pkguiform (
    uiform_id integer DEFAULT nextval('public.uiform_uiform_id_seq'::regclass)
)
INHERITS (public.uiform);


ALTER TABLE fixcountry.pkguiform OWNER TO admin;


--
-- TOC entry 420 (class 1259 OID 146568337)
-- Dependencies: 6286 8
-- Name: acalitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE acalitem (
    acalitem_id integer DEFAULT nextval(('"xcalitem_xcalitem_id_seq"'::text)::regclass) NOT NULL,
    acalitem_calhead_id integer,
    acalitem_periodstart date,
    acalitem_periodlength integer,
    acalitem_name text
);


ALTER TABLE public.acalitem OWNER TO admin;

--
-- TOC entry 9476 (class 0 OID 0)
-- Dependencies: 420
-- Name: TABLE acalitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE acalitem IS 'Absolute Calendar Item information';


--
-- TOC entry 421 (class 1259 OID 146568344)
-- Dependencies: 8
-- Name: accnt_accnt_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE accnt_accnt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.accnt_accnt_id_seq OWNER TO admin;

--
-- TOC entry 422 (class 1259 OID 146568346)
-- Dependencies: 234 8
-- Name: addr_addr_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE addr_addr_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.addr_addr_id_seq OWNER TO admin;

--
-- TOC entry 9479 (class 0 OID 0)
-- Dependencies: 422
-- Name: addr_addr_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE addr_addr_id_seq OWNED BY addr.addr_id;


--
-- TOC entry 423 (class 1259 OID 146568348)
-- Dependencies: 8567 8
-- Name: address; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW address AS
    SELECT addresses.addr_id, addresses.addr_active, addresses.addr_line1, addresses.addr_line2, addresses.addr_line3, addresses.addr_city, addresses.addr_state, addresses.addr_postalcode, addresses.addr_country, addresses.addr_notes, addresses.addr_number, addresses.crmacct_id, addresses.crmacct_number, addresses.crmacct_name FROM ((((SELECT base.addr_id, base.addr_active, base.addr_line1, base.addr_line2, base.addr_line3, base.addr_city, base.addr_state, base.addr_postalcode, base.addr_country, base.addr_notes, base.addr_number, base.crmacct_id, base.crmacct_number, base.crmacct_name FROM ((((SELECT addr.addr_id, addr.addr_active, addr.addr_line1, addr.addr_line2, addr.addr_line3, addr.addr_city, addr.addr_state, addr.addr_postalcode, addr.addr_country, addr.addr_notes, addr.addr_number, COALESCE(crmacct.crmacct_id, (-1)) AS crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM ((addr LEFT JOIN cntct ON ((cntct.cntct_addr_id = addr.addr_id))) LEFT JOIN crmacct ON ((crmacct.crmacct_id = cntct.cntct_crmacct_id))) EXCEPT SELECT addr.addr_id, addr.addr_active, addr.addr_line1, addr.addr_line2, addr.addr_line3, addr.addr_city, addr.addr_state, addr.addr_postalcode, addr.addr_country, addr.addr_notes, addr.addr_number, (-1), NULL::text AS unknown, NULL::text AS unknown FROM ((addr JOIN vendinfo ON ((vendinfo.vend_addr_id = addr.addr_id))) JOIN crmacct ON ((vendinfo.vend_id = crmacct.crmacct_vend_id)))) EXCEPT SELECT addr.addr_id, addr.addr_active, addr.addr_line1, addr.addr_line2, addr.addr_line3, addr.addr_city, addr.addr_state, addr.addr_postalcode, addr.addr_country, addr.addr_notes, addr.addr_number, (-1), NULL::text AS unknown, NULL::text AS unknown FROM ((addr JOIN vendaddrinfo ON ((vendaddrinfo.vendaddr_addr_id = addr.addr_id))) JOIN crmacct ON ((vendaddrinfo.vendaddr_vend_id = crmacct.crmacct_vend_id)))) EXCEPT SELECT addr.addr_id, addr.addr_active, addr.addr_line1, addr.addr_line2, addr.addr_line3, addr.addr_city, addr.addr_state, addr.addr_postalcode, addr.addr_country, addr.addr_notes, addr.addr_number, (-1), NULL::text AS unknown, NULL::text AS unknown FROM ((addr JOIN taxauth ON ((taxauth.taxauth_addr_id = addr.addr_id))) JOIN crmacct ON ((taxauth.taxauth_id = crmacct.crmacct_taxauth_id)))) EXCEPT SELECT addr.addr_id, addr.addr_active, addr.addr_line1, addr.addr_line2, addr.addr_line3, addr.addr_city, addr.addr_state, addr.addr_postalcode, addr.addr_country, addr.addr_notes, addr.addr_number, (-1), NULL::text AS unknown, NULL::text AS unknown FROM ((addr JOIN shiptoinfo ON ((shiptoinfo.shipto_addr_id = addr.addr_id))) JOIN crmacct ON ((shiptoinfo.shipto_cust_id = crmacct.crmacct_cust_id)))) base UNION SELECT addr.addr_id, addr.addr_active, addr.addr_line1, addr.addr_line2, addr.addr_line3, addr.addr_city, addr.addr_state, addr.addr_postalcode, addr.addr_country, addr.addr_notes, addr.addr_number, crmacct.crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM ((addr JOIN vendinfo ON ((vendinfo.vend_addr_id = addr.addr_id))) JOIN crmacct ON ((vendinfo.vend_id = crmacct.crmacct_vend_id)))) UNION SELECT addr.addr_id, addr.addr_active, addr.addr_line1, addr.addr_line2, addr.addr_line3, addr.addr_city, addr.addr_state, addr.addr_postalcode, addr.addr_country, addr.addr_notes, addr.addr_number, crmacct.crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM ((addr JOIN vendaddrinfo ON ((vendaddrinfo.vendaddr_addr_id = addr.addr_id))) JOIN crmacct ON ((vendaddrinfo.vendaddr_vend_id = crmacct.crmacct_vend_id)))) UNION SELECT addr.addr_id, addr.addr_active, addr.addr_line1, addr.addr_line2, addr.addr_line3, addr.addr_city, addr.addr_state, addr.addr_postalcode, addr.addr_country, addr.addr_notes, addr.addr_number, crmacct.crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM ((addr JOIN taxauth ON ((taxauth.taxauth_addr_id = addr.addr_id))) JOIN crmacct ON ((taxauth.taxauth_id = crmacct.crmacct_taxauth_id)))) UNION SELECT addr.addr_id, addr.addr_active, addr.addr_line1, addr.addr_line2, addr.addr_line3, addr.addr_city, addr.addr_state, addr.addr_postalcode, addr.addr_country, addr.addr_notes, addr.addr_number, crmacct.crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM ((addr JOIN shiptoinfo ON ((shiptoinfo.shipto_addr_id = addr.addr_id))) JOIN crmacct ON ((shiptoinfo.shipto_cust_id = crmacct.crmacct_cust_id)))) addresses ORDER BY addresses.addr_country, addresses.addr_state, addresses.addr_postalcode, addresses.addr_line1, addresses.addr_line2, addresses.addr_line3;


ALTER TABLE public.address OWNER TO admin;

--
-- TOC entry 424 (class 1259 OID 146568353)
-- Dependencies: 6287 6288 6289 8
-- Name: alarm; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE alarm (
    alarm_id integer NOT NULL,
    alarm_number text NOT NULL,
    alarm_event boolean DEFAULT false NOT NULL,
    alarm_email boolean DEFAULT false NOT NULL,
    alarm_sysmsg boolean DEFAULT false NOT NULL,
    alarm_trigger timestamp with time zone,
    alarm_time timestamp with time zone,
    alarm_time_offset integer,
    alarm_time_qualifier text,
    alarm_creator text,
    alarm_event_recipient text,
    alarm_email_recipient text,
    alarm_sysmsg_recipient text,
    alarm_source text,
    alarm_source_id integer
);


ALTER TABLE public.alarm OWNER TO admin;

--
-- TOC entry 9482 (class 0 OID 0)
-- Dependencies: 424
-- Name: TABLE alarm; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE alarm IS 'This table is the open alarms.';


--
-- TOC entry 425 (class 1259 OID 146568362)
-- Dependencies: 424 8
-- Name: alarm_alarm_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE alarm_alarm_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.alarm_alarm_id_seq OWNER TO admin;

--
-- TOC entry 9484 (class 0 OID 0)
-- Dependencies: 425
-- Name: alarm_alarm_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE alarm_alarm_id_seq OWNED BY alarm.alarm_id;


--
-- TOC entry 426 (class 1259 OID 146568364)
-- Dependencies: 8
-- Name: apaccnt; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE apaccnt (
    apaccnt_id integer NOT NULL,
    apaccnt_vendtype_id integer,
    apaccnt_vendtype text,
    apaccnt_ap_accnt_id integer NOT NULL,
    apaccnt_prepaid_accnt_id integer,
    apaccnt_discount_accnt_id integer
);


ALTER TABLE public.apaccnt OWNER TO admin;

--
-- TOC entry 9486 (class 0 OID 0)
-- Dependencies: 426
-- Name: TABLE apaccnt; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE apaccnt IS 'Accounts Payable (A/P) Account assignment information';


--
-- TOC entry 427 (class 1259 OID 146568370)
-- Dependencies: 426 8
-- Name: apaccnt_apaccnt_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE apaccnt_apaccnt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.apaccnt_apaccnt_id_seq OWNER TO admin;

--
-- TOC entry 9488 (class 0 OID 0)
-- Dependencies: 427
-- Name: apaccnt_apaccnt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE apaccnt_apaccnt_id_seq OWNED BY apaccnt.apaccnt_id;


--
-- TOC entry 428 (class 1259 OID 146568372)
-- Dependencies: 6293 8
-- Name: apapply; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE apapply (
    apapply_id integer NOT NULL,
    apapply_vend_id integer,
    apapply_postdate date,
    apapply_username text,
    apapply_source_apopen_id integer,
    apapply_source_doctype text,
    apapply_source_docnumber text,
    apapply_target_apopen_id integer,
    apapply_target_doctype text,
    apapply_target_docnumber text,
    apapply_journalnumber integer,
    apapply_amount numeric(20,2),
    apapply_curr_id integer DEFAULT basecurrid(),
    apapply_target_paid numeric(20,2),
    apapply_checkhead_id integer
);


ALTER TABLE public.apapply OWNER TO admin;

--
-- TOC entry 9490 (class 0 OID 0)
-- Dependencies: 428
-- Name: TABLE apapply; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE apapply IS 'Applications (e.g., Payments, A/P Credit Memos) made to Accounts Payable (A/P) Documents';


--
-- TOC entry 9491 (class 0 OID 0)
-- Dependencies: 428
-- Name: COLUMN apapply.apapply_source_apopen_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN apapply.apapply_source_apopen_id IS 'If apapply_source_doctype is "C" (credit memo) then apapply_source_apopen_id acts as a foreign key to the apopen table. If the source doctype is "K" (check) then the apapply_source_apopen_id acts as a foreign key to the checkhead table. If the apapply_source_apopen_id is -1 then the internal id of the source document is not known (always the case for checks posted before release 3.2.0BETA).';


--
-- TOC entry 429 (class 1259 OID 146568379)
-- Dependencies: 428 8
-- Name: apapply_apapply_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE apapply_apapply_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.apapply_apapply_id_seq OWNER TO admin;

--
-- TOC entry 9493 (class 0 OID 0)
-- Dependencies: 429
-- Name: apapply_apapply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE apapply_apapply_id_seq OWNED BY apapply.apapply_id;


--
-- TOC entry 430 (class 1259 OID 146568381)
-- Dependencies: 6294 6295 6296 6297 6298 6299 6300 6301 6303 6304 8
-- Name: checkhead; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE checkhead (
    checkhead_id integer NOT NULL,
    checkhead_recip_id integer NOT NULL,
    checkhead_recip_type text NOT NULL,
    checkhead_bankaccnt_id integer NOT NULL,
    checkhead_printed boolean DEFAULT false NOT NULL,
    checkhead_checkdate date NOT NULL,
    checkhead_number integer NOT NULL,
    checkhead_amount numeric(20,2) NOT NULL,
    checkhead_void boolean DEFAULT false NOT NULL,
    checkhead_replaced boolean DEFAULT false NOT NULL,
    checkhead_posted boolean DEFAULT false NOT NULL,
    checkhead_rec boolean DEFAULT false NOT NULL,
    checkhead_misc boolean DEFAULT false NOT NULL,
    checkhead_expcat_id integer,
    checkhead_for text NOT NULL,
    checkhead_notes text NOT NULL,
    checkhead_journalnumber integer,
    checkhead_curr_id integer DEFAULT basecurrid() NOT NULL,
    checkhead_deleted boolean DEFAULT false NOT NULL,
    checkhead_ach_batch text,
    checkhead_curr_rate numeric NOT NULL,
    CONSTRAINT checkhead_checkhead_amount_check CHECK ((checkhead_amount > (0)::numeric)),
    CONSTRAINT checkhead_checkhead_recip_type_check CHECK ((((checkhead_recip_type = 'C'::text) OR (checkhead_recip_type = 'V'::text)) OR (checkhead_recip_type = 'T'::text)))
);


ALTER TABLE public.checkhead OWNER TO admin;

--
-- TOC entry 9495 (class 0 OID 0)
-- Dependencies: 430
-- Name: TABLE checkhead; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE checkhead IS 'Accounts Payable Check Information';


--
-- TOC entry 431 (class 1259 OID 146568397)
-- Dependencies: 8568 8
-- Name: apchk; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW apchk AS
    SELECT checkhead.checkhead_id AS apchk_id, checkhead.checkhead_recip_id AS apchk_vend_id, checkhead.checkhead_bankaccnt_id AS apchk_bankaccnt_id, checkhead.checkhead_printed AS apchk_printed, checkhead.checkhead_checkdate AS apchk_checkdate, checkhead.checkhead_number AS apchk_number, checkhead.checkhead_amount AS apchk_amount, checkhead.checkhead_void AS apchk_void, checkhead.checkhead_replaced AS apchk_replaced, checkhead.checkhead_posted AS apchk_posted, checkhead.checkhead_rec AS apchk_rec, checkhead.checkhead_misc AS apchk_misc, checkhead.checkhead_expcat_id AS apchk_expcat_id, checkhead.checkhead_for AS apchk_for, checkhead.checkhead_notes AS apchk_notes, checkhead.checkhead_journalnumber AS apchk_journalnumber, checkhead.checkhead_curr_id AS apchk_curr_id, checkhead.checkhead_deleted AS apchk_deleted FROM checkhead WHERE (checkhead.checkhead_recip_type = 'V'::text);


ALTER TABLE public.apchk OWNER TO admin;

--
-- TOC entry 432 (class 1259 OID 146568401)
-- Dependencies: 6305 6306 6307 6309 8
-- Name: checkitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE checkitem (
    checkitem_id integer NOT NULL,
    checkitem_checkhead_id integer NOT NULL,
    checkitem_amount numeric(20,2) DEFAULT 0.0 NOT NULL,
    checkitem_discount numeric(20,2) DEFAULT 0.0 NOT NULL,
    checkitem_ponumber text,
    checkitem_vouchernumber text,
    checkitem_invcnumber text,
    checkitem_apopen_id integer,
    checkitem_aropen_id integer,
    checkitem_docdate date,
    checkitem_curr_id integer DEFAULT basecurrid() NOT NULL,
    checkitem_cmnumber text,
    checkitem_ranumber text,
    checkitem_curr_rate numeric,
    CONSTRAINT checkitem_check CHECK ((NOT ((checkitem_apopen_id IS NOT NULL) AND (checkitem_aropen_id IS NOT NULL))))
);


ALTER TABLE public.checkitem OWNER TO admin;

--
-- TOC entry 9498 (class 0 OID 0)
-- Dependencies: 432
-- Name: TABLE checkitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE checkitem IS 'Accounts Payable Check Line Item Information';


--
-- TOC entry 433 (class 1259 OID 146568411)
-- Dependencies: 8569 8
-- Name: apchkitem; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW apchkitem AS
    SELECT checkitem.checkitem_id AS apchkitem_id, checkitem.checkitem_checkhead_id AS apchkitem_apchk_id, checkitem.checkitem_vouchernumber AS apchkitem_vouchernumber, checkitem.checkitem_ponumber AS apchkitem_ponumber, checkitem.checkitem_amount AS apchkitem_amount, checkitem.checkitem_invcnumber AS apchkitem_invcnumber, checkitem.checkitem_apopen_id AS apchkitem_apopen_id, checkitem.checkitem_docdate AS apchkitem_docdate, checkitem.checkitem_curr_id AS apchkitem_curr_id, checkitem.checkitem_discount AS apchkitem_discount FROM checkhead, checkitem WHERE ((checkitem.checkitem_checkhead_id = checkhead.checkhead_id) AND (checkhead.checkhead_recip_type = 'V'::text));


ALTER TABLE public.apchkitem OWNER TO admin;

--
-- TOC entry 434 (class 1259 OID 146568415)
-- Dependencies: 6311 8
-- Name: apcreditapply; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE apcreditapply (
    apcreditapply_id integer NOT NULL,
    apcreditapply_source_apopen_id integer,
    apcreditapply_target_apopen_id integer,
    apcreditapply_amount numeric(20,2),
    apcreditapply_curr_id integer DEFAULT basecurrid()
);


ALTER TABLE public.apcreditapply OWNER TO admin;

--
-- TOC entry 9501 (class 0 OID 0)
-- Dependencies: 434
-- Name: TABLE apcreditapply; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE apcreditapply IS 'Temporary table for storing details of Accounts Payable (A/P) Credit Memo applications before those applications are posted';


--
-- TOC entry 435 (class 1259 OID 146568419)
-- Dependencies: 434 8
-- Name: apcreditapply_apcreditapply_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE apcreditapply_apcreditapply_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.apcreditapply_apcreditapply_id_seq OWNER TO admin;

--
-- TOC entry 9503 (class 0 OID 0)
-- Dependencies: 435
-- Name: apcreditapply_apcreditapply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE apcreditapply_apcreditapply_id_seq OWNED BY apcreditapply.apcreditapply_id;


--
-- TOC entry 436 (class 1259 OID 146568421)
-- Dependencies: 8570 8
-- Name: apmemo; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW apmemo AS
    SELECT apopen.apopen_id, apopen.apopen_docnumber FROM apopen WHERE (apopen.apopen_doctype = ANY (ARRAY['D'::bpchar, 'C'::bpchar]));


ALTER TABLE public.apmemo OWNER TO admin;

--
-- TOC entry 437 (class 1259 OID 146568425)
-- Dependencies: 8
-- Name: apopen_apopen_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE apopen_apopen_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.apopen_apopen_id_seq OWNER TO admin;

--
-- TOC entry 438 (class 1259 OID 146568427)
-- Dependencies: 377 8
-- Name: apopentax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE apopentax (
)
INHERITS (taxhist);


ALTER TABLE public.apopentax OWNER TO admin;

--
-- TOC entry 439 (class 1259 OID 146568433)
-- Dependencies: 6314 6315 8
-- Name: apselect; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE apselect (
    apselect_id integer NOT NULL,
    apselect_apopen_id integer NOT NULL,
    apselect_amount numeric(20,2) NOT NULL,
    apselect_bankaccnt_id integer,
    apselect_curr_id integer DEFAULT basecurrid(),
    apselect_date date,
    apselect_discount numeric(20,2) DEFAULT 0.0 NOT NULL
);


ALTER TABLE public.apselect OWNER TO admin;

--
-- TOC entry 9508 (class 0 OID 0)
-- Dependencies: 439
-- Name: TABLE apselect; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE apselect IS 'Temporary table for storing details of Accounts Payable (A/P) Payment selections';


--
-- TOC entry 440 (class 1259 OID 146568438)
-- Dependencies: 439 8
-- Name: apselect_apselect_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE apselect_apselect_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.apselect_apselect_id_seq OWNER TO admin;

--
-- TOC entry 9510 (class 0 OID 0)
-- Dependencies: 440
-- Name: apselect_apselect_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE apselect_apselect_id_seq OWNED BY apselect.apselect_id;


--
-- TOC entry 441 (class 1259 OID 146568440)
-- Dependencies: 6316 8
-- Name: araccnt; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE araccnt (
    araccnt_id integer DEFAULT nextval(('araccnt_araccnt_id_seq'::text)::regclass) NOT NULL,
    araccnt_custtype_id integer,
    araccnt_custtype text,
    araccnt_freight_accnt_id integer,
    araccnt_ar_accnt_id integer,
    araccnt_prepaid_accnt_id integer,
    araccnt_deferred_accnt_id integer,
    araccnt_discount_accnt_id integer
);


ALTER TABLE public.araccnt OWNER TO admin;

--
-- TOC entry 9512 (class 0 OID 0)
-- Dependencies: 441
-- Name: TABLE araccnt; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE araccnt IS 'Accounts Receivable (A/R) Account assignment information';


--
-- TOC entry 442 (class 1259 OID 146568447)
-- Dependencies: 8
-- Name: araccnt_araccnt_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE araccnt_araccnt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.araccnt_araccnt_id_seq OWNER TO admin;

--
-- TOC entry 443 (class 1259 OID 146568449)
-- Dependencies: 6318 8
-- Name: arapply; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE arapply (
    arapply_id integer NOT NULL,
    arapply_postdate date,
    arapply_cust_id integer,
    arapply_source_doctype text,
    arapply_source_docnumber text,
    arapply_target_doctype text,
    arapply_target_docnumber text,
    arapply_fundstype text,
    arapply_refnumber text,
    arapply_applied numeric(20,2),
    arapply_closed boolean,
    arapply_journalnumber text,
    arapply_source_aropen_id integer,
    arapply_target_aropen_id integer,
    arapply_username text,
    arapply_curr_id integer DEFAULT basecurrid(),
    arapply_distdate date NOT NULL,
    arapply_target_paid numeric(20,2),
    arapply_reftype text,
    arapply_ref_id integer
);


ALTER TABLE public.arapply OWNER TO admin;

--
-- TOC entry 9515 (class 0 OID 0)
-- Dependencies: 443
-- Name: TABLE arapply; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE arapply IS 'Applications (e.g., Cash Receipts, A/R Credit Memos) made to Accounts Receivable (A/R) Documents';


--
-- TOC entry 444 (class 1259 OID 146568456)
-- Dependencies: 443 8
-- Name: arapply_arapply_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE arapply_arapply_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.arapply_arapply_id_seq OWNER TO admin;

--
-- TOC entry 9517 (class 0 OID 0)
-- Dependencies: 444
-- Name: arapply_arapply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE arapply_arapply_id_seq OWNED BY arapply.arapply_id;


--
-- TOC entry 445 (class 1259 OID 146568458)
-- Dependencies: 269 8
-- Name: cashrcptitem_cashrcptitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cashrcptitem_cashrcptitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cashrcptitem_cashrcptitem_id_seq OWNER TO admin;

--
-- TOC entry 9519 (class 0 OID 0)
-- Dependencies: 445
-- Name: cashrcptitem_cashrcptitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cashrcptitem_cashrcptitem_id_seq OWNED BY cashrcptitem.cashrcptitem_id;


--
-- TOC entry 446 (class 1259 OID 146568460)
-- Dependencies: 6319 6320 8
-- Name: arcreditapply; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE arcreditapply (
    arcreditapply_id integer DEFAULT nextval('cashrcptitem_cashrcptitem_id_seq'::regclass) NOT NULL,
    arcreditapply_source_aropen_id integer,
    arcreditapply_target_aropen_id integer,
    arcreditapply_amount numeric(20,2),
    arcreditapply_curr_id integer DEFAULT basecurrid(),
    arcreditapply_reftype text,
    arcreditapply_ref_id integer
);


ALTER TABLE public.arcreditapply OWNER TO admin;

--
-- TOC entry 9521 (class 0 OID 0)
-- Dependencies: 446
-- Name: TABLE arcreditapply; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE arcreditapply IS 'Temporary table for storing details of Accounts Receivable (A/R) Credit Memo applications before those applications are posted';


--
-- TOC entry 447 (class 1259 OID 146568468)
-- Dependencies: 446 8
-- Name: arcreditapply_arcreditapply_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE arcreditapply_arcreditapply_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.arcreditapply_arcreditapply_id_seq OWNER TO admin;

--
-- TOC entry 9523 (class 0 OID 0)
-- Dependencies: 447
-- Name: arcreditapply_arcreditapply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE arcreditapply_arcreditapply_id_seq OWNED BY arcreditapply.arcreditapply_id;


--
-- TOC entry 448 (class 1259 OID 146568470)
-- Dependencies: 8571 8
-- Name: armemo; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW armemo AS
    SELECT aropen.aropen_id, aropen.aropen_docnumber FROM aropen WHERE (aropen.aropen_doctype = ANY (ARRAY['D'::bpchar, 'C'::bpchar, 'R'::bpchar])) UNION SELECT cmhead.cmhead_id AS aropen_id, cmhead.cmhead_number AS aropen_docnumber FROM cmhead;


ALTER TABLE public.armemo OWNER TO admin;

--
-- TOC entry 449 (class 1259 OID 146568474)
-- Dependencies: 8
-- Name: aropen_aropen_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE aropen_aropen_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.aropen_aropen_id_seq OWNER TO admin;

--
-- TOC entry 450 (class 1259 OID 146568476)
-- Dependencies: 377 8
-- Name: aropentax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE aropentax (
)
INHERITS (taxhist);


ALTER TABLE public.aropentax OWNER TO admin;

--
-- TOC entry 451 (class 1259 OID 146568482)
-- Dependencies: 6323 8
-- Name: asohist; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE asohist (
    asohist_id integer NOT NULL,
    asohist_cust_id integer,
    asohist_itemsite_id integer,
    asohist_shipdate date,
    asohist_invcdate date,
    asohist_duedate date,
    asohist_promisedate date,
    asohist_ordernumber text,
    asohist_invcnumber text,
    asohist_qtyshipped numeric(18,6),
    asohist_unitprice numeric(16,4),
    asohist_unitcost numeric(16,6),
    asohist_billtoname text,
    asohist_billtoaddress1 text,
    asohist_billtoaddress2 text,
    asohist_billtoaddress3 text,
    asohist_billtocity text,
    asohist_billtostate text,
    asohist_billtozip text,
    asohist_shiptoname text,
    asohist_shiptoaddress1 text,
    asohist_shiptoaddress2 text,
    asohist_shiptoaddress3 text,
    asohist_shiptocity text,
    asohist_shiptostate text,
    asohist_shiptozip text,
    asohist_shipto_id integer,
    asohist_shipvia text,
    asohist_salesrep_id integer,
    asohist_misc_type character(1),
    asohist_misc_descrip text,
    asohist_misc_id integer,
    asohist_commission numeric(16,4),
    asohist_commissionpaid boolean,
    asohist_doctype text,
    asohist_orderdate date,
    asohist_imported boolean,
    asohist_ponumber text,
    asohist_curr_id integer DEFAULT basecurrid(),
    asohist_taxtype_id integer,
    asohist_taxzone_id integer
);


ALTER TABLE public.asohist OWNER TO admin;

--
-- TOC entry 9528 (class 0 OID 0)
-- Dependencies: 451
-- Name: TABLE asohist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE asohist IS 'Archived Sales history';


--
-- TOC entry 452 (class 1259 OID 146568489)
-- Dependencies: 451 8
-- Name: asohist_asohist_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE asohist_asohist_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.asohist_asohist_id_seq OWNER TO admin;

--
-- TOC entry 9530 (class 0 OID 0)
-- Dependencies: 452
-- Name: asohist_asohist_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE asohist_asohist_id_seq OWNED BY asohist.asohist_id;


--
-- TOC entry 453 (class 1259 OID 146568491)
-- Dependencies: 377 8
-- Name: asohisttax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE asohisttax (
)
INHERITS (taxhist);


ALTER TABLE public.asohisttax OWNER TO admin;

--
-- TOC entry 454 (class 1259 OID 146568497)
-- Dependencies: 6326 6327 8
-- Name: atlasmap; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE atlasmap (
    atlasmap_id integer NOT NULL,
    atlasmap_name text NOT NULL,
    atlasmap_filter text NOT NULL,
    atlasmap_filtertype text NOT NULL,
    atlasmap_atlas text NOT NULL,
    atlasmap_map text NOT NULL,
    atlasmap_headerline boolean DEFAULT false NOT NULL,
    CONSTRAINT atlasmap_atlasmap_name_check CHECK ((atlasmap_name <> ''::text))
);


ALTER TABLE public.atlasmap OWNER TO admin;

--
-- TOC entry 9533 (class 0 OID 0)
-- Dependencies: 454
-- Name: TABLE atlasmap; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE atlasmap IS 'Describes heuristics for finding a CSVImp atlas for a given CSV file. When looking for a CSV Atlas to use when importing a CSV file, the first atlasmap record found that matches the CSV file is used to select the Atlas file and Map in that Atlas to import the CSV file.';


--
-- TOC entry 9534 (class 0 OID 0)
-- Dependencies: 454
-- Name: COLUMN atlasmap.atlasmap_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN atlasmap.atlasmap_id IS 'The internal id of this CSVImp atlas mapping.';


--
-- TOC entry 9535 (class 0 OID 0)
-- Dependencies: 454
-- Name: COLUMN atlasmap.atlasmap_name; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN atlasmap.atlasmap_name IS 'The human-readable name of this atlas mapping.';


--
-- TOC entry 9536 (class 0 OID 0)
-- Dependencies: 454
-- Name: COLUMN atlasmap.atlasmap_filter; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN atlasmap.atlasmap_filter IS 'A regular expression that should match the CSV file. Which part of the file that matches is determined by the filter type.';


--
-- TOC entry 9537 (class 0 OID 0)
-- Dependencies: 454
-- Name: COLUMN atlasmap.atlasmap_filtertype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN atlasmap.atlasmap_filtertype IS 'A description of what aspect of the CSV file the filter should be compared with. Handled values are: ''filename'' - the filter is matched against the name of the file; and ''firstline'' - the filter is matched against the first line of the file contents.';


--
-- TOC entry 9538 (class 0 OID 0)
-- Dependencies: 454
-- Name: COLUMN atlasmap.atlasmap_atlas; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN atlasmap.atlasmap_atlas IS 'The name of the CSVImp Atlas file. This should be a simple pathname, not an absolute or relative name if possible. The full path will be determined by concatenating the operating-system-specific CSV Atlas default directory with the value here unless this is an absolute pathname.';


--
-- TOC entry 9539 (class 0 OID 0)
-- Dependencies: 454
-- Name: COLUMN atlasmap.atlasmap_map; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN atlasmap.atlasmap_map IS 'The name of the Map inside the Atlas to use if the filter and filter type match the CVS file.';


--
-- TOC entry 9540 (class 0 OID 0)
-- Dependencies: 454
-- Name: COLUMN atlasmap.atlasmap_headerline; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN atlasmap.atlasmap_headerline IS 'An indicator of whether the first line of the CSV file should be treated as a header line or as data.';


--
-- TOC entry 455 (class 1259 OID 146568505)
-- Dependencies: 454 8
-- Name: atlasmap_atlasmap_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE atlasmap_atlasmap_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.atlasmap_atlasmap_id_seq OWNER TO admin;

--
-- TOC entry 9542 (class 0 OID 0)
-- Dependencies: 455
-- Name: atlasmap_atlasmap_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE atlasmap_atlasmap_id_seq OWNED BY atlasmap.atlasmap_id;


--
-- TOC entry 456 (class 1259 OID 146568507)
-- Dependencies: 8
-- Name: backup_usr; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE backup_usr (
    usr_id integer,
    usr_username text,
    usr_propername text,
    usr_passwd text,
    usr_locale_id integer,
    usr_initials text,
    usr_agent boolean,
    usr_active boolean,
    usr_email text,
    usr_dept_id integer,
    usr_shift_id integer,
    usr_window text
);


ALTER TABLE public.backup_usr OWNER TO admin;

--
-- TOC entry 457 (class 1259 OID 146568513)
-- Dependencies: 266 8
-- Name: bankaccnt_bankaccnt_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bankaccnt_bankaccnt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.bankaccnt_bankaccnt_id_seq OWNER TO admin;

--
-- TOC entry 9545 (class 0 OID 0)
-- Dependencies: 457
-- Name: bankaccnt_bankaccnt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankaccnt_bankaccnt_id_seq OWNED BY bankaccnt.bankaccnt_id;


--
-- TOC entry 458 (class 1259 OID 146568515)
-- Dependencies: 6328 6329 6330 6331 8
-- Name: bankadj; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE bankadj (
    bankadj_id integer NOT NULL,
    bankadj_bankaccnt_id integer NOT NULL,
    bankadj_bankadjtype_id integer NOT NULL,
    bankadj_created timestamp without time zone DEFAULT now() NOT NULL,
    bankadj_username text DEFAULT geteffectivextuser() NOT NULL,
    bankadj_date date NOT NULL,
    bankadj_docnumber text,
    bankadj_amount numeric(10,2) NOT NULL,
    bankadj_notes text,
    bankadj_sequence integer,
    bankadj_posted boolean DEFAULT false NOT NULL,
    bankadj_curr_id integer DEFAULT basecurrid(),
    bankadj_curr_rate numeric
);


ALTER TABLE public.bankadj OWNER TO admin;

--
-- TOC entry 9547 (class 0 OID 0)
-- Dependencies: 458
-- Name: TABLE bankadj; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE bankadj IS 'Bank Adjustments information';


--
-- TOC entry 459 (class 1259 OID 146568525)
-- Dependencies: 458 8
-- Name: bankadj_bankadj_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bankadj_bankadj_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.bankadj_bankadj_id_seq OWNER TO admin;

--
-- TOC entry 9549 (class 0 OID 0)
-- Dependencies: 459
-- Name: bankadj_bankadj_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankadj_bankadj_id_seq OWNED BY bankadj.bankadj_id;


--
-- TOC entry 460 (class 1259 OID 146568527)
-- Dependencies: 6334 6335 8
-- Name: bankadjtype; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE bankadjtype (
    bankadjtype_id integer NOT NULL,
    bankadjtype_name text NOT NULL,
    bankadjtype_descrip text,
    bankadjtype_accnt_id integer NOT NULL,
    bankadjtype_iscredit boolean DEFAULT false NOT NULL,
    CONSTRAINT bankadjtype_bankadjtype_name_check CHECK ((bankadjtype_name <> ''::text))
);


ALTER TABLE public.bankadjtype OWNER TO admin;

--
-- TOC entry 9551 (class 0 OID 0)
-- Dependencies: 460
-- Name: TABLE bankadjtype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE bankadjtype IS 'Bank Adjustment Types information';


--
-- TOC entry 461 (class 1259 OID 146568535)
-- Dependencies: 460 8
-- Name: bankadjtype_bankadjtype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bankadjtype_bankadjtype_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.bankadjtype_bankadjtype_id_seq OWNER TO admin;

--
-- TOC entry 9553 (class 0 OID 0)
-- Dependencies: 461
-- Name: bankadjtype_bankadjtype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankadjtype_bankadjtype_id_seq OWNED BY bankadjtype.bankadjtype_id;


--
-- TOC entry 462 (class 1259 OID 146568537)
-- Dependencies: 6336 6337 6338 8
-- Name: bankrec; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE bankrec (
    bankrec_id integer NOT NULL,
    bankrec_created timestamp without time zone DEFAULT ('now'::text)::timestamp(6) with time zone NOT NULL,
    bankrec_username text DEFAULT geteffectivextuser() NOT NULL,
    bankrec_bankaccnt_id integer,
    bankrec_opendate date,
    bankrec_enddate date,
    bankrec_openbal numeric(20,2),
    bankrec_endbal numeric(20,2),
    bankrec_posted boolean DEFAULT false,
    bankrec_postdate timestamp without time zone
);


ALTER TABLE public.bankrec OWNER TO admin;

--
-- TOC entry 9555 (class 0 OID 0)
-- Dependencies: 462
-- Name: TABLE bankrec; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE bankrec IS 'Bank Reconciliation posting history';


--
-- TOC entry 463 (class 1259 OID 146568546)
-- Dependencies: 462 8
-- Name: bankrec_bankrec_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bankrec_bankrec_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.bankrec_bankrec_id_seq OWNER TO admin;

--
-- TOC entry 9557 (class 0 OID 0)
-- Dependencies: 463
-- Name: bankrec_bankrec_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankrec_bankrec_id_seq OWNED BY bankrec.bankrec_id;


--
-- TOC entry 464 (class 1259 OID 146568548)
-- Dependencies: 6341 8
-- Name: bankrecitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE bankrecitem (
    bankrecitem_id integer NOT NULL,
    bankrecitem_bankrec_id integer NOT NULL,
    bankrecitem_source text NOT NULL,
    bankrecitem_source_id integer NOT NULL,
    bankrecitem_cleared boolean DEFAULT false,
    bankrecitem_curr_rate numeric,
    bankrecitem_amount numeric
);


ALTER TABLE public.bankrecitem OWNER TO admin;

--
-- TOC entry 9559 (class 0 OID 0)
-- Dependencies: 464
-- Name: TABLE bankrecitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE bankrecitem IS 'Posted Bank Reconciliation Line Item information';


--
-- TOC entry 465 (class 1259 OID 146568555)
-- Dependencies: 464 8
-- Name: bankrecitem_bankrecitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bankrecitem_bankrecitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.bankrecitem_bankrecitem_id_seq OWNER TO admin;

--
-- TOC entry 9561 (class 0 OID 0)
-- Dependencies: 465
-- Name: bankrecitem_bankrecitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankrecitem_bankrecitem_id_seq OWNED BY bankrecitem.bankrecitem_id;


--
-- TOC entry 466 (class 1259 OID 146568557)
-- Dependencies: 8
-- Name: bomhead_bomhead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bomhead_bomhead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.bomhead_bomhead_id_seq OWNER TO admin;

--
-- TOC entry 467 (class 1259 OID 146568559)
-- Dependencies: 8
-- Name: bomitem_bomitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bomitem_bomitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.bomitem_bomitem_id_seq OWNER TO admin;

--
-- TOC entry 468 (class 1259 OID 146568561)
-- Dependencies: 6342 6343 6344 6345 8
-- Name: bomitemcost; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE bomitemcost (
    bomitemcost_id integer NOT NULL,
    bomitemcost_bomitem_id integer NOT NULL,
    bomitemcost_costelem_id integer NOT NULL,
    bomitemcost_lowlevel boolean DEFAULT false NOT NULL,
    bomitemcost_stdcost numeric(16,6) DEFAULT 0 NOT NULL,
    bomitemcost_posted date,
    bomitemcost_actcost numeric(16,6) DEFAULT 0 NOT NULL,
    bomitemcost_updated date,
    bomitemcost_curr_id integer DEFAULT basecurrid() NOT NULL
);


ALTER TABLE public.bomitemcost OWNER TO admin;

--
-- TOC entry 9565 (class 0 OID 0)
-- Dependencies: 468
-- Name: TABLE bomitemcost; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE bomitemcost IS 'Bomitem Cost information';


--
-- TOC entry 469 (class 1259 OID 146568568)
-- Dependencies: 468 8
-- Name: bomitemcost_bomitemcost_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bomitemcost_bomitemcost_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.bomitemcost_bomitemcost_id_seq OWNER TO admin;

--
-- TOC entry 9567 (class 0 OID 0)
-- Dependencies: 469
-- Name: bomitemcost_bomitemcost_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bomitemcost_bomitemcost_id_seq OWNED BY bomitemcost.bomitemcost_id;


--
-- TOC entry 470 (class 1259 OID 146568570)
-- Dependencies: 258 8
-- Name: bomitemsub_bomitemsub_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bomitemsub_bomitemsub_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.bomitemsub_bomitemsub_id_seq OWNER TO admin;

--
-- TOC entry 9569 (class 0 OID 0)
-- Dependencies: 470
-- Name: bomitemsub_bomitemsub_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bomitemsub_bomitemsub_id_seq OWNED BY bomitemsub.bomitemsub_id;


--
-- TOC entry 471 (class 1259 OID 146568572)
-- Dependencies: 6348 6349 8
-- Name: bomwork; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE bomwork (
    bomwork_id integer NOT NULL,
    bomwork_set_id integer,
    bomwork_seqnumber integer,
    bomwork_item_id integer,
    bomwork_item_type character(1),
    bomwork_qtyper numeric(20,8),
    bomwork_scrap numeric(20,10),
    bomwork_status character(1),
    bomwork_level integer,
    bomwork_parent_id integer,
    bomwork_effective date,
    bomwork_expires date,
    bomwork_stdunitcost numeric(16,6),
    bomwork_actunitcost numeric(16,6),
    bomwork_parent_seqnumber integer,
    bomwork_createwo boolean,
    bomwork_issuemethod character(1),
    bomwork_char_id integer,
    bomwork_value text,
    bomwork_notes text,
    bomwork_ref text,
    bomwork_bomitem_id integer,
    bomwork_ecn text,
    bomwork_qtyfxd numeric(20,8) DEFAULT 0 NOT NULL,
    bomwork_qtyreq numeric(20,8) DEFAULT 0 NOT NULL
);


ALTER TABLE public.bomwork OWNER TO admin;

--
-- TOC entry 9571 (class 0 OID 0)
-- Dependencies: 471
-- Name: TABLE bomwork; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE bomwork IS 'Temporary table for storing information requested by Bill of Materials (BOM) displays and reports';


--
-- TOC entry 9572 (class 0 OID 0)
-- Dependencies: 471
-- Name: COLUMN bomwork.bomwork_qtyfxd; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN bomwork.bomwork_qtyfxd IS 'The fixed quantity required';


--
-- TOC entry 9573 (class 0 OID 0)
-- Dependencies: 471
-- Name: COLUMN bomwork.bomwork_qtyreq; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN bomwork.bomwork_qtyreq IS 'The total quantity required';


--
-- TOC entry 472 (class 1259 OID 146568580)
-- Dependencies: 471 8
-- Name: bomwork_bomwork_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE bomwork_bomwork_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.bomwork_bomwork_id_seq OWNER TO admin;

--
-- TOC entry 9575 (class 0 OID 0)
-- Dependencies: 472
-- Name: bomwork_bomwork_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bomwork_bomwork_id_seq OWNED BY bomwork.bomwork_id;


--
-- TOC entry 473 (class 1259 OID 146568582)
-- Dependencies: 8572 8
-- Name: budget; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW budget AS
    SELECT budgitem.budgitem_id AS budget_id, budgitem.budgitem_period_id AS budget_period_id, budgitem.budgitem_accnt_id AS budget_accnt_id, budgitem.budgitem_amount AS budget_amount FROM budgitem;


ALTER TABLE public.budget OWNER TO admin;

--
-- TOC entry 474 (class 1259 OID 146568586)
-- Dependencies: 260 8
-- Name: budghead_budghead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE budghead_budghead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.budghead_budghead_id_seq OWNER TO admin;

--
-- TOC entry 9578 (class 0 OID 0)
-- Dependencies: 474
-- Name: budghead_budghead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE budghead_budghead_id_seq OWNED BY budghead.budghead_id;


--
-- TOC entry 475 (class 1259 OID 146568588)
-- Dependencies: 263 8
-- Name: budgitem_budgitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE budgitem_budgitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.budgitem_budgitem_id_seq OWNER TO admin;

--
-- TOC entry 9580 (class 0 OID 0)
-- Dependencies: 475
-- Name: budgitem_budgitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE budgitem_budgitem_id_seq OWNED BY budgitem.budgitem_id;


--
-- TOC entry 476 (class 1259 OID 146568590)
-- Dependencies: 6350 6351 8
-- Name: calhead; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE calhead (
    calhead_id integer DEFAULT nextval(('"calhead_calhead_id_seq"'::text)::regclass) NOT NULL,
    calhead_type character(1),
    calhead_name text NOT NULL,
    calhead_descrip text,
    calhead_origin character(1),
    CONSTRAINT calhead_calhead_name_check CHECK ((calhead_name <> ''::text))
);


ALTER TABLE public.calhead OWNER TO admin;

--
-- TOC entry 9582 (class 0 OID 0)
-- Dependencies: 476
-- Name: TABLE calhead; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE calhead IS 'Calendar header information';


--
-- TOC entry 477 (class 1259 OID 146568598)
-- Dependencies: 8
-- Name: calhead_calhead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE calhead_calhead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.calhead_calhead_id_seq OWNER TO admin;

--
-- TOC entry 478 (class 1259 OID 146568600)
-- Dependencies: 8
-- Name: carrier_carrier_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE carrier_carrier_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.carrier_carrier_id_seq OWNER TO admin;

--
-- TOC entry 479 (class 1259 OID 146568602)
-- Dependencies: 267 8
-- Name: cashrcpt_cashrcpt_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cashrcpt_cashrcpt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cashrcpt_cashrcpt_id_seq OWNER TO admin;

--
-- TOC entry 9586 (class 0 OID 0)
-- Dependencies: 479
-- Name: cashrcpt_cashrcpt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cashrcpt_cashrcpt_id_seq OWNED BY cashrcpt.cashrcpt_id;


--
-- TOC entry 480 (class 1259 OID 146568604)
-- Dependencies: 271 8
-- Name: cashrcptmisc_cashrcptmisc_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cashrcptmisc_cashrcptmisc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cashrcptmisc_cashrcptmisc_id_seq OWNER TO admin;

--
-- TOC entry 9588 (class 0 OID 0)
-- Dependencies: 480
-- Name: cashrcptmisc_cashrcptmisc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cashrcptmisc_cashrcptmisc_id_seq OWNED BY cashrcptmisc.cashrcptmisc_id;


--
-- TOC entry 481 (class 1259 OID 146568606)
-- Dependencies: 278 8
-- Name: ccard_ccard_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ccard_ccard_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ccard_ccard_id_seq OWNER TO admin;

--
-- TOC entry 9590 (class 0 OID 0)
-- Dependencies: 481
-- Name: ccard_ccard_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ccard_ccard_id_seq OWNED BY ccard.ccard_id;


--
-- TOC entry 482 (class 1259 OID 146568608)
-- Dependencies: 6353 6354 8
-- Name: ccardaud; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE ccardaud (
    ccardaud_id integer NOT NULL,
    ccardaud_ccard_id integer,
    ccardaud_ccard_seq_old integer,
    ccardaud_ccard_seq_new integer,
    ccardaud_ccard_cust_id_old integer,
    ccardaud_ccard_cust_id_new integer,
    ccardaud_ccard_active_old boolean,
    ccardaud_ccard_active_new boolean,
    ccardaud_ccard_name_old bytea,
    ccardaud_ccard_name_new bytea,
    ccardaud_ccard_address1_old bytea,
    ccardaud_ccard_address1_new bytea,
    ccardaud_ccard_address2_old bytea,
    ccardaud_ccard_address2_new bytea,
    ccardaud_ccard_city_old bytea,
    ccardaud_ccard_city_new bytea,
    ccardaud_ccard_state_old bytea,
    ccardaud_ccard_state_new bytea,
    ccardaud_ccard_zip_old bytea,
    ccardaud_ccard_zip_new bytea,
    ccardaud_ccard_country_old bytea,
    ccardaud_ccard_country_new bytea,
    ccardaud_ccard_number_old bytea,
    ccardaud_ccard_number_new bytea,
    ccardaud_ccard_debit_old boolean,
    ccardaud_ccard_debit_new boolean,
    ccardaud_ccard_month_expired_old bytea,
    ccardaud_ccard_month_expired_new bytea,
    ccardaud_ccard_year_expired_old bytea,
    ccardaud_ccard_year_expired_new bytea,
    ccardaud_ccard_type_old character(1),
    ccardaud_ccard_type_new character(1),
    ccardaud_ccard_last_updated timestamp without time zone DEFAULT ('now'::text)::timestamp(6) with time zone NOT NULL,
    ccardaud_ccard_last_updated_by_username text DEFAULT geteffectivextuser() NOT NULL
);


ALTER TABLE public.ccardaud OWNER TO admin;

--
-- TOC entry 9592 (class 0 OID 0)
-- Dependencies: 482
-- Name: TABLE ccardaud; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE ccardaud IS 'Credit Card Information tracking data';


--
-- TOC entry 483 (class 1259 OID 146568616)
-- Dependencies: 482 8
-- Name: ccardaud_ccardaud_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ccardaud_ccardaud_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ccardaud_ccardaud_id_seq OWNER TO admin;

--
-- TOC entry 9594 (class 0 OID 0)
-- Dependencies: 483
-- Name: ccardaud_ccardaud_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ccardaud_ccardaud_id_seq OWNED BY ccardaud.ccardaud_id;


--
-- TOC entry 484 (class 1259 OID 146568618)
-- Dependencies: 6356 8
-- Name: ccbank; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE ccbank (
    ccbank_id integer NOT NULL,
    ccbank_ccard_type text NOT NULL,
    ccbank_bankaccnt_id integer,
    CONSTRAINT ccbank_ccbank_ccard_type_check CHECK ((ccbank_ccard_type = ANY (ARRAY['A'::text, 'D'::text, 'M'::text, 'P'::text, 'V'::text])))
);


ALTER TABLE public.ccbank OWNER TO admin;

--
-- TOC entry 485 (class 1259 OID 146568625)
-- Dependencies: 484 8
-- Name: ccbank_ccbank_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ccbank_ccbank_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ccbank_ccbank_id_seq OWNER TO admin;

--
-- TOC entry 9597 (class 0 OID 0)
-- Dependencies: 485
-- Name: ccbank_ccbank_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ccbank_ccbank_id_seq OWNED BY ccbank.ccbank_id;


--
-- TOC entry 486 (class 1259 OID 146568627)
-- Dependencies: 6357 6358 6359 6360 6361 8
-- Name: ccpay; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE ccpay (
    ccpay_id integer NOT NULL,
    ccpay_ccard_id integer,
    ccpay_cust_id integer,
    ccpay_amount numeric(20,2) DEFAULT 0.00 NOT NULL,
    ccpay_auth boolean DEFAULT true NOT NULL,
    ccpay_status character(1) NOT NULL,
    ccpay_type character(1) NOT NULL,
    ccpay_auth_charge character(1) NOT NULL,
    ccpay_order_number text,
    ccpay_order_number_seq integer,
    ccpay_r_avs text,
    ccpay_r_ordernum text,
    ccpay_r_error text,
    ccpay_r_approved text,
    ccpay_r_code text,
    ccpay_r_message text,
    ccpay_yp_r_time timestamp without time zone,
    ccpay_r_ref text,
    ccpay_yp_r_tdate text,
    ccpay_r_tax text,
    ccpay_r_shipping text,
    ccpay_yp_r_score integer,
    ccpay_transaction_datetime timestamp without time zone DEFAULT ('now'::text)::timestamp(6) with time zone NOT NULL,
    ccpay_by_username text DEFAULT geteffectivextuser() NOT NULL,
    ccpay_curr_id integer DEFAULT basecurrid(),
    ccpay_ccpay_id integer
);


ALTER TABLE public.ccpay OWNER TO admin;

--
-- TOC entry 9599 (class 0 OID 0)
-- Dependencies: 486
-- Name: TABLE ccpay; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE ccpay IS 'Track Credit Card PAYments, although really this table tracs communications with Credit Card processing companies. Records in this table may progress from preauthorizations through captures to credits, or they may simply remain in their original state if there is no further processing.';


--
-- TOC entry 9600 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_id IS 'Internal ID of this ccpay record.';


--
-- TOC entry 9601 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_ccard_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_ccard_id IS 'Internal ID of the Credit Card used for this transaction.';


--
-- TOC entry 9602 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_cust_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_cust_id IS 'Internal ID of the Customer owning the Credit Card';


--
-- TOC entry 9603 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_amount; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_amount IS 'Actual amount of this transaction.';


--
-- TOC entry 9604 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_auth; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_auth IS 'Boolean indicator of whether this transaction started out as a pre-authorization or not.';


--
-- TOC entry 9605 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_status; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_status IS 'The status of the last attempted transaction for this record. Values include A = Authorized, C = Charged, D = Declined or otherwise rejected, V = Voided, X = Error.';


--
-- TOC entry 9606 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_type; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_type IS 'The most recent type of transaction attempted with this record. Values include A = Authorize, C = Capture or Charge, R = cRedit, V = reVerse or Void.';


--
-- TOC entry 9607 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_auth_charge; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_auth_charge IS 'The original type of transaction attempted with this record. Values are the same as for ccpay_type.';


--
-- TOC entry 9608 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_order_number; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_order_number IS 'The original xTuple ERP order for which this credit card transaction applies. This will usually be either a Sales Order number or Credit Memo number.';


--
-- TOC entry 9609 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_order_number_seq; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_order_number_seq IS 'A sequence number to differentiate between different transactions for the same ccpay_order_number. For example, if a Customer makes a down payment and a final payment for a single order, there will be two distinct ccpay records with the same ccpay_order_number but different ccpay_order_number_seq values (1 and 2, respectively).';


--
-- TOC entry 9610 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_r_avs; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_r_avs IS 'The Address Verification System code returned by the credit card processing company.';


--
-- TOC entry 9611 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_r_ordernum; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_r_ordernum IS 'A transaction ID returned by the credit card processing company to be used when referring to this transaction later. It may be used for voiding, crediting, or capturing previous transactions.';


--
-- TOC entry 9612 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_r_error; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_r_error IS 'Error message, if any, describing why this record failed to be processed properly.';


--
-- TOC entry 9613 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_r_approved; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_r_approved IS 'English text stating whether the transaction was approved, declined, hit an error, or was held for review. Specific values differ depending on the credit card processor.';


--
-- TOC entry 9614 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_r_code; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_r_code IS 'The transaction Approval code returned by the credit card processor. Specific values differ depending on the credit card processor.';


--
-- TOC entry 9615 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_r_message; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_r_message IS 'Additional text that describes the status of the transaction. This may be empty.';


--
-- TOC entry 9616 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_yp_r_time; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_yp_r_time IS 'The time the transaction was posted according to the credit card processing company. May be blank.';


--
-- TOC entry 9617 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_r_ref; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_r_ref IS 'An additional reference number assigned to this transaction by the credit card processing company.';


--
-- TOC entry 9618 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_yp_r_tdate; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_yp_r_tdate IS 'The date the transaction was posted according to the credit card processing company. May be blank.';


--
-- TOC entry 9619 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_r_tax; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_r_tax IS '[ deprecated ]';


--
-- TOC entry 9620 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_r_shipping; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_r_shipping IS '[ deprecated ]';


--
-- TOC entry 9621 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_yp_r_score; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_yp_r_score IS 'A potential fraud score returned by the credit card company. May be blank.';


--
-- TOC entry 9622 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_transaction_datetime; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_transaction_datetime IS 'The date and time this record was created, unless explicitly set by the application.';


--
-- TOC entry 9623 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_by_username; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_by_username IS 'The user who created this record, unless explicitly set by the application.';


--
-- TOC entry 9624 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_curr_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_curr_id IS 'The internal ID of the currency of the ccpay_amount.';


--
-- TOC entry 9625 (class 0 OID 0)
-- Dependencies: 486
-- Name: COLUMN ccpay.ccpay_ccpay_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_ccpay_id IS 'Foreign key to another ccpay record. This will have a value if a new ccpay record is created to record a Refund for part or all of another ccpay record.';


--
-- TOC entry 487 (class 1259 OID 146568638)
-- Dependencies: 486 8
-- Name: ccpay_ccpay_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ccpay_ccpay_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ccpay_ccpay_id_seq OWNER TO admin;

--
-- TOC entry 9627 (class 0 OID 0)
-- Dependencies: 487
-- Name: ccpay_ccpay_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ccpay_ccpay_id_seq OWNED BY ccpay.ccpay_id;


--
-- TOC entry 488 (class 1259 OID 146568640)
-- Dependencies: 236 8
-- Name: char_char_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE char_char_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.char_char_id_seq OWNER TO admin;

--
-- TOC entry 9629 (class 0 OID 0)
-- Dependencies: 488
-- Name: char_char_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE char_char_id_seq OWNED BY "char".char_id;


--
-- TOC entry 489 (class 1259 OID 146568642)
-- Dependencies: 237 8
-- Name: charass_charass_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE charass_charass_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.charass_charass_id_seq OWNER TO admin;

--
-- TOC entry 9631 (class 0 OID 0)
-- Dependencies: 489
-- Name: charass_charass_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE charass_charass_id_seq OWNED BY charass.charass_id;


--
-- TOC entry 490 (class 1259 OID 146568644)
-- Dependencies: 6364 8
-- Name: charopt; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE charopt (
    charopt_id integer NOT NULL,
    charopt_char_id integer,
    charopt_value text NOT NULL,
    charopt_order integer DEFAULT 0 NOT NULL
);


ALTER TABLE public.charopt OWNER TO admin;

--
-- TOC entry 9633 (class 0 OID 0)
-- Dependencies: 490
-- Name: TABLE charopt; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE charopt IS 'Stores list options for characteristics';


--
-- TOC entry 9634 (class 0 OID 0)
-- Dependencies: 490
-- Name: COLUMN charopt.charopt_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN charopt.charopt_id IS 'Primary key';


--
-- TOC entry 9635 (class 0 OID 0)
-- Dependencies: 490
-- Name: COLUMN charopt.charopt_char_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN charopt.charopt_char_id IS 'Reference to char table';


--
-- TOC entry 9636 (class 0 OID 0)
-- Dependencies: 490
-- Name: COLUMN charopt.charopt_value; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN charopt.charopt_value IS 'Option value';


--
-- TOC entry 9637 (class 0 OID 0)
-- Dependencies: 490
-- Name: COLUMN charopt.charopt_order; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN charopt.charopt_order IS 'Option sort order';


--
-- TOC entry 491 (class 1259 OID 146568651)
-- Dependencies: 490 8
-- Name: charopt_charopt_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE charopt_charopt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.charopt_charopt_id_seq OWNER TO admin;

--
-- TOC entry 9639 (class 0 OID 0)
-- Dependencies: 491
-- Name: charopt_charopt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE charopt_charopt_id_seq OWNED BY charopt.charopt_id;


--
-- TOC entry 492 (class 1259 OID 146568653)
-- Dependencies: 430 8
-- Name: checkhead_checkhead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE checkhead_checkhead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.checkhead_checkhead_id_seq OWNER TO admin;

--
-- TOC entry 9641 (class 0 OID 0)
-- Dependencies: 492
-- Name: checkhead_checkhead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE checkhead_checkhead_id_seq OWNED BY checkhead.checkhead_id;


--
-- TOC entry 493 (class 1259 OID 146568655)
-- Dependencies: 432 8
-- Name: checkitem_checkitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE checkitem_checkitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.checkitem_checkitem_id_seq OWNER TO admin;

--
-- TOC entry 9643 (class 0 OID 0)
-- Dependencies: 493
-- Name: checkitem_checkitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE checkitem_checkitem_id_seq OWNED BY checkitem.checkitem_id;


--
-- TOC entry 494 (class 1259 OID 146568657)
-- Dependencies: 8573 8
-- Name: checkrecip; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW checkrecip AS
    (SELECT custinfo.cust_id AS checkrecip_id, 'C'::text AS checkrecip_type, custinfo.cust_number AS checkrecip_number, custinfo.cust_name AS checkrecip_name, 'A/R'::text AS checkrecip_gltrans_source, findaraccount(custinfo.cust_id) AS checkrecip_accnt_id, cntct.cntct_addr_id AS checkrecip_addr_id FROM (custinfo LEFT JOIN cntct ON ((custinfo.cust_cntct_id = cntct.cntct_id))) UNION ALL SELECT taxauth.taxauth_id AS checkrecip_id, 'T'::text AS checkrecip_type, taxauth.taxauth_code AS checkrecip_number, taxauth.taxauth_name AS checkrecip_name, 'G/L'::text AS checkrecip_gltrans_source, taxauth.taxauth_accnt_id AS checkrecip_accnt_id, taxauth.taxauth_addr_id AS checkrecip_addr_id FROM taxauth) UNION ALL SELECT vendinfo.vend_id AS checkrecip_id, 'V'::text AS checkrecip_type, vendinfo.vend_number AS checkrecip_number, vendinfo.vend_name AS checkrecip_name, 'A/P'::text AS checkrecip_gltrans_source, findapaccount(vendinfo.vend_id) AS checkrecip_accnt_id, vendaddrinfo.vendaddr_addr_id AS checkrecip_addr_id FROM (vendinfo LEFT JOIN vendaddrinfo ON (((vendinfo.vend_id = vendaddrinfo.vendaddr_vend_id) AND (upper(vendaddrinfo.vendaddr_code) = 'REMIT'::text))));


ALTER TABLE public.checkrecip OWNER TO admin;

--
-- TOC entry 495 (class 1259 OID 146568662)
-- Dependencies: 8
-- Name: classcode_classcode_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE classcode_classcode_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.classcode_classcode_id_seq OWNER TO admin;

--
-- TOC entry 496 (class 1259 OID 146568664)
-- Dependencies: 8
-- Name: cmhead_cmhead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cmhead_cmhead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cmhead_cmhead_id_seq OWNER TO admin;

--
-- TOC entry 497 (class 1259 OID 146568666)
-- Dependencies: 377 8
-- Name: cmheadtax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cmheadtax (
)
INHERITS (taxhist);


ALTER TABLE public.cmheadtax OWNER TO admin;

--
-- TOC entry 498 (class 1259 OID 146568672)
-- Dependencies: 8
-- Name: cmitem_cmitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cmitem_cmitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cmitem_cmitem_id_seq OWNER TO admin;

--
-- TOC entry 499 (class 1259 OID 146568674)
-- Dependencies: 377 8
-- Name: cmitemtax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cmitemtax (
)
INHERITS (taxhist);


ALTER TABLE public.cmitemtax OWNER TO admin;

--
-- TOC entry 500 (class 1259 OID 146568680)
-- Dependencies: 239 8
-- Name: cmnttype_cmnttype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cmnttype_cmnttype_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cmnttype_cmnttype_id_seq OWNER TO admin;

--
-- TOC entry 9651 (class 0 OID 0)
-- Dependencies: 500
-- Name: cmnttype_cmnttype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cmnttype_cmnttype_id_seq OWNED BY cmnttype.cmnttype_id;


--
-- TOC entry 501 (class 1259 OID 146568682)
-- Dependencies: 8
-- Name: cmnttypesource; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cmnttypesource (
    cmnttypesource_id integer NOT NULL,
    cmnttypesource_cmnttype_id integer,
    cmnttypesource_source_id integer
);


ALTER TABLE public.cmnttypesource OWNER TO admin;

--
-- TOC entry 9653 (class 0 OID 0)
-- Dependencies: 501
-- Name: TABLE cmnttypesource; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE cmnttypesource IS 'Comment Type/Source association';


--
-- TOC entry 502 (class 1259 OID 146568685)
-- Dependencies: 501 8
-- Name: cmnttypesource_cmnttypesource_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cmnttypesource_cmnttypesource_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cmnttypesource_cmnttypesource_id_seq OWNER TO admin;

--
-- TOC entry 9655 (class 0 OID 0)
-- Dependencies: 502
-- Name: cmnttypesource_cmnttypesource_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cmnttypesource_cmnttypesource_id_seq OWNED BY cmnttypesource.cmnttypesource_id;


--
-- TOC entry 503 (class 1259 OID 146568687)
-- Dependencies: 204 8
-- Name: cntct_cntct_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cntct_cntct_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cntct_cntct_id_seq OWNER TO admin;

--
-- TOC entry 9657 (class 0 OID 0)
-- Dependencies: 503
-- Name: cntct_cntct_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cntct_cntct_id_seq OWNED BY cntct.cntct_id;


--
-- TOC entry 504 (class 1259 OID 146568689)
-- Dependencies: 8
-- Name: cntctaddr; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cntctaddr (
    cntctaddr_id integer NOT NULL,
    cntctaddr_cntct_id integer,
    cntctaddr_primary boolean NOT NULL,
    cntctaddr_addr_id integer NOT NULL,
    cntctaddr_type character(2) NOT NULL
);


ALTER TABLE public.cntctaddr OWNER TO admin;

--
-- TOC entry 505 (class 1259 OID 146568692)
-- Dependencies: 504 8
-- Name: cntctaddr_cntctaddr_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cntctaddr_cntctaddr_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cntctaddr_cntctaddr_id_seq OWNER TO admin;

--
-- TOC entry 9660 (class 0 OID 0)
-- Dependencies: 505
-- Name: cntctaddr_cntctaddr_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cntctaddr_cntctaddr_id_seq OWNED BY cntctaddr.cntctaddr_id;


--
-- TOC entry 506 (class 1259 OID 146568694)
-- Dependencies: 8
-- Name: cntctdata; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cntctdata (
    cntctdata_id integer NOT NULL,
    cntctdata_cntct_id integer,
    cntctdata_primary boolean NOT NULL,
    cntctdata_text text NOT NULL,
    cntctdata_type character(2) NOT NULL
);


ALTER TABLE public.cntctdata OWNER TO admin;

--
-- TOC entry 507 (class 1259 OID 146568700)
-- Dependencies: 506 8
-- Name: cntctdata_cntctdata_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cntctdata_cntctdata_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cntctdata_cntctdata_id_seq OWNER TO admin;

--
-- TOC entry 9663 (class 0 OID 0)
-- Dependencies: 507
-- Name: cntctdata_cntctdata_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cntctdata_cntctdata_id_seq OWNED BY cntctdata.cntctdata_id;


--
-- TOC entry 508 (class 1259 OID 146568702)
-- Dependencies: 6371 8
-- Name: cntcteml; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cntcteml (
    cntcteml_id integer NOT NULL,
    cntcteml_cntct_id integer,
    cntcteml_primary boolean DEFAULT false NOT NULL,
    cntcteml_email text NOT NULL
);


ALTER TABLE public.cntcteml OWNER TO admin;

--
-- TOC entry 9665 (class 0 OID 0)
-- Dependencies: 508
-- Name: TABLE cntcteml; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE cntcteml IS 'Stores email addresses for contacts';


--
-- TOC entry 9666 (class 0 OID 0)
-- Dependencies: 508
-- Name: COLUMN cntcteml.cntcteml_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN cntcteml.cntcteml_id IS 'Primary key';


--
-- TOC entry 9667 (class 0 OID 0)
-- Dependencies: 508
-- Name: COLUMN cntcteml.cntcteml_cntct_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN cntcteml.cntcteml_cntct_id IS 'Reference to contact table';


--
-- TOC entry 9668 (class 0 OID 0)
-- Dependencies: 508
-- Name: COLUMN cntcteml.cntcteml_primary; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN cntcteml.cntcteml_primary IS 'Flags whether this is the primary email address';


--
-- TOC entry 9669 (class 0 OID 0)
-- Dependencies: 508
-- Name: COLUMN cntcteml.cntcteml_email; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN cntcteml.cntcteml_email IS 'Alternate information';


--
-- TOC entry 509 (class 1259 OID 146568709)
-- Dependencies: 508 8
-- Name: cntcteml_cntcteml_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cntcteml_cntcteml_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cntcteml_cntcteml_id_seq OWNER TO admin;

--
-- TOC entry 9671 (class 0 OID 0)
-- Dependencies: 509
-- Name: cntcteml_cntcteml_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cntcteml_cntcteml_id_seq OWNED BY cntcteml.cntcteml_id;


--
-- TOC entry 510 (class 1259 OID 146568711)
-- Dependencies: 6372 8
-- Name: cntctmrgd; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cntctmrgd (
    cntctmrgd_cntct_id integer NOT NULL,
    cntctmrgd_error boolean DEFAULT false
);


ALTER TABLE public.cntctmrgd OWNER TO admin;

--
-- TOC entry 511 (class 1259 OID 146568715)
-- Dependencies: 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 8
-- Name: cntctsel; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cntctsel (
    cntctsel_cntct_id integer NOT NULL,
    cntctsel_target boolean,
    cntctsel_mrg_crmacct_id boolean DEFAULT false,
    cntctsel_mrg_addr_id boolean DEFAULT false,
    cntctsel_mrg_first_name boolean DEFAULT false,
    cntctsel_mrg_last_name boolean DEFAULT false,
    cntctsel_mrg_honorific boolean DEFAULT false,
    cntctsel_mrg_initials boolean DEFAULT false,
    cntctsel_mrg_phone boolean DEFAULT false,
    cntctsel_mrg_phone2 boolean DEFAULT false,
    cntctsel_mrg_fax boolean DEFAULT false,
    cntctsel_mrg_email boolean DEFAULT false,
    cntctsel_mrg_webaddr boolean DEFAULT false,
    cntctsel_mrg_notes boolean DEFAULT false,
    cntctsel_mrg_title boolean DEFAULT false,
    cntctsel_mrg_middle boolean DEFAULT false,
    cntctsel_mrg_suffix boolean DEFAULT false,
    cntctsel_mrg_owner_username boolean DEFAULT false
);


ALTER TABLE public.cntctsel OWNER TO admin;

--
-- TOC entry 512 (class 1259 OID 146568734)
-- Dependencies: 8
-- Name: cntslip_cntslip_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cntslip_cntslip_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cntslip_cntslip_id_seq OWNER TO admin;

--
-- TOC entry 513 (class 1259 OID 146568736)
-- Dependencies: 6389 8
-- Name: cobill; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cobill (
    cobill_id integer DEFAULT nextval(('cobill_cobill_id_seq'::text)::regclass) NOT NULL,
    cobill_coitem_id integer,
    cobill_selectdate timestamp with time zone,
    cobill_qty numeric(18,6),
    cobill_invcnum integer,
    cobill_toclose boolean,
    cobill_cobmisc_id integer,
    cobill_select_username text,
    cobill_invcitem_id integer,
    cobill_taxtype_id integer
);


ALTER TABLE public.cobill OWNER TO admin;

--
-- TOC entry 9676 (class 0 OID 0)
-- Dependencies: 513
-- Name: TABLE cobill; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE cobill IS 'Billing Selection Line Item information';


--
-- TOC entry 514 (class 1259 OID 146568743)
-- Dependencies: 8
-- Name: cobill_cobill_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cobill_cobill_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cobill_cobill_id_seq OWNER TO admin;

--
-- TOC entry 515 (class 1259 OID 146568745)
-- Dependencies: 377 8
-- Name: cobilltax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cobilltax (
)
INHERITS (taxhist);


ALTER TABLE public.cobilltax OWNER TO admin;

--
-- TOC entry 516 (class 1259 OID 146568751)
-- Dependencies: 6391 6392 8
-- Name: cobmisc; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cobmisc (
    cobmisc_id integer DEFAULT nextval(('cobmisc_cobmisc_id_seq'::text)::regclass) NOT NULL,
    cobmisc_cohead_id integer,
    cobmisc_shipvia text,
    cobmisc_freight numeric(16,4),
    cobmisc_misc numeric(16,4),
    cobmisc_payment numeric(16,4),
    cobmisc_paymentref text,
    cobmisc_notes text,
    cobmisc_shipdate date,
    cobmisc_invcnumber integer,
    cobmisc_invcdate date,
    cobmisc_posted boolean,
    cobmisc_misc_accnt_id integer,
    cobmisc_misc_descrip text,
    cobmisc_closeorder boolean,
    cobmisc_curr_id integer DEFAULT basecurrid(),
    cobmisc_invchead_id integer,
    cobmisc_taxzone_id integer,
    cobmisc_taxtype_id integer
);


ALTER TABLE public.cobmisc OWNER TO admin;

--
-- TOC entry 9680 (class 0 OID 0)
-- Dependencies: 516
-- Name: TABLE cobmisc; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE cobmisc IS 'General information about Billing Selections';


--
-- TOC entry 517 (class 1259 OID 146568759)
-- Dependencies: 8
-- Name: cobmisc_cobmisc_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cobmisc_cobmisc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cobmisc_cobmisc_id_seq OWNER TO admin;

--
-- TOC entry 518 (class 1259 OID 146568761)
-- Dependencies: 377 8
-- Name: cobmisctax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cobmisctax (
)
INHERITS (taxhist);


ALTER TABLE public.cobmisctax OWNER TO admin;

--
-- TOC entry 519 (class 1259 OID 146568767)
-- Dependencies: 8
-- Name: cohead_cohead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cohead_cohead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cohead_cohead_id_seq OWNER TO admin;

--
-- TOC entry 520 (class 1259 OID 146568769)
-- Dependencies: 8
-- Name: cohist_cohist_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cohist_cohist_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cohist_cohist_id_seq OWNER TO admin;

--
-- TOC entry 521 (class 1259 OID 146568771)
-- Dependencies: 8
-- Name: coitem_coitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE coitem_coitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.coitem_coitem_id_seq OWNER TO admin;

--
-- TOC entry 522 (class 1259 OID 146568773)
-- Dependencies: 8
-- Name: comment_comment_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE comment_comment_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.comment_comment_id_seq OWNER TO admin;

--
-- TOC entry 523 (class 1259 OID 146568775)
-- Dependencies: 6395 6396 8
-- Name: company; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE company (
    company_id integer NOT NULL,
    company_number text NOT NULL,
    company_descrip text,
    company_external boolean DEFAULT false NOT NULL,
    company_server text,
    company_port integer,
    company_database text,
    company_curr_id integer,
    company_yearend_accnt_id integer,
    company_gainloss_accnt_id integer,
    company_dscrp_accnt_id integer,
    company_unrlzgainloss_accnt_id integer,
    CONSTRAINT company_company_number_check CHECK ((company_number <> ''::text))
);


ALTER TABLE public.company OWNER TO admin;

--
-- TOC entry 9688 (class 0 OID 0)
-- Dependencies: 523
-- Name: TABLE company; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE company IS 'Company information';


--
-- TOC entry 524 (class 1259 OID 146568783)
-- Dependencies: 523 8
-- Name: company_company_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE company_company_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.company_company_id_seq OWNER TO admin;

--
-- TOC entry 9690 (class 0 OID 0)
-- Dependencies: 524
-- Name: company_company_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE company_company_id_seq OWNED BY company.company_id;


--
-- TOC entry 525 (class 1259 OID 146568785)
-- Dependencies: 329 8
-- Name: contrct_contrct_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE contrct_contrct_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.contrct_contrct_id_seq OWNER TO admin;

--
-- TOC entry 9692 (class 0 OID 0)
-- Dependencies: 525
-- Name: contrct_contrct_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE contrct_contrct_id_seq OWNED BY contrct.contrct_id;


--
-- TOC entry 526 (class 1259 OID 146568787)
-- Dependencies: 6397 6398 6399 6401 6402 6403 8
-- Name: shiphead; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE shiphead (
    shiphead_id integer NOT NULL,
    shiphead_order_id integer NOT NULL,
    shiphead_order_type text NOT NULL,
    shiphead_number text NOT NULL,
    shiphead_shipvia text,
    shiphead_freight numeric(16,4) DEFAULT 0.0 NOT NULL,
    shiphead_freight_curr_id integer DEFAULT basecurrid() NOT NULL,
    shiphead_notes text,
    shiphead_shipped boolean DEFAULT false NOT NULL,
    shiphead_shipdate date,
    shiphead_shipchrg_id integer,
    shiphead_shipform_id integer,
    shiphead_sfstatus character(1) NOT NULL,
    shiphead_tracknum text,
    CONSTRAINT shiphead_shiphead_number_check CHECK ((shiphead_number <> ''::text)),
    CONSTRAINT shiphead_shiphead_order_type_check CHECK (((shiphead_order_type = 'SO'::text) OR (shiphead_order_type = 'TO'::text))),
    CONSTRAINT shiphead_shiphead_sfstatus_check CHECK ((((shiphead_sfstatus = 'D'::bpchar) OR (shiphead_sfstatus = 'N'::bpchar)) OR (shiphead_sfstatus = 'P'::bpchar)))
);


ALTER TABLE public.shiphead OWNER TO admin;

--
-- TOC entry 9694 (class 0 OID 0)
-- Dependencies: 526
-- Name: TABLE shiphead; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE shiphead IS 'General information about Shipments';


--
-- TOC entry 527 (class 1259 OID 146568799)
-- Dependencies: 6405 6406 8
-- Name: shipitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE shipitem (
    shipitem_id integer NOT NULL,
    shipitem_orderitem_id integer NOT NULL,
    shipitem_shiphead_id integer NOT NULL,
    shipitem_qty numeric(18,6) NOT NULL,
    shipitem_shipped boolean DEFAULT false NOT NULL,
    shipitem_shipdate timestamp with time zone,
    shipitem_transdate timestamp with time zone,
    shipitem_trans_username text,
    shipitem_invoiced boolean DEFAULT false NOT NULL,
    shipitem_invcitem_id integer,
    shipitem_value numeric(18,6),
    shipitem_invhist_id integer
);


ALTER TABLE public.shipitem OWNER TO admin;

--
-- TOC entry 9696 (class 0 OID 0)
-- Dependencies: 527
-- Name: TABLE shipitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE shipitem IS 'Information about Shipment Line Items';


--
-- TOC entry 528 (class 1259 OID 146568807)
-- Dependencies: 8574 8
-- Name: coship; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW coship AS
    SELECT shipitem.shipitem_id AS coship_id, shipitem.shipitem_orderitem_id AS coship_coitem_id, shipitem.shipitem_shipdate AS coship_shipdate, shipitem.shipitem_qty AS coship_qty, shipitem.shipitem_transdate AS coship_transdate, shipitem.shipitem_shipped AS coship_shipped, shipitem.shipitem_invoiced AS coship_invoiced, shipitem.shipitem_shiphead_id AS coship_cosmisc_id, shipitem.shipitem_trans_username AS coship_trans_username, shipitem.shipitem_invcitem_id AS coship_invcitem_id FROM shipitem, shiphead WHERE ((shipitem.shipitem_shiphead_id = shiphead.shiphead_id) AND (shiphead.shiphead_order_type = 'SO'::text));


ALTER TABLE public.coship OWNER TO admin;

--
-- TOC entry 529 (class 1259 OID 146568811)
-- Dependencies: 8
-- Name: coship_coship_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE coship_coship_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.coship_coship_id_seq OWNER TO admin;

--
-- TOC entry 530 (class 1259 OID 146568813)
-- Dependencies: 8575 8
-- Name: cosmisc; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW cosmisc AS
    SELECT shiphead.shiphead_id AS cosmisc_id, shiphead.shiphead_order_id AS cosmisc_cohead_id, shiphead.shiphead_shipvia AS cosmisc_shipvia, shiphead.shiphead_freight AS cosmisc_freight, shiphead.shiphead_notes AS cosmisc_notes, shiphead.shiphead_shipdate AS cosmisc_shipdate, shiphead.shiphead_shipchrg_id AS cosmisc_shipchrg_id, shiphead.shiphead_shipform_id AS cosmisc_shipform_id, shiphead.shiphead_shipped AS cosmisc_shipped, shiphead.shiphead_sfstatus AS cosmisc_sfstatus, shiphead.shiphead_tracknum AS cosmisc_tracknum, shiphead.shiphead_number AS cosmisc_number FROM shiphead WHERE (shiphead.shiphead_order_type = 'SO'::text);


ALTER TABLE public.cosmisc OWNER TO admin;

--
-- TOC entry 531 (class 1259 OID 146568817)
-- Dependencies: 8
-- Name: cosmisc_cosmisc_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cosmisc_cosmisc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cosmisc_cosmisc_id_seq OWNER TO admin;

--
-- TOC entry 532 (class 1259 OID 146568819)
-- Dependencies: 8
-- Name: cosrc_cosrc_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cosrc_cosrc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cosrc_cosrc_id_seq OWNER TO admin;

--
-- TOC entry 533 (class 1259 OID 146568821)
-- Dependencies: 8
-- Name: costcat_costcat_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE costcat_costcat_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.costcat_costcat_id_seq OWNER TO admin;

--
-- TOC entry 534 (class 1259 OID 146568823)
-- Dependencies: 8
-- Name: costelem_costelem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE costelem_costelem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.costelem_costelem_id_seq OWNER TO admin;

--
-- TOC entry 535 (class 1259 OID 146568825)
-- Dependencies: 6407 6408 6409 8
-- Name: costhist; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE costhist (
    costhist_id integer DEFAULT nextval(('"costhist_costhist_id_seq"'::text)::regclass) NOT NULL,
    costhist_item_id integer,
    costhist_costelem_id integer,
    costhist_type character(1),
    costhist_date timestamp with time zone,
    costhist_oldcost numeric(16,6),
    costhist_newcost numeric(16,6),
    costhist_lowlevel boolean,
    costhist_oldcurr_id integer DEFAULT basecurrid(),
    costhist_newcurr_id integer DEFAULT basecurrid(),
    costhist_username text
);


ALTER TABLE public.costhist OWNER TO admin;

--
-- TOC entry 9705 (class 0 OID 0)
-- Dependencies: 535
-- Name: TABLE costhist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE costhist IS 'Item Cost history';


--
-- TOC entry 536 (class 1259 OID 146568834)
-- Dependencies: 8
-- Name: costhist_costhist_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE costhist_costhist_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.costhist_costhist_id_seq OWNER TO admin;

--
-- TOC entry 537 (class 1259 OID 146568836)
-- Dependencies: 6410 8
-- Name: costupdate; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE costupdate (
    costupdate_item_id integer,
    costupdate_lowlevel_code integer DEFAULT 1 NOT NULL,
    costupdate_item_type character(1)
);


ALTER TABLE public.costupdate OWNER TO admin;

--
-- TOC entry 9708 (class 0 OID 0)
-- Dependencies: 537
-- Name: TABLE costupdate; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE costupdate IS 'Scratch area for sequencing the updating of item costs';


--
-- TOC entry 538 (class 1259 OID 146568840)
-- Dependencies: 6412 6413 8
-- Name: country; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE country (
    country_id integer NOT NULL,
    country_abbr character(2),
    country_name text,
    country_curr_abbr character(3),
    country_curr_name text,
    country_curr_number character(3),
    country_curr_symbol character varying(9),
    country_qt_number integer,
    CONSTRAINT country_country_abbr_check CHECK ((country_abbr <> ''::bpchar)),
    CONSTRAINT country_country_name_check CHECK ((country_name <> ''::text))
);


ALTER TABLE public.country OWNER TO admin;

--
-- TOC entry 9710 (class 0 OID 0)
-- Dependencies: 538
-- Name: TABLE country; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE country IS 'Basic information and properties about countries.';


--
-- TOC entry 539 (class 1259 OID 146568848)
-- Dependencies: 538 8
-- Name: country_country_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE country_country_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.country_country_id_seq OWNER TO admin;

--
-- TOC entry 9712 (class 0 OID 0)
-- Dependencies: 539
-- Name: country_country_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE country_country_id_seq OWNED BY country.country_id;


--
-- TOC entry 540 (class 1259 OID 146568850)
-- Dependencies: 6414 8
-- Name: salesaccnt; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE salesaccnt (
    salesaccnt_id integer DEFAULT nextval(('"salesaccnt_salesaccnt_id_seq"'::text)::regclass) NOT NULL,
    salesaccnt_custtype_id integer,
    salesaccnt_prodcat_id integer,
    salesaccnt_warehous_id integer,
    salesaccnt_sales_accnt_id integer,
    salesaccnt_credit_accnt_id integer,
    salesaccnt_cos_accnt_id integer,
    salesaccnt_custtype text,
    salesaccnt_prodcat text,
    salesaccnt_returns_accnt_id integer,
    salesaccnt_cor_accnt_id integer,
    salesaccnt_cow_accnt_id integer,
    salesaccnt_saletype_id integer,
    salesaccnt_shipzone_id integer
);


ALTER TABLE public.salesaccnt OWNER TO admin;

--
-- TOC entry 9714 (class 0 OID 0)
-- Dependencies: 540
-- Name: TABLE salesaccnt; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE salesaccnt IS 'Sales Account assignment information';


--
-- TOC entry 9715 (class 0 OID 0)
-- Dependencies: 540
-- Name: COLUMN salesaccnt.salesaccnt_saletype_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN salesaccnt.salesaccnt_saletype_id IS 'Associated sale type for sales account.';


--
-- TOC entry 9716 (class 0 OID 0)
-- Dependencies: 540
-- Name: COLUMN salesaccnt.salesaccnt_shipzone_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN salesaccnt.salesaccnt_shipzone_id IS 'Associated shipping zone for sales account.';


--
-- TOC entry 541 (class 1259 OID 146568857)
-- Dependencies: 8576 8
-- Name: creditmemoeditlist; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW creditmemoeditlist AS
    ((((SELECT cmhead.cmhead_id AS orderid, (-2) AS itemid, ('C/M-'::text || formatcreditmemonumber(cmhead.cmhead_id)) AS documentnumber, custinfo.cust_number, cmhead.cmhead_billtoname AS billtoname, cmhead.cmhead_number AS ordernumber, (-1) AS linenumber, ''::text AS item, ''::text AS itemdescrip, ''::text AS iteminvuom, ''::text AS qtytobill, ''::text AS price, formatmoney((((calccmheadamt(cmhead.cmhead_id) + cmhead.cmhead_freight) + cmhead.cmhead_misc) + calccmheadtax(cmhead.cmhead_id))) AS extprice, 'Credit'::text AS sence, COALESCE((SELECT formatglaccountlong(accnt.accnt_id) AS formatglaccountlong FROM accnt WHERE (accnt.accnt_id = findaraccount(custinfo.cust_id))), 'Not Assigned'::text) AS account FROM custinfo, cmhead WHERE ((((cmhead.cmhead_cust_id = custinfo.cust_id) AND (cmhead.cmhead_cust_id = custinfo.cust_id)) AND (NOT cmhead.cmhead_posted)) AND (NOT cmhead.cmhead_hold)) UNION SELECT cmhead.cmhead_id AS orderid, (-1) AS itemid, ''::text AS documentnumber, ''::text AS cust_number, ''::text AS billtoname, cmhead.cmhead_number AS ordernumber, (-1) AS linenumber, 'Freight'::text AS item, 'Freight Charge'::text AS itemdescrip, ''::text AS iteminvuom, ''::text AS qtytobill, formatmoney(cmhead.cmhead_freight) AS price, formatmoney(cmhead.cmhead_freight) AS extprice, 'Debit'::text AS sence, CASE WHEN (accnt.accnt_id IS NULL) THEN 'Not Assigned'::text ELSE formatglaccountlong(accnt.accnt_id) END AS account FROM (cmhead LEFT JOIN accnt ON ((accnt.accnt_id = findfreightaccount(cmhead.cmhead_cust_id)))) WHERE (((NOT cmhead.cmhead_posted) AND (NOT cmhead.cmhead_hold)) AND (cmhead.cmhead_freight <> (0)::numeric))) UNION SELECT cmhead.cmhead_id AS orderid, (-1) AS itemid, ''::text AS documentnumber, ''::text AS cust_number, ''::text AS billtoname, cmhead.cmhead_number AS ordernumber, (-1) AS linenumber, 'Misc. Charge'::text AS item, cmhead.cmhead_misc_descrip AS itemdescrip, ''::text AS iteminvuom, ''::text AS qtytobill, formatmoney(cmhead.cmhead_misc) AS price, formatmoney(cmhead.cmhead_misc) AS extprice, 'Debit'::text AS sence, formatglaccountlong(cmhead.cmhead_misc_accnt_id) AS account FROM cmhead WHERE (((NOT cmhead.cmhead_posted) AND (NOT cmhead.cmhead_hold)) AND (cmhead.cmhead_misc <> (0)::numeric))) UNION SELECT cmhead.cmhead_id AS orderid, (-1) AS itemid, ''::text AS documentnumber, ''::text AS cust_number, ''::text AS billtoname, cmhead.cmhead_number AS ordernumber, (-1) AS linenumber, 'Sales Tax'::text AS item, tax.tax_descrip AS itemdescrip, ''::text AS iteminvuom, ''::text AS qtytobill, formatmoney((cmheadtax.taxhist_tax * (-1.0))) AS price, formatmoney((cmheadtax.taxhist_tax * (-1.0))) AS extprice, 'Debit'::text AS sence, CASE WHEN (accnt.accnt_id IS NULL) THEN 'Not Assigned'::text ELSE ((formatglaccountlong(accnt.accnt_id) || ' - '::text) || accnt.accnt_descrip) END AS account FROM (((cmhead JOIN cmheadtax ON ((cmheadtax.taxhist_parent_id = cmhead.cmhead_id))) JOIN tax ON ((tax.tax_id = cmheadtax.taxhist_tax_id))) LEFT JOIN accnt ON ((accnt.accnt_id = tax.tax_sales_accnt_id))) WHERE ((NOT cmhead.cmhead_posted) AND (NOT cmhead.cmhead_hold))) UNION SELECT cmhead.cmhead_id AS orderid, (-1) AS itemid, ''::text AS documentnumber, ''::text AS cust_number, ''::text AS billtoname, cmhead.cmhead_number AS ordernumber, (-1) AS linenumber, 'Sales Tax'::text AS item, tax.tax_descrip AS itemdescrip, ''::text AS iteminvuom, ''::text AS qtytobill, formatmoney((cmitemtax.taxhist_tax * (-1.0))) AS price, formatmoney((cmitemtax.taxhist_tax * (-1.0))) AS extprice, 'Debit'::text AS sence, CASE WHEN (accnt.accnt_id IS NULL) THEN 'Not Assigned'::text ELSE ((formatglaccountlong(accnt.accnt_id) || ' - '::text) || accnt.accnt_descrip) END AS account FROM ((((cmhead JOIN cmitem ON ((cmitem.cmitem_cmhead_id = cmhead.cmhead_id))) JOIN cmitemtax ON ((cmitemtax.taxhist_parent_id = cmitem.cmitem_id))) JOIN tax ON ((tax.tax_id = cmitemtax.taxhist_tax_id))) LEFT JOIN accnt ON ((accnt.accnt_id = tax.tax_sales_accnt_id))) WHERE ((NOT cmhead.cmhead_posted) AND (NOT cmhead.cmhead_hold))) UNION SELECT cmhead.cmhead_id AS orderid, cmitem.cmitem_id AS itemid, ''::text AS documentnumber, ''::text AS cust_number, ''::text AS billtoname, cmhead.cmhead_number AS ordernumber, cmitem.cmitem_linenumber AS linenumber, item.item_number AS item, item.item_descrip1 AS itemdescrip, uom.uom_name AS iteminvuom, formatqty(COALESCE((cmitem.cmitem_qtycredit * cmitem.cmitem_qty_invuomratio), (0)::numeric)) AS qtytobill, formatprice(COALESCE((cmitem.cmitem_unitprice / cmitem.cmitem_price_invuomratio), (0)::numeric)) AS price, formatmoney(COALESCE(round(((cmitem.cmitem_qtycredit * cmitem.cmitem_qty_invuomratio) * (cmitem.cmitem_unitprice / cmitem.cmitem_price_invuomratio)), 2), (0)::numeric)) AS extprice, 'Debit'::text AS sence, COALESCE((SELECT formatglaccountlong(accnt.accnt_id) AS formatglaccountlong FROM accnt, salesaccnt WHERE ((salesaccnt.salesaccnt_sales_accnt_id = accnt.accnt_id) AND (salesaccnt.salesaccnt_id = findsalesaccnt(cmitem.cmitem_itemsite_id, 'IS'::text, cmhead.cmhead_cust_id, cmhead.cmhead_saletype_id, cmhead.cmhead_shipzone_id)))), 'Not Assigned'::text) AS account FROM item, itemsite, cmhead, cmitem, uom WHERE ((((((cmitem.cmitem_cmhead_id = cmhead.cmhead_id) AND (cmitem.cmitem_itemsite_id = itemsite.itemsite_id)) AND (itemsite.itemsite_item_id = item.item_id)) AND (item.item_inv_uom_id = uom.uom_id)) AND (NOT cmhead.cmhead_posted)) AND (NOT cmhead.cmhead_hold)) ORDER BY 6, 7;


ALTER TABLE public.creditmemoeditlist OWNER TO admin;

--
-- TOC entry 542 (class 1259 OID 146568862)
-- Dependencies: 8577 8
-- Name: creditmemoitem; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW creditmemoitem AS
    SELECT cmitem.cmitem_id, cmitem.cmitem_cmhead_id, cmitem.cmitem_linenumber, cmitem.cmitem_itemsite_id, cmitem.cmitem_qtycredit, cmitem.cmitem_qtyreturned, cmitem.cmitem_unitprice, cmitem.cmitem_comments, cmitem.cmitem_rsncode_id, cmitem.cmitem_taxtype_id, cmitem.cmitem_qty_uom_id, cmitem.cmitem_qty_invuomratio, cmitem.cmitem_price_uom_id, cmitem.cmitem_price_invuomratio, cmitem.cmitem_raitem_id, cmitem.cmitem_updateinv, itemsite.itemsite_item_id AS item_id, COALESCE((cmitem.cmitem_qtycredit * cmitem.cmitem_qty_invuomratio), (0)::numeric) AS qty, COALESCE((cmitem.cmitem_unitprice / cmitem.cmitem_price_invuomratio), (0)::numeric) AS unitprice, COALESCE(round(((cmitem.cmitem_qtycredit * cmitem.cmitem_qty_invuomratio) * (cmitem.cmitem_unitprice / cmitem.cmitem_price_invuomratio)), 2), (0)::numeric) AS extprice, currtobase(cmhead.cmhead_curr_id, COALESCE(round(((cmitem.cmitem_qtycredit * cmitem.cmitem_qty_invuomratio) * (cmitem.cmitem_unitprice / cmitem.cmitem_price_invuomratio)), 2), (0)::numeric), cmhead.cmhead_docdate) AS baseextprice, (SELECT COALESCE(sum(cmitemtax.taxhist_tax), (0)::numeric) AS "coalesce" FROM cmitemtax WHERE (cmitemtax.taxhist_parent_id = cmitem.cmitem_id)) AS tax, CASE WHEN (itemsite.itemsite_costmethod = 'A'::bpchar) THEN avgcost(itemsite.itemsite_id) ELSE stdcost(itemsite.itemsite_item_id) END AS unitcost FROM ((cmitem JOIN cmhead ON ((cmhead.cmhead_id = cmitem.cmitem_cmhead_id))) LEFT JOIN itemsite ON ((itemsite.itemsite_id = cmitem.cmitem_itemsite_id)));


ALTER TABLE public.creditmemoitem OWNER TO admin;

--
-- TOC entry 9719 (class 0 OID 0)
-- Dependencies: 542
-- Name: VIEW creditmemoitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON VIEW creditmemoitem IS 'Single point for credit memo item (cmitem) calculations.';


--
-- TOC entry 543 (class 1259 OID 146568867)
-- Dependencies: 205 8
-- Name: crmacct_crmacct_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE crmacct_crmacct_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.crmacct_crmacct_id_seq OWNER TO admin;

--
-- TOC entry 9721 (class 0 OID 0)
-- Dependencies: 543
-- Name: crmacct_crmacct_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE crmacct_crmacct_id_seq OWNED BY crmacct.crmacct_id;


--
-- TOC entry 544 (class 1259 OID 146568869)
-- Dependencies: 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 8
-- Name: crmacctsel; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE crmacctsel (
    crmacctsel_src_crmacct_id integer NOT NULL,
    crmacctsel_dest_crmacct_id integer,
    crmacctsel_mrg_crmacct_active boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_cntct_id_1 boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_cntct_id_2 boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_competitor_id boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_cust_id boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_emp_id boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_name boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_notes boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_owner_username boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_parent_id boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_partner_id boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_prospect_id boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_salesrep_id boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_taxauth_id boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_type boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_usr_username boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_vend_id boolean DEFAULT false NOT NULL,
    crmacctsel_mrg_crmacct_number boolean DEFAULT false NOT NULL
);


ALTER TABLE public.crmacctsel OWNER TO admin;

--
-- TOC entry 9723 (class 0 OID 0)
-- Dependencies: 544
-- Name: TABLE crmacctsel; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE crmacctsel IS 'This table records the proposed conditions of a CRM Account merge. When this merge is performed, the BOOLEAN columns in this table indicate which values in the crmacct table will be copied to the target record. Data in this table are temporary and will be removed by a purge.';


--
-- TOC entry 9724 (class 0 OID 0)
-- Dependencies: 544
-- Name: COLUMN crmacctsel.crmacctsel_src_crmacct_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN crmacctsel.crmacctsel_src_crmacct_id IS 'This is the internal ID of the CRM Account record the data will come from during the merge.';


--
-- TOC entry 9725 (class 0 OID 0)
-- Dependencies: 544
-- Name: COLUMN crmacctsel.crmacctsel_dest_crmacct_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN crmacctsel.crmacctsel_dest_crmacct_id IS 'This is the internal ID of the CRM Account record the data will go to during the merge. If crmacctsel_src_crmacct_id = crmacctsel_dest_crmacct_id, they indicate which crmacct record is the destination of the merge, meaning this is the record that will remain in the database after the merge has been completed and the intermediate data have been purged.';


--
-- TOC entry 545 (class 1259 OID 146568890)
-- Dependencies: 6434 8
-- Name: curr_rate; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE curr_rate (
    curr_rate_id integer NOT NULL,
    curr_id integer NOT NULL,
    curr_rate numeric(16,8) NOT NULL,
    curr_effective date NOT NULL,
    curr_expires date NOT NULL,
    CONSTRAINT curr_rate_curr_rate_check CHECK ((curr_rate > (0)::numeric))
);


ALTER TABLE public.curr_rate OWNER TO admin;

--
-- TOC entry 9727 (class 0 OID 0)
-- Dependencies: 545
-- Name: TABLE curr_rate; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE curr_rate IS 'Exchange Rates Between Base and Foreign Currencies';


--
-- TOC entry 546 (class 1259 OID 146568894)
-- Dependencies: 545 8
-- Name: curr_rate_curr_rate_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE curr_rate_curr_rate_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.curr_rate_curr_rate_id_seq OWNER TO admin;

--
-- TOC entry 9729 (class 0 OID 0)
-- Dependencies: 546
-- Name: curr_rate_curr_rate_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE curr_rate_curr_rate_id_seq OWNED BY curr_rate.curr_rate_id;


--
-- TOC entry 547 (class 1259 OID 146568896)
-- Dependencies: 208 8
-- Name: curr_symbol_curr_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE curr_symbol_curr_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.curr_symbol_curr_id_seq OWNER TO admin;

--
-- TOC entry 9731 (class 0 OID 0)
-- Dependencies: 547
-- Name: curr_symbol_curr_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE curr_symbol_curr_id_seq OWNED BY curr_symbol.curr_id;


--
-- TOC entry 548 (class 1259 OID 146568898)
-- Dependencies: 8578 8
-- Name: cust; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW cust AS
    SELECT custinfo.cust_id, custinfo.cust_active, custinfo.cust_custtype_id, custinfo.cust_salesrep_id, custinfo.cust_commprcnt, custinfo.cust_name, m.addr_line1 AS cust_address1, m.addr_line2 AS cust_address2, m.addr_line3 AS cust_address3, m.addr_city AS cust_city, m.addr_state AS cust_state, m.addr_postalcode AS cust_zipcode, btrim(((mc.cntct_first_name || ' '::text) || mc.cntct_last_name)) AS cust_contact, mc.cntct_phone AS cust_phone, mc.cntct_fax AS cust_fax, mc.cntct_email AS cust_email, c.addr_line1 AS cust_corraddress1, c.addr_line2 AS cust_corraddress2, c.addr_line3 AS cust_corraddress3, c.addr_city AS cust_corrcity, c.addr_state AS cust_corrstate, c.addr_postalcode AS cust_corrzipcode, btrim(((cc.cntct_first_name || ' '::text) || cc.cntct_last_name)) AS cust_corrcontact, cc.cntct_phone AS cust_corrphone, cc.cntct_fax AS cust_corrfax, cc.cntct_email AS cust_corremail, custinfo.cust_creditlmt, custinfo.cust_creditrating, custinfo.cust_financecharge, custinfo.cust_backorder, custinfo.cust_partialship, custinfo.cust_terms_id, custinfo.cust_discntprcnt, custinfo.cust_taxzone_id, custinfo.cust_balmethod, custinfo.cust_ffshipto, custinfo.cust_shipform_id, custinfo.cust_shipvia, custinfo.cust_blanketpos, custinfo.cust_shipchrg_id, custinfo.cust_creditstatus, custinfo.cust_comments, custinfo.cust_ffbillto, m.addr_country AS cust_country, c.addr_country AS cust_corrcountry, custinfo.cust_usespos, custinfo.cust_number, custinfo.cust_dateadded, custinfo.cust_exported, custinfo.cust_emaildelivery, custinfo.cust_ediemail, custinfo.cust_edisubject, custinfo.cust_edifilename, custinfo.cust_ediemailbody, custinfo.cust_autoupdatestatus, custinfo.cust_autoholdorders, custinfo.cust_edicc, custinfo.cust_ediprofile_id, custinfo.cust_preferred_warehous_id, custinfo.cust_curr_id, custinfo.cust_creditlmt_curr_id FROM ((((custinfo LEFT JOIN cntct mc ON ((custinfo.cust_cntct_id = mc.cntct_id))) LEFT JOIN addr m ON ((mc.cntct_addr_id = m.addr_id))) LEFT JOIN cntct cc ON ((custinfo.cust_corrcntct_id = cc.cntct_id))) LEFT JOIN addr c ON ((cc.cntct_addr_id = c.addr_id)));


ALTER TABLE public.cust OWNER TO admin;

--
-- TOC entry 549 (class 1259 OID 146568903)
-- Dependencies: 8
-- Name: cust_serial_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE cust_serial_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.cust_serial_seq OWNER TO admin;

--
-- TOC entry 550 (class 1259 OID 146568905)
-- Dependencies: 6435 8
-- Name: custform; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE custform (
    custform_id integer DEFAULT nextval(('"custform_custform_id_seq"'::text)::regclass) NOT NULL,
    custform_custtype_id integer,
    custform_custtype text,
    custform_invoice_report_id integer,
    custform_creditmemo_report_id integer,
    custform_quote_report_id integer,
    custform_packinglist_report_id integer,
    custform_statement_report_id integer,
    custform_sopicklist_report_id integer,
    custform_invoice_report_name text,
    custform_creditmemo_report_name text,
    custform_quote_report_name text,
    custform_packinglist_report_name text,
    custform_statement_report_name text,
    custform_sopicklist_report_name text
);


ALTER TABLE public.custform OWNER TO admin;

--
-- TOC entry 9735 (class 0 OID 0)
-- Dependencies: 550
-- Name: TABLE custform; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE custform IS 'Customer Form assignment information';


--
-- TOC entry 9736 (class 0 OID 0)
-- Dependencies: 550
-- Name: COLUMN custform.custform_invoice_report_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN custform.custform_invoice_report_id IS 'Obsolete -- reference custform_invoice_report_name instead.';


--
-- TOC entry 9737 (class 0 OID 0)
-- Dependencies: 550
-- Name: COLUMN custform.custform_creditmemo_report_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN custform.custform_creditmemo_report_id IS 'Obsolete -- reference custform_creditmemo_report_name instead.';


--
-- TOC entry 9738 (class 0 OID 0)
-- Dependencies: 550
-- Name: COLUMN custform.custform_quote_report_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN custform.custform_quote_report_id IS 'Obsolete -- reference custform_quote_report_name instead.';


--
-- TOC entry 9739 (class 0 OID 0)
-- Dependencies: 550
-- Name: COLUMN custform.custform_packinglist_report_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN custform.custform_packinglist_report_id IS 'Obsolete -- reference custform_packinglist_report_name instead.';


--
-- TOC entry 9740 (class 0 OID 0)
-- Dependencies: 550
-- Name: COLUMN custform.custform_statement_report_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN custform.custform_statement_report_id IS 'Obsolete -- reference custform_statement_report_name instead.';


--
-- TOC entry 9741 (class 0 OID 0)
-- Dependencies: 550
-- Name: COLUMN custform.custform_sopicklist_report_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN custform.custform_sopicklist_report_id IS 'Obsolete -- reference custform_sopicklist_report_name instead.';


--
-- TOC entry 551 (class 1259 OID 146568912)
-- Dependencies: 8
-- Name: custform_custform_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE custform_custform_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.custform_custform_id_seq OWNER TO admin;

--
-- TOC entry 552 (class 1259 OID 146568914)
-- Dependencies: 6436 6437 8
-- Name: custgrp; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE custgrp (
    custgrp_id integer DEFAULT nextval(('"custgrp_custgrp_id_seq"'::text)::regclass) NOT NULL,
    custgrp_name text NOT NULL,
    custgrp_descrip text,
    CONSTRAINT custgrp_custgrp_name_check CHECK ((custgrp_name <> ''::text))
);


ALTER TABLE public.custgrp OWNER TO admin;

--
-- TOC entry 9744 (class 0 OID 0)
-- Dependencies: 552
-- Name: TABLE custgrp; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE custgrp IS 'Customer Group information';


--
-- TOC entry 553 (class 1259 OID 146568922)
-- Dependencies: 8
-- Name: custgrp_custgrp_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE custgrp_custgrp_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.custgrp_custgrp_id_seq OWNER TO admin;

--
-- TOC entry 554 (class 1259 OID 146568924)
-- Dependencies: 6438 8
-- Name: custgrpitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE custgrpitem (
    custgrpitem_id integer DEFAULT nextval(('"custgrpitem_custgrpitem_id_seq"'::text)::regclass) NOT NULL,
    custgrpitem_custgrp_id integer,
    custgrpitem_cust_id integer
);


ALTER TABLE public.custgrpitem OWNER TO admin;

--
-- TOC entry 9747 (class 0 OID 0)
-- Dependencies: 554
-- Name: TABLE custgrpitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE custgrpitem IS 'Customer Group Item information';


--
-- TOC entry 555 (class 1259 OID 146568928)
-- Dependencies: 8
-- Name: custgrpitem_custgrpitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE custgrpitem_custgrpitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.custgrpitem_custgrpitem_id_seq OWNER TO admin;

--
-- TOC entry 556 (class 1259 OID 146568930)
-- Dependencies: 8
-- Name: custtype_custtype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE custtype_custtype_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.custtype_custtype_id_seq OWNER TO admin;

--
-- TOC entry 557 (class 1259 OID 146568932)
-- Dependencies: 291 8
-- Name: dept_dept_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE dept_dept_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.dept_dept_id_seq OWNER TO admin;

--
-- TOC entry 9751 (class 0 OID 0)
-- Dependencies: 557
-- Name: dept_dept_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE dept_dept_id_seq OWNED BY dept.dept_id;


--
-- TOC entry 558 (class 1259 OID 146568934)
-- Dependencies: 6439 8
-- Name: destination; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE destination (
    destination_id integer DEFAULT nextval(('"destination_destination_id_seq"'::text)::regclass) NOT NULL,
    destination_name text,
    destination_city text,
    destination_state text,
    destination_comments text
);


ALTER TABLE public.destination OWNER TO admin;

--
-- TOC entry 9753 (class 0 OID 0)
-- Dependencies: 558
-- Name: TABLE destination; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE destination IS 'Destination information';


--
-- TOC entry 559 (class 1259 OID 146568941)
-- Dependencies: 8
-- Name: destination_destination_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE destination_destination_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.destination_destination_id_seq OWNER TO admin;

--
-- TOC entry 560 (class 1259 OID 146568943)
-- Dependencies: 6440 6441 6442 6443 6444 6445 6446 6447 6448 8
-- Name: wo; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE wo (
    wo_id integer DEFAULT nextval(('wo_wo_id_seq'::text)::regclass) NOT NULL,
    wo_number integer,
    wo_subnumber integer,
    wo_status character(1),
    wo_itemsite_id integer,
    wo_startdate date,
    wo_duedate date,
    wo_ordtype character(1),
    wo_ordid integer,
    wo_qtyord numeric(18,6),
    wo_qtyrcv numeric(18,6),
    wo_adhoc boolean,
    wo_itemcfg_series integer,
    wo_imported boolean,
    wo_wipvalue numeric(16,6) DEFAULT 0,
    wo_postedvalue numeric(16,6) DEFAULT 0,
    wo_prodnotes text,
    wo_prj_id integer,
    wo_priority integer DEFAULT 1 NOT NULL,
    wo_brdvalue numeric(16,6) DEFAULT 0,
    wo_bom_rev_id integer DEFAULT (-1),
    wo_boo_rev_id integer DEFAULT (-1),
    wo_cosmethod character(1),
    wo_womatl_id integer,
    wo_username text DEFAULT geteffectivextuser(),
    CONSTRAINT chk_wo_cosmethod CHECK ((((wo_cosmethod = NULL::bpchar) OR (wo_cosmethod = 'D'::bpchar)) OR (wo_cosmethod = 'P'::bpchar)))
);


ALTER TABLE public.wo OWNER TO admin;

--
-- TOC entry 9756 (class 0 OID 0)
-- Dependencies: 560
-- Name: TABLE wo; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE wo IS 'Work Order information';


--
-- TOC entry 561 (class 1259 OID 146568958)
-- Dependencies: 8579 8
-- Name: docinfo; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW docinfo AS
    (((((((((((((((((((((((((((((SELECT imageass.imageass_id AS id, (image.image_id)::text AS target_number, 'IMG'::text AS target_type, imageass.imageass_image_id AS target_id, imageass.imageass_source AS source_type, imageass.imageass_source_id AS source_id, image.image_name AS name, image.image_descrip AS description, imageass.imageass_purpose AS purpose FROM imageass, image WHERE (imageass.imageass_image_id = image.image_id) UNION ALL SELECT url.url_id AS id, (url.url_id)::text AS target_number, 'URL'::text AS target_type, url.url_id AS target_id, url.url_source AS source_type, url.url_source_id AS source_id, url.url_title AS name, url.url_url AS description, 'S'::bpchar AS purpose FROM url WHERE (url.url_stream IS NULL)) UNION ALL SELECT url.url_id AS id, (url.url_id)::text AS target_number, 'FILE'::text AS target_type, url.url_id AS target_id, url.url_source AS source_type, url.url_source_id AS source_id, url.url_title AS name, url.url_url AS description, 'S'::bpchar AS purpose FROM url WHERE (url.url_stream IS NOT NULL)) UNION ALL SELECT docass.docass_id AS id, (incdt.incdt_number)::text AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, incdt.incdt_summary AS name, firstline(incdt.incdt_descrip) AS description, docass.docass_purpose AS purpose FROM docass, incdt WHERE ((docass.docass_target_type = 'INCDT'::text) AND (docass.docass_target_id = incdt.incdt_id))) UNION ALL SELECT docass.docass_id AS id, (incdt.incdt_number)::text AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, incdt.incdt_summary AS name, firstline(incdt.incdt_descrip) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, incdt WHERE ((docass.docass_source_type = 'INCDT'::text) AND (docass.docass_source_id = incdt.incdt_id))) UNION ALL SELECT docass.docass_id AS id, (todoitem.todoitem_id)::text AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, todoitem.todoitem_name AS name, firstline(todoitem.todoitem_description) AS description, docass.docass_purpose AS purpose FROM docass, todoitem WHERE ((docass.docass_target_type = 'TODO'::text) AND (docass.docass_target_id = todoitem.todoitem_id))) UNION ALL SELECT docass.docass_id AS id, (todoitem.todoitem_id)::text AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, todoitem.todoitem_name AS name, firstline(todoitem.todoitem_description) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, todoitem WHERE ((docass.docass_source_type = 'TODO'::text) AND (docass.docass_source_id = todoitem.todoitem_id))) UNION ALL SELECT docass.docass_id AS id, prj.prj_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, prj.prj_name AS name, firstline(prj.prj_descrip) AS description, docass.docass_purpose AS purpose FROM docass, prj WHERE ((docass.docass_target_type = 'J'::text) AND (docass.docass_target_id = prj.prj_id))) UNION ALL SELECT docass.docass_id AS id, prj.prj_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, prj.prj_name AS name, firstline(prj.prj_descrip) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, prj WHERE ((docass.docass_source_type = 'J'::text) AND (docass.docass_source_id = prj.prj_id))) UNION ALL SELECT docass.docass_id AS id, item.item_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, firstline(item.item_descrip1) AS name, firstline(item.item_descrip2) AS description, docass.docass_purpose AS purpose FROM docass, item WHERE ((docass.docass_target_type = 'I'::text) AND (docass.docass_target_id = item.item_id))) UNION ALL SELECT docass.docass_id AS id, item.item_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, firstline(item.item_descrip1) AS name, firstline(item.item_descrip2) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, item WHERE ((docass.docass_source_type = 'I'::text) AND (docass.docass_source_id = item.item_id))) UNION ALL SELECT docass.docass_id AS id, crmacct.crmacct_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, crmacct.crmacct_name AS name, firstline(crmacct.crmacct_notes) AS description, docass.docass_purpose AS purpose FROM docass, crmacct WHERE ((docass.docass_target_type = 'CRMA'::text) AND (docass.docass_target_id = crmacct.crmacct_id))) UNION ALL SELECT docass.docass_id AS id, crmacct.crmacct_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, crmacct.crmacct_name AS name, firstline(crmacct.crmacct_notes) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, crmacct WHERE ((docass.docass_source_type = 'CRMA'::text) AND (docass.docass_source_id = crmacct.crmacct_id))) UNION SELECT docass.docass_id AS id, custinfo.cust_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, custinfo.cust_name AS name, firstline(custinfo.cust_comments) AS description, docass.docass_purpose AS purpose FROM docass, custinfo WHERE ((docass.docass_target_type = 'C'::text) AND (docass.docass_target_id = custinfo.cust_id))) UNION ALL SELECT docass.docass_id AS id, custinfo.cust_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, custinfo.cust_name AS name, firstline(custinfo.cust_comments) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, custinfo WHERE ((docass.docass_source_type = 'C'::text) AND (docass.docass_source_id = custinfo.cust_id))) UNION ALL SELECT docass.docass_id AS id, vendinfo.vend_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, vendinfo.vend_name AS name, firstline(vendinfo.vend_comments) AS description, docass.docass_purpose AS purpose FROM docass, vendinfo WHERE ((docass.docass_target_type = 'V'::text) AND (docass.docass_target_id = vendinfo.vend_id))) UNION ALL SELECT docass.docass_id AS id, vendinfo.vend_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, vendinfo.vend_name AS name, firstline(vendinfo.vend_comments) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, vendinfo WHERE ((docass.docass_source_type = 'V'::text) AND (docass.docass_source_id = vendinfo.vend_id))) UNION ALL SELECT docass.docass_id AS id, cntct.cntct_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, cntct.cntct_name AS name, cntct.cntct_title AS description, docass.docass_purpose AS purpose FROM docass, cntct WHERE ((docass.docass_target_type = 'T'::text) AND (docass.docass_target_id = cntct.cntct_id))) UNION ALL SELECT docass.docass_id AS id, cntct.cntct_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, cntct.cntct_name AS name, cntct.cntct_title AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, cntct WHERE ((docass.docass_source_type = 'T'::text) AND (docass.docass_source_id = cntct.cntct_id))) UNION ALL SELECT docass.docass_id AS id, (ophead.ophead_id)::text AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, ophead.ophead_name AS name, firstline(ophead.ophead_notes) AS description, docass.docass_purpose AS purpose FROM docass, ophead WHERE ((docass.docass_target_type = 'OPP'::text) AND (docass.docass_target_id = ophead.ophead_id))) UNION ALL SELECT docass.docass_id AS id, (ophead.ophead_id)::text AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, ophead.ophead_name AS name, firstline(ophead.ophead_notes) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, ophead WHERE ((docass.docass_source_type = 'OPP'::text) AND (docass.docass_source_id = ophead.ophead_id))) UNION ALL SELECT docass.docass_id AS id, quhead.quhead_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, custinfo.cust_name AS name, firstline(quhead.quhead_ordercomments) AS description, docass.docass_purpose AS purpose FROM docass, quhead, custinfo WHERE (((docass.docass_target_type = 'Q'::text) AND (docass.docass_target_id = quhead.quhead_id)) AND (custinfo.cust_id = quhead.quhead_cust_id))) UNION ALL SELECT docass.docass_id AS id, quhead.quhead_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, custinfo.cust_name AS name, firstline(quhead.quhead_ordercomments) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, quhead, custinfo WHERE (((docass.docass_source_type = 'Q'::text) AND (docass.docass_source_id = quhead.quhead_id)) AND (custinfo.cust_id = quhead.quhead_cust_id))) UNION ALL SELECT docass.docass_id AS id, cohead.cohead_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, custinfo.cust_name AS name, firstline(cohead.cohead_ordercomments) AS description, docass.docass_purpose AS purpose FROM docass, cohead, custinfo WHERE (((docass.docass_target_type = 'S'::text) AND (docass.docass_target_id = cohead.cohead_id)) AND (custinfo.cust_id = cohead.cohead_cust_id))) UNION ALL SELECT docass.docass_id AS id, cohead.cohead_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, custinfo.cust_name AS name, firstline(cohead.cohead_ordercomments) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, cohead, custinfo WHERE (((docass.docass_source_type = 'S'::text) AND (docass.docass_source_id = cohead.cohead_id)) AND (custinfo.cust_id = cohead.cohead_cust_id))) UNION ALL SELECT docass.docass_id AS id, pohead.pohead_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, vendinfo.vend_name AS name, firstline(pohead.pohead_comments) AS description, docass.docass_purpose AS purpose FROM docass, pohead, vendinfo WHERE (((docass.docass_target_type = 'P'::text) AND (docass.docass_target_id = pohead.pohead_id)) AND (vendinfo.vend_id = pohead.pohead_vend_id))) UNION ALL SELECT docass.docass_id AS id, pohead.pohead_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, vendinfo.vend_name AS name, firstline(pohead.pohead_comments) AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, pohead, vendinfo WHERE (((docass.docass_source_type = 'P'::text) AND (docass.docass_source_id = pohead.pohead_id)) AND (vendinfo.vend_id = pohead.pohead_vend_id))) UNION ALL SELECT docass.docass_id AS id, formatwonumber(wo.wo_id) AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, item.item_descrip1 AS name, item.item_descrip2 AS description, docass.docass_purpose AS purpose FROM docass, wo, itemsite, item WHERE ((((docass.docass_target_type = 'W'::text) AND (docass.docass_target_id = wo.wo_id)) AND (wo.wo_itemsite_id = itemsite.itemsite_id)) AND (itemsite.itemsite_item_id = item.item_id))) UNION ALL SELECT docass.docass_id AS id, formatwonumber(wo.wo_id) AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, item.item_descrip1 AS name, item.item_descrip2 AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, wo, itemsite, item WHERE ((((docass.docass_source_type = 'W'::text) AND (docass.docass_source_id = wo.wo_id)) AND (wo.wo_itemsite_id = itemsite.itemsite_id)) AND (itemsite.itemsite_item_id = item.item_id))) UNION ALL SELECT docass.docass_id AS id, emp.emp_number AS target_number, docass.docass_target_type AS target_type, docass.docass_target_id AS target_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id, cntct.cntct_name AS name, cntct.cntct_title AS description, docass.docass_purpose AS purpose FROM docass, (emp LEFT JOIN cntct ON ((emp.emp_cntct_id = cntct.cntct_id))) WHERE ((docass.docass_target_type = 'EMP'::text) AND (docass.docass_target_id = emp.emp_id))) UNION ALL SELECT docass.docass_id AS id, emp.emp_number AS target_number, docass.docass_source_type AS target_type, docass.docass_source_id AS target_id, docass.docass_target_type AS source_type, docass.docass_target_id AS source_id, cntct.cntct_name AS name, cntct.cntct_title AS description, CASE WHEN (docass.docass_purpose = 'A'::bpchar) THEN 'C'::bpchar WHEN (docass.docass_purpose = 'C'::bpchar) THEN 'A'::bpchar ELSE docass.docass_purpose END AS purpose FROM docass, (emp LEFT JOIN cntct ON ((emp.emp_cntct_id = cntct.cntct_id))) WHERE ((docass.docass_source_type = 'EMP'::text) AND (docass.docass_source_id = emp.emp_id));


ALTER TABLE public.docinfo OWNER TO admin;

--
-- TOC entry 562 (class 1259 OID 146568963)
-- Dependencies: 292 8
-- Name: emp_emp_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE emp_emp_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.emp_emp_id_seq OWNER TO admin;

--
-- TOC entry 9759 (class 0 OID 0)
-- Dependencies: 562
-- Name: emp_emp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE emp_emp_id_seq OWNED BY emp.emp_id;


--
-- TOC entry 563 (class 1259 OID 146568965)
-- Dependencies: 6450 8
-- Name: empgrp; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE empgrp (
    empgrp_id integer NOT NULL,
    empgrp_name text NOT NULL,
    empgrp_descrip text NOT NULL,
    CONSTRAINT empgrp_empgrp_name_check CHECK ((empgrp_name <> ''::text))
);


ALTER TABLE public.empgrp OWNER TO admin;

--
-- TOC entry 564 (class 1259 OID 146568972)
-- Dependencies: 563 8
-- Name: empgrp_empgrp_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE empgrp_empgrp_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.empgrp_empgrp_id_seq OWNER TO admin;

--
-- TOC entry 9762 (class 0 OID 0)
-- Dependencies: 564
-- Name: empgrp_empgrp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE empgrp_empgrp_id_seq OWNED BY empgrp.empgrp_id;


--
-- TOC entry 565 (class 1259 OID 146568974)
-- Dependencies: 8
-- Name: empgrpitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE empgrpitem (
    empgrpitem_id integer NOT NULL,
    empgrpitem_empgrp_id integer NOT NULL,
    empgrpitem_emp_id integer NOT NULL
);


ALTER TABLE public.empgrpitem OWNER TO admin;

--
-- TOC entry 566 (class 1259 OID 146568977)
-- Dependencies: 565 8
-- Name: empgrpitem_empgrpitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE empgrpitem_empgrpitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.empgrpitem_empgrpitem_id_seq OWNER TO admin;

--
-- TOC entry 9765 (class 0 OID 0)
-- Dependencies: 566
-- Name: empgrpitem_empgrpitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE empgrpitem_empgrpitem_id_seq OWNED BY empgrpitem.empgrpitem_id;


--
-- TOC entry 567 (class 1259 OID 146568979)
-- Dependencies: 6452 8
-- Name: evntlog; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE evntlog (
    evntlog_id integer DEFAULT nextval(('evntlog_evntlog_id_seq'::text)::regclass) NOT NULL,
    evntlog_evnttime timestamp with time zone,
    evntlog_evnttype_id integer,
    evntlog_ord_id integer,
    evntlog_dispatched timestamp with time zone,
    evntlog_action text,
    evntlog_warehous_id integer,
    evntlog_number text,
    evntlog_newvalue numeric(20,10),
    evntlog_oldvalue numeric(20,10),
    evntlog_newdate date,
    evntlog_olddate date,
    evntlog_ordtype character(2),
    evntlog_username text
);


ALTER TABLE public.evntlog OWNER TO admin;

--
-- TOC entry 9767 (class 0 OID 0)
-- Dependencies: 567
-- Name: TABLE evntlog; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE evntlog IS 'Event Notification history';


--
-- TOC entry 568 (class 1259 OID 146568986)
-- Dependencies: 8
-- Name: evntlog_evntlog_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE evntlog_evntlog_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.evntlog_evntlog_id_seq OWNER TO admin;

--
-- TOC entry 569 (class 1259 OID 146568988)
-- Dependencies: 6453 8
-- Name: evntnot; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE evntnot (
    evntnot_id integer DEFAULT nextval(('evntnot_evntnot_id_seq'::text)::regclass) NOT NULL,
    evntnot_evnttype_id integer,
    evntnot_warehous_id integer,
    evntnot_username text
);


ALTER TABLE public.evntnot OWNER TO admin;

--
-- TOC entry 9770 (class 0 OID 0)
-- Dependencies: 569
-- Name: TABLE evntnot; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE evntnot IS 'Temporary table for storing information about user Event Notification selections';


--
-- TOC entry 570 (class 1259 OID 146568995)
-- Dependencies: 8
-- Name: evntnot_evntnot_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE evntnot_evntnot_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.evntnot_evntnot_id_seq OWNER TO admin;

--
-- TOC entry 571 (class 1259 OID 146568997)
-- Dependencies: 6454 6455 8
-- Name: evnttype; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE evnttype (
    evnttype_id integer DEFAULT nextval(('evnttype_evnttype_id_seq'::text)::regclass) NOT NULL,
    evnttype_name text NOT NULL,
    evnttype_descrip text,
    evnttype_module text,
    CONSTRAINT evnttype_evnttype_name_check CHECK ((evnttype_name <> ''::text))
);


ALTER TABLE public.evnttype OWNER TO admin;

--
-- TOC entry 9773 (class 0 OID 0)
-- Dependencies: 571
-- Name: TABLE evnttype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE evnttype IS 'Event Type information';


--
-- TOC entry 572 (class 1259 OID 146569005)
-- Dependencies: 8
-- Name: evnttype_evnttype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE evnttype_evnttype_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.evnttype_evnttype_id_seq OWNER TO admin;

--
-- TOC entry 573 (class 1259 OID 146569007)
-- Dependencies: 358 8
-- Name: expcat_expcat_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE expcat_expcat_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.expcat_expcat_id_seq OWNER TO admin;

--
-- TOC entry 9776 (class 0 OID 0)
-- Dependencies: 573
-- Name: expcat_expcat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE expcat_expcat_id_seq OWNED BY expcat.expcat_id;


--
-- TOC entry 574 (class 1259 OID 146569009)
-- Dependencies: 243 8
-- Name: file_file_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE file_file_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.file_file_id_seq OWNER TO admin;

--
-- TOC entry 9778 (class 0 OID 0)
-- Dependencies: 574
-- Name: file_file_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE file_file_id_seq OWNED BY file.file_id;


--
-- TOC entry 575 (class 1259 OID 146569011)
-- Dependencies: 6457 8
-- Name: filter; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE filter (
    filter_id integer NOT NULL,
    filter_screen text NOT NULL,
    filter_value text NOT NULL,
    filter_username text,
    filter_name text NOT NULL,
    filter_selected boolean DEFAULT false
);


ALTER TABLE public.filter OWNER TO admin;

--
-- TOC entry 576 (class 1259 OID 146569018)
-- Dependencies: 575 8
-- Name: filter_filter_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE filter_filter_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.filter_filter_id_seq OWNER TO admin;

--
-- TOC entry 9781 (class 0 OID 0)
-- Dependencies: 576
-- Name: filter_filter_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE filter_filter_id_seq OWNED BY filter.filter_id;


--
-- TOC entry 577 (class 1259 OID 146569020)
-- Dependencies: 8
-- Name: fincharg; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE fincharg (
    fincharg_id integer NOT NULL,
    fincharg_mincharg numeric NOT NULL,
    fincharg_graceperiod integer NOT NULL,
    fincharg_assessoverdue boolean NOT NULL,
    fincharg_calcfrom integer NOT NULL,
    fincharg_markoninvoice text NOT NULL,
    fincharg_air numeric NOT NULL,
    fincharg_accnt_id integer NOT NULL,
    fincharg_salescat_id integer NOT NULL,
    fincharg_lastfc_statementcyclefrom text,
    fincharg_lastfc_custidfrom text,
    fincharg_lastfc_custidto text,
    fincharg_lastfc_statementcycleto text
);


ALTER TABLE public.fincharg OWNER TO admin;

--
-- TOC entry 9783 (class 0 OID 0)
-- Dependencies: 577
-- Name: TABLE fincharg; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE fincharg IS 'Finance Charge configuration information';


--
-- TOC entry 578 (class 1259 OID 146569026)
-- Dependencies: 577 8
-- Name: fincharg_fincharg_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE fincharg_fincharg_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.fincharg_fincharg_id_seq OWNER TO admin;

--
-- TOC entry 9785 (class 0 OID 0)
-- Dependencies: 578
-- Name: fincharg_fincharg_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE fincharg_fincharg_id_seq OWNED BY fincharg.fincharg_id;


--
-- TOC entry 579 (class 1259 OID 146569028)
-- Dependencies: 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6478 8
-- Name: flhead; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE flhead (
    flhead_id integer NOT NULL,
    flhead_name text NOT NULL,
    flhead_descrip text,
    flhead_showtotal boolean DEFAULT false NOT NULL,
    flhead_showstart boolean DEFAULT true NOT NULL,
    flhead_showend boolean DEFAULT true NOT NULL,
    flhead_showdelta boolean DEFAULT true NOT NULL,
    flhead_showbudget boolean DEFAULT true NOT NULL,
    flhead_showdiff boolean DEFAULT false NOT NULL,
    flhead_showcustom boolean DEFAULT false NOT NULL,
    flhead_custom_label text,
    flhead_usealttotal boolean DEFAULT false NOT NULL,
    flhead_alttotal text,
    flhead_usealtbegin boolean DEFAULT false NOT NULL,
    flhead_altbegin text,
    flhead_usealtend boolean DEFAULT false NOT NULL,
    flhead_altend text,
    flhead_usealtdebits boolean DEFAULT false NOT NULL,
    flhead_altdebits text,
    flhead_usealtcredits boolean DEFAULT false NOT NULL,
    flhead_altcredits text,
    flhead_usealtbudget boolean DEFAULT false NOT NULL,
    flhead_altbudget text,
    flhead_usealtdiff boolean DEFAULT false NOT NULL,
    flhead_altdiff text,
    flhead_type character(1) DEFAULT 'A'::bpchar NOT NULL,
    flhead_active boolean DEFAULT true NOT NULL,
    flhead_sys boolean DEFAULT false,
    flhead_notes text DEFAULT ''::text,
    CONSTRAINT flhead_flhead_name_check CHECK ((flhead_name <> ''::text))
);


ALTER TABLE public.flhead OWNER TO admin;

--
-- TOC entry 9787 (class 0 OID 0)
-- Dependencies: 579
-- Name: TABLE flhead; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE flhead IS 'Financial Layout header information';


--
-- TOC entry 580 (class 1259 OID 146569053)
-- Dependencies: 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 8
-- Name: flitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE flitem (
    flitem_id integer NOT NULL,
    flitem_flhead_id integer,
    flitem_flgrp_id integer,
    flitem_order integer,
    flitem_accnt_id integer,
    flitem_showstart boolean,
    flitem_showend boolean,
    flitem_showdelta boolean,
    flitem_showbudget boolean DEFAULT false NOT NULL,
    flitem_subtract boolean DEFAULT false NOT NULL,
    flitem_showstartprcnt boolean DEFAULT false NOT NULL,
    flitem_showendprcnt boolean DEFAULT false NOT NULL,
    flitem_showdeltaprcnt boolean DEFAULT false NOT NULL,
    flitem_showbudgetprcnt boolean DEFAULT false NOT NULL,
    flitem_prcnt_flgrp_id integer DEFAULT (-1) NOT NULL,
    flitem_showdiff boolean DEFAULT false NOT NULL,
    flitem_showdiffprcnt boolean DEFAULT false NOT NULL,
    flitem_showcustom boolean DEFAULT false NOT NULL,
    flitem_showcustomprcnt boolean DEFAULT false NOT NULL,
    flitem_custom_source character(1),
    flitem_company text,
    flitem_profit text,
    flitem_number text,
    flitem_sub text,
    flitem_type character(1),
    flitem_subaccnttype_code text
);


ALTER TABLE public.flitem OWNER TO admin;

--
-- TOC entry 9789 (class 0 OID 0)
-- Dependencies: 580
-- Name: TABLE flitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE flitem IS 'Financial Layout Account information';


--
-- TOC entry 581 (class 1259 OID 146569070)
-- Dependencies: 8580 8
-- Name: flaccnt; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW flaccnt AS
    SELECT flhead.flhead_type, flitem.flitem_id, flitem.flitem_flhead_id, flitem.flitem_flgrp_id, flitem.flitem_order, flitem.flitem_accnt_id, flitem.flitem_showstart, flitem.flitem_showend, flitem.flitem_showdelta, flitem.flitem_showbudget, flitem.flitem_subtract, flitem.flitem_showstartprcnt, flitem.flitem_showendprcnt, flitem.flitem_showdeltaprcnt, flitem.flitem_showbudgetprcnt, flitem.flitem_prcnt_flgrp_id, flitem.flitem_showdiff, flitem.flitem_showdiffprcnt, flitem.flitem_showcustom, flitem.flitem_showcustomprcnt, flitem.flitem_custom_source, flitem.flitem_company, flitem.flitem_profit, flitem.flitem_number, flitem.flitem_sub, flitem.flitem_type, flitem.flitem_subaccnttype_code, accnt.accnt_id, accnt.accnt_type, accnt.accnt_company, accnt.accnt_profit, accnt.accnt_number, accnt.accnt_sub, (-1) AS prj_id FROM ((flhead JOIN flitem ON ((flhead.flhead_id = flitem.flitem_flhead_id))) JOIN accnt ON ((flitem.flitem_accnt_id = accnt.accnt_id))) UNION ALL SELECT flhead.flhead_type, flitem.flitem_id, flitem.flitem_flhead_id, flitem.flitem_flgrp_id, flitem.flitem_order, flitem.flitem_accnt_id, flitem.flitem_showstart, flitem.flitem_showend, flitem.flitem_showdelta, flitem.flitem_showbudget, flitem.flitem_subtract, flitem.flitem_showstartprcnt, flitem.flitem_showendprcnt, flitem.flitem_showdeltaprcnt, flitem.flitem_showbudgetprcnt, flitem.flitem_prcnt_flgrp_id, flitem.flitem_showdiff, flitem.flitem_showdiffprcnt, flitem.flitem_showcustom, flitem.flitem_showcustomprcnt, flitem.flitem_custom_source, flitem.flitem_company, flitem.flitem_profit, flitem.flitem_number, flitem.flitem_sub, flitem.flitem_type, flitem.flitem_subaccnttype_code, accnt.accnt_id, accnt.accnt_type, accnt.accnt_company, accnt.accnt_profit, accnt.accnt_number, accnt.accnt_sub, (-1) AS prj_id FROM (flhead JOIN flitem ON ((flhead.flhead_id = flitem.flitem_flhead_id))), accnt WHERE (((((((flitem.flitem_accnt_id = (-1)) AND ((flitem.flitem_type = ''::bpchar) OR (accnt.accnt_type = flitem.flitem_type))) AND ((flitem.flitem_company = 'All'::text) OR (accnt.accnt_company = flitem.flitem_company))) AND ((flitem.flitem_profit = 'All'::text) OR (accnt.accnt_profit = flitem.flitem_profit))) AND ((flitem.flitem_number = 'All'::text) OR (accnt.accnt_number = flitem.flitem_number))) AND ((flitem.flitem_sub = 'All'::text) OR (accnt.accnt_sub = flitem.flitem_sub))) AND ((flitem.flitem_subaccnttype_code = 'All'::text) OR (accnt.accnt_subaccnttype_code = flitem.flitem_subaccnttype_code))) ORDER BY 30, 31, 32, 33;


ALTER TABLE public.flaccnt OWNER TO admin;

--
-- TOC entry 582 (class 1259 OID 146569075)
-- Dependencies: 8
-- Name: flcol; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE flcol (
    flcol_id integer NOT NULL,
    flcol_flhead_id integer NOT NULL,
    flcol_name text,
    flcol_descrip text,
    flcol_report_id integer,
    flcol_month boolean,
    flcol_quarter boolean,
    flcol_year boolean,
    flcol_showdb boolean,
    flcol_prcnt boolean,
    flcol_priortype character(1),
    flcol_priormonth boolean,
    flcol_priorquarter boolean,
    flcol_prioryear character(1),
    flcol_priorprcnt boolean,
    flcol_priordiff boolean,
    flcol_priordiffprcnt boolean,
    flcol_budget boolean,
    flcol_budgetprcnt boolean,
    flcol_budgetdiff boolean,
    flcol_budgetdiffprcnt boolean
);


ALTER TABLE public.flcol OWNER TO admin;

--
-- TOC entry 583 (class 1259 OID 146569081)
-- Dependencies: 582 8
-- Name: flcol_flcol_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE flcol_flcol_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.flcol_flcol_id_seq OWNER TO admin;

--
-- TOC entry 9793 (class 0 OID 0)
-- Dependencies: 583
-- Name: flcol_flcol_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flcol_flcol_id_seq OWNED BY flcol.flcol_id;


--
-- TOC entry 584 (class 1259 OID 146569083)
-- Dependencies: 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 8
-- Name: flgrp; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE flgrp (
    flgrp_id integer NOT NULL,
    flgrp_flhead_id integer,
    flgrp_flgrp_id integer,
    flgrp_order integer,
    flgrp_name text,
    flgrp_descrip text,
    flgrp_subtotal boolean DEFAULT false NOT NULL,
    flgrp_summarize boolean DEFAULT false NOT NULL,
    flgrp_subtract boolean DEFAULT false NOT NULL,
    flgrp_showstart boolean DEFAULT true NOT NULL,
    flgrp_showend boolean DEFAULT true NOT NULL,
    flgrp_showdelta boolean DEFAULT true NOT NULL,
    flgrp_showbudget boolean DEFAULT true NOT NULL,
    flgrp_showstartprcnt boolean DEFAULT false NOT NULL,
    flgrp_showendprcnt boolean DEFAULT false NOT NULL,
    flgrp_showdeltaprcnt boolean DEFAULT false NOT NULL,
    flgrp_showbudgetprcnt boolean DEFAULT false NOT NULL,
    flgrp_prcnt_flgrp_id integer DEFAULT (-1) NOT NULL,
    flgrp_showdiff boolean DEFAULT false NOT NULL,
    flgrp_showdiffprcnt boolean DEFAULT false NOT NULL,
    flgrp_showcustom boolean DEFAULT false NOT NULL,
    flgrp_showcustomprcnt boolean DEFAULT false NOT NULL,
    flgrp_usealtsubtotal boolean DEFAULT false NOT NULL,
    flgrp_altsubtotal text
);


ALTER TABLE public.flgrp OWNER TO admin;

--
-- TOC entry 9795 (class 0 OID 0)
-- Dependencies: 584
-- Name: TABLE flgrp; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE flgrp IS 'Financial Layout Group information';


--
-- TOC entry 585 (class 1259 OID 146569106)
-- Dependencies: 584 8
-- Name: flgrp_flgrp_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE flgrp_flgrp_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.flgrp_flgrp_id_seq OWNER TO admin;

--
-- TOC entry 9797 (class 0 OID 0)
-- Dependencies: 585
-- Name: flgrp_flgrp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flgrp_flgrp_id_seq OWNED BY flgrp.flgrp_id;


--
-- TOC entry 586 (class 1259 OID 146569108)
-- Dependencies: 579 8
-- Name: flhead_flhead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE flhead_flhead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.flhead_flhead_id_seq OWNER TO admin;

--
-- TOC entry 9799 (class 0 OID 0)
-- Dependencies: 586
-- Name: flhead_flhead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flhead_flhead_id_seq OWNED BY flhead.flhead_id;


--
-- TOC entry 587 (class 1259 OID 146569110)
-- Dependencies: 580 8
-- Name: flitem_flitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE flitem_flitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.flitem_flitem_id_seq OWNER TO admin;

--
-- TOC entry 9801 (class 0 OID 0)
-- Dependencies: 587
-- Name: flitem_flitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flitem_flitem_id_seq OWNED BY flitem.flitem_id;


--
-- TOC entry 588 (class 1259 OID 146569112)
-- Dependencies: 6511 8
-- Name: flnotes; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE flnotes (
    flnotes_id integer NOT NULL,
    flnotes_flhead_id integer,
    flnotes_period_id integer,
    flnotes_notes text DEFAULT ''::text
);


ALTER TABLE public.flnotes OWNER TO admin;

--
-- TOC entry 589 (class 1259 OID 146569119)
-- Dependencies: 588 8
-- Name: flnotes_flnotes_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE flnotes_flnotes_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.flnotes_flnotes_id_seq OWNER TO admin;

--
-- TOC entry 9804 (class 0 OID 0)
-- Dependencies: 589
-- Name: flnotes_flnotes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flnotes_flnotes_id_seq OWNED BY flnotes.flnotes_id;


--
-- TOC entry 590 (class 1259 OID 146569121)
-- Dependencies: 8
-- Name: flrpt; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE flrpt (
    flrpt_flhead_id integer NOT NULL,
    flrpt_period_id integer NOT NULL,
    flrpt_username text NOT NULL,
    flrpt_order integer NOT NULL,
    flrpt_level integer NOT NULL,
    flrpt_type text NOT NULL,
    flrpt_type_id integer NOT NULL,
    flrpt_beginning numeric,
    flrpt_ending numeric,
    flrpt_debits numeric,
    flrpt_credits numeric,
    flrpt_budget numeric,
    flrpt_beginningprcnt numeric,
    flrpt_endingprcnt numeric,
    flrpt_debitsprcnt numeric,
    flrpt_creditsprcnt numeric,
    flrpt_budgetprcnt numeric,
    flrpt_parent_id integer,
    flrpt_diff numeric,
    flrpt_diffprcnt numeric,
    flrpt_custom numeric,
    flrpt_customprcnt numeric,
    flrpt_altname text,
    flrpt_accnt_id integer,
    flrpt_interval character(1),
    flrpt_id integer NOT NULL
);


ALTER TABLE public.flrpt OWNER TO admin;

--
-- TOC entry 9806 (class 0 OID 0)
-- Dependencies: 590
-- Name: TABLE flrpt; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE flrpt IS 'Scratch table where financial reporting information is processed before being displayed.';


--
-- TOC entry 591 (class 1259 OID 146569127)
-- Dependencies: 590 8
-- Name: flrpt_flrpt_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE flrpt_flrpt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.flrpt_flrpt_id_seq OWNER TO admin;

--
-- TOC entry 9808 (class 0 OID 0)
-- Dependencies: 591
-- Name: flrpt_flrpt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flrpt_flrpt_id_seq OWNED BY flrpt.flrpt_id;


--
-- TOC entry 592 (class 1259 OID 146569129)
-- Dependencies: 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 8
-- Name: flspec; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE flspec (
    flspec_id integer NOT NULL,
    flspec_flhead_id integer NOT NULL,
    flspec_flgrp_id integer NOT NULL,
    flspec_order integer NOT NULL,
    flspec_name text,
    flspec_type text,
    flspec_showstart boolean DEFAULT true NOT NULL,
    flspec_showend boolean DEFAULT true NOT NULL,
    flspec_showdelta boolean DEFAULT true NOT NULL,
    flspec_showbudget boolean DEFAULT false NOT NULL,
    flspec_subtract boolean DEFAULT false NOT NULL,
    flspec_showstartprcnt boolean DEFAULT false NOT NULL,
    flspec_showendprcnt boolean DEFAULT false NOT NULL,
    flspec_showdeltaprcnt boolean DEFAULT false NOT NULL,
    flspec_showbudgetprcnt boolean DEFAULT false NOT NULL,
    flspec_showdiff boolean DEFAULT false NOT NULL,
    flspec_showdiffprcnt boolean DEFAULT false NOT NULL,
    flspec_prcnt_flgrp_id integer DEFAULT (-1) NOT NULL,
    flspec_showcustom boolean DEFAULT false NOT NULL,
    flspec_showcustomprcnt boolean DEFAULT false NOT NULL,
    flspec_custom_source character(1)
);


ALTER TABLE public.flspec OWNER TO admin;

--
-- TOC entry 9810 (class 0 OID 0)
-- Dependencies: 592
-- Name: TABLE flspec; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE flspec IS 'Financial Layout Special entries.';


--
-- TOC entry 593 (class 1259 OID 146569149)
-- Dependencies: 592 8
-- Name: flspec_flspec_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE flspec_flspec_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.flspec_flspec_id_seq OWNER TO admin;

--
-- TOC entry 9812 (class 0 OID 0)
-- Dependencies: 593
-- Name: flspec_flspec_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flspec_flspec_id_seq OWNED BY flspec.flspec_id;


--
-- TOC entry 594 (class 1259 OID 146569151)
-- Dependencies: 6528 6529 8
-- Name: form; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE form (
    form_id integer DEFAULT nextval(('"form_form_id_seq"'::text)::regclass) NOT NULL,
    form_name text NOT NULL,
    form_descrip text,
    form_report_id integer,
    form_key character varying(4),
    form_report_name text,
    CONSTRAINT form_form_name_check CHECK ((form_name <> ''::text))
);


ALTER TABLE public.form OWNER TO admin;

--
-- TOC entry 9814 (class 0 OID 0)
-- Dependencies: 594
-- Name: TABLE form; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE form IS 'Form information';


--
-- TOC entry 9815 (class 0 OID 0)
-- Dependencies: 594
-- Name: COLUMN form.form_report_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN form.form_report_id IS 'Obsolete -- reference form_report_name instead.';


--
-- TOC entry 595 (class 1259 OID 146569159)
-- Dependencies: 8
-- Name: form_form_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE form_form_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.form_form_id_seq OWNER TO admin;

--
-- TOC entry 596 (class 1259 OID 146569161)
-- Dependencies: 299 8
-- Name: freightclass_freightclass_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE freightclass_freightclass_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.freightclass_freightclass_id_seq OWNER TO admin;

--
-- TOC entry 9818 (class 0 OID 0)
-- Dependencies: 596
-- Name: freightclass_freightclass_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE freightclass_freightclass_id_seq OWNED BY freightclass.freightclass_id;


--
-- TOC entry 597 (class 1259 OID 146569163)
-- Dependencies: 6530 8
-- Name: glseries; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE glseries (
    glseries_id integer DEFAULT nextval(('"glseries_glseries_id_seq"'::text)::regclass) NOT NULL,
    glseries_sequence integer,
    glseries_doctype character(2),
    glseries_docnumber text,
    glseries_accnt_id integer,
    glseries_amount numeric(20,2),
    glseries_source text,
    glseries_distdate date,
    glseries_notes text,
    glseries_misc_id integer
);


ALTER TABLE public.glseries OWNER TO admin;

--
-- TOC entry 9820 (class 0 OID 0)
-- Dependencies: 597
-- Name: TABLE glseries; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE glseries IS 'Temporary table for storing information about General Ledger (G/L) Series Entries before Series Entries are posted';


--
-- TOC entry 598 (class 1259 OID 146569170)
-- Dependencies: 8
-- Name: glseries_glseries_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE glseries_glseries_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.glseries_glseries_id_seq OWNER TO admin;

--
-- TOC entry 599 (class 1259 OID 146569172)
-- Dependencies: 8
-- Name: gltrans_gltrans_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE gltrans_gltrans_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.gltrans_gltrans_id_seq OWNER TO admin;

--
-- TOC entry 600 (class 1259 OID 146569174)
-- Dependencies: 8
-- Name: gltrans_sequence_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE gltrans_sequence_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.gltrans_sequence_seq OWNER TO admin;

--
-- TOC entry 601 (class 1259 OID 146569176)
-- Dependencies: 6532 8
-- Name: grp; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE grp (
    grp_id integer NOT NULL,
    grp_name text NOT NULL,
    grp_descrip text,
    CONSTRAINT grp_grp_name_check CHECK ((grp_name <> ''::text))
);


ALTER TABLE public.grp OWNER TO admin;

--
-- TOC entry 9825 (class 0 OID 0)
-- Dependencies: 601
-- Name: TABLE grp; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE grp IS 'This table is the basic group information.';


--
-- TOC entry 602 (class 1259 OID 146569183)
-- Dependencies: 601 8
-- Name: grp_grp_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE grp_grp_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.grp_grp_id_seq OWNER TO admin;

--
-- TOC entry 9827 (class 0 OID 0)
-- Dependencies: 602
-- Name: grp_grp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE grp_grp_id_seq OWNED BY grp.grp_id;


--
-- TOC entry 603 (class 1259 OID 146569185)
-- Dependencies: 8
-- Name: grppriv; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE grppriv (
    grppriv_id integer NOT NULL,
    grppriv_grp_id integer NOT NULL,
    grppriv_priv_id integer NOT NULL
);


ALTER TABLE public.grppriv OWNER TO admin;

--
-- TOC entry 9829 (class 0 OID 0)
-- Dependencies: 603
-- Name: TABLE grppriv; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE grppriv IS 'This is a specific priv for a specific group.';


--
-- TOC entry 604 (class 1259 OID 146569188)
-- Dependencies: 603 8
-- Name: grppriv_grppriv_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE grppriv_grppriv_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.grppriv_grppriv_id_seq OWNER TO admin;

--
-- TOC entry 9831 (class 0 OID 0)
-- Dependencies: 604
-- Name: grppriv_grppriv_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE grppriv_grppriv_id_seq OWNED BY grppriv.grppriv_id;


--
-- TOC entry 605 (class 1259 OID 146569190)
-- Dependencies: 6535 8
-- Name: hnfc; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE hnfc (
    hnfc_id integer NOT NULL,
    hnfc_code text NOT NULL,
    CONSTRAINT hnfc_hnfc_code_check CHECK ((hnfc_code <> ''::text))
);


ALTER TABLE public.hnfc OWNER TO admin;

--
-- TOC entry 9833 (class 0 OID 0)
-- Dependencies: 605
-- Name: TABLE hnfc; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE hnfc IS 'List of personal titles/honorifics used in cntct table.';


--
-- TOC entry 606 (class 1259 OID 146569197)
-- Dependencies: 605 8
-- Name: hnfc_hnfc_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE hnfc_hnfc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.hnfc_hnfc_id_seq OWNER TO admin;

--
-- TOC entry 9835 (class 0 OID 0)
-- Dependencies: 606
-- Name: hnfc_hnfc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE hnfc_hnfc_id_seq OWNED BY hnfc.hnfc_id;


--
-- TOC entry 607 (class 1259 OID 146569199)
-- Dependencies: 206 8
-- Name: incdt_incdt_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE incdt_incdt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.incdt_incdt_id_seq OWNER TO admin;

--
-- TOC entry 9837 (class 0 OID 0)
-- Dependencies: 607
-- Name: incdt_incdt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdt_incdt_id_seq OWNED BY incdt.incdt_id;


--
-- TOC entry 608 (class 1259 OID 146569201)
-- Dependencies: 304 8
-- Name: incdtcat_incdtcat_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE incdtcat_incdtcat_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.incdtcat_incdtcat_id_seq OWNER TO admin;

--
-- TOC entry 9839 (class 0 OID 0)
-- Dependencies: 608
-- Name: incdtcat_incdtcat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdtcat_incdtcat_id_seq OWNED BY incdtcat.incdtcat_id;


--
-- TOC entry 609 (class 1259 OID 146569203)
-- Dependencies: 6537 6538 8
-- Name: incdthist; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE incdthist (
    incdthist_id integer NOT NULL,
    incdthist_incdt_id integer NOT NULL,
    incdthist_change character(1),
    incdthist_target_id integer,
    incdthist_timestamp timestamp without time zone DEFAULT now() NOT NULL,
    incdthist_username text DEFAULT geteffectivextuser() NOT NULL,
    incdthist_descrip text
);


ALTER TABLE public.incdthist OWNER TO admin;

--
-- TOC entry 9841 (class 0 OID 0)
-- Dependencies: 609
-- Name: TABLE incdthist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE incdthist IS 'Incident history changes';


--
-- TOC entry 610 (class 1259 OID 146569211)
-- Dependencies: 609 8
-- Name: incdthist_incdthist_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE incdthist_incdthist_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.incdthist_incdthist_id_seq OWNER TO admin;

--
-- TOC entry 9843 (class 0 OID 0)
-- Dependencies: 610
-- Name: incdthist_incdthist_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdthist_incdthist_id_seq OWNED BY incdthist.incdthist_id;


--
-- TOC entry 611 (class 1259 OID 146569213)
-- Dependencies: 305 8
-- Name: incdtpriority_incdtpriority_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE incdtpriority_incdtpriority_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.incdtpriority_incdtpriority_id_seq OWNER TO admin;

--
-- TOC entry 9845 (class 0 OID 0)
-- Dependencies: 611
-- Name: incdtpriority_incdtpriority_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdtpriority_incdtpriority_id_seq OWNED BY incdtpriority.incdtpriority_id;


--
-- TOC entry 612 (class 1259 OID 146569215)
-- Dependencies: 306 8
-- Name: incdtresolution_incdtresolution_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE incdtresolution_incdtresolution_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.incdtresolution_incdtresolution_id_seq OWNER TO admin;

--
-- TOC entry 9847 (class 0 OID 0)
-- Dependencies: 612
-- Name: incdtresolution_incdtresolution_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdtresolution_incdtresolution_id_seq OWNED BY incdtresolution.incdtresolution_id;


--
-- TOC entry 613 (class 1259 OID 146569217)
-- Dependencies: 307 8
-- Name: incdtseverity_incdtseverity_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE incdtseverity_incdtseverity_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.incdtseverity_incdtseverity_id_seq OWNER TO admin;

--
-- TOC entry 9849 (class 0 OID 0)
-- Dependencies: 613
-- Name: incdtseverity_incdtseverity_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdtseverity_incdtseverity_id_seq OWNED BY incdtseverity.incdtseverity_id;


--
-- TOC entry 614 (class 1259 OID 146569219)
-- Dependencies: 202 8
-- Name: invbal_invbal_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE invbal_invbal_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.invbal_invbal_id_seq OWNER TO admin;

--
-- TOC entry 9851 (class 0 OID 0)
-- Dependencies: 614
-- Name: invbal_invbal_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE invbal_invbal_id_seq OWNED BY invbal.invbal_id;


--
-- TOC entry 615 (class 1259 OID 146569221)
-- Dependencies: 8
-- Name: invc_invc_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE invc_invc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.invc_invc_id_seq OWNER TO admin;

--
-- TOC entry 616 (class 1259 OID 146569223)
-- Dependencies: 224 8
-- Name: invchead_invchead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE invchead_invchead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.invchead_invchead_id_seq OWNER TO admin;

--
-- TOC entry 9854 (class 0 OID 0)
-- Dependencies: 616
-- Name: invchead_invchead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE invchead_invchead_id_seq OWNED BY invchead.invchead_id;


--
-- TOC entry 617 (class 1259 OID 146569225)
-- Dependencies: 377 8
-- Name: invcheadtax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE invcheadtax (
)
INHERITS (taxhist);


ALTER TABLE public.invcheadtax OWNER TO admin;

--
-- TOC entry 618 (class 1259 OID 146569231)
-- Dependencies: 229 8
-- Name: invcitem_invcitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE invcitem_invcitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.invcitem_invcitem_id_seq OWNER TO admin;

--
-- TOC entry 9857 (class 0 OID 0)
-- Dependencies: 618
-- Name: invcitem_invcitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE invcitem_invcitem_id_seq OWNED BY invcitem.invcitem_id;


--
-- TOC entry 619 (class 1259 OID 146569233)
-- Dependencies: 377 8
-- Name: invcitemtax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE invcitemtax (
)
INHERITS (taxhist);


ALTER TABLE public.invcitemtax OWNER TO admin;

--
-- TOC entry 620 (class 1259 OID 146569239)
-- Dependencies: 8
-- Name: invcnt_invcnt_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE invcnt_invcnt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.invcnt_invcnt_id_seq OWNER TO admin;

--
-- TOC entry 621 (class 1259 OID 146569241)
-- Dependencies: 6541 8
-- Name: invdetail; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE invdetail (
    invdetail_id integer DEFAULT nextval(('"invdetail_invdetail_id_seq"'::text)::regclass) NOT NULL,
    invdetail_transtype character(2),
    invdetail_invhist_id integer,
    invdetail_location_id integer,
    invdetail_qty numeric(18,6),
    invdetail_comments text,
    invdetail_qty_before numeric(18,6),
    invdetail_qty_after numeric(18,6),
    invdetail_invcitem_id integer,
    invdetail_expiration date,
    invdetail_warrpurc date,
    invdetail_ls_id integer
);


ALTER TABLE public.invdetail OWNER TO admin;

--
-- TOC entry 9861 (class 0 OID 0)
-- Dependencies: 621
-- Name: TABLE invdetail; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE invdetail IS 'Detailed Inventory transaction information for Lot/Serial and Multiple Location Control (MLC) Items';


--
-- TOC entry 622 (class 1259 OID 146569248)
-- Dependencies: 8
-- Name: invdetail_invdetail_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE invdetail_invdetail_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.invdetail_invdetail_id_seq OWNER TO admin;

--
-- TOC entry 623 (class 1259 OID 146569250)
-- Dependencies: 6542 6543 6544 6545 6546 6547 6548 8
-- Name: invhist; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE invhist (
    invhist_id integer DEFAULT nextval(('invhist_invhist_id_seq'::text)::regclass) NOT NULL,
    invhist_itemsite_id integer,
    invhist_transdate timestamp with time zone DEFAULT ('now'::text)::timestamp(6) with time zone,
    invhist_transtype character(2),
    invhist_invqty numeric(18,6),
    invhist_invuom text,
    invhist_ordnumber text,
    invhist_docnumber text,
    invhist_qoh_before numeric(18,6),
    invhist_qoh_after numeric(18,6),
    invhist_unitcost numeric(16,6),
    invhist_acct_id integer,
    invhist_xfer_warehous_id integer,
    invhist_comments text,
    invhist_posted boolean DEFAULT true,
    invhist_imported boolean,
    invhist_hasdetail boolean DEFAULT false,
    invhist_ordtype text,
    invhist_analyze boolean DEFAULT true,
    invhist_user text DEFAULT geteffectivextuser(),
    invhist_created timestamp with time zone DEFAULT now() NOT NULL,
    invhist_costmethod character(1) NOT NULL,
    invhist_value_before numeric(12,2) NOT NULL,
    invhist_value_after numeric(12,2) NOT NULL,
    invhist_series integer
);


ALTER TABLE public.invhist OWNER TO admin;

--
-- TOC entry 9864 (class 0 OID 0)
-- Dependencies: 623
-- Name: TABLE invhist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE invhist IS 'Inventory transaction history';


--
-- TOC entry 624 (class 1259 OID 146569263)
-- Dependencies: 8
-- Name: invhist_invhist_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE invhist_invhist_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.invhist_invhist_id_seq OWNER TO admin;

--
-- TOC entry 625 (class 1259 OID 146569265)
-- Dependencies: 8
-- Name: invhistexpcat; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE invhistexpcat (
    invhistexpcat_id integer NOT NULL,
    invhistexpcat_invhist_id integer NOT NULL,
    invhistexpcat_expcat_id integer NOT NULL
);


ALTER TABLE public.invhistexpcat OWNER TO admin;

--
-- TOC entry 9867 (class 0 OID 0)
-- Dependencies: 625
-- Name: TABLE invhistexpcat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE invhistexpcat IS 'Track the relationship between an EX transaction in the invhist table and the corresponding Expense Category.';


--
-- TOC entry 626 (class 1259 OID 146569268)
-- Dependencies: 625 8
-- Name: invhistexpcat_invhistexpcat_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE invhistexpcat_invhistexpcat_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.invhistexpcat_invhistexpcat_id_seq OWNER TO admin;

--
-- TOC entry 9869 (class 0 OID 0)
-- Dependencies: 626
-- Name: invhistexpcat_invhistexpcat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE invhistexpcat_invhistexpcat_id_seq OWNED BY invhistexpcat.invhistexpcat_id;


--
-- TOC entry 627 (class 1259 OID 146569270)
-- Dependencies: 8581 8
-- Name: invoiceitem; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW invoiceitem AS
    SELECT invcitem.invcitem_id, invcitem.invcitem_invchead_id, invcitem.invcitem_linenumber, invcitem.invcitem_item_id, invcitem.invcitem_warehous_id, invcitem.invcitem_custpn, invcitem.invcitem_number, invcitem.invcitem_descrip, invcitem.invcitem_ordered, invcitem.invcitem_billed, invcitem.invcitem_custprice, invcitem.invcitem_price, invcitem.invcitem_notes, invcitem.invcitem_salescat_id, invcitem.invcitem_taxtype_id, invcitem.invcitem_qty_uom_id, invcitem.invcitem_qty_invuomratio, invcitem.invcitem_price_uom_id, invcitem.invcitem_price_invuomratio, invcitem.invcitem_coitem_id, invcitem.invcitem_updateinv, invcitem.invcitem_rev_accnt_id, itemsite.itemsite_id, cohead.cohead_number, COALESCE((invcitem.invcitem_billed * invcitem.invcitem_qty_invuomratio), (0)::numeric) AS qty, COALESCE((invcitem.invcitem_price / invcitem.invcitem_price_invuomratio), (0)::numeric) AS unitprice, COALESCE(round(((invcitem.invcitem_billed * invcitem.invcitem_qty_invuomratio) * (invcitem.invcitem_price / invcitem.invcitem_price_invuomratio)), 2), (0)::numeric) AS extprice, currtobase(invchead.invchead_curr_id, COALESCE(round(((invcitem.invcitem_billed * invcitem.invcitem_qty_invuomratio) * (invcitem.invcitem_price / invcitem.invcitem_price_invuomratio)), 2), (0)::numeric), invchead.invchead_invcdate) AS baseextprice, (SELECT COALESCE(sum(invcitemtax.taxhist_tax), (0)::numeric) AS "coalesce" FROM invcitemtax WHERE (invcitemtax.taxhist_parent_id = invcitem.invcitem_id)) AS tax, ((SELECT COALESCE(sum(shipitem.shipitem_value), (itemcost(itemsite.itemsite_id) * invcitem.invcitem_billed), (0)::numeric) AS "coalesce" FROM shipitem WHERE (shipitem.shipitem_invcitem_id = invcitem.invcitem_id)) / CASE WHEN (invcitem.invcitem_billed <> (0)::numeric) THEN (invcitem.invcitem_billed * invcitem.invcitem_qty_invuomratio) ELSE (1)::numeric END) AS unitcost FROM ((((invcitem JOIN invchead ON ((invchead.invchead_id = invcitem.invcitem_invchead_id))) LEFT JOIN coitem ON ((coitem.coitem_id = invcitem.invcitem_coitem_id))) LEFT JOIN cohead ON ((cohead.cohead_id = coitem.coitem_cohead_id))) LEFT JOIN itemsite ON (((itemsite.itemsite_item_id = invcitem.invcitem_item_id) AND (itemsite.itemsite_warehous_id = invcitem.invcitem_warehous_id))));


ALTER TABLE public.invoiceitem OWNER TO admin;

--
-- TOC entry 9871 (class 0 OID 0)
-- Dependencies: 627
-- Name: VIEW invoiceitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON VIEW invoiceitem IS 'Single point for invoice item (invcitem) calculations.';


--
-- TOC entry 628 (class 1259 OID 146569275)
-- Dependencies: 347 8
-- Name: ipsass_ipsass_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ipsass_ipsass_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ipsass_ipsass_id_seq OWNER TO admin;

--
-- TOC entry 9873 (class 0 OID 0)
-- Dependencies: 628
-- Name: ipsass_ipsass_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ipsass_ipsass_id_seq OWNED BY ipsass.ipsass_id;


--
-- TOC entry 629 (class 1259 OID 146569277)
-- Dependencies: 8
-- Name: ipsctyp_ipsctyp_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ipsctyp_ipsctyp_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ipsctyp_ipsctyp_id_seq OWNER TO admin;

--
-- TOC entry 630 (class 1259 OID 146569279)
-- Dependencies: 8
-- Name: ipscust_ipscust_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ipscust_ipscust_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ipscust_ipscust_id_seq OWNER TO admin;

--
-- TOC entry 631 (class 1259 OID 146569281)
-- Dependencies: 300 8
-- Name: ipsfreight_ipsfreight_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ipsfreight_ipsfreight_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ipsfreight_ipsfreight_id_seq OWNER TO admin;

--
-- TOC entry 9877 (class 0 OID 0)
-- Dependencies: 631
-- Name: ipsfreight_ipsfreight_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ipsfreight_ipsfreight_id_seq OWNED BY ipsfreight.ipsfreight_id;


--
-- TOC entry 632 (class 1259 OID 146569283)
-- Dependencies: 8
-- Name: ipshead_ipshead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ipshead_ipshead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ipshead_ipshead_id_seq OWNER TO admin;

--
-- TOC entry 633 (class 1259 OID 146569285)
-- Dependencies: 8
-- Name: ipsitem_ipsitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ipsitem_ipsitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ipsitem_ipsitem_id_seq OWNER TO admin;

--
-- TOC entry 634 (class 1259 OID 146569287)
-- Dependencies: 351 8
-- Name: ipsitemchar_ipsitemchar_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ipsitemchar_ipsitemchar_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ipsitemchar_ipsitemchar_id_seq OWNER TO admin;

--
-- TOC entry 9881 (class 0 OID 0)
-- Dependencies: 634
-- Name: ipsitemchar_ipsitemchar_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ipsitemchar_ipsitemchar_id_seq OWNED BY ipsitemchar.ipsitemchar_id;


--
-- TOC entry 635 (class 1259 OID 146569289)
-- Dependencies: 8582 8
-- Name: ipsprice; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW ipsprice AS
    SELECT ipsiteminfo.ipsitem_id AS ipsprice_id, 'I'::text AS ipsprice_source, ipsiteminfo.ipsitem_ipshead_id AS ipsprice_ipshead_id, ipsiteminfo.ipsitem_item_id AS ipsprice_item_id, itemuomtouom(ipsiteminfo.ipsitem_item_id, ipsiteminfo.ipsitem_qty_uom_id, NULL::integer, ipsiteminfo.ipsitem_qtybreak) AS ipsprice_qtybreak, CASE WHEN (ipsiteminfo.ipsitem_type = 'N'::bpchar) THEN ((ipsiteminfo.ipsitem_price * itemuomtouomratio(ipsiteminfo.ipsitem_item_id, NULL::integer, ipsiteminfo.ipsitem_price_uom_id)) * iteminvpricerat(ipsiteminfo.ipsitem_item_id)) WHEN (ipsiteminfo.ipsitem_type = 'D'::bpchar) THEN ((item.item_listprice - (item.item_listprice * ipsiteminfo.ipsitem_discntprcnt)) - ipsiteminfo.ipsitem_fixedamtdiscount) WHEN ((ipsiteminfo.ipsitem_type = 'M'::bpchar) AND fetchmetricbool('Long30Markups'::text)) THEN ((stdcost(item.item_id) / (1.0 - ipsiteminfo.ipsitem_discntprcnt)) + ipsiteminfo.ipsitem_fixedamtdiscount) WHEN (ipsiteminfo.ipsitem_type = 'M'::bpchar) THEN ((item.item_listcost + (item.item_listcost * ipsiteminfo.ipsitem_discntprcnt)) + ipsiteminfo.ipsitem_fixedamtdiscount) ELSE NULL::numeric END AS ipsprice_price, ipsiteminfo.ipsitem_qtybreak AS ipsprice_uomqtybreak, ipsiteminfo.ipsitem_qty_uom_id AS ipsprice_uomqtybreak_uom_id, CASE WHEN (ipsiteminfo.ipsitem_type = 'N'::bpchar) THEN ipsiteminfo.ipsitem_price WHEN (ipsiteminfo.ipsitem_type = 'D'::bpchar) THEN ((item.item_listprice - (item.item_listprice * ipsiteminfo.ipsitem_discntprcnt)) - ipsiteminfo.ipsitem_fixedamtdiscount) WHEN ((ipsiteminfo.ipsitem_type = 'M'::bpchar) AND fetchmetricbool('Long30Markups'::text)) THEN ((stdcost(item.item_id) / (1.0 - ipsiteminfo.ipsitem_discntprcnt)) + ipsiteminfo.ipsitem_fixedamtdiscount) WHEN (ipsiteminfo.ipsitem_type = 'M'::bpchar) THEN ((item.item_listcost + (item.item_listcost * ipsiteminfo.ipsitem_discntprcnt)) + ipsiteminfo.ipsitem_fixedamtdiscount) ELSE NULL::numeric END AS ipsprice_uomprice, ipsiteminfo.ipsitem_price_uom_id AS ipsprice_uomprice_uom_id, ipsiteminfo.ipsitem_discntprcnt AS ipsprice_discountpercent, ipsiteminfo.ipsitem_fixedamtdiscount AS ipsprice_discountfixed, ipsiteminfo.ipsitem_type AS ipsprice_type FROM (ipsiteminfo JOIN item ON ((item.item_id = ipsiteminfo.ipsitem_item_id))) UNION SELECT ipsiteminfo.ipsitem_id AS ipsprice_id, 'P'::text AS ipsprice_source, ipsiteminfo.ipsitem_ipshead_id AS ipsprice_ipshead_id, item.item_id AS ipsprice_item_id, ipsiteminfo.ipsitem_qtybreak AS ipsprice_qtybreak, CASE WHEN (ipsiteminfo.ipsitem_type = 'D'::bpchar) THEN ((item.item_listprice - (item.item_listprice * ipsiteminfo.ipsitem_discntprcnt)) - ipsiteminfo.ipsitem_fixedamtdiscount) WHEN ((ipsiteminfo.ipsitem_type = 'M'::bpchar) AND fetchmetricbool('Long30Markups'::text)) THEN ((stdcost(item.item_id) / (1.0 - ipsiteminfo.ipsitem_discntprcnt)) + ipsiteminfo.ipsitem_fixedamtdiscount) WHEN (ipsiteminfo.ipsitem_type = 'M'::bpchar) THEN ((item.item_listcost + (item.item_listcost * ipsiteminfo.ipsitem_discntprcnt)) + ipsiteminfo.ipsitem_fixedamtdiscount) ELSE NULL::numeric END AS ipsprice_price, ipsiteminfo.ipsitem_qtybreak AS ipsprice_uomqtybreak, item.item_inv_uom_id AS ipsprice_uomqtybreak_uom_id, CASE WHEN (ipsiteminfo.ipsitem_type = 'D'::bpchar) THEN ((item.item_listprice - (item.item_listprice * ipsiteminfo.ipsitem_discntprcnt)) - ipsiteminfo.ipsitem_fixedamtdiscount) WHEN ((ipsiteminfo.ipsitem_type = 'M'::bpchar) AND fetchmetricbool('Long30Markups'::text)) THEN ((stdcost(item.item_id) / (1.0 - ipsiteminfo.ipsitem_discntprcnt)) + ipsiteminfo.ipsitem_fixedamtdiscount) WHEN (ipsiteminfo.ipsitem_type = 'M'::bpchar) THEN ((item.item_listcost + (item.item_listcost * ipsiteminfo.ipsitem_discntprcnt)) + ipsiteminfo.ipsitem_fixedamtdiscount) ELSE NULL::numeric END AS ipsprice_uomprice, item.item_price_uom_id AS ipsprice_uomprice_uom_id, ipsiteminfo.ipsitem_discntprcnt AS ipsprice_discountpercent, ipsiteminfo.ipsitem_fixedamtdiscount AS ipsprice_discountfixed, ipsiteminfo.ipsitem_type AS ipsprice_type FROM (ipsiteminfo JOIN item ON ((ipsiteminfo.ipsitem_prodcat_id = item.item_prodcat_id)));


ALTER TABLE public.ipsprice OWNER TO admin;

--
-- TOC entry 636 (class 1259 OID 146569294)
-- Dependencies: 6551 8
-- Name: ipsprodcat_bak; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE ipsprodcat_bak (
    ipsprodcat_id integer NOT NULL,
    ipsprodcat_ipshead_id integer NOT NULL,
    ipsprodcat_prodcat_id integer NOT NULL,
    ipsprodcat_qtybreak numeric(18,6) NOT NULL,
    ipsprodcat_discntprcnt numeric(10,6) NOT NULL,
    ipsprodcat_fixedamtdiscount numeric(16,4) DEFAULT 0.00 NOT NULL
);


ALTER TABLE public.ipsprodcat_bak OWNER TO admin;

--
-- TOC entry 9884 (class 0 OID 0)
-- Dependencies: 636
-- Name: TABLE ipsprodcat_bak; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE ipsprodcat_bak IS 'Pricing Schedule Product Category information.';


--
-- TOC entry 637 (class 1259 OID 146569298)
-- Dependencies: 636 8
-- Name: ipsprodcat_ipsprodcat_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ipsprodcat_ipsprodcat_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ipsprodcat_ipsprodcat_id_seq OWNER TO admin;

--
-- TOC entry 9886 (class 0 OID 0)
-- Dependencies: 637
-- Name: ipsprodcat_ipsprodcat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ipsprodcat_ipsprodcat_id_seq OWNED BY ipsprodcat_bak.ipsprodcat_id;


--
-- TOC entry 638 (class 1259 OID 146569300)
-- Dependencies: 8
-- Name: item_item_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE item_item_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.item_item_id_seq OWNER TO admin;

--
-- TOC entry 639 (class 1259 OID 146569302)
-- Dependencies: 8
-- Name: itemalias_itemalias_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemalias_itemalias_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemalias_itemalias_id_seq OWNER TO admin;

--
-- TOC entry 640 (class 1259 OID 146569304)
-- Dependencies: 8
-- Name: itematr_itematr_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itematr_itematr_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itematr_itematr_id_seq OWNER TO admin;

--
-- TOC entry 641 (class 1259 OID 146569306)
-- Dependencies: 8
-- Name: itemcost_itemcost_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemcost_itemcost_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemcost_itemcost_id_seq OWNER TO admin;

--
-- TOC entry 642 (class 1259 OID 146569308)
-- Dependencies: 8
-- Name: itemfrez_itemfrez_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemfrez_itemfrez_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemfrez_itemfrez_seq OWNER TO admin;

--
-- TOC entry 643 (class 1259 OID 146569310)
-- Dependencies: 6552 6553 6554 8
-- Name: itemgrp; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE itemgrp (
    itemgrp_id integer DEFAULT nextval(('"itemgrp_itemgrp_id_seq"'::text)::regclass) NOT NULL,
    itemgrp_name text NOT NULL,
    itemgrp_descrip text,
    itemgrp_catalog boolean DEFAULT false NOT NULL,
    CONSTRAINT itemgrp_itemgrp_name_check CHECK ((itemgrp_name <> ''::text))
);


ALTER TABLE public.itemgrp OWNER TO admin;

--
-- TOC entry 9893 (class 0 OID 0)
-- Dependencies: 643
-- Name: TABLE itemgrp; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemgrp IS 'Item Group information';


--
-- TOC entry 644 (class 1259 OID 146569319)
-- Dependencies: 8
-- Name: itemgrp_itemgrp_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemgrp_itemgrp_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemgrp_itemgrp_id_seq OWNER TO admin;

--
-- TOC entry 645 (class 1259 OID 146569321)
-- Dependencies: 6555 6556 6557 8
-- Name: itemgrpitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE itemgrpitem (
    itemgrpitem_id integer DEFAULT nextval(('"itemgrpitem_itemgrpitem_id_seq"'::text)::regclass) NOT NULL,
    itemgrpitem_itemgrp_id integer,
    itemgrpitem_item_id integer,
    itemgrpitem_item_type character(1) DEFAULT 'I'::bpchar NOT NULL,
    CONSTRAINT itemgrpitem_valid_item_type CHECK ((itemgrpitem_item_type = ANY (ARRAY['I'::bpchar, 'G'::bpchar])))
);


ALTER TABLE public.itemgrpitem OWNER TO admin;

--
-- TOC entry 9896 (class 0 OID 0)
-- Dependencies: 645
-- Name: TABLE itemgrpitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemgrpitem IS 'Item Group Item information';


--
-- TOC entry 646 (class 1259 OID 146569327)
-- Dependencies: 8
-- Name: itemgrpitem_itemgrpitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemgrpitem_itemgrpitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemgrpitem_itemgrpitem_id_seq OWNER TO admin;

--
-- TOC entry 647 (class 1259 OID 146569329)
-- Dependencies: 8583 8
-- Name: itemimage; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW itemimage AS
    SELECT imageass.imageass_id AS itemimage_id, imageass.imageass_source_id AS itemimage_item_id, imageass.imageass_image_id AS itemimage_image_id, imageass.imageass_purpose AS itemimage_purpose FROM imageass WHERE (imageass.imageass_source = 'I'::text);


ALTER TABLE public.itemimage OWNER TO admin;

--
-- TOC entry 9899 (class 0 OID 0)
-- Dependencies: 647
-- Name: VIEW itemimage; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON VIEW itemimage IS 'Itemimage view for legacy support. Use of itemimage is deprecated. Use imageass table for future development';


--
-- TOC entry 648 (class 1259 OID 146569333)
-- Dependencies: 8
-- Name: itemimage_itemimage_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemimage_itemimage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.itemimage_itemimage_id_seq OWNER TO admin;

--
-- TOC entry 649 (class 1259 OID 146569335)
-- Dependencies: 6558 8
-- Name: itemloc; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE itemloc (
    itemloc_id integer DEFAULT nextval(('"itemloc_itemloc_id_seq"'::text)::regclass) NOT NULL,
    itemloc_itemsite_id integer NOT NULL,
    itemloc_location_id integer NOT NULL,
    itemloc_qty numeric(18,6) NOT NULL,
    itemloc_expiration date NOT NULL,
    itemloc_consolflag boolean,
    itemloc_ls_id integer,
    itemloc_warrpurc date
);


ALTER TABLE public.itemloc OWNER TO admin;

--
-- TOC entry 9902 (class 0 OID 0)
-- Dependencies: 649
-- Name: TABLE itemloc; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemloc IS 'Detailed Location information for Lot/Serial and Multiple Location Control (MLC) Items';


--
-- TOC entry 650 (class 1259 OID 146569339)
-- Dependencies: 8
-- Name: itemloc_itemloc_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemloc_itemloc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.itemloc_itemloc_id_seq OWNER TO admin;

--
-- TOC entry 651 (class 1259 OID 146569341)
-- Dependencies: 8
-- Name: itemloc_series_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemloc_series_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemloc_series_seq OWNER TO admin;

--
-- TOC entry 652 (class 1259 OID 146569343)
-- Dependencies: 6559 6560 6561 8
-- Name: itemlocdist; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE itemlocdist (
    itemlocdist_id integer DEFAULT nextval(('"itemlocdist_itemlocdist_id_seq"'::text)::regclass) NOT NULL,
    itemlocdist_itemlocdist_id integer,
    itemlocdist_source_type character(1),
    itemlocdist_source_id integer,
    itemlocdist_qty numeric(18,6),
    itemlocdist_series integer,
    itemlocdist_invhist_id integer,
    itemlocdist_itemsite_id integer,
    itemlocdist_reqlotserial boolean DEFAULT false,
    itemlocdist_flush boolean DEFAULT false,
    itemlocdist_expiration date,
    itemlocdist_distlotserial boolean,
    itemlocdist_warranty date,
    itemlocdist_ls_id integer,
    itemlocdist_order_type text,
    itemlocdist_order_id integer
);


ALTER TABLE public.itemlocdist OWNER TO admin;

--
-- TOC entry 9906 (class 0 OID 0)
-- Dependencies: 652
-- Name: TABLE itemlocdist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemlocdist IS 'Temporary table for storing information about Inventory distributions involving Lot/Serial and Multiple Location Control (MLC) Items';


--
-- TOC entry 653 (class 1259 OID 146569352)
-- Dependencies: 8
-- Name: itemlocdist_itemlocdist_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemlocdist_itemlocdist_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.itemlocdist_itemlocdist_id_seq OWNER TO admin;

--
-- TOC entry 654 (class 1259 OID 146569354)
-- Dependencies: 8
-- Name: itemlocpost; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE itemlocpost (
    itemlocpost_id integer NOT NULL,
    itemlocpost_itemlocseries integer,
    itemlocpost_glseq integer
);


ALTER TABLE public.itemlocpost OWNER TO admin;

--
-- TOC entry 9909 (class 0 OID 0)
-- Dependencies: 654
-- Name: TABLE itemlocpost; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemlocpost IS 'Temporary table for storing information about Inventory distribution G/L postings involving Lot/Serial and Multiple Location Control (MLC) Items';


--
-- TOC entry 655 (class 1259 OID 146569357)
-- Dependencies: 654 8
-- Name: itemlocpost_itemlocpost_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemlocpost_itemlocpost_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.itemlocpost_itemlocpost_id_seq OWNER TO admin;

--
-- TOC entry 9911 (class 0 OID 0)
-- Dependencies: 655
-- Name: itemlocpost_itemlocpost_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemlocpost_itemlocpost_id_seq OWNED BY itemlocpost.itemlocpost_id;


--
-- TOC entry 656 (class 1259 OID 146569359)
-- Dependencies: 8
-- Name: itemopn_itemopn_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemopn_itemopn_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemopn_itemopn_id_seq OWNER TO admin;

--
-- TOC entry 657 (class 1259 OID 146569361)
-- Dependencies: 8
-- Name: itemsite_itemsite_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemsite_itemsite_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemsite_itemsite_id_seq OWNER TO admin;

--
-- TOC entry 658 (class 1259 OID 146569363)
-- Dependencies: 8
-- Name: itemsrc_itemsrc_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemsrc_itemsrc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemsrc_itemsrc_id_seq OWNER TO admin;

--
-- TOC entry 659 (class 1259 OID 146569365)
-- Dependencies: 8
-- Name: itemsrcp_itemsrcp_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemsrcp_itemsrcp_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemsrcp_itemsrcp_id_seq OWNER TO admin;

--
-- TOC entry 660 (class 1259 OID 146569367)
-- Dependencies: 8
-- Name: itemsub_itemsub_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemsub_itemsub_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.itemsub_itemsub_id_seq OWNER TO admin;

--
-- TOC entry 661 (class 1259 OID 146569369)
-- Dependencies: 336 8
-- Name: itemtax_itemtax_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemtax_itemtax_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.itemtax_itemtax_id_seq OWNER TO admin;

--
-- TOC entry 9918 (class 0 OID 0)
-- Dependencies: 661
-- Name: itemtax_itemtax_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemtax_itemtax_id_seq OWNED BY itemtax.itemtax_id;


--
-- TOC entry 662 (class 1259 OID 146569371)
-- Dependencies: 8
-- Name: itemtrans; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE itemtrans (
    itemtrans_id integer NOT NULL,
    itemtrans_source_item_id integer,
    itemtrans_target_item_id integer
);


ALTER TABLE public.itemtrans OWNER TO admin;

--
-- TOC entry 9920 (class 0 OID 0)
-- Dependencies: 662
-- Name: TABLE itemtrans; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemtrans IS 'Item Transformation information';


--
-- TOC entry 663 (class 1259 OID 146569374)
-- Dependencies: 662 8
-- Name: itemtrans_itemtrans_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemtrans_itemtrans_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.itemtrans_itemtrans_id_seq OWNER TO admin;

--
-- TOC entry 9922 (class 0 OID 0)
-- Dependencies: 663
-- Name: itemtrans_itemtrans_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemtrans_itemtrans_id_seq OWNED BY itemtrans.itemtrans_id;


--
-- TOC entry 664 (class 1259 OID 146569376)
-- Dependencies: 8
-- Name: itemuom; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE itemuom (
    itemuom_id integer NOT NULL,
    itemuom_itemuomconv_id integer NOT NULL,
    itemuom_uomtype_id integer NOT NULL
);


ALTER TABLE public.itemuom OWNER TO admin;

--
-- TOC entry 9924 (class 0 OID 0)
-- Dependencies: 664
-- Name: TABLE itemuom; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemuom IS 'A UOM type relation for a specific conversion.';


--
-- TOC entry 665 (class 1259 OID 146569379)
-- Dependencies: 664 8
-- Name: itemuom_itemuom_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemuom_itemuom_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.itemuom_itemuom_id_seq OWNER TO admin;

--
-- TOC entry 9926 (class 0 OID 0)
-- Dependencies: 665
-- Name: itemuom_itemuom_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemuom_itemuom_id_seq OWNED BY itemuom.itemuom_id;


--
-- TOC entry 666 (class 1259 OID 146569381)
-- Dependencies: 338 8
-- Name: itemuomconv_itemuomconv_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE itemuomconv_itemuomconv_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.itemuomconv_itemuomconv_id_seq OWNER TO admin;

--
-- TOC entry 9928 (class 0 OID 0)
-- Dependencies: 666
-- Name: itemuomconv_itemuomconv_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemuomconv_itemuomconv_id_seq OWNED BY itemuomconv.itemuomconv_id;


--
-- TOC entry 667 (class 1259 OID 146569383)
-- Dependencies: 8
-- Name: journal_number_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE journal_number_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.journal_number_seq OWNER TO admin;

--
-- TOC entry 668 (class 1259 OID 146569385)
-- Dependencies: 6565 8
-- Name: jrnluse; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE jrnluse (
    jrnluse_id integer DEFAULT nextval(('"jrnluse_jrnluse_id_seq"'::text)::regclass) NOT NULL,
    jrnluse_date timestamp without time zone,
    jrnluse_number integer,
    jrnluse_use text
);


ALTER TABLE public.jrnluse OWNER TO admin;

--
-- TOC entry 9931 (class 0 OID 0)
-- Dependencies: 668
-- Name: TABLE jrnluse; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE jrnluse IS 'Journal entry and use information';


--
-- TOC entry 669 (class 1259 OID 146569392)
-- Dependencies: 8
-- Name: jrnluse_jrnluse_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE jrnluse_jrnluse_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.jrnluse_jrnluse_id_seq OWNER TO admin;

--
-- TOC entry 670 (class 1259 OID 146569394)
-- Dependencies: 8
-- Name: labeldef; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE labeldef (
    labeldef_id integer NOT NULL,
    labeldef_name text NOT NULL,
    labeldef_papersize text NOT NULL,
    labeldef_columns integer NOT NULL,
    labeldef_rows integer NOT NULL,
    labeldef_width integer NOT NULL,
    labeldef_height integer NOT NULL,
    labeldef_start_offset_x integer NOT NULL,
    labeldef_start_offset_y integer NOT NULL,
    labeldef_horizontal_gap integer NOT NULL,
    labeldef_vertical_gap integer NOT NULL
);


ALTER TABLE public.labeldef OWNER TO admin;

--
-- TOC entry 671 (class 1259 OID 146569400)
-- Dependencies: 670 8
-- Name: labeldef_labeldef_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE labeldef_labeldef_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.labeldef_labeldef_id_seq OWNER TO admin;

--
-- TOC entry 9935 (class 0 OID 0)
-- Dependencies: 671
-- Name: labeldef_labeldef_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE labeldef_labeldef_id_seq OWNED BY labeldef.labeldef_id;


--
-- TOC entry 672 (class 1259 OID 146569402)
-- Dependencies: 6567 6568 8
-- Name: labelform; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE labelform (
    labelform_id integer DEFAULT nextval(('"labelform_labelform_id_seq"'::text)::regclass) NOT NULL,
    labelform_name text NOT NULL,
    labelform_report_id integer,
    labelform_perpage integer,
    labelform_report_name text,
    CONSTRAINT labelform_labelform_name_check CHECK ((labelform_name <> ''::text))
);


ALTER TABLE public.labelform OWNER TO admin;

--
-- TOC entry 9937 (class 0 OID 0)
-- Dependencies: 672
-- Name: TABLE labelform; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE labelform IS 'Label Form information';


--
-- TOC entry 9938 (class 0 OID 0)
-- Dependencies: 672
-- Name: COLUMN labelform.labelform_report_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN labelform.labelform_report_id IS 'Obsolete -- reference labelform_report_name instead.';


--
-- TOC entry 673 (class 1259 OID 146569410)
-- Dependencies: 8
-- Name: labelform_labelform_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE labelform_labelform_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.labelform_labelform_id_seq OWNER TO admin;

--
-- TOC entry 674 (class 1259 OID 146569412)
-- Dependencies: 8
-- Name: lang; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE lang (
    lang_id integer NOT NULL,
    lang_qt_number integer,
    lang_abbr3 text,
    lang_abbr2 text,
    lang_name text NOT NULL
);


ALTER TABLE public.lang OWNER TO admin;

--
-- TOC entry 9941 (class 0 OID 0)
-- Dependencies: 674
-- Name: TABLE lang; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE lang IS 'Table mapping ISO 639-1 and 639-2 language codes to Qt''s enum QLocale::Language integer values. See http://www.loc.gov/standards/iso639-2/php/code_list.php and the QLocale documentation..';


--
-- TOC entry 9942 (class 0 OID 0)
-- Dependencies: 674
-- Name: COLUMN lang.lang_abbr3; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN lang.lang_abbr3 IS 'ISO 639-2 code for language. Where there is a choice between bibliographic (B) and terminology (T) usage, this value is the T code';


--
-- TOC entry 9943 (class 0 OID 0)
-- Dependencies: 674
-- Name: COLUMN lang.lang_abbr2; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN lang.lang_abbr2 IS 'ISO 639-1 code for language';


--
-- TOC entry 9944 (class 0 OID 0)
-- Dependencies: 674
-- Name: COLUMN lang.lang_name; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN lang.lang_name IS 'Name of a human language, taken from the ISO 639-2 documentation';


--
-- TOC entry 675 (class 1259 OID 146569418)
-- Dependencies: 674 8
-- Name: lang_lang_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE lang_lang_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.lang_lang_id_seq OWNER TO admin;

--
-- TOC entry 9946 (class 0 OID 0)
-- Dependencies: 675
-- Name: lang_lang_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE lang_lang_id_seq OWNED BY lang.lang_id;


--
-- TOC entry 676 (class 1259 OID 146569420)
-- Dependencies: 6570 6571 6572 6573 8
-- Name: locale; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE locale (
    locale_id integer DEFAULT nextval(('locale_locale_id_seq'::text)::regclass) NOT NULL,
    locale_code text NOT NULL,
    locale_descrip text,
    locale_lang_file text,
    locale_dateformat text,
    locale_currformat text,
    locale_qtyformat text,
    locale_comments text,
    locale_qtyperformat text,
    locale_salespriceformat text,
    locale_extpriceformat text,
    locale_timeformat text,
    locale_timestampformat text,
    local_costformat text,
    locale_costformat text,
    locale_purchpriceformat text,
    locale_uomratioformat text,
    locale_intervalformat text,
    locale_lang_id integer,
    locale_country_id integer,
    locale_error_color text,
    locale_warning_color text,
    locale_emphasis_color text,
    locale_altemphasis_color text,
    locale_expired_color text,
    locale_future_color text,
    locale_curr_scale integer,
    locale_salesprice_scale integer,
    locale_purchprice_scale integer,
    locale_extprice_scale integer,
    locale_cost_scale integer,
    locale_qty_scale integer,
    locale_qtyper_scale integer,
    locale_uomratio_scale integer,
    locale_percent_scale integer DEFAULT 2,
    locale_weight_scale integer DEFAULT 2 NOT NULL,
    CONSTRAINT locale_locale_code_check CHECK ((locale_code <> ''::text))
);


ALTER TABLE public.locale OWNER TO admin;

--
-- TOC entry 9948 (class 0 OID 0)
-- Dependencies: 676
-- Name: TABLE locale; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE locale IS 'The locale table holds information required to show data to the user in a localized format. Colors are either names documented by the WWW Consortium or RGB colors. Format for RGB colors is #RGB, #RRGGBB, or #RRRGGGBBB, where the letters R, G, and B stand for hexidecimal digits.';


--
-- TOC entry 9949 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_lang_file; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_lang_file IS 'Deprecated';


--
-- TOC entry 9950 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_dateformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_dateformat IS 'Deprecated';


--
-- TOC entry 9951 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_currformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_currformat IS 'Deprecated';


--
-- TOC entry 9952 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_qtyformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_qtyformat IS 'Deprecated';


--
-- TOC entry 9953 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_qtyperformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_qtyperformat IS 'Deprecated';


--
-- TOC entry 9954 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_salespriceformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_salespriceformat IS 'Deprecated';


--
-- TOC entry 9955 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_extpriceformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_extpriceformat IS 'Deprecated';


--
-- TOC entry 9956 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_timeformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_timeformat IS 'Deprecated';


--
-- TOC entry 9957 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_timestampformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_timestampformat IS 'Deprecated';


--
-- TOC entry 9958 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.local_costformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.local_costformat IS 'Deprecated';


--
-- TOC entry 9959 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_costformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_costformat IS 'Deprecated';


--
-- TOC entry 9960 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_purchpriceformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_purchpriceformat IS 'Deprecated';


--
-- TOC entry 9961 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_uomratioformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_uomratioformat IS 'Deprecated';


--
-- TOC entry 9962 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_intervalformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_intervalformat IS 'Deprecated';


--
-- TOC entry 9963 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_error_color; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_error_color IS 'Color to use to mark data that require immediate attention.';


--
-- TOC entry 9964 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_warning_color; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_warning_color IS 'Color to use to mark data that require attention soon.';


--
-- TOC entry 9965 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_emphasis_color; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_emphasis_color IS 'Color to use to mark data that need to stand out but are not in error.';


--
-- TOC entry 9966 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_altemphasis_color; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_altemphasis_color IS 'Color to use to mark data that need to stand out and be differentiated from other emphasized data.';


--
-- TOC entry 9967 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_expired_color; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_expired_color IS 'Color to use to mark data that are no longer current.';


--
-- TOC entry 9968 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_future_color; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_future_color IS 'Color to use to mark data that will not be effective until some point in the future.';


--
-- TOC entry 9969 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_curr_scale; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_curr_scale IS 'Number of decimal places to show when displaying Currency values.';


--
-- TOC entry 9970 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_salesprice_scale; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_salesprice_scale IS 'Number of decimal places to show when displaying Sales Prices.';


--
-- TOC entry 9971 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_purchprice_scale; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_purchprice_scale IS 'Number of decimal places to show when displaying Purchase Prices.';


--
-- TOC entry 9972 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_extprice_scale; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_extprice_scale IS 'Number of decimal places to show when displaying Extended Prices.';


--
-- TOC entry 9973 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_cost_scale; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_cost_scale IS 'Number of decimal places to show when displaying Costs.';


--
-- TOC entry 9974 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_qty_scale; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_qty_scale IS 'Number of decimal places to show when displaying Quantities.';


--
-- TOC entry 9975 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_qtyper_scale; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_qtyper_scale IS 'Number of decimal places to show when displaying Quantities Per.';


--
-- TOC entry 9976 (class 0 OID 0)
-- Dependencies: 676
-- Name: COLUMN locale.locale_uomratio_scale; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_uomratio_scale IS 'Number of decimal places to show when displaying UOM Ratios.';


--
-- TOC entry 677 (class 1259 OID 146569430)
-- Dependencies: 8
-- Name: locale_locale_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE locale_locale_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.locale_locale_id_seq OWNER TO admin;

--
-- TOC entry 678 (class 1259 OID 146569432)
-- Dependencies: 8
-- Name: location_location_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE location_location_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.location_location_id_seq OWNER TO admin;

--
-- TOC entry 679 (class 1259 OID 146569434)
-- Dependencies: 6574 8
-- Name: locitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE locitem (
    locitem_id integer DEFAULT nextval(('"locitem_locitem_id_seq"'::text)::regclass) NOT NULL,
    locitem_location_id integer,
    locitem_item_id integer
);


ALTER TABLE public.locitem OWNER TO admin;

--
-- TOC entry 9980 (class 0 OID 0)
-- Dependencies: 679
-- Name: TABLE locitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE locitem IS 'Restricted Warehouse Location Allowable Items information';


--
-- TOC entry 680 (class 1259 OID 146569438)
-- Dependencies: 8
-- Name: locitem_locitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE locitem_locitem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.locitem_locitem_id_seq OWNER TO admin;

--
-- TOC entry 681 (class 1259 OID 146569440)
-- Dependencies: 8
-- Name: log_log_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE log_log_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.log_log_id_seq OWNER TO admin;

--
-- TOC entry 682 (class 1259 OID 146569442)
-- Dependencies: 6575 6576 8
-- Name: metric; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE metric (
    metric_id integer DEFAULT nextval(('metric_metric_id_seq'::text)::regclass) NOT NULL,
    metric_name text NOT NULL,
    metric_value text,
    metric_module text,
    CONSTRAINT metric_metric_name_check CHECK ((metric_name <> ''::text))
);


ALTER TABLE public.metric OWNER TO admin;

--
-- TOC entry 9984 (class 0 OID 0)
-- Dependencies: 682
-- Name: TABLE metric; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE metric IS 'Application-wide settings information';


--
-- TOC entry 683 (class 1259 OID 146569450)
-- Dependencies: 8
-- Name: metric_metric_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE metric_metric_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.metric_metric_id_seq OWNER TO admin;

--
-- TOC entry 684 (class 1259 OID 146569452)
-- Dependencies: 6578 8
-- Name: metricenc; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE metricenc (
    metricenc_id integer NOT NULL,
    metricenc_name text NOT NULL,
    metricenc_value bytea,
    metricenc_module text,
    CONSTRAINT metricenc_metricenc_name_check CHECK ((metricenc_name <> ''::text))
);


ALTER TABLE public.metricenc OWNER TO admin;

--
-- TOC entry 9987 (class 0 OID 0)
-- Dependencies: 684
-- Name: TABLE metricenc; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE metricenc IS 'Application-wide settings information encrypted data';


--
-- TOC entry 685 (class 1259 OID 146569459)
-- Dependencies: 684 8
-- Name: metricenc_metricenc_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE metricenc_metricenc_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.metricenc_metricenc_id_seq OWNER TO admin;

--
-- TOC entry 9989 (class 0 OID 0)
-- Dependencies: 685
-- Name: metricenc_metricenc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE metricenc_metricenc_id_seq OWNED BY metricenc.metricenc_id;


--
-- TOC entry 686 (class 1259 OID 146569461)
-- Dependencies: 8
-- Name: misc_index_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE misc_index_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.misc_index_seq OWNER TO admin;

--
-- TOC entry 687 (class 1259 OID 146569463)
-- Dependencies: 8
-- Name: mrghist; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE mrghist (
    mrghist_cntct_id integer NOT NULL,
    mrghist_table text NOT NULL,
    mrghist_pkey_col text NOT NULL,
    mrghist_pkey_id integer NOT NULL,
    mrghist_cntct_col text NOT NULL
);


ALTER TABLE public.mrghist OWNER TO admin;

--
-- TOC entry 688 (class 1259 OID 146569469)
-- Dependencies: 8
-- Name: mrgundo; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE mrgundo (
    mrgundo_base_schema text,
    mrgundo_base_table text,
    mrgundo_base_id integer,
    mrgundo_schema text,
    mrgundo_table text,
    mrgundo_pkey_col text,
    mrgundo_pkey_id integer,
    mrgundo_col text,
    mrgundo_value text,
    mrgundo_type text
);


ALTER TABLE public.mrgundo OWNER TO admin;

--
-- TOC entry 9993 (class 0 OID 0)
-- Dependencies: 688
-- Name: TABLE mrgundo; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE mrgundo IS 'This table keeps track of the original values of changes made while merging two records. It is a generalization of mrghist and trgthist, which are specific to merging contacts. The schema, table, and pkey_id columns uniquely identify the record that was changed while the _base_ columns identify the merge target. The _base_ columns are required to allow finding all of the records that pertain to a particular merge (e.g. find changes to the comment table that pertain to a crmacct merge).';


--
-- TOC entry 9994 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_base_schema; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_base_schema IS 'The schema in which the merge target resides.';


--
-- TOC entry 9995 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_base_table; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_base_table IS 'The table in which the merge target resides.';


--
-- TOC entry 9996 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_base_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_base_id IS 'The internal id of the merge target record.';


--
-- TOC entry 9997 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_schema; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_schema IS 'The name of the schema in which the modified table resides.';


--
-- TOC entry 9998 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_table; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_table IS 'The name of the table that was modified during a merge.';


--
-- TOC entry 9999 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_pkey_col; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_pkey_col IS 'The name of the primary key column in the modified table. This could be derived during the undo processing but it is simpler just to store it during the merge.';


--
-- TOC entry 10000 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_pkey_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_pkey_id IS 'The primary key of the modified record.';


--
-- TOC entry 10001 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_col; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_col IS 'The column that was modified.';


--
-- TOC entry 10002 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_value; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_value IS 'The value of the column before the change.';


--
-- TOC entry 10003 (class 0 OID 0)
-- Dependencies: 688
-- Name: COLUMN mrgundo.mrgundo_type; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_type IS 'The data type of the modified column. This could be derived during the undo processing but it is simpler just to store it during the merge.';


--
-- TOC entry 689 (class 1259 OID 146569475)
-- Dependencies: 6579 8
-- Name: msg; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE msg (
    msg_id integer DEFAULT nextval(('"msg_msg_id_seq"'::text)::regclass) NOT NULL,
    msg_posted timestamp with time zone,
    msg_scheduled timestamp with time zone,
    msg_text text,
    msg_expires timestamp with time zone,
    msg_username text
);


ALTER TABLE public.msg OWNER TO admin;

--
-- TOC entry 10005 (class 0 OID 0)
-- Dependencies: 689
-- Name: TABLE msg; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE msg IS 'System Message information';


--
-- TOC entry 690 (class 1259 OID 146569482)
-- Dependencies: 8
-- Name: msg_msg_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE msg_msg_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.msg_msg_id_seq OWNER TO admin;

--
-- TOC entry 691 (class 1259 OID 146569484)
-- Dependencies: 6580 8
-- Name: msguser; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE msguser (
    msguser_id integer DEFAULT nextval(('"msguser_msguser_id_seq"'::text)::regclass) NOT NULL,
    msguser_msg_id integer,
    msguser_viewed timestamp with time zone,
    msguser_username text
);


ALTER TABLE public.msguser OWNER TO admin;

--
-- TOC entry 10008 (class 0 OID 0)
-- Dependencies: 691
-- Name: TABLE msguser; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE msguser IS 'System Message user information';


--
-- TOC entry 692 (class 1259 OID 146569491)
-- Dependencies: 8
-- Name: msguser_msguser_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE msguser_msguser_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.msguser_msguser_id_seq OWNER TO admin;

--
-- TOC entry 693 (class 1259 OID 146569493)
-- Dependencies: 8
-- Name: nvend_nvend_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE nvend_nvend_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.nvend_nvend_id_seq OWNER TO admin;

--
-- TOC entry 694 (class 1259 OID 146569495)
-- Dependencies: 6581 6582 6583 8
-- Name: obsolete_tax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE obsolete_tax (
    tax_id integer DEFAULT nextval(('"tax_tax_id_seq"'::text)::regclass) NOT NULL,
    tax_code text,
    tax_descrip text,
    tax_ratea numeric(8,4),
    tax_sales_accnt_id integer,
    tax_freight boolean DEFAULT false NOT NULL,
    tax_cumulative boolean DEFAULT false NOT NULL,
    tax_rateb numeric(8,4),
    tax_salesb_accnt_id integer,
    tax_ratec numeric(8,4),
    tax_salesc_accnt_id integer
);


ALTER TABLE public.obsolete_tax OWNER TO admin;

--
-- TOC entry 10012 (class 0 OID 0)
-- Dependencies: 694
-- Name: TABLE obsolete_tax; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE obsolete_tax IS 'Tax information. Obsolete table structure.';


--
-- TOC entry 10013 (class 0 OID 0)
-- Dependencies: 694
-- Name: COLUMN obsolete_tax.tax_freight; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN obsolete_tax.tax_freight IS 'Deprecated in 2.1 and moved to taxsel table where taxtype is the system defined Freight.';


--
-- TOC entry 695 (class 1259 OID 146569504)
-- Dependencies: 231 8
-- Name: ophead_ophead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE ophead_ophead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ophead_ophead_id_seq OWNER TO admin;

--
-- TOC entry 10015 (class 0 OID 0)
-- Dependencies: 695
-- Name: ophead_ophead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ophead_ophead_id_seq OWNED BY ophead.ophead_id;


--
-- TOC entry 696 (class 1259 OID 146569506)
-- Dependencies: 6585 8
-- Name: opsource; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE opsource (
    opsource_id integer NOT NULL,
    opsource_name text NOT NULL,
    opsource_descrip text,
    CONSTRAINT opsource_opsource_name_check CHECK ((opsource_name <> ''::text))
);


ALTER TABLE public.opsource OWNER TO admin;

--
-- TOC entry 10017 (class 0 OID 0)
-- Dependencies: 696
-- Name: TABLE opsource; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE opsource IS 'Opportunity Lead Source values.';


--
-- TOC entry 697 (class 1259 OID 146569513)
-- Dependencies: 696 8
-- Name: opsource_opsource_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE opsource_opsource_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.opsource_opsource_id_seq OWNER TO admin;

--
-- TOC entry 10019 (class 0 OID 0)
-- Dependencies: 697
-- Name: opsource_opsource_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE opsource_opsource_id_seq OWNED BY opsource.opsource_id;


--
-- TOC entry 698 (class 1259 OID 146569515)
-- Dependencies: 6587 6588 6589 8
-- Name: opstage; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE opstage (
    opstage_id integer NOT NULL,
    opstage_name text NOT NULL,
    opstage_descrip text,
    opstage_order integer DEFAULT 0 NOT NULL,
    opstage_opinactive boolean DEFAULT false,
    CONSTRAINT opstage_opstage_name_check CHECK ((opstage_name <> ''::text))
);


ALTER TABLE public.opstage OWNER TO admin;

--
-- TOC entry 10021 (class 0 OID 0)
-- Dependencies: 698
-- Name: TABLE opstage; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE opstage IS 'Opportunity stage values.';


--
-- TOC entry 699 (class 1259 OID 146569524)
-- Dependencies: 698 8
-- Name: opstage_opstage_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE opstage_opstage_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.opstage_opstage_id_seq OWNER TO admin;

--
-- TOC entry 10023 (class 0 OID 0)
-- Dependencies: 699
-- Name: opstage_opstage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE opstage_opstage_id_seq OWNED BY opstage.opstage_id;


--
-- TOC entry 700 (class 1259 OID 146569526)
-- Dependencies: 6591 8
-- Name: optype; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE optype (
    optype_id integer NOT NULL,
    optype_name text NOT NULL,
    optype_descrip text,
    CONSTRAINT optype_optype_name_check CHECK ((optype_name <> ''::text))
);


ALTER TABLE public.optype OWNER TO admin;

--
-- TOC entry 10025 (class 0 OID 0)
-- Dependencies: 700
-- Name: TABLE optype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE optype IS 'Opportunity Type values.';


--
-- TOC entry 701 (class 1259 OID 146569533)
-- Dependencies: 700 8
-- Name: optype_optype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE optype_optype_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.optype_optype_id_seq OWNER TO admin;

--
-- TOC entry 10027 (class 0 OID 0)
-- Dependencies: 701
-- Name: optype_optype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE optype_optype_id_seq OWNED BY optype.optype_id;


--
-- TOC entry 702 (class 1259 OID 146569535)
-- Dependencies: 8584 8
-- Name: orderhead; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW orderhead AS
    SELECT DISTINCT data.orderhead_id, data.orderhead_type, data.orderhead_number, data.orderhead_status, data.orderhead_orderdate, data.orderhead_linecount, data.orderhead_from_id, data.orderhead_from, data.orderhead_to_id, data.orderhead_to, data.orderhead_curr_id, data.orderhead_agent_username, data.orderhead_shipvia FROM (SELECT pohead.pohead_id AS orderhead_id, 'PO'::text AS orderhead_type, pohead.pohead_number AS orderhead_number, pohead.pohead_status AS orderhead_status, pohead.pohead_orderdate AS orderhead_orderdate, (SELECT count(*) AS count FROM poitem WHERE (poitem.poitem_pohead_id = pohead.pohead_id)) AS orderhead_linecount, pohead.pohead_vend_id AS orderhead_from_id, vendinfo.vend_name AS orderhead_from, NULL::integer AS orderhead_to_id, ''::text AS orderhead_to, pohead.pohead_curr_id AS orderhead_curr_id, pohead.pohead_agent_username AS orderhead_agent_username, pohead.pohead_shipvia AS orderhead_shipvia FROM (pohead LEFT JOIN vendinfo ON ((pohead.pohead_vend_id = vendinfo.vend_id))) UNION ALL SELECT cohead.cohead_id AS orderhead_id, 'SO'::text AS orderhead_type, cohead.cohead_number AS orderhead_number, cohead.cohead_status AS orderhead_status, cohead.cohead_orderdate AS orderhead_orderdate, (SELECT count(*) AS count FROM coitem WHERE (coitem.coitem_cohead_id = cohead.cohead_id)) AS orderhead_linecount, NULL::integer AS orderhead_from_id, ''::text AS orderhead_from, cohead.cohead_cust_id AS orderhead_to_id, CASE WHEN (length(cohead.cohead_shiptoname) > 0) THEN cohead.cohead_shiptoname ELSE cohead.cohead_billtoname END AS orderhead_to, cohead.cohead_curr_id AS orderhead_curr_id, ''::text AS orderhead_agent_username, cohead.cohead_shipvia AS orderhead_shipvia FROM cohead) data;


ALTER TABLE public.orderhead OWNER TO admin;

--
-- TOC entry 10029 (class 0 OID 0)
-- Dependencies: 702
-- Name: VIEW orderhead; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON VIEW orderhead IS 'Union of all orders for use by widgets and stored procedures which process multiple types of order';


--
-- TOC entry 703 (class 1259 OID 146569540)
-- Dependencies: 8585 8
-- Name: orderitem; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW orderitem AS
    (SELECT poitem.poitem_id AS orderitem_id, 'PO'::text AS orderitem_orderhead_type, poitem.poitem_pohead_id AS orderitem_orderhead_id, poitem.poitem_linenumber AS orderitem_linenumber, poitem.poitem_status AS orderitem_status, poitem.poitem_itemsite_id AS orderitem_itemsite_id, poitem.poitem_duedate AS orderitem_scheddate, poitem.poitem_qty_ordered AS orderitem_qty_ordered, poitem.poitem_qty_returned AS orderitem_qty_shipped, poitem.poitem_qty_received AS orderitem_qty_received, uom.uom_id AS orderitem_qty_uom_id, poitem.poitem_invvenduomratio AS orderitem_qty_invuomratio, poitem.poitem_unitprice AS orderitem_unitcost, pohead.pohead_curr_id AS orderitem_unitcost_curr_id, poitem.poitem_freight AS orderitem_freight, poitem.poitem_freight_received AS orderitem_freight_received, pohead.pohead_curr_id AS orderitem_freight_curr_id FROM ((poitem LEFT JOIN pohead ON ((poitem.poitem_pohead_id = pohead.pohead_id))) LEFT JOIN uom ON ((uom.uom_name = poitem.poitem_vend_uom))) UNION ALL SELECT coitem.coitem_id AS orderitem_id, 'SO'::text AS orderitem_orderhead_type, coitem.coitem_cohead_id AS orderitem_orderhead_id, coitem.coitem_linenumber AS orderitem_linenumber, coitem.coitem_status AS orderitem_status, coitem.coitem_itemsite_id AS orderitem_itemsite_id, coitem.coitem_scheddate AS orderitem_scheddate, coitem.coitem_qtyord AS orderitem_qty_ordered, coitem.coitem_qtyshipped AS orderitem_qty_shipped, coitem.coitem_qtyreturned AS orderitem_qty_received, coitem.coitem_qty_uom_id AS orderitem_qty_uom_id, coitem.coitem_qty_invuomratio AS orderitem_qty_invuomratio, coitem.coitem_unitcost AS orderitem_unitcost, basecurrid() AS orderitem_unitcost_curr_id, NULL::numeric AS orderitem_freight, NULL::numeric AS orderitem_freight_received, basecurrid() AS orderitem_freight_curr_id FROM coitem) UNION ALL SELECT quitem.quitem_id AS orderitem_id, 'QU'::text AS orderitem_orderhead_type, quitem.quitem_quhead_id AS orderitem_orderhead_id, quitem.quitem_linenumber AS orderitem_linenumber, 'O'::bpchar AS orderitem_status, quitem.quitem_itemsite_id AS orderitem_itemsite_id, quitem.quitem_scheddate AS orderitem_scheddate, quitem.quitem_qtyord AS orderitem_qty_ordered, 0 AS orderitem_qty_shipped, 0 AS orderitem_qty_received, quitem.quitem_qty_uom_id AS orderitem_qty_uom_id, quitem.quitem_qty_invuomratio AS orderitem_qty_invuomratio, quitem.quitem_unitcost AS orderitem_unitcost, basecurrid() AS orderitem_unitcost_curr_id, NULL::numeric AS orderitem_freight, NULL::numeric AS orderitem_freight_received, basecurrid() AS orderitem_freight_curr_id FROM quitem;


ALTER TABLE public.orderitem OWNER TO admin;

--
-- TOC entry 10031 (class 0 OID 0)
-- Dependencies: 703
-- Name: VIEW orderitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON VIEW orderitem IS 'Union of all order line items for use by widgets and stored procedures which process multiple types of order';


--
-- TOC entry 704 (class 1259 OID 146569545)
-- Dependencies: 6592 6593 8 2700
-- Name: orderseq; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE orderseq (
    orderseq_id integer DEFAULT nextval(('orderseq_orderseq_id_seq'::text)::regclass) NOT NULL,
    orderseq_name text NOT NULL,
    orderseq_number integer,
    orderseq_table text,
    orderseq_numcol text,
    orderseq_seqiss seqiss[],
    CONSTRAINT orderseq_orderseq_name_check CHECK ((orderseq_name <> ''::text))
);


ALTER TABLE public.orderseq OWNER TO admin;

--
-- TOC entry 10033 (class 0 OID 0)
-- Dependencies: 704
-- Name: TABLE orderseq; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE orderseq IS 'Configuration information for common numbering sequences';


--
-- TOC entry 705 (class 1259 OID 146569553)
-- Dependencies: 8
-- Name: orderseq_orderseq_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE orderseq_orderseq_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    MAXVALUE 2147483647
    CACHE 1;


ALTER TABLE public.orderseq_orderseq_id_seq OWNER TO admin;

--
-- TOC entry 706 (class 1259 OID 146569555)
-- Dependencies: 6595 6596 8
-- Name: pack; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE pack (
    pack_id integer NOT NULL,
    pack_head_id integer NOT NULL,
    pack_head_type text NOT NULL,
    pack_shiphead_id integer,
    pack_printed boolean DEFAULT false NOT NULL,
    CONSTRAINT pack_pack_head_type_check CHECK (((pack_head_type = 'SO'::text) OR (pack_head_type = 'TO'::text)))
);


ALTER TABLE public.pack OWNER TO admin;

--
-- TOC entry 10036 (class 0 OID 0)
-- Dependencies: 706
-- Name: TABLE pack; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE pack IS 'Temporary table for storing information about Orders added to the Packing List Batch';


--
-- TOC entry 707 (class 1259 OID 146569563)
-- Dependencies: 706 8
-- Name: pack_pack_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE pack_pack_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pack_pack_id_seq OWNER TO admin;

--
-- TOC entry 10038 (class 0 OID 0)
-- Dependencies: 707
-- Name: pack_pack_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE pack_pack_id_seq OWNED BY pack.pack_id;


--
-- TOC entry 708 (class 1259 OID 146569565)
-- Dependencies: 6597 6598 8
-- Name: payaropen; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE payaropen (
    payaropen_ccpay_id integer NOT NULL,
    payaropen_aropen_id integer NOT NULL,
    payaropen_amount numeric(20,2) DEFAULT 0.00 NOT NULL,
    payaropen_curr_id integer DEFAULT basecurrid()
);


ALTER TABLE public.payaropen OWNER TO admin;

--
-- TOC entry 10040 (class 0 OID 0)
-- Dependencies: 708
-- Name: TABLE payaropen; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE payaropen IS 'Credit Card payment to credit memo join table';


--
-- TOC entry 709 (class 1259 OID 146569570)
-- Dependencies: 6599 6600 8
-- Name: payco; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE payco (
    payco_ccpay_id integer NOT NULL,
    payco_cohead_id integer NOT NULL,
    payco_amount numeric(20,2) DEFAULT 0.00 NOT NULL,
    payco_curr_id integer DEFAULT basecurrid()
);


ALTER TABLE public.payco OWNER TO admin;

--
-- TOC entry 10042 (class 0 OID 0)
-- Dependencies: 709
-- Name: TABLE payco; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE payco IS 'Credit Card payment to sales order join table';


--
-- TOC entry 710 (class 1259 OID 146569575)
-- Dependencies: 264 8
-- Name: period_period_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE period_period_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.period_period_id_seq OWNER TO admin;

--
-- TOC entry 10044 (class 0 OID 0)
-- Dependencies: 710
-- Name: period_period_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE period_period_id_seq OWNED BY period.period_id;


--
-- TOC entry 711 (class 1259 OID 146569577)
-- Dependencies: 8
-- Name: pkgdep; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE pkgdep (
    pkgdep_id integer NOT NULL,
    pkgdep_pkghead_id integer NOT NULL,
    pkgdep_parent_pkghead_id integer NOT NULL
);


ALTER TABLE public.pkgdep OWNER TO admin;

--
-- TOC entry 10046 (class 0 OID 0)
-- Dependencies: 711
-- Name: TABLE pkgdep; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE pkgdep IS 'Package Dependencies list describing which packages are dependent on which other packages.';


--
-- TOC entry 10047 (class 0 OID 0)
-- Dependencies: 711
-- Name: COLUMN pkgdep.pkgdep_pkghead_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN pkgdep.pkgdep_pkghead_id IS 'This is the internal ID of a package which requires at least one other package to be installed first to operate successfully';


--
-- TOC entry 10048 (class 0 OID 0)
-- Dependencies: 711
-- Name: COLUMN pkgdep.pkgdep_parent_pkghead_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN pkgdep.pkgdep_parent_pkghead_id IS 'This is the internal ID of a package which must be installed for the package pointed to by pkgdep_pkghead_id to operate successfully.';


--
-- TOC entry 712 (class 1259 OID 146569580)
-- Dependencies: 711 8
-- Name: pkgdep_pkgdep_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

CREATE SEQUENCE pkgdep_pkgdep_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pkgdep_pkgdep_id_seq OWNER TO admin;

--
-- TOC entry 10050 (class 0 OID 0)
-- Dependencies: 712
-- Name: pkgdep_pkgdep_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE pkgdep_pkgdep_id_seq OWNED BY pkgdep.pkgdep_id;


--
-- TOC entry 713 (class 1259 OID 146569582)
-- Dependencies: 6603 6604 8
-- Name: pkghead; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE pkghead (
    pkghead_id integer NOT NULL,
    pkghead_name text NOT NULL,
    pkghead_descrip text,
    pkghead_version text NOT NULL,
    pkghead_developer text NOT NULL,
    pkghead_notes text,
    pkghead_created timestamp with time zone,
    pkghead_updated timestamp with time zone,
    pkghead_indev boolean DEFAULT false NOT NULL,
    CONSTRAINT pkghead_pkghead_name_check CHECK ((pkghead_name <> ''::text))
);


ALTER TABLE public.pkghead OWNER TO admin;

--
-- TOC entry 10052 (class 0 OID 0)
-- Dependencies: 713
