-- Name: TABLE cohist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE cohist IS 'Sales Order history';


--
-- Name: COLUMN cohist.cohist_cohead_ccpay_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN cohist.cohist_cohead_ccpay_id IS 'Credit card payments made at sales order time (as opposed to invoice time) need special treatment. This field allows checking for this case.';


--
-- Name: COLUMN cohist.cohist_saletype_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN cohist.cohist_saletype_id IS 'Associated sale type for sales history.';


--
-- Name: COLUMN cohist.cohist_shipzone_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN cohist.cohist_shipzone_id IS 'Associated shipping zone for sales history.';


--
-- Name: taxhist; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE taxhist (
    taxhist_id integer NOT NULL,
    taxhist_parent_id integer NOT NULL,
    taxhist_taxtype_id integer,
    taxhist_tax_id integer NOT NULL,
    taxhist_basis numeric(16,2) NOT NULL,
    taxhist_basis_tax_id integer,
    taxhist_sequence integer,
    taxhist_percent numeric(10,6) NOT NULL,
    taxhist_amount numeric(16,2) NOT NULL,
    taxhist_tax numeric(16,6) NOT NULL,
    taxhist_docdate date NOT NULL,
    taxhist_distdate date,
    taxhist_curr_id integer,
    taxhist_curr_rate numeric,
    taxhist_journalnumber integer
);


ALTER TABLE taxhist OWNER TO admin;

--
-- Name: TABLE taxhist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE taxhist IS 'A table type to record tax transaction history. Inherited by other tables that actually record history. As the parent, queries can be run against it that will join all child tables. ';


--
-- Name: COLUMN taxhist.taxhist_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_id IS 'Primary key';


--
-- Name: COLUMN taxhist.taxhist_parent_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_parent_id IS 'Source parent id.';


--
-- Name: COLUMN taxhist.taxhist_taxtype_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_taxtype_id IS 'Tax type id';


--
-- Name: COLUMN taxhist.taxhist_tax_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_tax_id IS 'Tax code id.';


--
-- Name: COLUMN taxhist.taxhist_basis; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_basis IS 'Base price amount on which the tax calculation is based.';


--
-- Name: COLUMN taxhist.taxhist_basis_tax_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_basis_tax_id IS 'Tax rate calculation basis.  If null, then the amount of the parent document, otherwise calculated on the result amount of the tax code id referenced.';


--
-- Name: COLUMN taxhist.taxhist_amount; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_amount IS 'Flat tax amount.';


--
-- Name: COLUMN taxhist.taxhist_tax; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_tax IS 'Calculated tax amount.';


--
-- Name: COLUMN taxhist.taxhist_docdate; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_docdate IS 'The date of the parent document.';


--
-- Name: COLUMN taxhist.taxhist_distdate; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN taxhist.taxhist_distdate IS 'The G/L distribution date of the parent document.';


--
-- Name: cohisttax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cohisttax (
)
INHERITS (taxhist);


ALTER TABLE cohisttax OWNER TO admin;


--
-- Name: saleshistory; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW saleshistory AS
    SELECT custinfo.cust_number AS customer_number, item.item_number, whsinfo.warehous_code AS site_code, cohist.cohist_shipdate AS ship_date, cohist.cohist_shipvia AS ship_via, cohist.cohist_ordernumber AS order_number, cohist.cohist_ponumber AS purchase_order_number, cohist.cohist_orderdate AS order_date, cohist.cohist_invcnumber AS invoice_number, cohist.cohist_invcdate AS invoice_date, cohist.cohist_qtyshipped AS quantity_shipped, cohist.cohist_unitprice AS unit_price, shiptoinfo.shipto_num AS shipto_number, salesrep.salesrep_number AS sales_rep, cohist.cohist_duedate AS due_date, cohist.cohist_promisedate AS promise_date, cohist.cohist_imported AS imported, cohist.cohist_billtoname AS billto_name, cohist.cohist_billtoaddress1 AS billto_address1, cohist.cohist_billtoaddress2 AS billto_address2, cohist.cohist_billtoaddress3 AS billto_address3, cohist.cohist_billtocity AS billto_city, cohist.cohist_billtostate AS billto_state, cohist.cohist_billtozip AS billto_zip, cohist.cohist_shiptoname AS shipto_name, cohist.cohist_shiptoaddress1 AS shipto_address1, cohist.cohist_shiptoaddress2 AS shipto_address2, cohist.cohist_shiptoaddress3 AS shipto_address3, cohist.cohist_shiptocity AS shipto_city, cohist.cohist_shiptostate AS shipto_state, cohist.cohist_shiptozip AS shipto_zip, cohist.cohist_commission AS commission, cohist.cohist_commissionpaid AS commission_paid, cohist.cohist_unitcost AS unit_cost, CASE WHEN (cohist.cohist_misc_type IS NULL) THEN ''::text WHEN (cohist.cohist_misc_type = 'M'::bpchar) THEN 'Misc. Charge'::text WHEN (cohist.cohist_misc_type = 'F'::bpchar) THEN 'Freight'::text ELSE 'Unknown'::text END AS misc_type, cohist.cohist_misc_descrip AS misc_description, CASE WHEN (cohist.cohist_misc_id IS NULL) THEN ''::text WHEN (cohist.cohist_misc_type = 'M'::bpchar) THEN public.formatglaccount(cohist.cohist_misc_id) ELSE 'Unknown'::text END AS misc_info, taxzone.taxzone_code AS tax_zone, taxtype.taxtype_name AS tax_type, CASE WHEN (cohist.cohist_doctype = 'I'::text) THEN 'Invoice'::text WHEN (cohist.cohist_doctype = 'C'::text) THEN 'Credit Memo'::text ELSE 'Unknown'::text END AS document_type, curr_symbol.curr_abbr AS currency, cohist.cohist_sequence AS gl_sequence, (SELECT sum(cohisttax.taxhist_tax) AS sum FROM public.cohisttax WHERE (cohisttax.taxhist_parent_id = cohist.cohist_id)) AS tax FROM (((((((((public.cohist LEFT JOIN public.custinfo ON ((cohist.cohist_cust_id = custinfo.cust_id))) LEFT JOIN public.shiptoinfo ON ((cohist.cohist_shipto_id = shiptoinfo.shipto_id))) LEFT JOIN public.taxzone ON ((cohist.cohist_taxzone_id = taxzone.taxzone_id))) LEFT JOIN public.taxtype ON ((cohist.cohist_taxtype_id = taxtype.taxtype_id))) LEFT JOIN public.salesrep ON ((cohist.cohist_salesrep_id = salesrep.salesrep_id))) LEFT JOIN public.itemsite ON ((cohist.cohist_itemsite_id = itemsite.itemsite_id))) LEFT JOIN public.item ON ((itemsite.itemsite_item_id = item.item_id))) LEFT JOIN public.whsinfo ON ((itemsite.itemsite_warehous_id = whsinfo.warehous_id))) LEFT JOIN public.curr_symbol ON ((cohist.cohist_curr_id = curr_symbol.curr_id)));


ALTER TABLE saleshistory OWNER TO admin;

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

COMMENT ON VIEW saleshistory IS 'Sales History';


--
-- Name: saleslinechar; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW saleslinechar AS
    SELECT (data.order_number)::character varying AS order_number, data.line_number, data.characteristic, COALESCE(si.charass_value, i3.charass_value) AS value, (COALESCE(si.charass_price, public.itemcharprice(data.item_id, data.char_id, COALESCE(si.charass_value, i3.charass_value), data.cohead_cust_id, data.cohead_shipto_id, data.coitem_qtyord, data.cohead_curr_id, data.cohead_orderdate), (0)::numeric))::numeric(16,4) AS price FROM (((((SELECT DISTINCT cohead.cohead_cust_id, cohead.cohead_shipto_id, cohead.cohead_curr_id, cohead.cohead_orderdate, coitem.coitem_id, coitem.coitem_itemsite_id, coitem.coitem_qtyord, "char".char_id, item.item_id, cohead.cohead_number AS order_number, CASE WHEN (coitem.coitem_subnumber = 0) THEN ((coitem.coitem_linenumber)::character varying)::text ELSE ((((coitem.coitem_linenumber)::character varying)::text || ('.'::character varying)::text) || ((coitem.coitem_subnumber)::character varying)::text) END AS line_number, "char".char_name AS characteristic FROM public.cohead, public.coitem, public.itemsite, public.item, public.charass, public."char" WHERE ((((((cohead.cohead_id = coitem.coitem_cohead_id) AND (coitem.coitem_itemsite_id = itemsite.itemsite_id)) AND (itemsite.itemsite_item_id = item.item_id)) AND (charass.charass_char_id = "char".char_id)) AND (charass.charass_target_type = 'I'::text)) AND (charass.charass_target_id = item.item_id))) data LEFT JOIN public.charass si ON ((((data.coitem_id = si.charass_target_id) AND ('SI'::text = si.charass_target_type)) AND (si.charass_char_id = data.char_id)))) LEFT JOIN public.itemsite i1 ON ((data.coitem_itemsite_id = i1.itemsite_id))) LEFT JOIN public.item i2 ON ((i1.itemsite_item_id = i2.item_id))) LEFT JOIN public.charass i3 ON (((((i2.item_id = i3.charass_target_id) AND ('I'::text = i3.charass_target_type)) AND (i3.charass_char_id = data.char_id)) AND i3.charass_default))) ORDER BY (data.order_number)::character varying, data.line_number, data.characteristic;


ALTER TABLE saleslinechar OWNER TO admin;

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

COMMENT ON VIEW saleslinechar IS 'Sales Order Line Item Characteristic';


--
-- Name: saleslinecomment; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW saleslinecomment AS
    SELECT (cohead.cohead_number)::character varying AS order_number, CASE WHEN (coitem.coitem_subnumber = 0) THEN ((coitem.coitem_linenumber)::character varying)::text ELSE ((((coitem.coitem_linenumber)::character varying)::text || ('.'::character varying)::text) || ((coitem.coitem_subnumber)::character varying)::text) END AS line_number, cmnttype.cmnttype_name AS type, comment.comment_date AS date, comment.comment_user AS username, comment.comment_text AS text FROM public.cohead, public.coitem, public.cmnttype, public.comment WHERE ((((cohead.cohead_id = coitem.coitem_cohead_id) AND (comment.comment_source = 'SI'::text)) AND (comment.comment_source_id = coitem.coitem_id)) AND (comment.comment_cmnttype_id = cmnttype.cmnttype_id)) ORDER BY cohead.cohead_number, coitem.coitem_linenumber, comment.comment_date DESC;


ALTER TABLE saleslinecomment OWNER TO admin;

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

COMMENT ON VIEW saleslinecomment IS 'Sales Order Line Item Comment';


--
-- Name: salesorder; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW salesorder AS
    SELECT (cohead.cohead_number)::character varying AS order_number, whsinfo.warehous_code AS site, cohead.cohead_orderdate AS order_date, cohead.cohead_packdate AS pack_date, saletype.saletype_code AS sale_type, salesrep.salesrep_number AS sales_rep, cohead.cohead_commission AS commission, COALESCE(taxzone.taxzone_code, 'None'::text) AS tax_zone, terms.terms_code AS terms, prj.prj_number AS project_number, custinfo.cust_number AS customer_number, bc.cntct_number AS billto_contact_number, cohead.cohead_billto_cntct_honorific AS billto_contact_name, cohead.cohead_billto_cntct_first_name AS billto_contact_first, cohead.cohead_billto_cntct_middle AS billto_contact_middle, cohead.cohead_billto_cntct_last_name AS billto_contact_last, cohead.cohead_billto_cntct_suffix AS billto_contact_suffix, cohead.cohead_billto_cntct_phone AS billto_contact_phone, cohead.cohead_billto_cntct_title AS billto_contact_title, cohead.cohead_billto_cntct_fax AS billto_contct_fax, cohead.cohead_billto_cntct_email AS billto_contact_email, cohead.cohead_billtoname AS billto_name, cohead.cohead_billtoaddress1 AS billto_address1, cohead.cohead_billtoaddress2 AS billto_address2, cohead.cohead_billtoaddress3 AS billto_address3, cohead.cohead_billtocity AS billto_city, cohead.cohead_billtostate AS billto_state, cohead.cohead_billtozipcode AS billto_postal_code, cohead.cohead_billtocountry AS billto_country, shiptoinfo.shipto_num AS shipto_number, sc.cntct_number AS shipto_contact_number, cohead.cohead_shipto_cntct_honorific AS shipto_contact_honorific, cohead.cohead_shipto_cntct_first_name AS shipto_contact_first, cohead.cohead_shipto_cntct_middle AS shipto_contact_middle, cohead.cohead_shipto_cntct_last_name AS shipto_contact_last, cohead.cohead_shipto_cntct_suffix AS shipto_contact_suffix, cohead.cohead_shipto_cntct_phone AS shipto_contact_phone, cohead.cohead_shipto_cntct_title AS shipto_contact_title, cohead.cohead_shipto_cntct_fax AS shipto_contact_fax, cohead.cohead_shipto_cntct_email AS shipto_contact_email, cohead.cohead_shiptoname AS shipto_name, cohead.cohead_shiptophone AS shipto_phone, cohead.cohead_shiptoaddress1 AS shipto_address1, cohead.cohead_shiptoaddress2 AS shipto_address2, cohead.cohead_shiptoaddress3 AS shipto_address3, cohead.cohead_shiptocity AS shipto_city, cohead.cohead_shiptostate AS shipto_state, cohead.cohead_shiptozipcode AS shipto_postal_code, cohead.cohead_shiptocountry AS shipto_country, shipzone.shipzone_name AS shipto_shipzone, cohead.cohead_custponumber AS cust_po_number, cohead.cohead_fob AS fob, cohead.cohead_shipvia AS ship_via, CASE WHEN (cohead.cohead_holdtype = 'N'::bpchar) THEN 'None'::text WHEN (cohead.cohead_holdtype = 'C'::bpchar) THEN 'Credit'::text WHEN (cohead.cohead_holdtype = 'S'::bpchar) THEN 'Shipping'::text WHEN (cohead.cohead_holdtype = 'P'::bpchar) THEN 'Packing'::text WHEN (cohead.cohead_holdtype = 'R'::bpchar) THEN 'Return'::text ELSE 'Error'::text END AS hold_type, shipchrg.shipchrg_name AS shipping_chgs, shipform.shipform_name AS shipping_form, cohead.cohead_shipcomplete AS ship_complete, curr_symbol.curr_abbr AS currency, cohead.cohead_misc_descrip AS misc_charge_description, CASE WHEN (cohead.cohead_misc_accnt_id IS NULL) THEN NULL::text ELSE public.formatglaccount(cohead.cohead_misc_accnt_id) END AS misc_account_number, cohead.cohead_misc AS misc_charge, cohead.cohead_freight AS freight, cohead.cohead_calcfreight AS calculate_freight, cohead.cohead_ordercomments AS order_notes, cohead.cohead_shipcomments AS shipping_notes, false AS add_to_packing_list_batch FROM (((((((((public.cohead LEFT JOIN public.cntct bc ON ((cohead.cohead_billto_cntct_id = bc.cntct_id))) LEFT JOIN public.cntct sc ON ((cohead.cohead_shipto_cntct_id = sc.cntct_id))) LEFT JOIN public.whsinfo ON ((cohead.cohead_warehous_id = whsinfo.warehous_id))) LEFT JOIN public.prj ON ((cohead.cohead_prj_id = prj.prj_id))) LEFT JOIN public.shiptoinfo ON ((cohead.cohead_shipto_id = shiptoinfo.shipto_id))) LEFT JOIN public.shipchrg ON ((cohead.cohead_shipchrg_id = shipchrg.shipchrg_id))) LEFT JOIN public.taxzone ON ((cohead.cohead_taxzone_id = taxzone.taxzone_id))) LEFT JOIN public.saletype ON ((cohead.cohead_saletype_id = saletype.saletype_id))) LEFT JOIN public.shipzone ON ((cohead.cohead_shipzone_id = shipzone.shipzone_id))), public.custinfo, public.shipform, public.salesrep, public.terms, public.curr_symbol WHERE (((((cohead.cohead_cust_id = custinfo.cust_id) AND (cohead.cohead_shipform_id = shipform.shipform_id)) AND (cohead.cohead_salesrep_id = salesrep.salesrep_id)) AND (cohead.cohead_terms_id = terms.terms_id)) AND (cohead.cohead_curr_id = curr_symbol.curr_id));


ALTER TABLE salesorder OWNER TO admin;

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

COMMENT ON VIEW salesorder IS 'Sales Order';


--
-- Name: salesordercomment; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW salesordercomment AS
    SELECT (cohead.cohead_number)::character varying AS order_number, cmnttype.cmnttype_name AS type, comment.comment_date AS date, comment.comment_user AS username, comment.comment_text AS text FROM public.cohead, public.cmnttype, public.comment WHERE (((comment.comment_source = 'S'::text) AND (comment.comment_source_id = cohead.cohead_id)) AND (comment.comment_cmnttype_id = cmnttype.cmnttype_id));


ALTER TABLE salesordercomment OWNER TO admin;

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

COMMENT ON VIEW salesordercomment IS 'Sales Order Comment';


--
-- Name: salesrep; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW salesrep AS
    SELECT (salesrep.salesrep_number)::character varying AS number, salesrep.salesrep_active AS active, salesrep.salesrep_name AS name, (salesrep.salesrep_commission * (100)::numeric) AS commission_percent, emp.emp_number AS employee FROM (public.salesrep LEFT JOIN public.emp ON ((emp.emp_id = salesrep.salesrep_emp_id))) ORDER BY salesrep.salesrep_number;


ALTER TABLE salesrep OWNER TO admin;

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

COMMENT ON VIEW salesrep IS 'Sales Rep';



--
-- Name: shipvia; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE shipvia (
    shipvia_id integer DEFAULT nextval(('shipvia_shipvia_id_seq'::text)::regclass) NOT NULL,
    shipvia_code text NOT NULL,
    shipvia_descrip text,
    CONSTRAINT shipvia_shipvia_code_check CHECK ((shipvia_code <> ''::text))
);


ALTER TABLE shipvia OWNER TO admin;

--
-- Name: TABLE shipvia; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE shipvia IS 'Ship Via information';


--
-- Name: sitetype; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE sitetype (
    sitetype_id integer NOT NULL,
    sitetype_name text NOT NULL,
    sitetype_descrip text,
    CONSTRAINT sitetype_sitetype_name_check CHECK ((sitetype_name <> ''::text))
);


ALTER TABLE sitetype OWNER TO admin;

--
-- Name: TABLE sitetype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE sitetype IS 'This table is the different types of sites.';



--
-- Name: site; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW site AS
    SELECT (whsinfo.warehous_code)::character varying AS code, st.sitetype_name AS type, whsinfo.warehous_active AS active, whsinfo.warehous_descrip AS description, m.addr_number AS address_number, m.addr_line1 AS address1, m.addr_line2 AS address2, m.addr_line3 AS address3, m.addr_city AS city, m.addr_state AS state, m.addr_postalcode AS postal_code, m.addr_country AS country, ''::text AS address_change, c.cntct_number AS contact_number, c.cntct_honorific AS honorific, c.cntct_first_name AS first, c.cntct_middle AS middle, c.cntct_last_name AS last, c.cntct_suffix AS suffix, c.cntct_title AS job_title, c.cntct_phone AS phone, c.cntct_fax AS fax, c.cntct_email AS email, ''::text AS contact_change, public.formatglaccount(a.accnt_id) AS post_unassigned_transactions_to, a.accnt_descrip AS post_unassigned_transactions_to_description, whsinfo.warehous_transit AS transit_type, CASE WHEN whsinfo.warehous_transit THEN false ELSE true END AS inventory_type, CASE WHEN whsinfo.warehous_transit THEN ''::text ELSE whsinfo.warehous_bol_prefix END AS next_bill_of_lading_prefix, CASE WHEN whsinfo.warehous_transit THEN 0 ELSE whsinfo.warehous_bol_number END AS next_bill_of_lading_number, CASE WHEN whsinfo.warehous_transit THEN false ELSE whsinfo.warehous_shipping END AS shipping_site, CASE WHEN whsinfo.warehous_transit THEN ''::text ELSE whsinfo.warehous_counttag_prefix END AS next_count_tag_prefix, CASE WHEN whsinfo.warehous_transit THEN 0 ELSE whsinfo.warehous_counttag_number END AS next_count_tag_number, CASE WHEN whsinfo.warehous_transit THEN false ELSE whsinfo.warehous_useslips END AS force_the_use_of_count_slips, CASE WHEN whsinfo.warehous_transit THEN false ELSE whsinfo.warehous_usezones END AS force_the_use_of_zones, CASE WHEN whsinfo.warehous_transit THEN 0 ELSE whsinfo.warehous_sequence END AS scheduling_sequence, CASE WHEN whsinfo.warehous_transit THEN (0)::numeric ELSE (whsinfo.warehous_shipping_commission * 100.0) END AS shipping_commission, CASE WHEN whsinfo.warehous_transit THEN ''::text ELSE t.taxzone_code END AS tax_zone, CASE WHEN whsinfo.warehous_transit THEN ''::text ELSE whsinfo.warehous_fob END AS default_fob, CASE WHEN whsinfo.warehous_transit THEN s.shipvia_code ELSE ''::text END AS default_ship_via, CASE WHEN whsinfo.warehous_transit THEN f.shipform_name ELSE ''::text END AS default_shipping_form, CASE WHEN whsinfo.warehous_transit THEN cc.costcat_code ELSE ''::text END AS default_cost_category, CASE WHEN whsinfo.warehous_transit THEN whsinfo.warehous_shipcomments ELSE ''::text END AS shipping_comments, CASE WHEN whsinfo.warehous_transit THEN false ELSE whsinfo.warehous_enforcearbl END AS enforce_arbl_naming_convention, CASE WHEN whsinfo.warehous_transit THEN 0 WHEN whsinfo.warehous_enforcearbl THEN whsinfo.warehous_aislesize ELSE 0 END AS aisle_size, CASE WHEN whsinfo.warehous_transit THEN false WHEN (whsinfo.warehous_enforcearbl AND whsinfo.warehous_aislealpha) THEN true ELSE false END AS aisle_allow_alpha_characters, CASE WHEN whsinfo.warehous_transit THEN 0 WHEN whsinfo.warehous_enforcearbl THEN whsinfo.warehous_racksize ELSE 0 END AS rack_size, CASE WHEN whsinfo.warehous_transit THEN false WHEN (whsinfo.warehous_enforcearbl AND whsinfo.warehous_rackalpha) THEN true ELSE false END AS rack_allow_alpha_characters, CASE WHEN whsinfo.warehous_transit THEN 0 WHEN whsinfo.warehous_enforcearbl THEN whsinfo.warehous_binsize ELSE 0 END AS bin_size, CASE WHEN whsinfo.warehous_transit THEN false WHEN (whsinfo.warehous_enforcearbl AND whsinfo.warehous_binalpha) THEN true ELSE false END AS bin_allow_alpha_characters, CASE WHEN whsinfo.warehous_transit THEN 0 WHEN whsinfo.warehous_enforcearbl THEN whsinfo.warehous_locationsize ELSE 0 END AS location_size, CASE WHEN whsinfo.warehous_transit THEN false WHEN (whsinfo.warehous_enforcearbl AND whsinfo.warehous_locationalpha) THEN true ELSE false END AS location_allow_alpha_characters FROM ((((((((public.whsinfo LEFT JOIN public.addr m ON ((whsinfo.warehous_addr_id = m.addr_id))) LEFT JOIN public.cntct c ON ((whsinfo.warehous_cntct_id = c.cntct_id))) LEFT JOIN public.accnt a ON ((whsinfo.warehous_default_accnt_id = a.accnt_id))) LEFT JOIN public.taxzone t ON ((whsinfo.warehous_taxzone_id = t.taxzone_id))) LEFT JOIN public.shipvia s ON ((whsinfo.warehous_shipvia_id = s.shipvia_id))) LEFT JOIN public.shipform f ON ((whsinfo.warehous_shipform_id = f.shipform_id))) LEFT JOIN public.costcat cc ON ((whsinfo.warehous_costcat_id = cc.costcat_id))) LEFT JOIN public.sitetype st ON ((whsinfo.warehous_sitetype_id = st.sitetype_id))) ORDER BY whsinfo.warehous_code;


ALTER TABLE site OWNER TO admin;

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

COMMENT ON VIEW site IS 'Site';


--
-- Name: sitezone; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW sitezone AS
    SELECT (whsinfo.warehous_code)::character varying AS site, (whsezone.whsezone_name)::character varying AS name, whsezone.whsezone_descrip AS description FROM (public.whsezone LEFT JOIN public.whsinfo ON ((whsinfo.warehous_id = whsezone.whsezone_warehous_id)));


ALTER TABLE sitezone OWNER TO admin;

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

COMMENT ON VIEW sitezone IS 'Site Zone';


--
-- Name: task; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW task AS
    SELECT prj.prj_number AS project_number, prjtask.prjtask_number AS number, CASE WHEN (prjtask.prjtask_status = 'P'::bpchar) THEN 'Concept'::text WHEN (prjtask.prjtask_status = 'O'::bpchar) THEN 'In-Process'::text WHEN (prjtask.prjtask_status = 'C'::bpchar) THEN 'Closed'::text ELSE 'Error'::text END AS status, prjtask.prjtask_name AS name, prjtask.prjtask_descrip AS description, prjtask.prjtask_owner_username AS owner, prjtask.prjtask_username AS assigned_to, prjtask.prjtask_hours_budget AS hours_budgeted, prjtask.prjtask_hours_actual AS hours_actual, prjtask.prjtask_exp_budget AS expenses_budgeted, prjtask.prjtask_exp_actual AS expenses_actual, prjtask.prjtask_due_date AS due, prjtask.prjtask_assigned_date AS assigned, prjtask.prjtask_start_date AS started, prjtask.prjtask_completed_date AS completed FROM (public.prjtask JOIN public.prj ON ((prj.prj_id = prjtask.prjtask_prj_id)));


ALTER TABLE task OWNER TO admin;

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

COMMENT ON VIEW task IS 'Task';


--
-- Name: taskcomment; Type: VIEW; Schema: api; Owner: admin
--

CREATE VIEW taskcomment AS
    SELECT (prj.prj_number)::character varying AS project_number, (prjtask.prjtask_number)::character varying AS task_number, cmnttype.cmnttype_name AS type, comment.comment_date AS date, comment.comment_user AS username, comment.comment_text AS text FROM public.prj, public.prjtask, public.cmnttype, public.comment WHERE ((((comment.comment_source = 'TA'::text) AND (prj.prj_id = prjtask.prjtask_prj_id)) AND (comment.comment_source_id = prjtask.prjtask_id)) AND (comment.comment_cmnttype_id = cmnttype.cmnttype_id));


ALTER TABLE taskcomment OWNER TO admin;

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

COMMENT ON VIEW taskcomment IS 'Task Comment';


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

CREATE VIEW todo AS
    SELECT todoitem.todoitem_id AS task_number, todoitem.todoitem_owner_username AS owner, todoitem.todoitem_username AS assigned_to, todoitem.todoitem_name AS task_name, incdtpriority.incdtpriority_name AS priority, incdt.incdt_number AS incident, ophead.ophead_name AS opportunity, crmacct.crmacct_number AS account, public.formatdate(todoitem.todoitem_due_date) AS date_due, public.formatdate(todoitem.todoitem_assigned_date) AS date_assigned, public.formatdate(todoitem.todoitem_start_date) AS date_started, public.formatdate(todoitem.todoitem_completed_date) AS date_completed, CASE WHEN (todoitem.todoitem_status = 'P'::bpchar) THEN 'Pending Input'::text WHEN (todoitem.todoitem_status = 'D'::bpchar) THEN 'Deferred'::text ELSE 'Neither'::text END AS status, todoitem.todoitem_active AS active, todoitem.todoitem_description AS description, todoitem.todoitem_notes AS notes FROM ((((public.todoitem LEFT JOIN public.incdt ON ((incdt.incdt_id = todoitem.todoitem_incdt_id))) LEFT JOIN public.ophead ON ((ophead.ophead_id = todoitem.todoitem_ophead_id))) LEFT JOIN public.crmacct ON ((crmacct.crmacct_id = todoitem.todoitem_crmacct_id))) LEFT JOIN public.incdtpriority ON ((incdtpriority.incdtpriority_id = todoitem.todoitem_priority_id)));


ALTER TABLE todo OWNER TO admin;

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

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



--
-- 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 vendtype OWNER TO admin;

--
-- Name: TABLE vendtype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE vendtype IS 'Vendor Type information';



--
-- 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 vendor OWNER TO admin;

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

COMMENT ON VIEW vendor IS 'vendor';


--
-- 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 vendoraddress OWNER TO admin;

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

COMMENT ON VIEW vendoraddress IS 'vendor address';


--
-- 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 vendortype OWNER TO admin;

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

COMMENT ON VIEW vendortype IS 'Vendor Type';



--
-- 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 cmd OWNER TO admin;

--
-- Name: TABLE cmd; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 cmd_cmd_id_seq OWNER TO admin;

--
-- Name: cmd_cmd_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cmd_cmd_id_seq OWNED BY cmd.cmd_id;



--
-- 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 pkgcmd OWNER TO admin;


--
-- 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 cmdarg OWNER TO admin;

--
-- Name: TABLE cmdarg; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 cmdarg_cmdarg_id_seq OWNER TO admin;

--
-- Name: cmdarg_cmdarg_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cmdarg_cmdarg_id_seq OWNED BY cmdarg.cmdarg_id;



--
-- 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 pkgcmdarg OWNER TO admin;


--
-- 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 image_image_id_seq OWNER TO admin;


--
-- 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 pkgimage OWNER TO admin;


--
-- 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 metasql OWNER TO admin;

--
-- Name: TABLE metasql; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE metasql IS 'MetaSQL Table';


--
-- 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 metasql_metasql_id_seq OWNER TO admin;

--
-- Name: metasql_metasql_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE metasql_metasql_id_seq OWNED BY metasql.metasql_id;



--
-- 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 pkgmetasql OWNER TO admin;


--
-- 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 priv OWNER TO admin;

--
-- Name: TABLE priv; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE priv IS 'System Privilege information';


--
-- 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 priv_priv_id_seq OWNER TO admin;


--
-- 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 pkgpriv OWNER TO admin;


--
-- 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 report OWNER TO admin;

--
-- Name: TABLE report; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE report IS 'Report definition information';


--
-- 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 report_report_id_seq OWNER TO admin;


--
-- 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 pkgreport OWNER TO admin;


--
-- 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 script OWNER TO admin;

--
-- 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 script_script_id_seq OWNER TO admin;

--
-- Name: script_script_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE script_script_id_seq OWNED BY script.script_id;



--
-- 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 pkgscript OWNER TO admin;


--
-- 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 uiform OWNER TO admin;

--
-- 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 uiform_uiform_id_seq OWNER TO admin;

--
-- Name: uiform_uiform_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE uiform_uiform_id_seq OWNED BY uiform.uiform_id;



--
-- 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 pkguiform OWNER TO admin;


--
-- 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 acalitem OWNER TO admin;

--
-- Name: TABLE acalitem; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 accnt_accnt_id_seq OWNER TO admin;

--
-- 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 addr_addr_id_seq OWNER TO admin;

--
-- Name: addr_addr_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE addr_addr_id_seq OWNED BY addr.addr_id;


--
-- Name: address; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW address AS
    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(addresses.crmacct_id, (-1)) AS crmacct_id, addresses.crmacct_number, addresses.crmacct_name FROM (addr LEFT JOIN ((((SELECT cntct.cntct_addr_id AS join_id, crmacct.crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM (cntct JOIN crmacct ON ((cntct.cntct_crmacct_id = crmacct.crmacct_id))) UNION SELECT vendinfo.vend_addr_id, crmacct.crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM (vendinfo JOIN crmacct ON ((vendinfo.vend_id = crmacct.crmacct_vend_id)))) UNION SELECT vendaddrinfo.vendaddr_addr_id, crmacct.crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM (vendaddrinfo JOIN crmacct ON ((vendaddrinfo.vendaddr_vend_id = crmacct.crmacct_vend_id)))) UNION SELECT taxauth.taxauth_addr_id, crmacct.crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM (taxauth JOIN crmacct ON ((taxauth.taxauth_id = crmacct.crmacct_taxauth_id)))) UNION SELECT shiptoinfo.shipto_addr_id, crmacct.crmacct_id, crmacct.crmacct_number, crmacct.crmacct_name FROM (shiptoinfo JOIN crmacct ON ((shiptoinfo.shipto_cust_id = crmacct.crmacct_cust_id)))) addresses ON ((addr.addr_id = addresses.join_id)));


ALTER TABLE address OWNER TO admin;

--
-- 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 alarm OWNER TO admin;

--
-- Name: TABLE alarm; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 alarm_alarm_id_seq OWNER TO admin;

--
-- Name: alarm_alarm_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE alarm_alarm_id_seq OWNED BY alarm.alarm_id;


--
-- 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 apaccnt OWNER TO admin;

--
-- Name: TABLE apaccnt; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 apaccnt_apaccnt_id_seq OWNER TO admin;

--
-- Name: apaccnt_apaccnt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE apaccnt_apaccnt_id_seq OWNED BY apaccnt.apaccnt_id;


--
-- 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 apapply OWNER TO admin;

--
-- 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';


--
-- 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).';


--
-- 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 apapply_apapply_id_seq OWNER TO admin;

--
-- Name: apapply_apapply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE apapply_apapply_id_seq OWNED BY apapply.apapply_id;


--
-- 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,
    checkhead_alt_curr_rate numeric,
    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 checkhead OWNER TO admin;

--
-- Name: TABLE checkhead; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 apchk OWNER TO admin;

--
-- 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 checkitem OWNER TO admin;

--
-- Name: TABLE checkitem; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 apchkitem OWNER TO admin;

--
-- 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 apcreditapply OWNER TO admin;

--
-- 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';


--
-- 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 apcreditapply_apcreditapply_id_seq OWNER TO admin;

--
-- Name: apcreditapply_apcreditapply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE apcreditapply_apcreditapply_id_seq OWNED BY apcreditapply.apcreditapply_id;


--
-- 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 apmemo OWNER TO admin;

--
-- 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 apopen_apopen_id_seq OWNER TO admin;

--
-- Name: apopentax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE apopentax (
)
INHERITS (taxhist);


ALTER TABLE apopentax OWNER TO admin;

--
-- 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 apselect OWNER TO admin;

--
-- 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';


--
-- 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 apselect_apselect_id_seq OWNER TO admin;

--
-- Name: apselect_apselect_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE apselect_apselect_id_seq OWNED BY apselect.apselect_id;


--
-- 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 araccnt OWNER TO admin;

--
-- Name: TABLE araccnt; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 araccnt_araccnt_id_seq OWNER TO admin;

--
-- 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 arapply OWNER TO admin;

--
-- 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';


--
-- 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 arapply_arapply_id_seq OWNER TO admin;

--
-- Name: arapply_arapply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE arapply_arapply_id_seq OWNED BY arapply.arapply_id;


--
-- 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 cashrcptitem_cashrcptitem_id_seq OWNER TO admin;

--
-- Name: cashrcptitem_cashrcptitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cashrcptitem_cashrcptitem_id_seq OWNED BY cashrcptitem.cashrcptitem_id;


--
-- 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 arcreditapply OWNER TO admin;

--
-- 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';


--
-- 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 arcreditapply_arcreditapply_id_seq OWNER TO admin;

--
-- Name: arcreditapply_arcreditapply_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE arcreditapply_arcreditapply_id_seq OWNED BY arcreditapply.arcreditapply_id;


--
-- 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 armemo OWNER TO admin;

--
-- 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 aropen_aropen_id_seq OWNER TO admin;

--
-- Name: aropentax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE aropentax (
)
INHERITS (taxhist);


ALTER TABLE aropentax OWNER TO admin;

--
-- 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 asohist OWNER TO admin;

--
-- Name: TABLE asohist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE asohist IS 'Archived Sales history';


--
-- 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 asohist_asohist_id_seq OWNER TO admin;

--
-- Name: asohist_asohist_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE asohist_asohist_id_seq OWNED BY asohist.asohist_id;


--
-- Name: asohisttax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE asohisttax (
)
INHERITS (taxhist);


ALTER TABLE asohisttax OWNER TO admin;

--
-- 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 atlasmap OWNER TO admin;

--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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 atlasmap_atlasmap_id_seq OWNER TO admin;

--
-- Name: atlasmap_atlasmap_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE atlasmap_atlasmap_id_seq OWNED BY atlasmap.atlasmap_id;


--
-- 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 backup_usr OWNER TO admin;

--
-- 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 bankaccnt_bankaccnt_id_seq OWNER TO admin;

--
-- Name: bankaccnt_bankaccnt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankaccnt_bankaccnt_id_seq OWNED BY bankaccnt.bankaccnt_id;


--
-- 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 bankadj OWNER TO admin;

--
-- Name: TABLE bankadj; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE bankadj IS 'Bank Adjustments information';


--
-- 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 bankadj_bankadj_id_seq OWNER TO admin;

--
-- Name: bankadj_bankadj_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankadj_bankadj_id_seq OWNED BY bankadj.bankadj_id;


--
-- 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 bankadjtype OWNER TO admin;

--
-- Name: TABLE bankadjtype; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 bankadjtype_bankadjtype_id_seq OWNER TO admin;

--
-- Name: bankadjtype_bankadjtype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankadjtype_bankadjtype_id_seq OWNED BY bankadjtype.bankadjtype_id;


--
-- 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 bankrec OWNER TO admin;

--
-- Name: TABLE bankrec; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 bankrec_bankrec_id_seq OWNER TO admin;

--
-- Name: bankrec_bankrec_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankrec_bankrec_id_seq OWNED BY bankrec.bankrec_id;


--
-- Name: bankrecimport; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE bankrecimport (
    bankrecimport_id integer NOT NULL,
    bankrecimport_reference text,
    bankrecimport_descrip text,
    bankrecimport_comment text,
    bankrecimport_debit_amount numeric,
    bankrecimport_credit_amount numeric,
    bankrecimport_effdate date,
    bankrecimport_curr_rate numeric
);


ALTER TABLE bankrecimport OWNER TO admin;

--
-- Name: bankrecimport_bankrecimport_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE bankrecimport_bankrecimport_id_seq OWNER TO admin;

--
-- Name: bankrecimport_bankrecimport_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankrecimport_bankrecimport_id_seq OWNED BY bankrecimport.bankrecimport_id;


--
-- 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,
    bankrecitem_effdate date
);


ALTER TABLE bankrecitem OWNER TO admin;

--
-- Name: TABLE bankrecitem; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 bankrecitem_bankrecitem_id_seq OWNER TO admin;

--
-- Name: bankrecitem_bankrecitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bankrecitem_bankrecitem_id_seq OWNED BY bankrecitem.bankrecitem_id;


--
-- 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 bomhead_bomhead_id_seq OWNER TO admin;

--
-- 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 bomitem_bomitem_id_seq OWNER TO admin;

--
-- 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 bomitemcost OWNER TO admin;

--
-- Name: TABLE bomitemcost; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE bomitemcost IS 'Bomitem Cost information';


--
-- 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 bomitemcost_bomitemcost_id_seq OWNER TO admin;

--
-- Name: bomitemcost_bomitemcost_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bomitemcost_bomitemcost_id_seq OWNED BY bomitemcost.bomitemcost_id;


--
-- 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 bomitemsub_bomitemsub_id_seq OWNER TO admin;

--
-- Name: bomitemsub_bomitemsub_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bomitemsub_bomitemsub_id_seq OWNED BY bomitemsub.bomitemsub_id;


--
-- 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 bomwork OWNER TO admin;

--
-- 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';


--
-- Name: COLUMN bomwork.bomwork_qtyfxd; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- Name: COLUMN bomwork.bomwork_qtyreq; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 bomwork_bomwork_id_seq OWNER TO admin;

--
-- Name: bomwork_bomwork_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE bomwork_bomwork_id_seq OWNED BY bomwork.bomwork_id;


--
-- 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 budget OWNER TO admin;

--
-- 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 budghead_budghead_id_seq OWNER TO admin;

--
-- Name: budghead_budghead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE budghead_budghead_id_seq OWNED BY budghead.budghead_id;


--
-- 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 budgitem_budgitem_id_seq OWNER TO admin;

--
-- Name: budgitem_budgitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE budgitem_budgitem_id_seq OWNED BY budgitem.budgitem_id;


--
-- 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 calhead OWNER TO admin;

--
-- Name: TABLE calhead; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE calhead IS 'Calendar header information';


--
-- 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 calhead_calhead_id_seq OWNER TO admin;

--
-- 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 carrier_carrier_id_seq OWNER TO admin;

--
-- 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 cashrcpt_cashrcpt_id_seq OWNER TO admin;

--
-- Name: cashrcpt_cashrcpt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cashrcpt_cashrcpt_id_seq OWNED BY cashrcpt.cashrcpt_id;


--
-- 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 cashrcptmisc_cashrcptmisc_id_seq OWNER TO admin;

--
-- Name: cashrcptmisc_cashrcptmisc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cashrcptmisc_cashrcptmisc_id_seq OWNED BY cashrcptmisc.cashrcptmisc_id;


--
-- 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 ccard_ccard_id_seq OWNER TO admin;

--
-- Name: ccard_ccard_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ccard_ccard_id_seq OWNED BY ccard.ccard_id;


--
-- 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 ccardaud OWNER TO admin;

--
-- Name: TABLE ccardaud; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 ccardaud_ccardaud_id_seq OWNER TO admin;

--
-- Name: ccardaud_ccardaud_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ccardaud_ccardaud_id_seq OWNED BY ccardaud.ccardaud_id;


--
-- 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, 'O'::text])))
);


ALTER TABLE ccbank OWNER TO admin;

--
-- 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 ccbank_ccbank_id_seq OWNER TO admin;

--
-- Name: ccbank_ccbank_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ccbank_ccbank_id_seq OWNED BY ccbank.ccbank_id;


--
-- 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,
    ccpay_card_pan_trunc text,
    ccpay_card_type text
);


ALTER TABLE ccpay OWNER TO admin;

--
-- 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.';


--
-- Name: COLUMN ccpay.ccpay_id; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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.';


--
-- 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';


--
-- Name: COLUMN ccpay.ccpay_amount; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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).';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- Name: COLUMN ccpay.ccpay_r_tax; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- Name: COLUMN ccpay.ccpay_r_shipping; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- Name: COLUMN ccpay.ccpay_card_pan_trunc; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_card_pan_trunc IS 'External Pre-Auth truncated PAN. Last four digits of the card.';


--
-- Name: COLUMN ccpay.ccpay_card_type; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN ccpay.ccpay_card_type IS 'External Pre-Auth card type: V=Visa, M=MasterCard, A=American Express, D=Discover.';


--
-- 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 ccpay_ccpay_id_seq OWNER TO admin;

--
-- Name: ccpay_ccpay_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ccpay_ccpay_id_seq OWNED BY ccpay.ccpay_id;


--
-- 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 char_char_id_seq OWNER TO admin;

--
-- Name: char_char_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE char_char_id_seq OWNED BY "char".char_id;


--
-- 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 charass_charass_id_seq OWNER TO admin;

--
-- Name: charass_charass_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE charass_charass_id_seq OWNED BY charass.charass_id;


--
-- 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 charopt OWNER TO admin;

--
-- Name: TABLE charopt; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- Name: COLUMN charopt.charopt_id; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- Name: COLUMN charopt.charopt_char_id; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- Name: COLUMN charopt.charopt_value; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- Name: COLUMN charopt.charopt_order; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 charopt_charopt_id_seq OWNER TO admin;

--
-- Name: charopt_charopt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE charopt_charopt_id_seq OWNED BY charopt.charopt_id;


--
-- Name: charuse; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE charuse (
    charuse_id integer NOT NULL,
    charuse_char_id integer,
    charuse_target_type text DEFAULT ''::text NOT NULL,
    charuse_created timestamp with time zone DEFAULT now() NOT NULL,
    charuse_last_modified timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE charuse OWNER TO admin;

--
-- Name: COLUMN charuse.charuse_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN charuse.charuse_id IS 'Internal ID of this charuse record.';


--
-- Name: COLUMN charuse.charuse_target_type; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN charuse.charuse_target_type IS 'If a row exists in the charuse table for a given target type, characteristic assignments can be used';


--
-- Name: charuse_charuse_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE charuse_charuse_id_seq OWNER TO admin;

--
-- Name: charuse_charuse_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE charuse_charuse_id_seq OWNED BY charuse.charuse_id;


--
-- 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 checkhead_checkhead_id_seq OWNER TO admin;

--
-- Name: checkhead_checkhead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE checkhead_checkhead_id_seq OWNED BY checkhead.checkhead_id;


--
-- 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 checkitem_checkitem_id_seq OWNER TO admin;

--
-- Name: checkitem_checkitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE checkitem_checkitem_id_seq OWNED BY checkitem.checkitem_id;


--
-- 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 checkrecip OWNER TO admin;

--
-- 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 classcode_classcode_id_seq OWNER TO admin;

--
-- 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 cmhead_cmhead_id_seq OWNER TO admin;

--
-- Name: cmheadtax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cmheadtax (
)
INHERITS (taxhist);


ALTER TABLE cmheadtax OWNER TO admin;

--
-- 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 cmitem_cmitem_id_seq OWNER TO admin;

--
-- Name: cmitemtax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cmitemtax (
)
INHERITS (taxhist);


ALTER TABLE cmitemtax OWNER TO admin;

--
-- 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 cmnttype_cmnttype_id_seq OWNER TO admin;

--
-- Name: cmnttype_cmnttype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cmnttype_cmnttype_id_seq OWNED BY cmnttype.cmnttype_id;


--
-- Name: cmnttypesource; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

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


ALTER TABLE cmnttypesource OWNER TO admin;

--
-- Name: TABLE cmnttypesource; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE cmnttypesource IS 'Description of which types of comment the user should be allowed to select for various types of document (source).';


--
-- 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 cmnttypesource_cmnttypesource_id_seq OWNER TO admin;

--
-- Name: cmnttypesource_cmnttypesource_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cmnttypesource_cmnttypesource_id_seq OWNED BY cmnttypesource.cmnttypesource_id;


--
-- 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 cntct_cntct_id_seq OWNER TO admin;

--
-- Name: cntct_cntct_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cntct_cntct_id_seq OWNED BY cntct.cntct_id;


--
-- 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 cntctaddr OWNER TO admin;

--
-- 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 cntctaddr_cntctaddr_id_seq OWNER TO admin;

--
-- Name: cntctaddr_cntctaddr_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cntctaddr_cntctaddr_id_seq OWNED BY cntctaddr.cntctaddr_id;


--
-- 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 cntctdata OWNER TO admin;

--
-- 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 cntctdata_cntctdata_id_seq OWNER TO admin;

--
-- Name: cntctdata_cntctdata_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cntctdata_cntctdata_id_seq OWNED BY cntctdata.cntctdata_id;


--
-- 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 cntcteml OWNER TO admin;

--
-- Name: TABLE cntcteml; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- Name: COLUMN cntcteml.cntcteml_id; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- Name: COLUMN cntcteml.cntcteml_cntct_id; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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';


--
-- Name: COLUMN cntcteml.cntcteml_email; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 cntcteml_cntcteml_id_seq OWNER TO admin;

--
-- Name: cntcteml_cntcteml_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE cntcteml_cntcteml_id_seq OWNED BY cntcteml.cntcteml_id;


--
-- 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 cntctmrgd OWNER TO admin;

--
-- 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 cntctsel OWNER TO admin;

--
-- 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 cntslip_cntslip_id_seq OWNER TO admin;

--
-- 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 cobill OWNER TO admin;

--
-- Name: TABLE cobill; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 cobill_cobill_id_seq OWNER TO admin;

--
-- Name: cobilltax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cobilltax (
)
INHERITS (taxhist);


ALTER TABLE cobilltax OWNER TO admin;

--
-- 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 cobmisc OWNER TO admin;

--
-- Name: TABLE cobmisc; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 cobmisc_cobmisc_id_seq OWNER TO admin;

--
-- Name: cobmisctax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE cobmisctax (
)
INHERITS (taxhist);


ALTER TABLE cobmisctax OWNER TO admin;

--
-- 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 cohead_cohead_id_seq OWNER TO admin;

--
-- 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 cohist_cohist_id_seq OWNER TO admin;

--
-- 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 coitem_coitem_id_seq OWNER TO admin;

--
-- 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 comment_comment_id_seq OWNER TO admin;

--
-- 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,
    company_unassigned_accnt_id integer,
    CONSTRAINT company_company_number_check CHECK ((company_number <> ''::text))
);


ALTER TABLE company OWNER TO admin;

--
-- Name: TABLE company; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE company IS 'Company information';


--
-- 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 company_company_id_seq OWNER TO admin;

--
-- Name: company_company_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE company_company_id_seq OWNED BY company.company_id;


--
-- 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 contrct_contrct_id_seq OWNER TO admin;

--
-- Name: contrct_contrct_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE contrct_contrct_id_seq OWNED BY contrct.contrct_id;


--
-- 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 shiphead OWNER TO admin;

--
-- Name: TABLE shiphead; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 shipitem OWNER TO admin;

--
-- Name: TABLE shipitem; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 coship OWNER TO admin;

--
-- 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 coship_coship_id_seq OWNER TO admin;

--
-- 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 cosmisc OWNER TO admin;

--
-- 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 cosmisc_cosmisc_id_seq OWNER TO admin;

--
-- 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 cosrc_cosrc_id_seq OWNER TO admin;

--
-- 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 costcat_costcat_id_seq OWNER TO admin;

--
-- 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 costelem_costelem_id_seq OWNER TO admin;

--
-- 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 costhist OWNER TO admin;

--
-- Name: TABLE costhist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE costhist IS 'Item Cost history';


--
-- 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 costhist_costhist_id_seq OWNER TO admin;

--
-- 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 costupdate OWNER TO admin;

--
-- Name: TABLE costupdate; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 country OWNER TO admin;

--
-- Name: TABLE country; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 country_country_id_seq OWNER TO admin;

--
-- Name: country_country_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE country_country_id_seq OWNED BY country.country_id;


--
-- 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 salesaccnt OWNER TO admin;

--
-- Name: TABLE salesaccnt; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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.';


--
-- 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.';


--
-- 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 creditmemoeditlist OWNER TO admin;

--
-- 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 creditmemoitem OWNER TO admin;

--
-- Name: VIEW creditmemoitem; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 crmacct_crmacct_id_seq OWNER TO admin;

--
-- Name: crmacct_crmacct_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE crmacct_crmacct_id_seq OWNED BY crmacct.crmacct_id;


--
-- 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 crmacctsel OWNER TO admin;

--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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 curr_rate OWNER TO admin;

--
-- Name: TABLE curr_rate; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 curr_rate_curr_rate_id_seq OWNER TO admin;

--
-- 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;


--
-- 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 curr_symbol_curr_id_seq OWNER TO admin;

--
-- 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;


--
-- 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 cust OWNER TO admin;

--
-- 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 cust_serial_seq OWNER TO admin;

--
-- 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 custform OWNER TO admin;

--
-- Name: TABLE custform; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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 custform_custform_id_seq OWNER TO admin;

--
-- 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 custgrp OWNER TO admin;

--
-- Name: TABLE custgrp; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE custgrp IS 'Customer Group information';


--
-- 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 custgrp_custgrp_id_seq OWNER TO admin;

--
-- 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 custgrpitem OWNER TO admin;

--
-- Name: TABLE custgrpitem; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 custgrpitem_custgrpitem_id_seq OWNER TO admin;

--
-- 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 custtype_custtype_id_seq OWNER TO admin;

--
-- 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 dept_dept_id_seq OWNER TO admin;

--
-- Name: dept_dept_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE dept_dept_id_seq OWNED BY dept.dept_id;


--
-- 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 destination OWNER TO admin;

--
-- Name: TABLE destination; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE destination IS 'Destination information';


--
-- 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 destination_destination_id_seq OWNER TO admin;

--
-- Name: docinfo; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW docinfo AS
    SELECT outer_wrapper.id, outer_wrapper.target_number, outer_wrapper.target_type, outer_wrapper.target_id, outer_wrapper.source_type_docinfo, outer_wrapper.source_id_docinfo, outer_wrapper.name, outer_wrapper.description, outer_wrapper.purpose, outer_wrapper.source_type, outer_wrapper.source_id FROM (SELECT (unnest(inner_wrapper._docinfo)).id AS id, (unnest(inner_wrapper._docinfo)).target_number AS target_number, (unnest(inner_wrapper._docinfo)).target_type AS target_type, (unnest(inner_wrapper._docinfo)).target_id AS target_id, (unnest(inner_wrapper._docinfo)).source_type AS source_type_docinfo, (unnest(inner_wrapper._docinfo)).source_id AS source_id_docinfo, (unnest(inner_wrapper._docinfo)).name AS name, (unnest(inner_wrapper._docinfo)).description AS description, (unnest(inner_wrapper._docinfo)).purpose AS purpose, inner_wrapper.source_type, inner_wrapper.source_id FROM (SELECT docinfo.docass_source_type, docinfo.docass_source_id, docinfo.source_type, docinfo.source_id, ARRAY(SELECT _docinfo(docinfo.docass_source_id, docinfo.docass_source_type) AS _docinfo) AS _docinfo FROM (SELECT docass.docass_source_type, docass.docass_source_id, docass.docass_source_type AS source_type, docass.docass_source_id AS source_id FROM docass) docinfo) inner_wrapper) outer_wrapper;


ALTER TABLE docinfo OWNER TO admin;

--
-- 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 emp_emp_id_seq OWNER TO admin;

--
-- Name: emp_emp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE emp_emp_id_seq OWNED BY emp.emp_id;


--
-- 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 empgrp OWNER TO admin;

--
-- 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 empgrp_empgrp_id_seq OWNER TO admin;

--
-- Name: empgrp_empgrp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE empgrp_empgrp_id_seq OWNED BY empgrp.empgrp_id;


--
-- 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 empgrpitem OWNER TO admin;

--
-- 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 empgrpitem_empgrpitem_id_seq OWNER TO admin;

--
-- Name: empgrpitem_empgrpitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE empgrpitem_empgrpitem_id_seq OWNED BY empgrpitem.empgrpitem_id;


--
-- 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 evntlog OWNER TO admin;

--
-- Name: TABLE evntlog; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE evntlog IS 'Event Notification history';


--
-- 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 evntlog_evntlog_id_seq OWNER TO admin;

--
-- 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 evntnot OWNER TO admin;

--
-- Name: TABLE evntnot; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 evntnot_evntnot_id_seq OWNER TO admin;

--
-- 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 evnttype OWNER TO admin;

--
-- Name: TABLE evnttype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE evnttype IS 'Event Type information';


--
-- 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 evnttype_evnttype_id_seq OWNER TO admin;

--
-- 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 expcat_expcat_id_seq OWNER TO admin;

--
-- Name: expcat_expcat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE expcat_expcat_id_seq OWNED BY expcat.expcat_id;


--
-- 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 file_file_id_seq OWNER TO admin;

--
-- Name: file_file_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE file_file_id_seq OWNED BY file.file_id;


--
-- 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 filter OWNER TO admin;

--
-- 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 filter_filter_id_seq OWNER TO admin;

--
-- Name: filter_filter_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE filter_filter_id_seq OWNED BY filter.filter_id;


--
-- 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 fincharg OWNER TO admin;

--
-- Name: TABLE fincharg; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 fincharg_fincharg_id_seq OWNER TO admin;

--
-- Name: fincharg_fincharg_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE fincharg_fincharg_id_seq OWNED BY fincharg.fincharg_id;


--
-- 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 flhead OWNER TO admin;

--
-- Name: TABLE flhead; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 flitem OWNER TO admin;

--
-- Name: TABLE flitem; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 flaccnt OWNER TO admin;

--
-- 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 flcol OWNER TO admin;

--
-- 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 flcol_flcol_id_seq OWNER TO admin;

--
-- Name: flcol_flcol_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flcol_flcol_id_seq OWNED BY flcol.flcol_id;


--
-- 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 flgrp OWNER TO admin;

--
-- Name: TABLE flgrp; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 flgrp_flgrp_id_seq OWNER TO admin;

--
-- Name: flgrp_flgrp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flgrp_flgrp_id_seq OWNED BY flgrp.flgrp_id;


--
-- 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 flhead_flhead_id_seq OWNER TO admin;

--
-- Name: flhead_flhead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flhead_flhead_id_seq OWNED BY flhead.flhead_id;


--
-- 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 flitem_flitem_id_seq OWNER TO admin;

--
-- Name: flitem_flitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flitem_flitem_id_seq OWNED BY flitem.flitem_id;


--
-- 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 flnotes OWNER TO admin;

--
-- 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 flnotes_flnotes_id_seq OWNER TO admin;

--
-- Name: flnotes_flnotes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flnotes_flnotes_id_seq OWNED BY flnotes.flnotes_id;


--
-- 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 flrpt OWNER TO admin;

--
-- 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.';


--
-- 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 flrpt_flrpt_id_seq OWNER TO admin;

--
-- Name: flrpt_flrpt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flrpt_flrpt_id_seq OWNED BY flrpt.flrpt_id;


--
-- 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 flspec OWNER TO admin;

--
-- Name: TABLE flspec; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 flspec_flspec_id_seq OWNER TO admin;

--
-- Name: flspec_flspec_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE flspec_flspec_id_seq OWNED BY flspec.flspec_id;


--
-- 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 form OWNER TO admin;

--
-- Name: TABLE form; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE form IS 'Form information';


--
-- 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.';


--
-- 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 form_form_id_seq OWNER TO admin;

--
-- 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 freightclass_freightclass_id_seq OWNER TO admin;

--
-- Name: freightclass_freightclass_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE freightclass_freightclass_id_seq OWNED BY freightclass.freightclass_id;


--
-- 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 glseries OWNER TO admin;

--
-- 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';


--
-- 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 glseries_glseries_id_seq OWNER TO admin;

--
-- 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 gltrans_gltrans_id_seq OWNER TO admin;

--
-- 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 gltrans_sequence_seq OWNER TO admin;

--
-- 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 grp OWNER TO admin;

--
-- Name: TABLE grp; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 grp_grp_id_seq OWNER TO admin;

--
-- Name: grp_grp_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE grp_grp_id_seq OWNED BY grp.grp_id;


--
-- 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 grppriv OWNER TO admin;

--
-- Name: TABLE grppriv; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 grppriv_grppriv_id_seq OWNER TO admin;

--
-- Name: grppriv_grppriv_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE grppriv_grppriv_id_seq OWNED BY grppriv.grppriv_id;


--
-- 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 hnfc OWNER TO admin;

--
-- Name: TABLE hnfc; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 hnfc_hnfc_id_seq OWNER TO admin;

--
-- Name: hnfc_hnfc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE hnfc_hnfc_id_seq OWNED BY hnfc.hnfc_id;


--
-- 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 incdt_incdt_id_seq OWNER TO admin;

--
-- Name: incdt_incdt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdt_incdt_id_seq OWNED BY incdt.incdt_id;


--
-- 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 incdtcat_incdtcat_id_seq OWNER TO admin;

--
-- Name: incdtcat_incdtcat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdtcat_incdtcat_id_seq OWNED BY incdtcat.incdtcat_id;


--
-- 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 incdthist OWNER TO admin;

--
-- Name: TABLE incdthist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE incdthist IS 'Incident history changes';


--
-- 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 incdthist_incdthist_id_seq OWNER TO admin;

--
-- Name: incdthist_incdthist_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdthist_incdthist_id_seq OWNED BY incdthist.incdthist_id;


--
-- 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 incdtpriority_incdtpriority_id_seq OWNER TO admin;

--
-- Name: incdtpriority_incdtpriority_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdtpriority_incdtpriority_id_seq OWNED BY incdtpriority.incdtpriority_id;


--
-- 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 incdtresolution_incdtresolution_id_seq OWNER TO admin;

--
-- Name: incdtresolution_incdtresolution_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdtresolution_incdtresolution_id_seq OWNED BY incdtresolution.incdtresolution_id;


--
-- 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 incdtseverity_incdtseverity_id_seq OWNER TO admin;

--
-- Name: incdtseverity_incdtseverity_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE incdtseverity_incdtseverity_id_seq OWNED BY incdtseverity.incdtseverity_id;


--
-- 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 invbal_invbal_id_seq OWNER TO admin;

--
-- Name: invbal_invbal_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE invbal_invbal_id_seq OWNED BY invbal.invbal_id;


--
-- 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 invc_invc_id_seq OWNER TO admin;

--
-- 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 invchead_invchead_id_seq OWNER TO admin;

--
-- Name: invchead_invchead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE invchead_invchead_id_seq OWNED BY invchead.invchead_id;


--
-- Name: invcheadtax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE invcheadtax (
)
INHERITS (taxhist);


ALTER TABLE invcheadtax OWNER TO admin;

--
-- 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 invcitem_invcitem_id_seq OWNER TO admin;

--
-- Name: invcitem_invcitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE invcitem_invcitem_id_seq OWNED BY invcitem.invcitem_id;


--
-- Name: invcitemtax; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE invcitemtax (
)
INHERITS (taxhist);


ALTER TABLE invcitemtax OWNER TO admin;

--
-- 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 invcnt_invcnt_id_seq OWNER TO admin;

--
-- 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 invdetail OWNER TO admin;

--
-- 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';


--
-- 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 invdetail_invdetail_id_seq OWNER TO admin;

--
-- 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 invhist OWNER TO admin;

--
-- Name: TABLE invhist; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE invhist IS 'Inventory transaction history';


--
-- 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 invhist_invhist_id_seq OWNER TO admin;

--
-- 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 invhistexpcat OWNER TO admin;

--
-- 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.';


--
-- 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 invhistexpcat_invhistexpcat_id_seq OWNER TO admin;

--
-- Name: invhistexpcat_invhistexpcat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE invhistexpcat_invhistexpcat_id_seq OWNED BY invhistexpcat.invhistexpcat_id;


--
-- 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.0) 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 invoiceitem OWNER TO admin;

--
-- Name: VIEW invoiceitem; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 ipsass_ipsass_id_seq OWNER TO admin;

--
-- Name: ipsass_ipsass_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ipsass_ipsass_id_seq OWNED BY ipsass.ipsass_id;


--
-- 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 ipsctyp_ipsctyp_id_seq OWNER TO admin;

--
-- 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 ipscust_ipscust_id_seq OWNER TO admin;

--
-- 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 ipsfreight_ipsfreight_id_seq OWNER TO admin;

--
-- Name: ipsfreight_ipsfreight_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ipsfreight_ipsfreight_id_seq OWNED BY ipsfreight.ipsfreight_id;


--
-- 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 ipshead_ipshead_id_seq OWNER TO admin;

--
-- 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 ipsitem_ipsitem_id_seq OWNER TO admin;

--
-- 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 ipsitemchar_ipsitemchar_id_seq OWNER TO admin;

--
-- Name: ipsitemchar_ipsitemchar_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ipsitemchar_ipsitemchar_id_seq OWNED BY ipsitemchar.ipsitemchar_id;


--
-- 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 ipsprice OWNER TO admin;

--
-- 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 ipsprodcat_bak OWNER TO admin;

--
-- Name: TABLE ipsprodcat_bak; Type: COMMENT; Schema: public; Owner: admin
--

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


--
-- 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 ipsprodcat_ipsprodcat_id_seq OWNER TO admin;

--
-- 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;


--
-- 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 item_item_id_seq OWNER TO admin;

--
-- 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 itemalias_itemalias_id_seq OWNER TO admin;

--
-- 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 itematr_itematr_id_seq OWNER TO admin;

--
-- 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 itemcost_itemcost_id_seq OWNER TO admin;

--
-- 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 itemfrez_itemfrez_seq OWNER TO admin;

--
-- 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 itemgrp OWNER TO admin;

--
-- Name: TABLE itemgrp; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemgrp IS 'Item Group information';


--
-- 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 itemgrp_itemgrp_id_seq OWNER TO admin;

--
-- 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 itemgrpitem OWNER TO admin;

--
-- Name: TABLE itemgrpitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemgrpitem IS 'Item Group Item information';


--
-- 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 itemgrpitem_itemgrpitem_id_seq OWNER TO admin;

--
-- 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 itemimage OWNER TO admin;

--
-- 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';


--
-- 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 itemimage_itemimage_id_seq OWNER TO admin;

--
-- 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 itemloc OWNER TO admin;

--
-- 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';


--
-- 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 itemloc_itemloc_id_seq OWNER TO admin;

--
-- 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 itemloc_series_seq OWNER TO admin;

--
-- 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 itemlocdist OWNER TO admin;

--
-- 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';


--
-- 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 itemlocdist_itemlocdist_id_seq OWNER TO admin;

--
-- 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 itemlocpost OWNER TO admin;

--
-- 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';


--
-- 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 itemlocpost_itemlocpost_id_seq OWNER TO admin;

--
-- Name: itemlocpost_itemlocpost_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemlocpost_itemlocpost_id_seq OWNED BY itemlocpost.itemlocpost_id;


--
-- 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 itemopn_itemopn_id_seq OWNER TO admin;

--
-- 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 itemsite_itemsite_id_seq OWNER TO admin;

--
-- 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 itemsrc_itemsrc_id_seq OWNER TO admin;

--
-- 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 itemsrcp_itemsrcp_id_seq OWNER TO admin;

--
-- 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 itemsub_itemsub_id_seq OWNER TO admin;

--
-- 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 itemtax_itemtax_id_seq OWNER TO admin;

--
-- Name: itemtax_itemtax_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemtax_itemtax_id_seq OWNED BY itemtax.itemtax_id;


--
-- 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 itemtrans OWNER TO admin;

--
-- Name: TABLE itemtrans; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemtrans IS 'Item Transformation information';


--
-- 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 itemtrans_itemtrans_id_seq OWNER TO admin;

--
-- Name: itemtrans_itemtrans_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemtrans_itemtrans_id_seq OWNED BY itemtrans.itemtrans_id;


--
-- 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 itemuom OWNER TO admin;

--
-- Name: TABLE itemuom; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE itemuom IS 'A UOM type relation for a specific conversion.';


--
-- 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 itemuom_itemuom_id_seq OWNER TO admin;

--
-- Name: itemuom_itemuom_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemuom_itemuom_id_seq OWNED BY itemuom.itemuom_id;


--
-- 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 itemuomconv_itemuomconv_id_seq OWNER TO admin;

--
-- Name: itemuomconv_itemuomconv_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE itemuomconv_itemuomconv_id_seq OWNED BY itemuomconv.itemuomconv_id;


--
-- 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 journal_number_seq OWNER TO admin;

--
-- 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 jrnluse OWNER TO admin;

--
-- Name: TABLE jrnluse; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE jrnluse IS 'Journal entry and use information';


--
-- 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 jrnluse_jrnluse_id_seq OWNER TO admin;

--
-- 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 labeldef OWNER TO admin;

--
-- 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 labeldef_labeldef_id_seq OWNER TO admin;

--
-- Name: labeldef_labeldef_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE labeldef_labeldef_id_seq OWNED BY labeldef.labeldef_id;


--
-- 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 labelform OWNER TO admin;

--
-- Name: TABLE labelform; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE labelform IS 'Label Form information';


--
-- 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.';


--
-- 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 labelform_labelform_id_seq OWNER TO admin;

--
-- 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 lang OWNER TO admin;

--
-- 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..';


--
-- 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';


--
-- Name: COLUMN lang.lang_abbr2; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN lang.lang_abbr2 IS 'ISO 639-1 code for language';


--
-- 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';


--
-- 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 lang_lang_id_seq OWNER TO admin;

--
-- Name: lang_lang_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE lang_lang_id_seq OWNED BY lang.lang_id;


--
-- 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 locale OWNER TO admin;

--
-- 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.';


--
-- Name: COLUMN locale.locale_lang_file; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_lang_file IS 'Deprecated';


--
-- Name: COLUMN locale.locale_dateformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_dateformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_currformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_currformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_qtyformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_qtyformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_qtyperformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_qtyperformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_salespriceformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_salespriceformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_extpriceformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_extpriceformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_timeformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_timeformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_timestampformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_timestampformat IS 'Deprecated';


--
-- Name: COLUMN locale.local_costformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.local_costformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_costformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_costformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_purchpriceformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_purchpriceformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_uomratioformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_uomratioformat IS 'Deprecated';


--
-- Name: COLUMN locale.locale_intervalformat; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN locale.locale_intervalformat IS 'Deprecated';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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 locale_locale_id_seq OWNER TO admin;

--
-- 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 location_location_id_seq OWNER TO admin;

--
-- 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 locitem OWNER TO admin;

--
-- Name: TABLE locitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE locitem IS 'Restricted Warehouse Location Allowable Items information';


--
-- 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 locitem_locitem_id_seq OWNER TO admin;

--
-- 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 log_log_id_seq OWNER TO admin;

--
-- 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 metric OWNER TO admin;

--
-- Name: TABLE metric; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE metric IS 'Application-wide settings information';


--
-- 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 metric_metric_id_seq OWNER TO admin;

--
-- 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 metricenc OWNER TO admin;

--
-- Name: TABLE metricenc; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE metricenc IS 'Application-wide settings information encrypted data';


--
-- 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 metricenc_metricenc_id_seq OWNER TO admin;

--
-- Name: metricenc_metricenc_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE metricenc_metricenc_id_seq OWNED BY metricenc.metricenc_id;


--
-- 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 misc_index_seq OWNER TO admin;

--
-- 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 mrghist OWNER TO admin;

--
-- 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 mrgundo OWNER TO admin;

--
-- 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).';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- 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.';


--
-- Name: COLUMN mrgundo.mrgundo_col; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN mrgundo.mrgundo_col IS 'The column that was modified.';


--
-- 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.';


--
-- 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.';


--
-- 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 msg OWNER TO admin;

--
-- Name: TABLE msg; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE msg IS 'System Message information';


--
-- 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 msg_msg_id_seq OWNER TO admin;

--
-- 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 msguser OWNER TO admin;

--
-- Name: TABLE msguser; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE msguser IS 'System Message user information';


--
-- 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 msguser_msguser_id_seq OWNER TO admin;

--
-- 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 nvend_nvend_id_seq OWNER TO admin;

--
-- 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 obsolete_tax OWNER TO admin;

--
-- Name: TABLE obsolete_tax; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE obsolete_tax IS 'Tax information. Obsolete table structure.';


--
-- 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.';


--
-- 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 ophead_ophead_id_seq OWNER TO admin;

--
-- Name: ophead_ophead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE ophead_ophead_id_seq OWNED BY ophead.ophead_id;


--
-- 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 opsource OWNER TO admin;

--
-- Name: TABLE opsource; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE opsource IS 'Opportunity Lead Source values.';


--
-- 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 opsource_opsource_id_seq OWNER TO admin;

--
-- Name: opsource_opsource_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE opsource_opsource_id_seq OWNED BY opsource.opsource_id;


--
-- 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 opstage OWNER TO admin;

--
-- Name: TABLE opstage; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE opstage IS 'Opportunity stage values.';


--
-- 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 opstage_opstage_id_seq OWNER TO admin;

--
-- Name: opstage_opstage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE opstage_opstage_id_seq OWNED BY opstage.opstage_id;


--
-- 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 optype OWNER TO admin;

--
-- Name: TABLE optype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE optype IS 'Opportunity Type values.';


--
-- 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 optype_optype_id_seq OWNER TO admin;

--
-- Name: optype_optype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE optype_optype_id_seq OWNED BY optype.optype_id;


--
-- 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 orderhead OWNER TO admin;

--
-- 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';


--
-- 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 orderitem OWNER TO admin;

--
-- 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';


--
-- 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 orderseq OWNER TO admin;

--
-- Name: TABLE orderseq; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE orderseq IS 'Configuration information for common numbering sequences';


--
-- 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 orderseq_orderseq_id_seq OWNER TO admin;

--
-- 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 pack OWNER TO admin;

--
-- 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';


--
-- 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 pack_pack_id_seq OWNER TO admin;

--
-- Name: pack_pack_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE pack_pack_id_seq OWNED BY pack.pack_id;


--
-- 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 payaropen OWNER TO admin;

--
-- Name: TABLE payaropen; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE payaropen IS 'Credit Card payment to credit memo join table';


--
-- 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(),
    payco_id integer NOT NULL
);


ALTER TABLE payco OWNER TO admin;

--
-- Name: TABLE payco; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE payco IS 'Credit Card payment to sales order join table';


--
-- Name: COLUMN payco.payco_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN payco.payco_id IS 'payco table primary key.';


--
-- Name: payco_payco_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE payco_payco_id_seq OWNER TO admin;

--
-- Name: payco_payco_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE payco_payco_id_seq OWNED BY payco.payco_id;


--
-- 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 period_period_id_seq OWNER TO admin;

--
-- Name: period_period_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE period_period_id_seq OWNED BY period.period_id;


--
-- 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 pkgdep OWNER TO admin;

--
-- 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.';


--
-- 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';


--
-- 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.';


--
-- 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 pkgdep_pkgdep_id_seq OWNER TO admin;

--
-- Name: pkgdep_pkgdep_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE pkgdep_pkgdep_id_seq OWNED BY pkgdep.pkgdep_id;


--
-- 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 pkghead OWNER TO admin;

--
-- Name: TABLE pkghead; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE pkghead IS 'Information about non-core Packages added to the database';


--
-- Name: COLUMN pkghead.pkghead_indev; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN pkghead.pkghead_indev IS 'Flag indicating whether the contents of this package may be modified in-place - this package is /in dev/elopment.';


--
-- Name: pkghead_pkghead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE pkghead_pkghead_id_seq OWNER TO admin;

--
-- Name: pkghead_pkghead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE pkghead_pkghead_id_seq OWNED BY pkghead.pkghead_id;


--
-- Name: pkgitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE pkgitem (
    pkgitem_id integer NOT NULL,
    pkgitem_pkghead_id integer,
    pkgitem_type text,
    pkgitem_item_id integer NOT NULL,
    pkgitem_name text NOT NULL,
    pkgitem_descrip text,
    CONSTRAINT pkgitem_pkgitem_type_check CHECK (((((((((((((pkgitem_type = 'C'::text) OR (pkgitem_type = 'D'::text)) OR (pkgitem_type = 'F'::text)) OR (pkgitem_type = 'G'::text)) OR (pkgitem_type = 'I'::text)) OR (pkgitem_type = 'M'::text)) OR (pkgitem_type = 'P'::text)) OR (pkgitem_type = 'R'::text)) OR (pkgitem_type = 'S'::text)) OR (pkgitem_type = 'T'::text)) OR (pkgitem_type = 'U'::text)) OR (pkgitem_type = 'V'::text)))
);


ALTER TABLE pkgitem OWNER TO admin;

--
-- Name: TABLE pkgitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE pkgitem IS 'Deprecated - the pkgitem table is no longer used to track package contents. It has been replaced by direct queries to the database schema and component tables. This table will be removed when all users have switched to Updater 2.2.0 or later.';


--
-- Name: pkgitem_pkgitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE pkgitem_pkgitem_id_seq OWNER TO admin;

--
-- Name: pkgitem_pkgitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE pkgitem_pkgitem_id_seq OWNED BY pkgitem.pkgitem_id;


--
-- Name: plancode_plancode_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE plancode_plancode_id_seq OWNER TO admin;

--
-- Name: planord_planord_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE planord_planord_id_seq OWNER TO admin;

--
-- Name: pohead_pohead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE pohead_pohead_id_seq OWNER TO admin;

--
-- Name: poitem_poitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE poitem_poitem_id_seq OWNER TO admin;

--
-- Name: recv; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE recv (
    recv_id integer NOT NULL,
    recv_order_type text NOT NULL,
    recv_order_number text NOT NULL,
    recv_orderitem_id integer NOT NULL,
    recv_agent_username text,
    recv_itemsite_id integer,
    recv_vend_id integer,
    recv_vend_item_number text,
    recv_vend_item_descrip text,
    recv_vend_uom text,
    recv_purchcost numeric(16,6),
    recv_purchcost_curr_id integer,
    recv_duedate date,
    recv_qty numeric(18,6),
    recv_recvcost numeric(16,6),
    recv_recvcost_curr_id integer,
    recv_freight numeric(16,4),
    recv_freight_curr_id integer,
    recv_date timestamp with time zone,
    recv_value numeric(18,6),
    recv_posted boolean DEFAULT false NOT NULL,
    recv_invoiced boolean DEFAULT false NOT NULL,
    recv_vohead_id integer,
    recv_voitem_id integer,
    recv_trans_usr_name text DEFAULT geteffectivextuser() NOT NULL,
    recv_notes text,
    recv_gldistdate date,
    recv_splitfrom_id integer,
    recv_rlsd_duedate date,
    CONSTRAINT recv_recv_order_type_check CHECK ((((recv_order_type = 'PO'::text) OR (recv_order_type = 'RA'::text)) OR (recv_order_type = 'TO'::text)))
);


ALTER TABLE recv OWNER TO admin;

--
-- Name: TABLE recv; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE recv IS 'Information about Received Orders.';


--
-- Name: porecv; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW porecv AS
    SELECT recv.recv_id AS porecv_id, recv.recv_date AS porecv_date, recv.recv_rlsd_duedate AS porecv_rlsd_duedate, pohead.pohead_orderdate AS porecv_orderdate, pohead.pohead_released AS porecv_released, recv.recv_order_number AS porecv_ponumber, recv.recv_itemsite_id AS porecv_itemsite_id, recv.recv_vend_id AS porecv_vend_id, item.item_number AS porecv_item_number, recv.recv_vend_item_number AS porecv_vend_item_number, COALESCE(item.item_descrip1, recv.recv_vend_item_descrip) AS porecv_vend_item_descrip, recv.recv_vend_uom AS porecv_vend_uom, recv.recv_qty AS porecv_qty, recv.recv_posted AS porecv_posted, recv.recv_invoiced AS porecv_invoiced, (pg_user.usesysid)::integer AS porecv_trans_usr_id, recv.recv_orderitem_id AS porecv_poitem_id, NULL::integer AS porecv_linenumber, recv.recv_purchcost AS porecv_purchcost, recv.recv_vohead_id AS porecv_vohead_id, recv.recv_recvcost AS porecv_recvcost, recv.recv_duedate AS porecv_duedate, recv.recv_agent_username AS porecv_agent_username, recv.recv_notes AS porecv_notes, recv.recv_freight AS porecv_freight, recv.recv_freight_curr_id AS porecv_curr_id, recv.recv_gldistdate AS porecv_gldistdate, recv.recv_voitem_id AS porecv_voitem_id, recv.recv_value AS porecv_value FROM ((((recv LEFT JOIN pg_user ON ((recv.recv_trans_usr_name = (pg_user.usename)::text))) LEFT JOIN pohead ON ((recv.recv_order_number = pohead.pohead_number))) LEFT JOIN itemsite ON ((recv.recv_itemsite_id = itemsite.itemsite_id))) LEFT JOIN item ON ((itemsite.itemsite_item_id = item.item_id))) WHERE (recv.recv_order_type = 'PO'::text);


ALTER TABLE porecv OWNER TO admin;

--
-- Name: porecv_porecv_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE porecv_porecv_id_seq OWNER TO admin;

--
-- Name: poreject; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE poreject (
    poreject_id integer DEFAULT nextval(('"poreject_poreject_id_seq"'::text)::regclass) NOT NULL,
    poreject_date timestamp with time zone,
    poreject_ponumber text,
    poreject_itemsite_id integer,
    poreject_vend_id integer,
    poreject_vend_item_number text,
    poreject_vend_item_descrip text,
    poreject_vend_uom text,
    poreject_qty numeric(18,6),
    poreject_posted boolean,
    poreject_rjctcode_id integer,
    poreject_poitem_id integer,
    poreject_invoiced boolean,
    poreject_vohead_id integer,
    poreject_agent_username text,
    poreject_voitem_id integer,
    poreject_value numeric(18,6),
    poreject_trans_username text,
    poreject_recv_id integer
);


ALTER TABLE poreject OWNER TO admin;

--
-- Name: TABLE poreject; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE poreject IS 'The poreject table describes Purchase Order Items that were returned to Vendors.';


--
-- Name: COLUMN poreject.poreject_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_id IS 'This is the internal id of this poreject record';


--
-- Name: COLUMN poreject.poreject_date; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_date IS 'This is the date and time the return was entered into the database';


--
-- Name: COLUMN poreject.poreject_ponumber; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_ponumber IS 'This is the number of the original Purchase Order of this item';


--
-- Name: COLUMN poreject.poreject_itemsite_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_itemsite_id IS 'This is the Item Site into which the item had been received';


--
-- Name: COLUMN poreject.poreject_vend_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_vend_id IS 'This is the Vendor from which the item had been purchased';


--
-- Name: COLUMN poreject.poreject_vend_item_number; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_vend_item_number IS 'This is the Vendor''s item number for this item';


--
-- Name: COLUMN poreject.poreject_vend_item_descrip; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_vend_item_descrip IS 'This is the Vendor''s description of this item';


--
-- Name: COLUMN poreject.poreject_vend_uom; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_vend_uom IS 'This is the Unit of Measure in which the Vendor sold this item';


--
-- Name: COLUMN poreject.poreject_qty; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_qty IS 'This is the quantity of the item that was returned';


--
-- Name: COLUMN poreject.poreject_posted; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_posted IS 'This indicates whether or not the return has been recorded in the General Ledger, Inventory History, and Purchase Order Item';


--
-- Name: COLUMN poreject.poreject_rjctcode_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_rjctcode_id IS 'This indicates the reason for the return';


--
-- Name: COLUMN poreject.poreject_poitem_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_poitem_id IS 'This is the internal id of the original Purchase Order Item';


--
-- Name: COLUMN poreject.poreject_invoiced; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_invoiced IS 'This indicates whether the Credit Memo associated with the return has been posted';


--
-- Name: COLUMN poreject.poreject_vohead_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_vohead_id IS 'This is the Voucher associated with the Purchase Order Item';


--
-- Name: COLUMN poreject.poreject_agent_username; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_agent_username IS 'This is the Purchase Order Agent responsible for the original Purchase Order';


--
-- Name: COLUMN poreject.poreject_voitem_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_voitem_id IS 'This is the Voucher Item associated with the Purchase Order Item';


--
-- Name: COLUMN poreject.poreject_value; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_value IS 'This is the value (in base currency) of the return at the time it was posted to the General Ledger';


--
-- Name: COLUMN poreject.poreject_trans_username; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN poreject.poreject_trans_username IS 'This is the user who recorded the return';


--
-- Name: poreject_poreject_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE poreject_poreject_id_seq OWNER TO admin;

--
-- Name: pr; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE pr (
    pr_id integer DEFAULT nextval(('"pr_pr_id_seq"'::text)::regclass) NOT NULL,
    pr_number integer,
    pr_subnumber integer,
    pr_status character(1),
    pr_order_type character(1),
    pr_order_id integer,
    pr_poitem_id integer,
    pr_duedate date,
    pr_itemsite_id integer,
    pr_qtyreq numeric(18,6),
    pr_prj_id integer,
    pr_releasenote text,
    pr_createdate timestamp without time zone DEFAULT now()
);


ALTER TABLE pr OWNER TO admin;

--
-- Name: TABLE pr; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE pr IS 'Purchase Request information';


--
-- Name: pr_pr_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE pr_pr_id_seq OWNER TO admin;

--
-- Name: prftcntr; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE prftcntr (
    prftcntr_id integer NOT NULL,
    prftcntr_number text NOT NULL,
    prftcntr_descrip text,
    CONSTRAINT prftcntr_prftcntr_number_check CHECK ((prftcntr_number <> ''::text))
);


ALTER TABLE prftcntr OWNER TO admin;

--
-- Name: TABLE prftcntr; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE prftcntr IS 'Profit Center information';


--
-- Name: prftcntr_prftcntr_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE prftcntr_prftcntr_id_seq OWNER TO admin;

--
-- Name: prftcntr_prftcntr_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE prftcntr_prftcntr_id_seq OWNED BY prftcntr.prftcntr_id;


--
-- Name: usrgrp; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE usrgrp (
    usrgrp_id integer NOT NULL,
    usrgrp_grp_id integer NOT NULL,
    usrgrp_username text NOT NULL
);


ALTER TABLE usrgrp OWNER TO admin;

--
-- Name: TABLE usrgrp; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE usrgrp IS 'This is which group a user belongs to.';


--
-- Name: usrpriv; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE usrpriv (
    usrpriv_id integer DEFAULT nextval(('usrpriv_usrpriv_id_seq'::text)::regclass) NOT NULL,
    usrpriv_priv_id integer,
    usrpriv_username text
);


ALTER TABLE usrpriv OWNER TO admin;

--
-- Name: TABLE usrpriv; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE usrpriv IS 'User Privileges information';


--
-- Name: privgranted; Type: VIEW; Schema: public; Owner: admin
--

CREATE VIEW privgranted AS
    SELECT priv.priv_name AS privilege, (COALESCE(usrpriv.usrpriv_priv_id, grppriv.grppriv_priv_id, (-1)) > 0) AS granted, priv.priv_seq AS sequence FROM ((priv LEFT JOIN usrpriv ON (((priv.priv_id = usrpriv.usrpriv_priv_id) AND (usrpriv.usrpriv_username = geteffectivextuser())))) LEFT JOIN (SELECT DISTINCT grppriv.grppriv_priv_id FROM (grppriv JOIN usrgrp ON (((grppriv.grppriv_grp_id = usrgrp.usrgrp_grp_id) AND (usrgrp.usrgrp_username = geteffectivextuser()))))) grppriv ON ((grppriv.grppriv_priv_id = priv.priv_id)));


ALTER TABLE privgranted OWNER TO admin;

--
-- Name: prj_prj_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE prj_prj_id_seq OWNER TO admin;

--
-- Name: prj_prj_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE prj_prj_id_seq OWNED BY prj.prj_id;


--
-- Name: prjtask_prjtask_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE prjtask_prjtask_id_seq OWNER TO admin;

--
-- Name: prjtask_prjtask_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE prjtask_prjtask_id_seq OWNED BY prjtask.prjtask_id;


--
-- Name: prjtaskuser; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE prjtaskuser (
    prjtaskuser_id integer NOT NULL,
    prjtaskuser_prjtask_id integer,
    prjtaskuser_username text
);


ALTER TABLE prjtaskuser OWNER TO admin;

--
-- Name: TABLE prjtaskuser; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE prjtaskuser IS 'Project Task user information';


--
-- Name: prjtaskuser_prjtaskuser_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE prjtaskuser_prjtaskuser_id_seq OWNER TO admin;

--
-- Name: prjtaskuser_prjtaskuser_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE prjtaskuser_prjtaskuser_id_seq OWNED BY prjtaskuser.prjtaskuser_id;


--
-- Name: prjtype; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE prjtype (
    prjtype_id integer NOT NULL,
    prjtype_code text,
    prjtype_descr text,
    prjtype_active boolean DEFAULT true
);


ALTER TABLE prjtype OWNER TO admin;

--
-- Name: prjtype_prjtype_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE prjtype_prjtype_id_seq OWNER TO admin;

--
-- Name: prjtype_prjtype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE prjtype_prjtype_id_seq OWNED BY prjtype.prjtype_id;


--
-- Name: prodcat_prodcat_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE prodcat_prodcat_id_seq OWNER TO admin;

--
-- Name: qryhead; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE qryhead (
    qryhead_id integer NOT NULL,
    qryhead_name text NOT NULL,
    qryhead_descrip text,
    qryhead_notes text,
    qryhead_username text DEFAULT geteffectivextuser() NOT NULL,
    qryhead_updated date DEFAULT ('now'::text)::date NOT NULL,
    CONSTRAINT qryhead_qryhead_name_check CHECK ((qryhead_name <> ''::text))
);


ALTER TABLE qryhead OWNER TO admin;

--
-- Name: TABLE qryhead; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE qryhead IS 'A header record for a set of queries to be run sequentially. One use is for data export.';


--
-- Name: COLUMN qryhead.qryhead_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryhead.qryhead_id IS 'The primary key, holding an internal value used to cross-reference this table.';


--
-- Name: COLUMN qryhead.qryhead_name; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryhead.qryhead_name IS 'The user-assigned short name for this set of queries.';


--
-- Name: COLUMN qryhead.qryhead_descrip; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryhead.qryhead_descrip IS 'A long description of the purpose of this set of queries.';


--
-- Name: COLUMN qryhead.qryhead_notes; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryhead.qryhead_notes IS 'General information about this queryset.';


--
-- Name: COLUMN qryhead.qryhead_username; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryhead.qryhead_username IS 'The name of the user who last modified this qryhead record.';


--
-- Name: COLUMN qryhead.qryhead_updated; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryhead.qryhead_updated IS 'The date this qryhead was last modified.';


--
-- Name: qryhead_qryhead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE qryhead_qryhead_id_seq OWNER TO admin;

--
-- Name: qryhead_qryhead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE qryhead_qryhead_id_seq OWNED BY qryhead.qryhead_id;


--
-- Name: qryitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE qryitem (
    qryitem_id integer NOT NULL,
    qryitem_qryhead_id integer NOT NULL,
    qryitem_name text NOT NULL,
    qryitem_order integer NOT NULL,
    qryitem_src text NOT NULL,
    qryitem_group text,
    qryitem_detail text NOT NULL,
    qryitem_notes text DEFAULT ''::text NOT NULL,
    qryitem_username text DEFAULT geteffectivextuser() NOT NULL,
    qryitem_updated date DEFAULT ('now'::text)::date NOT NULL,
    CONSTRAINT qryitem_qryitem_detail_check CHECK ((btrim(qryitem_detail) <> ''::text)),
    CONSTRAINT qryitem_qryitem_src_check CHECK ((qryitem_src = ANY (ARRAY['REL'::text, 'MQL'::text, 'CUSTOM'::text])))
);


ALTER TABLE qryitem OWNER TO admin;

--
-- Name: TABLE qryitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE qryitem IS 'The description of a query to be run as part of a set (see qryhead).';


--
-- Name: COLUMN qryitem.qryitem_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryitem.qryitem_id IS 'The primary key, holding an internal value used to cross-reference this table.';


--
-- Name: COLUMN qryitem.qryitem_qryhead_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryitem.qryitem_qryhead_id IS 'The primary key of the query set to which this individual query belongs.';


--
-- Name: COLUMN qryitem.qryitem_order; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryitem.qryitem_order IS 'The order in which query items within a query set should be run.';


--
-- Name: COLUMN qryitem.qryitem_src; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryitem.qryitem_src IS 'The source of the query. If the qryitem_src is "REL" then the qryitem_group and _detail name a particular table or view and all rows will be returned. If the source is "MQL" then the qryitem_group and _detail name a pre-defined MetaSQL query in the metasql table. If the source is "CUSTOM" then the qryitem_detail contains the full MetaSQL text of the query to run.';


--
-- Name: COLUMN qryitem.qryitem_group; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryitem.qryitem_group IS 'Information to help find the query to run. If the qryitem_src is "REL" then this is the schema in which to find the table or view to query and all rows will be returned (the qryitem_detail names the table or view). If the qryitem_src is "MQL" then this is the group of the query in the metasql table to run (the name is in qryitem_detail). If the qryitem_src IS "CUSTOM" then this ignored.';


--
-- Name: COLUMN qryitem.qryitem_detail; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryitem.qryitem_detail IS 'The particular query to run. If the qryitem_src is "REL" then this is the name of the table or view to query and all rows will be returned. If the qryitem_src is "MQL" then this is the name of the query in the metasql table to run. If the qryitem_src IS "CUSTOM" then this is the actual MetaSQL query text to be parsed and run.';


--
-- Name: COLUMN qryitem.qryitem_notes; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryitem.qryitem_notes IS 'General information about this query.';


--
-- Name: COLUMN qryitem.qryitem_username; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryitem.qryitem_username IS 'The name of the user who last modified this qryitem record.';


--
-- Name: COLUMN qryitem.qryitem_updated; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN qryitem.qryitem_updated IS 'The date this qryitem was last modified.';


--
-- Name: qryitem_qryitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE qryitem_qryitem_id_seq OWNER TO admin;

--
-- Name: qryitem_qryitem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE qryitem_qryitem_id_seq OWNED BY qryitem.qryitem_id;


--
-- Name: quhead_quhead_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE quhead_quhead_id_seq OWNER TO admin;

--
-- Name: quitem_quitem_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE quitem_quitem_id_seq OWNER TO admin;

--
-- Name: rcalitem; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE rcalitem (
    rcalitem_id integer DEFAULT nextval(('"xcalitem_xcalitem_id_seq"'::text)::regclass) NOT NULL,
    rcalitem_calhead_id integer,
    rcalitem_offsettype character(1),
    rcalitem_offsetcount integer,
    rcalitem_periodtype character(1),
    rcalitem_periodcount integer,
    rcalitem_name text
);


ALTER TABLE rcalitem OWNER TO admin;

--
-- Name: TABLE rcalitem; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE rcalitem IS 'Relative Calendar Item information';


--
-- Name: recur; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE recur (
    recur_id integer NOT NULL,
    recur_parent_id integer NOT NULL,
    recur_parent_type text NOT NULL,
    recur_period text NOT NULL,
    recur_freq integer DEFAULT 1 NOT NULL,
    recur_start timestamp with time zone DEFAULT now(),
    recur_end timestamp with time zone,
    recur_max integer,
    recur_data text,
    CONSTRAINT recur_recur_period_check CHECK ((recur_period = ANY (ARRAY['m'::text, 'H'::text, 'D'::text, 'W'::text, 'M'::text, 'Y'::text, 'C'::text])))
);


ALTER TABLE recur OWNER TO admin;

--
-- Name: TABLE recur; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE recur IS 'Track recurring events and objects.';


--
-- Name: COLUMN recur.recur_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recur.recur_id IS 'Internal ID of this recurrence record.';


--
-- Name: COLUMN recur.recur_parent_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recur.recur_parent_id IS 'The internal ID of the event/object that recurs.';


--
-- Name: COLUMN recur.recur_parent_type; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recur.recur_parent_type IS 'The table in which the parent event or object is stored.';


--
-- Name: COLUMN recur.recur_period; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recur.recur_period IS 'With recur_freq, how often this event recurs. Values are "m" for every minute, "H" for every hour, "D" for daily, "W" for weekly, "M" for monthly, "Y" for yearly, and "C" for customized or complex.';


--
-- Name: COLUMN recur.recur_freq; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recur.recur_freq IS 'With recur_period, how often this event recurs. Values are integers counts of recur_periods. For example, if recur_freq = 2 and recur_period = w then the event recurs every 2 weeks.';


--
-- Name: COLUMN recur.recur_start; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recur.recur_start IS 'The first date/time when the event should occur.';


--
-- Name: COLUMN recur.recur_end; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recur.recur_end IS 'The last date/time when the event should occur. NULL means there is no end date/time and the event should recur forever.';


--
-- Name: COLUMN recur.recur_max; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recur.recur_max IS 'The maximum number of recurrence events to create at one time. If this is NULL then when new events are created, a system-wide default will limit the number.';


--
-- Name: COLUMN recur.recur_data; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recur.recur_data IS 'Not yet used and format still undetermined. Additional data to describe how to apply the period and frequency, particularly when period = "C".';


--
-- Name: recur_recur_id_seq; Type: SEQUENCE; Schema: public; Owner: admin
--

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


ALTER TABLE recur_recur_id_seq OWNER TO admin;

--
-- Name: recur_recur_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: admin
--

ALTER SEQUENCE recur_recur_id_seq OWNED BY recur.recur_id;


--
-- Name: recurtype; Type: TABLE; Schema: public; Owner: admin; Tablespace: 
--

CREATE TABLE recurtype (
    recurtype_id integer NOT NULL,
    recurtype_type text NOT NULL,
    recurtype_table text NOT NULL,
    recurtype_donecheck text NOT NULL,
    recurtype_schedcol text NOT NULL,
    recurtype_limit text,
    recurtype_copyfunc text NOT NULL,
    recurtype_copyargs text[] NOT NULL,
    recurtype_delfunc text
);


ALTER TABLE recurtype OWNER TO admin;

--
-- Name: TABLE recurtype; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON TABLE recurtype IS 'Describes the properties of recurring items/events in way that can be used by stored procedures to maintain the recurrence.';


--
-- Name: COLUMN recurtype.recurtype_id; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recurtype.recurtype_id IS 'The internal id of this recurrence description.';


--
-- Name: COLUMN recurtype.recurtype_type; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recurtype.recurtype_type IS 'A code value used by the RecurrenceWidget and the code that uses it to describe the item/event that will recur. Examples include "INCDT" for CRM Incidents and "J" for Projects.';


--
-- Name: COLUMN recurtype.recurtype_table; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recurtype.recurtype_table IS 'The table that holds the item/event that will recur.';


--
-- Name: COLUMN recurtype.recurtype_donecheck; Type: COMMENT; Schema: public; Owner: admin
--

COMMENT ON COLUMN recurtype.recurtype_donecheck IS 'A boolean expression that returns TRUE if an individual item/event record in the recurtype_table has already been completed.';


--
