
--
-- Name: pkgcmd_pkey; Type: CONSTRAINT; Schema: fixcountry; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgcmd
    ADD CONSTRAINT pkgcmd_pkey PRIMARY KEY (cmd_id);


--
-- Name: pkgcmdarg_pkey; Type: CONSTRAINT; Schema: fixcountry; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgcmdarg
    ADD CONSTRAINT pkgcmdarg_pkey PRIMARY KEY (cmdarg_id);


--
-- Name: pkgimage_pkey; Type: CONSTRAINT; Schema: fixcountry; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgimage
    ADD CONSTRAINT pkgimage_pkey PRIMARY KEY (image_id);


--
-- Name: pkgmetasql_pkey; Type: CONSTRAINT; Schema: fixcountry; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgmetasql
    ADD CONSTRAINT pkgmetasql_pkey PRIMARY KEY (metasql_id);


--
-- Name: pkgpriv_pkey; Type: CONSTRAINT; Schema: fixcountry; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgpriv
    ADD CONSTRAINT pkgpriv_pkey PRIMARY KEY (priv_id);


--
-- Name: pkgreport_pkey; Type: CONSTRAINT; Schema: fixcountry; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgreport
    ADD CONSTRAINT pkgreport_pkey PRIMARY KEY (report_id);


--
-- Name: pkgscript_pkey; Type: CONSTRAINT; Schema: fixcountry; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgscript
    ADD CONSTRAINT pkgscript_pkey PRIMARY KEY (script_id);


--
-- Name: pkguiform_pkey; Type: CONSTRAINT; Schema: fixcountry; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkguiform
    ADD CONSTRAINT pkguiform_pkey PRIMARY KEY (uiform_id);



--
-- Name: acalitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY acalitem
    ADD CONSTRAINT acalitem_pkey PRIMARY KEY (acalitem_id);


--
-- Name: accnt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY accnt
    ADD CONSTRAINT accnt_pkey PRIMARY KEY (accnt_id);


--
-- Name: addr_addr_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY addr
    ADD CONSTRAINT addr_addr_number_key UNIQUE (addr_number);


--
-- Name: addr_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY addr
    ADD CONSTRAINT addr_pkey PRIMARY KEY (addr_id);


--
-- Name: alarm_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY alarm
    ADD CONSTRAINT alarm_pkey PRIMARY KEY (alarm_id);


--
-- Name: apaccnt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY apaccnt
    ADD CONSTRAINT apaccnt_pkey PRIMARY KEY (apaccnt_id);


--
-- Name: apapply_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY apapply
    ADD CONSTRAINT apapply_pkey PRIMARY KEY (apapply_id);


--
-- Name: apcreditapply_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY apcreditapply
    ADD CONSTRAINT apcreditapply_pkey PRIMARY KEY (apcreditapply_id);


--
-- Name: apopen_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY apopen
    ADD CONSTRAINT apopen_pkey PRIMARY KEY (apopen_id);


--
-- Name: apopentax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY apopentax
    ADD CONSTRAINT apopentax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: apselect_apselect_apopen_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY apselect
    ADD CONSTRAINT apselect_apselect_apopen_id_key UNIQUE (apselect_apopen_id);


--
-- Name: apselect_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY apselect
    ADD CONSTRAINT apselect_pkey PRIMARY KEY (apselect_id);


--
-- Name: araccnt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY araccnt
    ADD CONSTRAINT araccnt_pkey PRIMARY KEY (araccnt_id);


--
-- Name: arapply_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY arapply
    ADD CONSTRAINT arapply_pkey PRIMARY KEY (arapply_id);


--
-- Name: arcreditapply_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY arcreditapply
    ADD CONSTRAINT arcreditapply_pkey PRIMARY KEY (arcreditapply_id);


--
-- Name: aropen_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY aropen
    ADD CONSTRAINT aropen_pkey PRIMARY KEY (aropen_id);


--
-- Name: aropenalloc_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY aropenalloc
    ADD CONSTRAINT aropenalloc_pkey PRIMARY KEY (aropenalloc_aropen_id, aropenalloc_doctype, aropenalloc_doc_id);


--
-- Name: aropentax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY aropentax
    ADD CONSTRAINT aropentax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: asohist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY asohist
    ADD CONSTRAINT asohist_pkey PRIMARY KEY (asohist_id);


--
-- Name: asohisttax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY asohisttax
    ADD CONSTRAINT asohisttax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: atlasmap_atlasmap_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY atlasmap
    ADD CONSTRAINT atlasmap_atlasmap_name_key UNIQUE (atlasmap_name);


--
-- Name: atlasmap_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY atlasmap
    ADD CONSTRAINT atlasmap_pkey PRIMARY KEY (atlasmap_id);


--
-- Name: bankaccnt_bankaccnt_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bankaccnt
    ADD CONSTRAINT bankaccnt_bankaccnt_name_key UNIQUE (bankaccnt_name);


--
-- Name: bankaccnt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bankaccnt
    ADD CONSTRAINT bankaccnt_pkey PRIMARY KEY (bankaccnt_id);


--
-- Name: bankadj_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bankadj
    ADD CONSTRAINT bankadj_pkey PRIMARY KEY (bankadj_id);


--
-- Name: bankadjtype_bankadjtype_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bankadjtype
    ADD CONSTRAINT bankadjtype_bankadjtype_name_key UNIQUE (bankadjtype_name);


--
-- Name: bankadjtype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bankadjtype
    ADD CONSTRAINT bankadjtype_pkey PRIMARY KEY (bankadjtype_id);


--
-- Name: bankrec_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bankrec
    ADD CONSTRAINT bankrec_pkey PRIMARY KEY (bankrec_id);


--
-- Name: bankrecimport_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bankrecimport
    ADD CONSTRAINT bankrecimport_pkey PRIMARY KEY (bankrecimport_id);


--
-- Name: bankrecitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bankrecitem
    ADD CONSTRAINT bankrecitem_pkey PRIMARY KEY (bankrecitem_id);


--
-- Name: bomhead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bomhead
    ADD CONSTRAINT bomhead_pkey PRIMARY KEY (bomhead_id);


--
-- Name: bomitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bomitem
    ADD CONSTRAINT bomitem_pkey PRIMARY KEY (bomitem_id);


--
-- Name: bomitemcost_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bomitemcost
    ADD CONSTRAINT bomitemcost_pkey PRIMARY KEY (bomitemcost_id);


--
-- Name: bomitemsub_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bomitemsub
    ADD CONSTRAINT bomitemsub_pkey PRIMARY KEY (bomitemsub_id);


--
-- Name: bomwork_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY bomwork
    ADD CONSTRAINT bomwork_pkey PRIMARY KEY (bomwork_id);


--
-- Name: budghead_budghead_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY budghead
    ADD CONSTRAINT budghead_budghead_name_key UNIQUE (budghead_name);


--
-- Name: budghead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY budghead
    ADD CONSTRAINT budghead_pkey PRIMARY KEY (budghead_id);


--
-- Name: budgitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY budgitem
    ADD CONSTRAINT budgitem_pkey PRIMARY KEY (budgitem_id);


--
-- Name: calhead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY calhead
    ADD CONSTRAINT calhead_pkey PRIMARY KEY (calhead_id);


--
-- Name: cashrcpt_cashrcpt_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cashrcpt
    ADD CONSTRAINT cashrcpt_cashrcpt_number_key UNIQUE (cashrcpt_number);


--
-- Name: cashrcpt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cashrcpt
    ADD CONSTRAINT cashrcpt_pkey PRIMARY KEY (cashrcpt_id);


--
-- Name: cashrcptitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cashrcptitem
    ADD CONSTRAINT cashrcptitem_pkey PRIMARY KEY (cashrcptitem_id);


--
-- Name: cashrcptmisc_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cashrcptmisc
    ADD CONSTRAINT cashrcptmisc_pkey PRIMARY KEY (cashrcptmisc_id);


--
-- Name: ccard_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ccard
    ADD CONSTRAINT ccard_pkey PRIMARY KEY (ccard_id);


--
-- Name: ccardaud_ccard_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ccardaud
    ADD CONSTRAINT ccardaud_ccard_pkey PRIMARY KEY (ccardaud_id);


--
-- Name: ccbank_ccbank_ccard_type_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ccbank
    ADD CONSTRAINT ccbank_ccbank_ccard_type_key UNIQUE (ccbank_ccard_type);


--
-- Name: ccbank_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ccbank
    ADD CONSTRAINT ccbank_pkey PRIMARY KEY (ccbank_id);


--
-- Name: ccpay_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ccpay
    ADD CONSTRAINT ccpay_pkey PRIMARY KEY (ccpay_id);


--
-- Name: char_char_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "char"
    ADD CONSTRAINT char_char_name_key UNIQUE (char_name);


--
-- Name: char_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY "char"
    ADD CONSTRAINT char_pkey PRIMARY KEY (char_id);


--
-- Name: charass_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY charass
    ADD CONSTRAINT charass_pkey PRIMARY KEY (charass_id);


--
-- Name: charopt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY charopt
    ADD CONSTRAINT charopt_pkey PRIMARY KEY (charopt_id);


--
-- Name: charuse_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY charuse
    ADD CONSTRAINT charuse_pkey PRIMARY KEY (charuse_id);


--
-- Name: checkhead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY checkhead
    ADD CONSTRAINT checkhead_pkey PRIMARY KEY (checkhead_id);


--
-- Name: checkitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY checkitem
    ADD CONSTRAINT checkitem_pkey PRIMARY KEY (checkitem_id);


--
-- Name: classcode_classcode_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY classcode
    ADD CONSTRAINT classcode_classcode_code_key UNIQUE (classcode_code);


--
-- Name: classcode_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY classcode
    ADD CONSTRAINT classcode_pkey PRIMARY KEY (classcode_id);


--
-- Name: cmd_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmd
    ADD CONSTRAINT cmd_pkey PRIMARY KEY (cmd_id);


--
-- Name: cmdarg_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmdarg
    ADD CONSTRAINT cmdarg_pkey PRIMARY KEY (cmdarg_id);


--
-- Name: cmhead_cmhead_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmhead
    ADD CONSTRAINT cmhead_cmhead_number_key UNIQUE (cmhead_number);


--
-- Name: cmhead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmhead
    ADD CONSTRAINT cmhead_pkey PRIMARY KEY (cmhead_id);


--
-- Name: cmheadtax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmheadtax
    ADD CONSTRAINT cmheadtax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: cmitem_cmhead_id_linenumber_unique; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmitem
    ADD CONSTRAINT cmitem_cmhead_id_linenumber_unique UNIQUE (cmitem_cmhead_id, cmitem_linenumber);


--
-- Name: cmitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmitem
    ADD CONSTRAINT cmitem_pkey PRIMARY KEY (cmitem_id);


--
-- Name: cmitemtax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmitemtax
    ADD CONSTRAINT cmitemtax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: cmnttype_cmnttype_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmnttype
    ADD CONSTRAINT cmnttype_cmnttype_name_key UNIQUE (cmnttype_name);


--
-- Name: cmnttype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmnttype
    ADD CONSTRAINT cmnttype_pkey PRIMARY KEY (cmnttype_id);


--
-- Name: cmnttypesource_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cmnttypesource
    ADD CONSTRAINT cmnttypesource_pkey PRIMARY KEY (cmnttypesource_id);


--
-- Name: cntct_cntct_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cntct
    ADD CONSTRAINT cntct_cntct_number_key UNIQUE (cntct_number);


--
-- Name: cntct_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cntct
    ADD CONSTRAINT cntct_pkey PRIMARY KEY (cntct_id);


--
-- Name: cntctaddr_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cntctaddr
    ADD CONSTRAINT cntctaddr_pkey PRIMARY KEY (cntctaddr_id);


--
-- Name: cntctdata_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cntctdata
    ADD CONSTRAINT cntctdata_pkey PRIMARY KEY (cntctdata_id);


--
-- Name: cntcteml_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cntcteml
    ADD CONSTRAINT cntcteml_pkey PRIMARY KEY (cntcteml_id);


--
-- Name: cntctmrgd_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cntctmrgd
    ADD CONSTRAINT cntctmrgd_pkey PRIMARY KEY (cntctmrgd_cntct_id);


--
-- Name: cntctsel_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cntctsel
    ADD CONSTRAINT cntctsel_pkey PRIMARY KEY (cntctsel_cntct_id);


--
-- Name: cntslip_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cntslip
    ADD CONSTRAINT cntslip_pkey PRIMARY KEY (cntslip_id);


--
-- Name: cobill_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cobill
    ADD CONSTRAINT cobill_pkey PRIMARY KEY (cobill_id);


--
-- Name: cobilltax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cobilltax
    ADD CONSTRAINT cobilltax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: cobmisc_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cobmisc
    ADD CONSTRAINT cobmisc_pkey PRIMARY KEY (cobmisc_id);


--
-- Name: cobmisctax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cobmisctax
    ADD CONSTRAINT cobmisctax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: cohead_cohead_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cohead
    ADD CONSTRAINT cohead_cohead_number_key UNIQUE (cohead_number);


--
-- Name: cohead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cohead
    ADD CONSTRAINT cohead_pkey PRIMARY KEY (cohead_id);


--
-- Name: cohist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cohist
    ADD CONSTRAINT cohist_pkey PRIMARY KEY (cohist_id);


--
-- Name: cohisttax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY cohisttax
    ADD CONSTRAINT cohisttax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: coitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY coitem
    ADD CONSTRAINT coitem_pkey PRIMARY KEY (coitem_id);


--
-- Name: comment_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY comment
    ADD CONSTRAINT comment_pkey PRIMARY KEY (comment_id);


--
-- Name: company_company_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY company
    ADD CONSTRAINT company_company_number_key UNIQUE (company_number);


--
-- Name: company_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY company
    ADD CONSTRAINT company_pkey PRIMARY KEY (company_id);


--
-- Name: contrct_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY contrct
    ADD CONSTRAINT contrct_pkey PRIMARY KEY (contrct_id);


--
-- Name: costcat_costcat_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY costcat
    ADD CONSTRAINT costcat_costcat_code_key UNIQUE (costcat_code);


--
-- Name: costcat_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY costcat
    ADD CONSTRAINT costcat_pkey PRIMARY KEY (costcat_id);


--
-- Name: costelem_costelem_type_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY costelem
    ADD CONSTRAINT costelem_costelem_type_key UNIQUE (costelem_type);


--
-- Name: costelem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY costelem
    ADD CONSTRAINT costelem_pkey PRIMARY KEY (costelem_id);


--
-- Name: costhist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY costhist
    ADD CONSTRAINT costhist_pkey PRIMARY KEY (costhist_id);


--
-- Name: costupdate_costupdate_item_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY costupdate
    ADD CONSTRAINT costupdate_costupdate_item_id_key UNIQUE (costupdate_item_id);


--
-- Name: country_country_abbr_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY country
    ADD CONSTRAINT country_country_abbr_key UNIQUE (country_abbr);


--
-- Name: country_country_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY country
    ADD CONSTRAINT country_country_name_key UNIQUE (country_name);


--
-- Name: country_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY country
    ADD CONSTRAINT country_pkey PRIMARY KEY (country_id);


--
-- Name: crmacct_crmacct_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY crmacct
    ADD CONSTRAINT crmacct_crmacct_number_key UNIQUE (crmacct_number);


--
-- Name: crmacct_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY crmacct
    ADD CONSTRAINT crmacct_pkey PRIMARY KEY (crmacct_id);


--
-- Name: crmacctsel_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY crmacctsel
    ADD CONSTRAINT crmacctsel_pkey PRIMARY KEY (crmacctsel_src_crmacct_id);


--
-- Name: curr_rate_curr_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY curr_rate
    ADD CONSTRAINT curr_rate_curr_id_key UNIQUE (curr_id, curr_effective);


--
-- Name: curr_rate_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY curr_rate
    ADD CONSTRAINT curr_rate_pkey PRIMARY KEY (curr_rate_id);


--
-- Name: curr_symbol_curr_abbr_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY curr_symbol
    ADD CONSTRAINT curr_symbol_curr_abbr_key UNIQUE (curr_abbr);


--
-- Name: curr_symbol_curr_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY curr_symbol
    ADD CONSTRAINT curr_symbol_curr_name_key UNIQUE (curr_name);


--
-- Name: curr_symbol_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY curr_symbol
    ADD CONSTRAINT curr_symbol_pkey PRIMARY KEY (curr_id);


--
-- Name: cust_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY custinfo
    ADD CONSTRAINT cust_pkey PRIMARY KEY (cust_id);


--
-- Name: custform_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY custform
    ADD CONSTRAINT custform_pkey PRIMARY KEY (custform_id);


--
-- Name: custgrp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY custgrp
    ADD CONSTRAINT custgrp_pkey PRIMARY KEY (custgrp_id);


--
-- Name: custgrpitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY custgrpitem
    ADD CONSTRAINT custgrpitem_pkey PRIMARY KEY (custgrpitem_id);


--
-- Name: custinfo_cust_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY custinfo
    ADD CONSTRAINT custinfo_cust_number_key UNIQUE (cust_number);


--
-- Name: custtype_custtype_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY custtype
    ADD CONSTRAINT custtype_custtype_code_key UNIQUE (custtype_code);


--
-- Name: custtype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY custtype
    ADD CONSTRAINT custtype_pkey PRIMARY KEY (custtype_id);


--
-- Name: dept_dept_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY dept
    ADD CONSTRAINT dept_dept_number_key UNIQUE (dept_number);


--
-- Name: dept_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY dept
    ADD CONSTRAINT dept_pkey PRIMARY KEY (dept_id);


--
-- Name: destination_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY destination
    ADD CONSTRAINT destination_pkey PRIMARY KEY (destination_id);


--
-- Name: docass_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY docass
    ADD CONSTRAINT docass_pkey PRIMARY KEY (docass_id);


--
-- Name: emp_emp_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY emp
    ADD CONSTRAINT emp_emp_code_key UNIQUE (emp_code);


--
-- Name: emp_emp_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY emp
    ADD CONSTRAINT emp_emp_number_key UNIQUE (emp_number);


--
-- Name: emp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY emp
    ADD CONSTRAINT emp_pkey PRIMARY KEY (emp_id);


--
-- Name: empgrp_empgrp_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY empgrp
    ADD CONSTRAINT empgrp_empgrp_name_key UNIQUE (empgrp_name);


--
-- Name: empgrp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY empgrp
    ADD CONSTRAINT empgrp_pkey PRIMARY KEY (empgrp_id);


--
-- Name: empgrpitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY empgrpitem
    ADD CONSTRAINT empgrpitem_pkey PRIMARY KEY (empgrpitem_id);


--
-- Name: evntlog_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY evntlog
    ADD CONSTRAINT evntlog_pkey PRIMARY KEY (evntlog_id);


--
-- Name: evntnot_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY evntnot
    ADD CONSTRAINT evntnot_pkey PRIMARY KEY (evntnot_id);


--
-- Name: evnttype_evnttype_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY evnttype
    ADD CONSTRAINT evnttype_evnttype_name_key UNIQUE (evnttype_name);


--
-- Name: evnttype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY evnttype
    ADD CONSTRAINT evnttype_pkey PRIMARY KEY (evnttype_id);


--
-- Name: expcat_expcat_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY expcat
    ADD CONSTRAINT expcat_expcat_code_key UNIQUE (expcat_code);


--
-- Name: expcat_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY expcat
    ADD CONSTRAINT expcat_pkey PRIMARY KEY (expcat_id);


--
-- Name: file_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY file
    ADD CONSTRAINT file_pkey PRIMARY KEY (file_id);


--
-- Name: filter_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY filter
    ADD CONSTRAINT filter_pkey PRIMARY KEY (filter_id);


--
-- Name: fincharg_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY fincharg
    ADD CONSTRAINT fincharg_pkey PRIMARY KEY (fincharg_id);


--
-- Name: fkey_flcol_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY flcol
    ADD CONSTRAINT fkey_flcol_key PRIMARY KEY (flcol_id);


--
-- Name: flgrp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY flgrp
    ADD CONSTRAINT flgrp_pkey PRIMARY KEY (flgrp_id);


--
-- Name: flhead_flhead_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY flhead
    ADD CONSTRAINT flhead_flhead_name_key UNIQUE (flhead_name);


--
-- Name: flhead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY flhead
    ADD CONSTRAINT flhead_pkey PRIMARY KEY (flhead_id);


--
-- Name: flitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY flitem
    ADD CONSTRAINT flitem_pkey PRIMARY KEY (flitem_id);


--
-- Name: flnotes_flnotes_flhead_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY flnotes
    ADD CONSTRAINT flnotes_flnotes_flhead_id_key UNIQUE (flnotes_flhead_id, flnotes_period_id);


--
-- Name: flrpt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY flrpt
    ADD CONSTRAINT flrpt_pkey PRIMARY KEY (flrpt_id);


--
-- Name: flspec_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY flspec
    ADD CONSTRAINT flspec_pkey PRIMARY KEY (flspec_id);


--
-- Name: form_form_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY form
    ADD CONSTRAINT form_form_name_key UNIQUE (form_name);


--
-- Name: form_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY form
    ADD CONSTRAINT form_pkey PRIMARY KEY (form_id);


--
-- Name: freightclass_freightclass_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY freightclass
    ADD CONSTRAINT freightclass_freightclass_code_key UNIQUE (freightclass_code);


--
-- Name: freightclass_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY freightclass
    ADD CONSTRAINT freightclass_pkey PRIMARY KEY (freightclass_id);


--
-- Name: glseries_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY glseries
    ADD CONSTRAINT glseries_pkey PRIMARY KEY (glseries_id);


--
-- Name: gltrans_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY gltrans
    ADD CONSTRAINT gltrans_pkey PRIMARY KEY (gltrans_id);


--
-- Name: grp_grp_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY grp
    ADD CONSTRAINT grp_grp_name_key UNIQUE (grp_name);


--
-- Name: grp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY grp
    ADD CONSTRAINT grp_pkey PRIMARY KEY (grp_id);


--
-- Name: grppriv_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY grppriv
    ADD CONSTRAINT grppriv_pkey PRIMARY KEY (grppriv_id);


--
-- Name: hnfc_hnfc_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY hnfc
    ADD CONSTRAINT hnfc_hnfc_code_key UNIQUE (hnfc_code);


--
-- Name: hnfc_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY hnfc
    ADD CONSTRAINT hnfc_pkey PRIMARY KEY (hnfc_id);


--
-- Name: image_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY image
    ADD CONSTRAINT image_pkey PRIMARY KEY (image_id);


--
-- Name: imageass_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY imageass
    ADD CONSTRAINT imageass_pkey PRIMARY KEY (imageass_id);


--
-- Name: incdt_incdt_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdt
    ADD CONSTRAINT incdt_incdt_number_key UNIQUE (incdt_number);


--
-- Name: incdt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdt
    ADD CONSTRAINT incdt_pkey PRIMARY KEY (incdt_id);


--
-- Name: incdtcat_incdtcat_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdtcat
    ADD CONSTRAINT incdtcat_incdtcat_name_key UNIQUE (incdtcat_name);


--
-- Name: incdtcat_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdtcat
    ADD CONSTRAINT incdtcat_pkey PRIMARY KEY (incdtcat_id);


--
-- Name: incdthist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdthist
    ADD CONSTRAINT incdthist_pkey PRIMARY KEY (incdthist_id);


--
-- Name: incdtpriority_incdtpriority_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdtpriority
    ADD CONSTRAINT incdtpriority_incdtpriority_name_key UNIQUE (incdtpriority_name);


--
-- Name: incdtpriority_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdtpriority
    ADD CONSTRAINT incdtpriority_pkey PRIMARY KEY (incdtpriority_id);


--
-- Name: incdtresolution_incdtresolution_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdtresolution
    ADD CONSTRAINT incdtresolution_incdtresolution_name_key UNIQUE (incdtresolution_name);


--
-- Name: incdtresolution_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdtresolution
    ADD CONSTRAINT incdtresolution_pkey PRIMARY KEY (incdtresolution_id);


--
-- Name: incdtseverity_incdtseverity_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdtseverity
    ADD CONSTRAINT incdtseverity_incdtseverity_name_key UNIQUE (incdtseverity_name);


--
-- Name: incdtseverity_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY incdtseverity
    ADD CONSTRAINT incdtseverity_pkey PRIMARY KEY (incdtseverity_id);


--
-- Name: invbal_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invbal
    ADD CONSTRAINT invbal_pkey PRIMARY KEY (invbal_id);


--
-- Name: invchead_invcnumber_unique; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invchead
    ADD CONSTRAINT invchead_invcnumber_unique UNIQUE (invchead_invcnumber);


--
-- Name: invchead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invchead
    ADD CONSTRAINT invchead_pkey PRIMARY KEY (invchead_id);


--
-- Name: invcheadtax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invcheadtax
    ADD CONSTRAINT invcheadtax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: invcitem_invchead_id_linenumber_unique; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invcitem
    ADD CONSTRAINT invcitem_invchead_id_linenumber_unique UNIQUE (invcitem_invchead_id, invcitem_linenumber);


--
-- Name: invcitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invcitem
    ADD CONSTRAINT invcitem_pkey PRIMARY KEY (invcitem_id);


--
-- Name: invcitemtax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invcitemtax
    ADD CONSTRAINT invcitemtax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: invcnt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invcnt
    ADD CONSTRAINT invcnt_pkey PRIMARY KEY (invcnt_id);


--
-- Name: invdetail_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invdetail
    ADD CONSTRAINT invdetail_pkey PRIMARY KEY (invdetail_id);


--
-- Name: invhist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invhist
    ADD CONSTRAINT invhist_pkey PRIMARY KEY (invhist_id);


--
-- Name: invhistexpcat_invhist_id_expcat_id; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invhistexpcat
    ADD CONSTRAINT invhistexpcat_invhist_id_expcat_id UNIQUE (invhistexpcat_invhist_id, invhistexpcat_expcat_id);


--
-- Name: invhistexpcat_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY invhistexpcat
    ADD CONSTRAINT invhistexpcat_pkey PRIMARY KEY (invhistexpcat_id);


--
-- Name: ipsass_ipsass_ipshead_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipsass
    ADD CONSTRAINT ipsass_ipsass_ipshead_id_key UNIQUE (ipsass_ipshead_id, ipsass_cust_id, ipsass_custtype_id, ipsass_custtype_pattern, ipsass_shipto_id, ipsass_shipto_pattern);


--
-- Name: ipsass_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipsass
    ADD CONSTRAINT ipsass_pkey PRIMARY KEY (ipsass_id);


--
-- Name: ipsfreight_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipsfreight
    ADD CONSTRAINT ipsfreight_pkey PRIMARY KEY (ipsfreight_id);


--
-- Name: ipshead_ipshead_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipshead
    ADD CONSTRAINT ipshead_ipshead_name_key UNIQUE (ipshead_name);


--
-- Name: ipshead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipshead
    ADD CONSTRAINT ipshead_pkey PRIMARY KEY (ipshead_id);


--
-- Name: ipsitem_ipsitem_ipshead_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipsiteminfo
    ADD CONSTRAINT ipsitem_ipsitem_ipshead_id_key UNIQUE (ipsitem_ipshead_id, ipsitem_item_id, ipsitem_prodcat_id, ipsitem_qtybreak, ipsitem_qty_uom_id, ipsitem_price_uom_id);


--
-- Name: ipsitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipsiteminfo
    ADD CONSTRAINT ipsitem_pkey PRIMARY KEY (ipsitem_id);


--
-- Name: ipsitemchar_ipsitemchar_ipsitem_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipsitemchar
    ADD CONSTRAINT ipsitemchar_ipsitemchar_ipsitem_id_key UNIQUE (ipsitemchar_ipsitem_id, ipsitemchar_char_id, ipsitemchar_value);


--
-- Name: ipsitemchar_ipsitemchar_ipsitem_id_key1; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipsitemchar
    ADD CONSTRAINT ipsitemchar_ipsitemchar_ipsitem_id_key1 UNIQUE (ipsitemchar_ipsitem_id, ipsitemchar_char_id, ipsitemchar_value);


--
-- Name: ipsitemchar_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipsitemchar
    ADD CONSTRAINT ipsitemchar_pkey PRIMARY KEY (ipsitemchar_id);


--
-- Name: ipsprodcat_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ipsprodcat_bak
    ADD CONSTRAINT ipsprodcat_pkey PRIMARY KEY (ipsprodcat_id);


--
-- Name: item_item_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY item
    ADD CONSTRAINT item_item_number_key UNIQUE (item_number);


--
-- Name: item_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY item
    ADD CONSTRAINT item_pkey PRIMARY KEY (item_id);


--
-- Name: itemalias_itemalias_item_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemalias
    ADD CONSTRAINT itemalias_itemalias_item_id_key UNIQUE (itemalias_item_id, itemalias_number);


--
-- Name: itemalias_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemalias
    ADD CONSTRAINT itemalias_pkey PRIMARY KEY (itemalias_id);


--
-- Name: itemcost_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemcost
    ADD CONSTRAINT itemcost_pkey PRIMARY KEY (itemcost_id);


--
-- Name: itemgrp_itemgrp_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemgrp
    ADD CONSTRAINT itemgrp_itemgrp_name_key UNIQUE (itemgrp_name);


--
-- Name: itemgrp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemgrp
    ADD CONSTRAINT itemgrp_pkey PRIMARY KEY (itemgrp_id);


--
-- Name: itemgrpitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemgrpitem
    ADD CONSTRAINT itemgrpitem_pkey PRIMARY KEY (itemgrpitem_id);


--
-- Name: itemgrpitem_unique_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemgrpitem
    ADD CONSTRAINT itemgrpitem_unique_key UNIQUE (itemgrpitem_itemgrp_id, itemgrpitem_item_id, itemgrpitem_item_type);


--
-- Name: itemloc_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemloc
    ADD CONSTRAINT itemloc_pkey PRIMARY KEY (itemloc_id);


--
-- Name: itemlocdist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemlocdist
    ADD CONSTRAINT itemlocdist_pkey PRIMARY KEY (itemlocdist_id);


--
-- Name: itemlocpost_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemlocpost
    ADD CONSTRAINT itemlocpost_pkey PRIMARY KEY (itemlocpost_id);


--
-- Name: itemsite_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemsite
    ADD CONSTRAINT itemsite_pkey PRIMARY KEY (itemsite_id);


--
-- Name: itemsrc_itemsrc_vend_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemsrc
    ADD CONSTRAINT itemsrc_itemsrc_vend_id_key UNIQUE (itemsrc_vend_id, itemsrc_item_id, itemsrc_effective, itemsrc_expires, itemsrc_vend_item_number, itemsrc_manuf_name, itemsrc_manuf_item_number, itemsrc_contrct_id);


--
-- Name: itemsrc_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemsrc
    ADD CONSTRAINT itemsrc_pkey PRIMARY KEY (itemsrc_id);


--
-- Name: itemsrcp_itemsrcp_itemsrc_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemsrcp
    ADD CONSTRAINT itemsrcp_itemsrcp_itemsrc_id_key UNIQUE (itemsrcp_itemsrc_id, itemsrcp_warehous_id, itemsrcp_dropship, itemsrcp_qtybreak);


--
-- Name: itemsrcp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemsrcp
    ADD CONSTRAINT itemsrcp_pkey PRIMARY KEY (itemsrcp_id);


--
-- Name: itemsub_itemsub_parent_item_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemsub
    ADD CONSTRAINT itemsub_itemsub_parent_item_id_key UNIQUE (itemsub_parent_item_id, itemsub_sub_item_id);


--
-- Name: itemsub_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemsub
    ADD CONSTRAINT itemsub_pkey PRIMARY KEY (itemsub_id);


--
-- Name: itemtax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemtax
    ADD CONSTRAINT itemtax_pkey PRIMARY KEY (itemtax_id);


--
-- Name: itemtrans_itemtrans_source_item_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemtrans
    ADD CONSTRAINT itemtrans_itemtrans_source_item_id_key UNIQUE (itemtrans_source_item_id, itemtrans_target_item_id);


--
-- Name: itemtrans_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemtrans
    ADD CONSTRAINT itemtrans_pkey PRIMARY KEY (itemtrans_id);


--
-- Name: itemuom_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemuom
    ADD CONSTRAINT itemuom_pkey PRIMARY KEY (itemuom_id);


--
-- Name: itemuomconv_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY itemuomconv
    ADD CONSTRAINT itemuomconv_pkey PRIMARY KEY (itemuomconv_id);


--
-- Name: jrnluse_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY jrnluse
    ADD CONSTRAINT jrnluse_pkey PRIMARY KEY (jrnluse_id);


--
-- Name: labeldef_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY labeldef
    ADD CONSTRAINT labeldef_pkey PRIMARY KEY (labeldef_id);


--
-- Name: labelform_labelform_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY labelform
    ADD CONSTRAINT labelform_labelform_name_key UNIQUE (labelform_name);


--
-- Name: labelform_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY labelform
    ADD CONSTRAINT labelform_pkey PRIMARY KEY (labelform_id);


--
-- Name: lang_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY lang
    ADD CONSTRAINT lang_pkey PRIMARY KEY (lang_id);


--
-- Name: locale_locale_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY locale
    ADD CONSTRAINT locale_locale_code_key UNIQUE (locale_code);


--
-- Name: locale_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY locale
    ADD CONSTRAINT locale_pkey PRIMARY KEY (locale_id);


--
-- Name: location_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY location
    ADD CONSTRAINT location_pkey PRIMARY KEY (location_id);


--
-- Name: locitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY locitem
    ADD CONSTRAINT locitem_pkey PRIMARY KEY (locitem_id);


--
-- Name: metasql_metasql_group_name_grade_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY metasql
    ADD CONSTRAINT metasql_metasql_group_name_grade_key UNIQUE (metasql_group, metasql_name, metasql_grade);


--
-- Name: metasql_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY metasql
    ADD CONSTRAINT metasql_pkey PRIMARY KEY (metasql_id);


--
-- Name: metric_metric_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY metric
    ADD CONSTRAINT metric_metric_name_key UNIQUE (metric_name);


--
-- Name: metric_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY metric
    ADD CONSTRAINT metric_pkey PRIMARY KEY (metric_id);


--
-- Name: metricenc_metricenc_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY metricenc
    ADD CONSTRAINT metricenc_metricenc_name_key UNIQUE (metricenc_name);


--
-- Name: metricenc_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY metricenc
    ADD CONSTRAINT metricenc_pkey PRIMARY KEY (metricenc_id);


--
-- Name: mrghist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY mrghist
    ADD CONSTRAINT mrghist_pkey PRIMARY KEY (mrghist_cntct_id, mrghist_table, mrghist_pkey_col, mrghist_pkey_id, mrghist_cntct_col);


--
-- Name: mrgundo_mrgundo_schema_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY mrgundo
    ADD CONSTRAINT mrgundo_mrgundo_schema_key UNIQUE (mrgundo_schema, mrgundo_table, mrgundo_pkey_col, mrgundo_pkey_id, mrgundo_col);


--
-- Name: msg_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY msg
    ADD CONSTRAINT msg_pkey PRIMARY KEY (msg_id);


--
-- Name: msguser_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY msguser
    ADD CONSTRAINT msguser_pkey PRIMARY KEY (msguser_id);


--
-- Name: obsolete_tax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY obsolete_tax
    ADD CONSTRAINT obsolete_tax_pkey PRIMARY KEY (tax_id);


--
-- Name: ophead_ophead_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ophead
    ADD CONSTRAINT ophead_ophead_number_key UNIQUE (ophead_number);


--
-- Name: ophead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY ophead
    ADD CONSTRAINT ophead_pkey PRIMARY KEY (ophead_id);


--
-- Name: opsource_opsource_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY opsource
    ADD CONSTRAINT opsource_opsource_name_key UNIQUE (opsource_name);


--
-- Name: opsource_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY opsource
    ADD CONSTRAINT opsource_pkey PRIMARY KEY (opsource_id);


--
-- Name: opstage_opstage_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY opstage
    ADD CONSTRAINT opstage_opstage_name_key UNIQUE (opstage_name);


--
-- Name: opstage_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY opstage
    ADD CONSTRAINT opstage_pkey PRIMARY KEY (opstage_id);


--
-- Name: optype_optype_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY optype
    ADD CONSTRAINT optype_optype_name_key UNIQUE (optype_name);


--
-- Name: optype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY optype
    ADD CONSTRAINT optype_pkey PRIMARY KEY (optype_id);


--
-- Name: orderseq_orderseq_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY orderseq
    ADD CONSTRAINT orderseq_orderseq_name_key UNIQUE (orderseq_name);


--
-- Name: orderseq_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY orderseq
    ADD CONSTRAINT orderseq_pkey PRIMARY KEY (orderseq_id);


--
-- Name: pack_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pack
    ADD CONSTRAINT pack_pkey PRIMARY KEY (pack_id);


--
-- Name: payaropen_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY payaropen
    ADD CONSTRAINT payaropen_pkey PRIMARY KEY (payaropen_ccpay_id, payaropen_aropen_id);


--
-- Name: payco_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY payco
    ADD CONSTRAINT payco_pkey PRIMARY KEY (payco_id);


--
-- Name: payco_unique_ccpay_id_cohead_id; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY payco
    ADD CONSTRAINT payco_unique_ccpay_id_cohead_id UNIQUE (payco_ccpay_id, payco_cohead_id);


--
-- Name: period_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY period
    ADD CONSTRAINT period_pkey PRIMARY KEY (period_id);


--
-- Name: pk_prjtype; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prjtype
    ADD CONSTRAINT pk_prjtype PRIMARY KEY (prjtype_id);


--
-- Name: pkgdep_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgdep
    ADD CONSTRAINT pkgdep_pkey PRIMARY KEY (pkgdep_id);


--
-- Name: pkghead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkghead
    ADD CONSTRAINT pkghead_pkey PRIMARY KEY (pkghead_id);


--
-- Name: pkgitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgitem
    ADD CONSTRAINT pkgitem_pkey PRIMARY KEY (pkgitem_id);


--
-- Name: pkgitem_pkgitem_pkghead_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgitem
    ADD CONSTRAINT pkgitem_pkgitem_pkghead_id_key UNIQUE (pkgitem_pkghead_id, pkgitem_type, pkgitem_name);


--
-- Name: pkgitem_pkgitem_pkghead_id_key1; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgitem
    ADD CONSTRAINT pkgitem_pkgitem_pkghead_id_key1 UNIQUE (pkgitem_pkghead_id, pkgitem_type, pkgitem_item_id);


--
-- Name: plancode_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY plancode
    ADD CONSTRAINT plancode_pkey PRIMARY KEY (plancode_id);


--
-- Name: plancode_plancode_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY plancode
    ADD CONSTRAINT plancode_plancode_code_key UNIQUE (plancode_code);


--
-- Name: pohead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pohead
    ADD CONSTRAINT pohead_pkey PRIMARY KEY (pohead_id);


--
-- Name: pohead_pohead_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pohead
    ADD CONSTRAINT pohead_pohead_number_key UNIQUE (pohead_number);


--
-- Name: poitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY poitem
    ADD CONSTRAINT poitem_pkey PRIMARY KEY (poitem_id);


--
-- Name: poitem_poitem_pohead_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY poitem
    ADD CONSTRAINT poitem_poitem_pohead_id_key UNIQUE (poitem_pohead_id, poitem_linenumber);


--
-- Name: poreject_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY poreject
    ADD CONSTRAINT poreject_pkey PRIMARY KEY (poreject_id);


--
-- Name: pr_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pr
    ADD CONSTRAINT pr_pkey PRIMARY KEY (pr_id);


--
-- Name: prftcntr_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prftcntr
    ADD CONSTRAINT prftcntr_pkey PRIMARY KEY (prftcntr_id);


--
-- Name: prftcntr_prftcntr_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prftcntr
    ADD CONSTRAINT prftcntr_prftcntr_number_key UNIQUE (prftcntr_number);


--
-- Name: priv_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY priv
    ADD CONSTRAINT priv_pkey PRIMARY KEY (priv_id);


--
-- Name: prj_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prj
    ADD CONSTRAINT prj_pkey PRIMARY KEY (prj_id);


--
-- Name: prj_prj_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prj
    ADD CONSTRAINT prj_prj_number_key UNIQUE (prj_number);


--
-- Name: prjtask_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prjtask
    ADD CONSTRAINT prjtask_pkey PRIMARY KEY (prjtask_id);


--
-- Name: prjtask_prjtask_prj_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prjtask
    ADD CONSTRAINT prjtask_prjtask_prj_id_key UNIQUE (prjtask_prj_id, prjtask_number);


--
-- Name: prjtaskuser_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prjtaskuser
    ADD CONSTRAINT prjtaskuser_pkey PRIMARY KEY (prjtaskuser_id);


--
-- Name: prodcat_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prodcat
    ADD CONSTRAINT prodcat_pkey PRIMARY KEY (prodcat_id);


--
-- Name: prodcat_prodcat_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prodcat
    ADD CONSTRAINT prodcat_prodcat_code_key UNIQUE (prodcat_code);


--
-- Name: prospect_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prospect
    ADD CONSTRAINT prospect_pkey PRIMARY KEY (prospect_id);


--
-- Name: prospect_prospect_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prospect
    ADD CONSTRAINT prospect_prospect_number_key UNIQUE (prospect_number);


--
-- Name: qryhead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY qryhead
    ADD CONSTRAINT qryhead_pkey PRIMARY KEY (qryhead_id);


--
-- Name: qryhead_qryhead_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY qryhead
    ADD CONSTRAINT qryhead_qryhead_name_key UNIQUE (qryhead_name);


--
-- Name: qryitem_qryitem_qryhead_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY qryitem
    ADD CONSTRAINT qryitem_qryitem_qryhead_id_key UNIQUE (qryitem_qryhead_id, qryitem_name);


--
-- Name: qryitem_qryitem_qryhead_id_key1; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY qryitem
    ADD CONSTRAINT qryitem_qryitem_qryhead_id_key1 UNIQUE (qryitem_qryhead_id, qryitem_order);


--
-- Name: quhead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY quhead
    ADD CONSTRAINT quhead_pkey PRIMARY KEY (quhead_id);


--
-- Name: quhead_quhead_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY quhead
    ADD CONSTRAINT quhead_quhead_number_key UNIQUE (quhead_number);


--
-- Name: quitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY quitem
    ADD CONSTRAINT quitem_pkey PRIMARY KEY (quitem_id);


--
-- Name: rcalitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY rcalitem
    ADD CONSTRAINT rcalitem_pkey PRIMARY KEY (rcalitem_id);


--
-- Name: recur_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY recur
    ADD CONSTRAINT recur_pkey PRIMARY KEY (recur_id);


--
-- Name: recur_recur_parent_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY recur
    ADD CONSTRAINT recur_recur_parent_id_key UNIQUE (recur_parent_id, recur_parent_type);


--
-- Name: recurtype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY recurtype
    ADD CONSTRAINT recurtype_pkey PRIMARY KEY (recurtype_id);


--
-- Name: recurtype_recurtype_type_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY recurtype
    ADD CONSTRAINT recurtype_recurtype_type_key UNIQUE (recurtype_type);


--
-- Name: recv_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY recv
    ADD CONSTRAINT recv_pkey PRIMARY KEY (recv_id);


--
-- Name: report_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY report
    ADD CONSTRAINT report_pkey PRIMARY KEY (report_id);


--
-- Name: rjctcode_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY rjctcode
    ADD CONSTRAINT rjctcode_pkey PRIMARY KEY (rjctcode_id);


--
-- Name: rjctcode_rjctcode_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY rjctcode
    ADD CONSTRAINT rjctcode_rjctcode_code_key UNIQUE (rjctcode_code);


--
-- Name: rsncode_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY rsncode
    ADD CONSTRAINT rsncode_pkey PRIMARY KEY (rsncode_id);


--
-- Name: rsncode_rsncode_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY rsncode
    ADD CONSTRAINT rsncode_rsncode_code_key UNIQUE (rsncode_code);


--
-- Name: sale_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY sale
    ADD CONSTRAINT sale_pkey PRIMARY KEY (sale_id);


--
-- Name: sale_sale_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY sale
    ADD CONSTRAINT sale_sale_name_key UNIQUE (sale_name);


--
-- Name: salesaccnt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY salesaccnt
    ADD CONSTRAINT salesaccnt_pkey PRIMARY KEY (salesaccnt_id);


--
-- Name: salescat_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY salescat
    ADD CONSTRAINT salescat_pkey PRIMARY KEY (salescat_id);


--
-- Name: salescat_salescat_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY salescat
    ADD CONSTRAINT salescat_salescat_name_key UNIQUE (salescat_name);


--
-- Name: salesrep_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY salesrep
    ADD CONSTRAINT salesrep_pkey PRIMARY KEY (salesrep_id);


--
-- Name: salesrep_salesrep_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY salesrep
    ADD CONSTRAINT salesrep_salesrep_number_key UNIQUE (salesrep_number);


--
-- Name: saletype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY saletype
    ADD CONSTRAINT saletype_pkey PRIMARY KEY (saletype_id);


--
-- Name: schemaord_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY schemaord
    ADD CONSTRAINT schemaord_pkey PRIMARY KEY (schemaord_id);


--
-- Name: schemaord_schemaord_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY schemaord
    ADD CONSTRAINT schemaord_schemaord_name_key UNIQUE (schemaord_name);


--
-- Name: schemaord_schemaord_order_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY schemaord
    ADD CONSTRAINT schemaord_schemaord_order_key UNIQUE (schemaord_order);


--
-- Name: script_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY script
    ADD CONSTRAINT script_pkey PRIMARY KEY (script_id);


--
-- Name: shift_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shift
    ADD CONSTRAINT shift_pkey PRIMARY KEY (shift_id);


--
-- Name: shipchrg_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipchrg
    ADD CONSTRAINT shipchrg_pkey PRIMARY KEY (shipchrg_id);


--
-- Name: shipdata_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipdata
    ADD CONSTRAINT shipdata_pkey PRIMARY KEY (shipdata_cohead_number, shipdata_cosmisc_tracknum, shipdata_cosmisc_packnum_tracknum, shipdata_void_ind);


--
-- Name: shipdatasum_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipdatasum
    ADD CONSTRAINT shipdatasum_pkey PRIMARY KEY (shipdatasum_cohead_number, shipdatasum_cosmisc_tracknum, shipdatasum_cosmisc_packnum_tracknum);


--
-- Name: shipform_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipform
    ADD CONSTRAINT shipform_pkey PRIMARY KEY (shipform_id);


--
-- Name: shipform_shipform_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipform
    ADD CONSTRAINT shipform_shipform_name_key UNIQUE (shipform_name);


--
-- Name: shiphead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shiphead
    ADD CONSTRAINT shiphead_pkey PRIMARY KEY (shiphead_id);


--
-- Name: shiphead_shiphead_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shiphead
    ADD CONSTRAINT shiphead_shiphead_number_key UNIQUE (shiphead_number);


--
-- Name: shipitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipitem
    ADD CONSTRAINT shipitem_pkey PRIMARY KEY (shipitem_id);


--
-- Name: shipto_num_cust_unique; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shiptoinfo
    ADD CONSTRAINT shipto_num_cust_unique UNIQUE (shipto_cust_id, shipto_num);


--
-- Name: shipto_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shiptoinfo
    ADD CONSTRAINT shipto_pkey PRIMARY KEY (shipto_id);


--
-- Name: shipvia_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipvia
    ADD CONSTRAINT shipvia_pkey PRIMARY KEY (shipvia_id);


--
-- Name: shipvia_shipvia_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipvia
    ADD CONSTRAINT shipvia_shipvia_code_key UNIQUE (shipvia_code);


--
-- Name: shipzone_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipzone
    ADD CONSTRAINT shipzone_pkey PRIMARY KEY (shipzone_id);


--
-- Name: shipzone_shipzone_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY shipzone
    ADD CONSTRAINT shipzone_shipzone_name_key UNIQUE (shipzone_name);


--
-- Name: sitetype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY sitetype
    ADD CONSTRAINT sitetype_pkey PRIMARY KEY (sitetype_id);


--
-- Name: sitetype_sitetype_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY sitetype
    ADD CONSTRAINT sitetype_sitetype_name_key UNIQUE (sitetype_name);


--
-- Name: sltrans_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY sltrans
    ADD CONSTRAINT sltrans_pkey PRIMARY KEY (sltrans_id);


--
-- Name: source_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY source
    ADD CONSTRAINT source_pkey PRIMARY KEY (source_id);


--
-- Name: source_source_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY source
    ADD CONSTRAINT source_source_name_key UNIQUE (source_name);


--
-- Name: state_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY state
    ADD CONSTRAINT state_pkey PRIMARY KEY (state_id);


--
-- Name: state_state_country_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY state
    ADD CONSTRAINT state_state_country_id_key UNIQUE (state_country_id, state_name);


--
-- Name: status_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY status
    ADD CONSTRAINT status_pkey PRIMARY KEY (status_id);


--
-- Name: status_status_type_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY status
    ADD CONSTRAINT status_status_type_key UNIQUE (status_type, status_code);


--
-- Name: stdjrnl_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY stdjrnl
    ADD CONSTRAINT stdjrnl_pkey PRIMARY KEY (stdjrnl_id);


--
-- Name: stdjrnl_stdjrnl_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY stdjrnl
    ADD CONSTRAINT stdjrnl_stdjrnl_name_key UNIQUE (stdjrnl_name);


--
-- Name: stdjrnlgrp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY stdjrnlgrp
    ADD CONSTRAINT stdjrnlgrp_pkey PRIMARY KEY (stdjrnlgrp_id);


--
-- Name: stdjrnlgrp_stdjrnlgrp_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY stdjrnlgrp
    ADD CONSTRAINT stdjrnlgrp_stdjrnlgrp_name_key UNIQUE (stdjrnlgrp_name);


--
-- Name: stdjrnlgrpitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY stdjrnlgrpitem
    ADD CONSTRAINT stdjrnlgrpitem_pkey PRIMARY KEY (stdjrnlgrpitem_id);


--
-- Name: stdjrnlitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY stdjrnlitem
    ADD CONSTRAINT stdjrnlitem_pkey PRIMARY KEY (stdjrnlitem_id);


--
-- Name: subaccnt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY subaccnt
    ADD CONSTRAINT subaccnt_pkey PRIMARY KEY (subaccnt_id);


--
-- Name: subaccnt_subaccnt_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY subaccnt
    ADD CONSTRAINT subaccnt_subaccnt_number_key UNIQUE (subaccnt_number);


--
-- Name: subaccnttype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY subaccnttype
    ADD CONSTRAINT subaccnttype_pkey PRIMARY KEY (subaccnttype_id);


--
-- Name: tax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY tax
    ADD CONSTRAINT tax_pkey PRIMARY KEY (tax_id);


--
-- Name: taxass_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxass
    ADD CONSTRAINT taxass_pkey PRIMARY KEY (taxass_id);


--
-- Name: taxass_taxass_taxzone_id_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxass
    ADD CONSTRAINT taxass_taxass_taxzone_id_key UNIQUE (taxass_taxzone_id, taxass_taxtype_id, taxass_tax_id);


--
-- Name: taxauth_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxauth
    ADD CONSTRAINT taxauth_pkey PRIMARY KEY (taxauth_id);


--
-- Name: taxauth_taxauth_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxauth
    ADD CONSTRAINT taxauth_taxauth_code_key UNIQUE (taxauth_code);


--
-- Name: taxclass_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxclass
    ADD CONSTRAINT taxclass_pkey PRIMARY KEY (taxclass_id);


--
-- Name: taxclass_taxclass_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxclass
    ADD CONSTRAINT taxclass_taxclass_code_key UNIQUE (taxclass_code);


--
-- Name: taxhist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxhist
    ADD CONSTRAINT taxhist_pkey PRIMARY KEY (taxhist_id);


--
-- Name: taxpay_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxpay
    ADD CONSTRAINT taxpay_pkey PRIMARY KEY (taxpay_id);


--
-- Name: taxrate_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxrate
    ADD CONSTRAINT taxrate_pkey PRIMARY KEY (taxrate_id);


--
-- Name: taxreg_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxreg
    ADD CONSTRAINT taxreg_pkey PRIMARY KEY (taxreg_id);


--
-- Name: taxtype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxtype
    ADD CONSTRAINT taxtype_pkey PRIMARY KEY (taxtype_id);


--
-- Name: taxtype_taxtype_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxtype
    ADD CONSTRAINT taxtype_taxtype_name_key UNIQUE (taxtype_name);


--
-- Name: taxzone_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxzone
    ADD CONSTRAINT taxzone_pkey PRIMARY KEY (taxzone_id);


--
-- Name: taxzone_taxzone_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY taxzone
    ADD CONSTRAINT taxzone_taxzone_code_key UNIQUE (taxzone_code);


--
-- Name: terms_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY terms
    ADD CONSTRAINT terms_pkey PRIMARY KEY (terms_id);


--
-- Name: terms_terms_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY terms
    ADD CONSTRAINT terms_terms_code_key UNIQUE (terms_code);


--
-- Name: todoitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY todoitem
    ADD CONSTRAINT todoitem_pkey PRIMARY KEY (todoitem_id);


--
-- Name: trialbal_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY trialbal
    ADD CONSTRAINT trialbal_pkey PRIMARY KEY (trialbal_id);


--
-- Name: uiform_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY uiform
    ADD CONSTRAINT uiform_pkey PRIMARY KEY (uiform_id);


--
-- Name: unq_prjtype_code; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY prjtype
    ADD CONSTRAINT unq_prjtype_code UNIQUE (prjtype_code);


--
-- Name: uom_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY uom
    ADD CONSTRAINT uom_pkey PRIMARY KEY (uom_id);


--
-- Name: uom_uom_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY uom
    ADD CONSTRAINT uom_uom_name_key UNIQUE (uom_name);


--
-- Name: uomconv_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY uomconv
    ADD CONSTRAINT uomconv_pkey PRIMARY KEY (uomconv_id);


--
-- Name: uomtype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY uomtype
    ADD CONSTRAINT uomtype_pkey PRIMARY KEY (uomtype_id);


--
-- Name: uomtype_uomtype_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY uomtype
    ADD CONSTRAINT uomtype_uomtype_name_key UNIQUE (uomtype_name);


--
-- Name: urlinfo_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY urlinfo
    ADD CONSTRAINT urlinfo_pkey PRIMARY KEY (url_id);


--
-- Name: usr_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY usr_bak
    ADD CONSTRAINT usr_pkey PRIMARY KEY (usr_id);


--
-- Name: usr_usr_username_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY usr_bak
    ADD CONSTRAINT usr_usr_username_key UNIQUE (usr_username);


--
-- Name: usrgrp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY usrgrp
    ADD CONSTRAINT usrgrp_pkey PRIMARY KEY (usrgrp_id);


--
-- Name: usrpref_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY usrpref
    ADD CONSTRAINT usrpref_pkey PRIMARY KEY (usrpref_id);


--
-- Name: usrpriv_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY usrpriv
    ADD CONSTRAINT usrpriv_pkey PRIMARY KEY (usrpriv_id);


--
-- Name: vend_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY vendinfo
    ADD CONSTRAINT vend_pkey PRIMARY KEY (vend_id);


--
-- Name: vendaddr_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY vendaddrinfo
    ADD CONSTRAINT vendaddr_pkey PRIMARY KEY (vendaddr_id);


--
-- Name: vendinfo_vend_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY vendinfo
    ADD CONSTRAINT vendinfo_vend_number_key UNIQUE (vend_number);


--
-- Name: vendtype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY vendtype
    ADD CONSTRAINT vendtype_pkey PRIMARY KEY (vendtype_id);


--
-- Name: vendtype_vendtype_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY vendtype
    ADD CONSTRAINT vendtype_vendtype_code_key UNIQUE (vendtype_code);


--
-- Name: vodist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY vodist
    ADD CONSTRAINT vodist_pkey PRIMARY KEY (vodist_id);


--
-- Name: vohead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY vohead
    ADD CONSTRAINT vohead_pkey PRIMARY KEY (vohead_id);


--
-- Name: vohead_vohead_number_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY vohead
    ADD CONSTRAINT vohead_vohead_number_key UNIQUE (vohead_number);


--
-- Name: voheadtax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY voheadtax
    ADD CONSTRAINT voheadtax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: voitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY voitem
    ADD CONSTRAINT voitem_pkey PRIMARY KEY (voitem_id);


--
-- Name: voitemtax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY voitemtax
    ADD CONSTRAINT voitemtax_pkey PRIMARY KEY (taxhist_id);


--
-- Name: warehous_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY whsinfo
    ADD CONSTRAINT warehous_pkey PRIMARY KEY (warehous_id);


--
-- Name: whsezone_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY whsezone
    ADD CONSTRAINT whsezone_pkey PRIMARY KEY (whsezone_id);


--
-- Name: whsinfo_warehous_code_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY whsinfo
    ADD CONSTRAINT whsinfo_warehous_code_key UNIQUE (warehous_code);


--
-- Name: wo_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY wo
    ADD CONSTRAINT wo_pkey PRIMARY KEY (wo_id);


--
-- Name: womatl_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY womatl
    ADD CONSTRAINT womatl_pkey PRIMARY KEY (womatl_id);


--
-- Name: womatlpost_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY womatlpost
    ADD CONSTRAINT womatlpost_pkey PRIMARY KEY (womatlpost_id);


--
-- Name: womatlvar_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY womatlvar
    ADD CONSTRAINT womatlvar_pkey PRIMARY KEY (womatlvar_id);


--
-- Name: xsltmap_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY xsltmap
    ADD CONSTRAINT xsltmap_name_key UNIQUE (xsltmap_name);


--
-- Name: xsltmap_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY xsltmap
    ADD CONSTRAINT xsltmap_pkey PRIMARY KEY (xsltmap_id);


--
-- Name: yearperiod_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY yearperiod
    ADD CONSTRAINT yearperiod_pkey PRIMARY KEY (yearperiod_id);



--
-- Name: pkgcmd_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgcmd
    ADD CONSTRAINT pkgcmd_pkey PRIMARY KEY (cmd_id);


--
-- Name: pkgcmdarg_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgcmdarg
    ADD CONSTRAINT pkgcmdarg_pkey PRIMARY KEY (cmdarg_id);


--
-- Name: pkgimage_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgimage
    ADD CONSTRAINT pkgimage_pkey PRIMARY KEY (image_id);


--
-- Name: pkgmetasql_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgmetasql
    ADD CONSTRAINT pkgmetasql_pkey PRIMARY KEY (metasql_id);


--
-- Name: pkgpriv_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgpriv
    ADD CONSTRAINT pkgpriv_pkey PRIMARY KEY (priv_id);


--
-- Name: pkgreport_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgreport
    ADD CONSTRAINT pkgreport_pkey PRIMARY KEY (report_id);


--
-- Name: pkgscript_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgscript
    ADD CONSTRAINT pkgscript_pkey PRIMARY KEY (script_id);


--
-- Name: pkguiform_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkguiform
    ADD CONSTRAINT pkguiform_pkey PRIMARY KEY (uiform_id);


--
-- Name: tecustrate_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY tecustrate
    ADD CONSTRAINT tecustrate_pkey PRIMARY KEY (tecustrate_cust_id);


--
-- Name: teexp_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teexp
    ADD CONSTRAINT teexp_pkey PRIMARY KEY (teexp_id);


--
-- Name: tehead_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY tehead
    ADD CONSTRAINT tehead_pkey PRIMARY KEY (tehead_id);


--
-- Name: teitem_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teitem
    ADD CONSTRAINT teitem_pkey PRIMARY KEY (teitem_id);


--
-- Name: teprj_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teprj
    ADD CONSTRAINT teprj_pkey PRIMARY KEY (teprj_id);


--
-- Name: teprj_teprj_prj_id; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teprj
    ADD CONSTRAINT teprj_teprj_prj_id UNIQUE (teprj_prj_id);


--
-- Name: teprjtask_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teprjtask
    ADD CONSTRAINT teprjtask_pkey PRIMARY KEY (teprjtask_id);


--
-- Name: teprjtask_teprjtask_prjtask_id_key; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teprjtask
    ADD CONSTRAINT teprjtask_teprjtask_prjtask_id_key UNIQUE (teprjtask_prjtask_id);



--
-- Name: js_js_namespace_js_type_js_context; Type: CONSTRAINT; Schema: xt; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY js
    ADD CONSTRAINT js_js_namespace_js_type_js_context UNIQUE (js_namespace, js_type, js_context);


--
-- Name: js_pkey; Type: CONSTRAINT; Schema: xt; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY js
    ADD CONSTRAINT js_pkey PRIMARY KEY (js_id);



--
-- Name: pkgcmd_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgcmd
    ADD CONSTRAINT pkgcmd_pkey PRIMARY KEY (cmd_id);


--
-- Name: pkgcmdarg_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgcmdarg
    ADD CONSTRAINT pkgcmdarg_pkey PRIMARY KEY (cmdarg_id);


--
-- Name: pkgimage_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgimage
    ADD CONSTRAINT pkgimage_pkey PRIMARY KEY (image_id);


--
-- Name: pkgmetasql_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgmetasql
    ADD CONSTRAINT pkgmetasql_pkey PRIMARY KEY (metasql_id);


--
-- Name: pkgpriv_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgpriv
    ADD CONSTRAINT pkgpriv_pkey PRIMARY KEY (priv_id);


--
-- Name: pkgreport_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgreport
    ADD CONSTRAINT pkgreport_pkey PRIMARY KEY (report_id);


--
-- Name: pkgscript_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkgscript
    ADD CONSTRAINT pkgscript_pkey PRIMARY KEY (script_id);


--
-- Name: pkguiform_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY pkguiform
    ADD CONSTRAINT pkguiform_pkey PRIMARY KEY (uiform_id);



--
-- Name: accnt_unique_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX accnt_unique_idx ON accnt USING btree (accnt_number, accnt_profit, accnt_sub, accnt_company);


--
-- Name: apopen_apopen_open_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX apopen_apopen_open_idx ON apopen USING btree (apopen_open);


--
-- Name: apopen_apopen_vend_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX apopen_apopen_vend_id_idx ON apopen USING btree (apopen_vend_id);


--
-- Name: apopentax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX apopentax_taxhist_parent_id_idx ON apopentax USING btree (taxhist_parent_id);


--
-- Name: apopentax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX apopentax_taxhist_parent_type_idx ON apopentax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: apopentax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX apopentax_taxhist_taxtype_id_idx ON apopentax USING btree (taxhist_taxtype_id);


--
-- Name: apselect_apselect_apopen_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX apselect_apselect_apopen_id_idx ON apselect USING btree (apselect_apopen_id);


--
-- Name: arapply_arapply_target_docnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX arapply_arapply_target_docnumber_idx ON arapply USING btree (arapply_target_docnumber);


--
-- Name: aropen_aropen_cust_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropen_aropen_cust_id_idx ON aropen USING btree (aropen_cust_id);


--
-- Name: aropen_aropen_docnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropen_aropen_docnumber_idx ON aropen USING btree (aropen_docnumber);


--
-- Name: aropen_aropen_doctype_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropen_aropen_doctype_idx ON aropen USING btree (aropen_doctype);


--
-- Name: aropen_aropen_open_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropen_aropen_open_idx ON aropen USING btree (aropen_open);


--
-- Name: aropen_posted_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropen_posted_idx ON aropen USING btree (aropen_posted);


--
-- Name: aropenalloc_aropen_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropenalloc_aropen_id_idx ON aropenalloc USING btree (aropenalloc_aropen_id);


--
-- Name: aropenalloc_doc_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropenalloc_doc_id_idx ON aropenalloc USING btree (aropenalloc_doc_id);


--
-- Name: aropentax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropentax_taxhist_parent_id_idx ON aropentax USING btree (taxhist_parent_id);


--
-- Name: aropentax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropentax_taxhist_parent_type_idx ON aropentax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: aropentax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropentax_taxhist_taxtype_id_idx ON aropentax USING btree (taxhist_taxtype_id);


--
-- Name: asohisttax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX asohisttax_taxhist_parent_id_idx ON asohisttax USING btree (taxhist_parent_id);


--
-- Name: asohisttax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX asohisttax_taxhist_parent_type_idx ON asohisttax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: asohisttax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX asohisttax_taxhist_taxtype_id_idx ON asohisttax USING btree (taxhist_taxtype_id);


--
-- Name: bomitem_bomitem_item_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX bomitem_bomitem_item_id_idx ON bomitem USING btree (bomitem_item_id);


--
-- Name: bomitem_effective_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX bomitem_effective_key ON bomitem USING btree (bomitem_effective);


--
-- Name: bomitem_expires_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX bomitem_expires_key ON bomitem USING btree (bomitem_expires);


--
-- Name: bomitem_parent_item_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX bomitem_parent_item_id ON bomitem USING btree (bomitem_parent_item_id);


--
-- Name: bomitemcost_bomitem_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX bomitemcost_bomitem_id_key ON bomitemcost USING btree (bomitemcost_bomitem_id);


--
-- Name: bomitemcost_master_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX bomitemcost_master_idx ON bomitemcost USING btree (bomitemcost_bomitem_id, bomitemcost_costelem_id, bomitemcost_lowlevel);


--
-- Name: cashrcptitem_aropen_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cashrcptitem_aropen_idx ON cashrcptitem USING btree (cashrcptitem_aropen_id);


--
-- Name: cashrcptitem_cashrcpt_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cashrcptitem_cashrcpt_idx ON cashrcptitem USING btree (cashrcptitem_cashrcpt_id);


--
-- Name: ccard_cust_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX ccard_cust_id_idx ON ccard USING btree (ccard_cust_id);


--
-- Name: ccardaud_ccard_cust_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX ccardaud_ccard_cust_id_idx ON ccardaud USING btree (ccardaud_ccard_cust_id_new);


--
-- Name: ccardaud_ccard_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX ccardaud_ccard_id_idx ON ccardaud USING btree (ccardaud_ccard_id);


--
-- Name: ccpay_ccard_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX ccpay_ccard_id_idx ON ccpay USING btree (ccpay_ccard_id);


--
-- Name: ccpay_cust_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX ccpay_cust_id_idx ON ccpay USING btree (ccpay_cust_id);


--
-- Name: ccpay_order_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX ccpay_order_number_idx ON ccpay USING btree (ccpay_order_number);


--
-- Name: charass_char_id_target_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX charass_char_id_target_type_idx ON charass USING btree (charass_char_id, charass_target_type);


--
-- Name: charass_target_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX charass_target_idx ON charass USING btree (charass_target_type, charass_target_id);


--
-- Name: checkhead_posted_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX checkhead_posted_idx ON checkhead USING btree (checkhead_posted);


--
-- Name: checkhead_replaced_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX checkhead_replaced_idx ON checkhead USING btree (checkhead_replaced);


--
-- Name: checkitem_apopenitem_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX checkitem_apopenitem_id_idx ON checkitem USING btree (checkitem_apopen_id);


--
-- Name: cmhead_invcnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cmhead_invcnumber_idx ON cmhead USING btree (cmhead_invcnumber);


--
-- Name: cmheadtax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cmheadtax_taxhist_parent_id_idx ON cmheadtax USING btree (taxhist_parent_id);


--
-- Name: cmheadtax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cmheadtax_taxhist_parent_type_idx ON cmheadtax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: cmheadtax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cmheadtax_taxhist_taxtype_id_idx ON cmheadtax USING btree (taxhist_taxtype_id);


--
-- Name: cmitemtax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cmitemtax_taxhist_parent_id_idx ON cmitemtax USING btree (taxhist_parent_id);


--
-- Name: cmitemtax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cmitemtax_taxhist_parent_type_idx ON cmitemtax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: cmitemtax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cmitemtax_taxhist_taxtype_id_idx ON cmitemtax USING btree (taxhist_taxtype_id);


--
-- Name: cntct_email_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cntct_email_idx ON cntct USING btree (cntct_email);


--
-- Name: cntct_name_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cntct_name_idx ON cntct USING btree (cntct_name);


--
-- Name: cobill_cobmisc_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobill_cobmisc_id ON cobill USING btree (cobill_cobmisc_id);


--
-- Name: cobill_coitem_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobill_coitem_id ON cobill USING btree (cobill_coitem_id);


--
-- Name: cobilltax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobilltax_taxhist_parent_id_idx ON cobilltax USING btree (taxhist_parent_id);


--
-- Name: cobilltax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobilltax_taxhist_parent_type_idx ON cobilltax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: cobilltax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobilltax_taxhist_taxtype_id_idx ON cobilltax USING btree (taxhist_taxtype_id);


--
-- Name: cobmisc_cohead_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobmisc_cohead_id ON cobmisc USING btree (cobmisc_cohead_id);


--
-- Name: cobmisc_posted; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobmisc_posted ON cobmisc USING btree (cobmisc_posted);


--
-- Name: cobmisctax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobmisctax_taxhist_parent_id_idx ON cobmisctax USING btree (taxhist_parent_id);


--
-- Name: cobmisctax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobmisctax_taxhist_parent_type_idx ON cobmisctax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: cobmisctax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobmisctax_taxhist_taxtype_id_idx ON cobmisctax USING btree (taxhist_taxtype_id);


--
-- Name: cohead_cohead_status_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohead_cohead_status_idx ON cohead USING btree (cohead_status);


--
-- Name: cohead_cust_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohead_cust_id_key ON cohead USING btree (cohead_cust_id);


--
-- Name: cohead_custponumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohead_custponumber_idx ON cohead USING btree (cohead_custponumber);


--
-- Name: cohead_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX cohead_number_idx ON cohead USING btree (cohead_number);


--
-- Name: cohead_shipto_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohead_shipto_id ON cohead USING btree (cohead_shipto_id);


--
-- Name: cohist_cust_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_cust_id ON cohist USING btree (cohist_cust_id);


--
-- Name: cohist_invcnumber; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_invcnumber ON cohist USING btree (cohist_invcnumber);


--
-- Name: cohist_itemsite_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_itemsite_id ON cohist USING btree (cohist_itemsite_id);


--
-- Name: cohist_shipdate; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_shipdate ON cohist USING btree (cohist_shipdate);


--
-- Name: cohist_shipto_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_shipto_id ON cohist USING btree (cohist_shipto_id);


--
-- Name: cohisttax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohisttax_taxhist_parent_id_idx ON cohisttax USING btree (taxhist_parent_id);


--
-- Name: cohisttax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohisttax_taxhist_parent_type_idx ON cohisttax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: cohisttax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohisttax_taxhist_taxtype_id_idx ON cohisttax USING btree (taxhist_taxtype_id);


--
-- Name: coitem_cohead_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX coitem_cohead_id_key ON coitem USING btree (coitem_cohead_id);


--
-- Name: coitem_coitem_cohead_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX coitem_coitem_cohead_id_key ON coitem USING btree (coitem_cohead_id, coitem_linenumber, coitem_subnumber);


--
-- Name: coitem_itemsite_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX coitem_itemsite_id ON coitem USING btree (coitem_itemsite_id);


--
-- Name: coitem_linenumber_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX coitem_linenumber_key ON coitem USING btree (coitem_linenumber);


--
-- Name: coitem_status_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX coitem_status_key ON coitem USING btree (coitem_status);


--
-- Name: comment_comment_source_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX comment_comment_source_idx ON comment USING btree (comment_source, comment_source_id);


--
-- Name: contrct_master_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX contrct_master_idx ON contrct USING btree (contrct_number, contrct_vend_id);


--
-- Name: cust_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX cust_number_idx ON custinfo USING btree (cust_number);


--
-- Name: docass_source_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX docass_source_id_idx ON docass USING btree (docass_source_id);


--
-- Name: docass_source_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX docass_source_type_idx ON docass USING btree (docass_source_type);


--
-- Name: docass_target_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX docass_target_id_idx ON docass USING btree (docass_target_id);


--
-- Name: docass_target_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX docass_target_type_idx ON docass USING btree (docass_target_type);


--
-- Name: evntlog_dispatched_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX evntlog_dispatched_idx ON evntlog USING btree (evntlog_dispatched);


--
-- Name: evntlog_evntlog_username_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX evntlog_evntlog_username_idx ON evntlog USING btree (evntlog_username);


--
-- Name: evntnot_evnttype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX evntnot_evnttype_id_idx ON evntnot USING btree (evntnot_evnttype_id);


--
-- Name: evntnot_warehous_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX evntnot_warehous_id_idx ON evntnot USING btree (evntnot_warehous_id);


--
-- Name: filter_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX filter_idx ON filter USING btree (filter_screen, filter_username, filter_name);


--
-- Name: gltrans_gltrans_accnt_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX gltrans_gltrans_accnt_id_idx ON gltrans USING btree (gltrans_accnt_id);


--
-- Name: gltrans_gltrans_date_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX gltrans_gltrans_date_idx ON gltrans USING btree (gltrans_date);


--
-- Name: gltrans_gltrans_journalnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX gltrans_gltrans_journalnumber_idx ON gltrans USING btree (gltrans_journalnumber);


--
-- Name: gltrans_sequence_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX gltrans_sequence_idx ON gltrans USING btree (gltrans_sequence);


--
-- Name: invchead_invchead_cust_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invchead_invchead_cust_id_idx ON invchead USING btree (invchead_cust_id);


--
-- Name: invchead_invchead_ordernumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invchead_invchead_ordernumber_idx ON invchead USING btree (invchead_ordernumber);


--
-- Name: invcheadtax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invcheadtax_taxhist_parent_id_idx ON invcheadtax USING btree (taxhist_parent_id);


--
-- Name: invcheadtax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invcheadtax_taxhist_parent_type_idx ON invcheadtax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: invcheadtax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invcheadtax_taxhist_taxtype_id_idx ON invcheadtax USING btree (taxhist_taxtype_id);


--
-- Name: invcitem_invcitem_invchead_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invcitem_invcitem_invchead_id_idx ON invcitem USING btree (invcitem_invchead_id);


--
-- Name: invcitem_invcitem_itemsite_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invcitem_invcitem_itemsite_id_idx ON invcitem USING btree (invcitem_item_id, invcitem_warehous_id);


--
-- Name: invcitemtax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invcitemtax_taxhist_parent_id_idx ON invcitemtax USING btree (taxhist_parent_id);


--
-- Name: invcitemtax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invcitemtax_taxhist_parent_type_idx ON invcitemtax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: invcitemtax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invcitemtax_taxhist_taxtype_id_idx ON invcitemtax USING btree (taxhist_taxtype_id);


--
-- Name: invdetail_invdetail_invcitem_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invdetail_invdetail_invcitem_id_idx ON invdetail USING btree (invdetail_invcitem_id);


--
-- Name: invdetail_invdetail_invhist_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invdetail_invdetail_invhist_id_idx ON invdetail USING btree (invdetail_invhist_id);


--
-- Name: invhist_hasdetail; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_hasdetail ON invhist USING btree (invhist_hasdetail);


--
-- Name: invhist_invhist_ordnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_invhist_ordnumber_idx ON invhist USING btree (invhist_ordnumber);


--
-- Name: invhist_itemsite_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_itemsite_id ON invhist USING btree (invhist_itemsite_id);


--
-- Name: invhist_series; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_series ON invhist USING btree (invhist_series);


--
-- Name: invhist_transdate; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_transdate ON invhist USING btree (invhist_transdate);


--
-- Name: invhist_transtype; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_transtype ON invhist USING btree (invhist_transtype);


--
-- Name: ipsitem_ipshead_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX ipsitem_ipshead_id_idx ON ipsiteminfo USING btree (ipsitem_ipshead_id);


--
-- Name: item_classcode_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX item_classcode_id ON item USING btree (item_classcode_id);


--
-- Name: item_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX item_number_idx ON item USING btree (item_number);


--
-- Name: item_prodcat_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX item_prodcat_id_idx ON item USING btree (item_prodcat_id);


--
-- Name: item_upccode_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX item_upccode_idx ON item USING btree (item_upccode);


--
-- Name: itemcost_item_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemcost_item_id_key ON itemcost USING btree (itemcost_item_id);


--
-- Name: itemcost_master_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX itemcost_master_idx ON itemcost USING btree (itemcost_item_id, itemcost_costelem_id, itemcost_lowlevel);


--
-- Name: itemloc_itemsite_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemloc_itemsite_idx ON itemloc USING btree (itemloc_itemsite_id);


--
-- Name: itemloc_location_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemloc_location_idx ON itemloc USING btree (itemloc_location_id);


--
-- Name: itemsite_active_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemsite_active_key ON itemsite USING btree (itemsite_active);


--
-- Name: itemsite_item_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemsite_item_id_key ON itemsite USING btree (itemsite_item_id);


--
-- Name: itemsite_item_warehous_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX itemsite_item_warehous_id_key ON itemsite USING btree (itemsite_item_id, itemsite_warehous_id);


--
-- Name: itemsite_plancode_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemsite_plancode_id_key ON itemsite USING btree (itemsite_plancode_id);


--
-- Name: itemsite_warehous_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemsite_warehous_id_key ON itemsite USING btree (itemsite_warehous_id);


--
-- Name: itemsrc_vend_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemsrc_vend_id_idx ON itemsrc USING btree (itemsrc_vend_id);


--
-- Name: itemsrcp_itemsrc_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemsrcp_itemsrc_id_key ON itemsrcp USING btree (itemsrcp_itemsrc_id);


--
-- Name: itemsub_parent_item_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemsub_parent_item_id_key ON itemsub USING btree (itemsub_parent_item_id);


--
-- Name: itemsub_sub_item_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemsub_sub_item_id_key ON itemsub USING btree (itemsub_sub_item_id);


--
-- Name: location_location_formatname_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX location_location_formatname_idx ON location USING btree (location_formatname);


--
-- Name: location_warehous_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX location_warehous_idx ON location USING btree (location_warehous_id);


--
-- Name: payaropen_aropen_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX payaropen_aropen_id_idx ON payaropen USING btree (payaropen_aropen_id);


--
-- Name: payaropen_ccpay_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX payaropen_ccpay_id_idx ON payaropen USING btree (payaropen_ccpay_id);


--
-- Name: payco_ccpay_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX payco_ccpay_id_idx ON payco USING btree (payco_ccpay_id);


--
-- Name: payco_cohead_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX payco_cohead_id_idx ON payco USING btree (payco_cohead_id);


--
-- Name: pohead_pohead_status_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX pohead_pohead_status_idx ON pohead USING btree (pohead_status);


--
-- Name: poitem_itemsite_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX poitem_itemsite_id_key ON poitem USING btree (poitem_itemsite_id);


--
-- Name: poitem_itemsite_status_duedate_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX poitem_itemsite_status_duedate_key ON poitem USING btree (poitem_itemsite_id, poitem_status, poitem_duedate);


--
-- Name: poitem_pohead_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX poitem_pohead_id_key ON poitem USING btree (poitem_pohead_id);


--
-- Name: poitem_status_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX poitem_status_key ON poitem USING btree (poitem_status);


--
-- Name: priv_name_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX priv_name_idx ON priv USING btree (priv_name);


--
-- Name: quitem_quhead_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX quitem_quhead_id_key ON quitem USING btree (quitem_quhead_id);


--
-- Name: recv_ordertypeid_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX recv_ordertypeid_idx ON recv USING btree (recv_order_type, recv_orderitem_id);


--
-- Name: report_name_grade_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX report_name_grade_idx ON report USING btree (report_name, report_grade);


--
-- Name: salesaccnt_prodcat_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX salesaccnt_prodcat_id_idx ON salesaccnt USING btree (salesaccnt_prodcat_id);


--
-- Name: salesaccnt_warehous_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX salesaccnt_warehous_id_idx ON salesaccnt USING btree (salesaccnt_warehous_id);


--
-- Name: shipdata_cohead_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX shipdata_cohead_number_idx ON shipdata USING btree (shipdata_cohead_number);


--
-- Name: shipdatasum_cohead_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX shipdatasum_cohead_number_idx ON shipdatasum USING btree (shipdatasum_cohead_number);


--
-- Name: shipdatasum_cosmisc_tracknum_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX shipdatasum_cosmisc_tracknum_idx ON shipdatasum USING btree (shipdatasum_cosmisc_tracknum);


--
-- Name: shiphead_order_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX shiphead_order_id_idx ON shiphead USING btree (shiphead_order_id);


--
-- Name: shiphead_shipped_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX shiphead_shipped_idx ON shiphead USING btree (shiphead_shipped);


--
-- Name: shipitem_invcitem_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX shipitem_invcitem_id_idx ON shipitem USING btree (shipitem_invcitem_id);


--
-- Name: shipitem_orderitem_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX shipitem_orderitem_id_idx ON shipitem USING btree (shipitem_orderitem_id);


--
-- Name: shipitem_shiphead_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX shipitem_shiphead_id_idx ON shipitem USING btree (shipitem_shiphead_id);


--
-- Name: sltrans_sequence_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX sltrans_sequence_idx ON sltrans USING btree (sltrans_sequence);


--
-- Name: sltrans_sltrans_accnt_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX sltrans_sltrans_accnt_id_idx ON sltrans USING btree (sltrans_accnt_id);


--
-- Name: sltrans_sltrans_date_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX sltrans_sltrans_date_idx ON sltrans USING btree (sltrans_date);


--
-- Name: sltrans_sltrans_journalnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX sltrans_sltrans_journalnumber_idx ON sltrans USING btree (sltrans_journalnumber);


--
-- Name: subaccnttype_code_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX subaccnttype_code_idx ON subaccnttype USING btree (subaccnttype_code);


--
-- Name: taxhist_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX taxhist_taxhist_parent_id_idx ON taxhist USING btree (taxhist_parent_id);


--
-- Name: taxhist_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX taxhist_taxhist_parent_type_idx ON taxhist USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: taxhist_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX taxhist_taxhist_taxtype_id_idx ON taxhist USING btree (taxhist_taxtype_id);


--
-- Name: todoitem_todoitem_username_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX todoitem_todoitem_username_idx ON todoitem USING btree (todoitem_username);


--
-- Name: trialbal_accnt_period_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX trialbal_accnt_period_idx ON trialbal USING btree (trialbal_accnt_id, trialbal_period_id);


--
-- Name: usrpref_userpref_name_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX usrpref_userpref_name_idx ON usrpref USING btree (usrpref_name);


--
-- Name: vend_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX vend_number_idx ON vendinfo USING btree (vend_number);


--
-- Name: voheadtax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX voheadtax_taxhist_parent_id_idx ON voheadtax USING btree (taxhist_parent_id);


--
-- Name: voheadtax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX voheadtax_taxhist_parent_type_idx ON voheadtax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: voheadtax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX voheadtax_taxhist_taxtype_id_idx ON voheadtax USING btree (taxhist_taxtype_id);


--
-- Name: voitemtax_taxhist_parent_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX voitemtax_taxhist_parent_id_idx ON voitemtax USING btree (taxhist_parent_id);


--
-- Name: voitemtax_taxhist_parent_type_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX voitemtax_taxhist_parent_type_idx ON voitemtax USING btree (taxhist_parent_id, taxhist_taxtype_id);


--
-- Name: voitemtax_taxhist_taxtype_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX voitemtax_taxhist_taxtype_id_idx ON voitemtax USING btree (taxhist_taxtype_id);


--
-- Name: warehous_code_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX warehous_code_key ON whsinfo USING btree (warehous_code bpchar_ops);


--
-- Name: wo_duedate; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_duedate ON wo USING btree (wo_duedate);


--
-- Name: wo_itemsite_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_itemsite_id ON wo USING btree (wo_itemsite_id);


--
-- Name: wo_ordtype; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_ordtype ON wo USING btree (wo_ordtype);


--
-- Name: wo_startdate; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_startdate ON wo USING btree (wo_startdate);


--
-- Name: wo_status; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_status ON wo USING btree (wo_status);


--
-- Name: womatl_itemsite_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX womatl_itemsite_id_key ON womatl USING btree (womatl_itemsite_id);


--
-- Name: womatl_wo_id_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX womatl_wo_id_key ON womatl USING btree (womatl_wo_id);


--
-- Name: womatlpost_womatl_id_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX womatlpost_womatl_id_idx ON womatlpost USING btree (womatlpost_womatl_id);



--
-- Name: teitem_teitem_tehead_id_idx; Type: INDEX; Schema: te; Owner: admin; Tablespace: 
--

CREATE INDEX teitem_teitem_tehead_id_idx ON teitem USING btree (teitem_tehead_id);



--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO salesline DO INSTEAD DELETE FROM public.coitem WHERE (((coitem.coitem_cohead_id = public.getcoheadid((old.order_number)::text)) AND (((coitem.coitem_linenumber)::character varying)::text = (old.line_number)::text)) AND (coitem.coitem_subnumber = 0));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO apmemo DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO armemo DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO physinvcount DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO account DO INSTEAD DELETE FROM public.crmacct WHERE (crmacct.crmacct_number = (old.account_number)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO accountchar DO INSTEAD DELETE FROM public.charass WHERE (((charass.charass_target_type = 'CRMACCT'::text) AND (charass.charass_target_id = public.getcrmacctid((old.account_number)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'CRMACCT'::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO accountcomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO accountfile DO INSTEAD DELETE FROM public.url WHERE ((((url.url_source_id = public.getcrmacctid(old.account_number)) AND (url.url_source = 'CRMA'::text)) AND (url.url_title = old.title)) AND (url.url_url = old.url));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO accountimage DO INSTEAD DELETE FROM public.imageass WHERE (((imageass.imageass_source_id = public.getcrmacctid(old.account_number)) AND (imageass.imageass_source = 'CRMA'::text)) AND (imageass.imageass_image_id = public.getimageid(old.image_name)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO address DO INSTEAD SELECT public.deleteaddress(public.getaddrid((old.address_number)::text)) AS deleteaddress;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO addresschar DO INSTEAD DELETE FROM public.charass WHERE (((charass.charass_target_type = 'ADDR'::text) AND (charass.charass_target_id = public.getaddrid((old.address_number)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'ADDR'::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO addresscomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO bom DO INSTEAD SELECT public.deletebom(public.getitemid((old.item_number)::text)) AS deletebom;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO bomitem DO INSTEAD DELETE FROM public.bomitem WHERE ((bomitem.bomitem_id = old.id) AND public.fetchmetricbool('AllowBOMItemDelete'::text));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO bomitemcomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO bomitemsubstitute DO INSTEAD DELETE FROM public.bomitemsub WHERE ((bomitemsub.bomitemsub_bomitem_id = old.bomitem_id) AND (bomitemsub.bomitemsub_item_id = public.getitemid((old.substitute_item_number)::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO budget DO INSTEAD DELETE FROM public.budghead WHERE (budghead.budghead_name = old.name);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO budgetentry DO INSTEAD DELETE FROM public.budgitem WHERE (((budgitem.budgitem_budghead_id = public.getbudgheadid(old.name)) AND (budgitem.budgitem_period_id = public.getperiodid(old.period_start))) AND (budgitem.budgitem_accnt_id = public.getglaccntid(old.account)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO cashreceipt DO INSTEAD SELECT public.deletecashrcpt(cashrcpt.cashrcpt_id) AS deletecashrcpt FROM public.cashrcpt WHERE (cashrcpt.cashrcpt_id = public.getcashrcptid((old.customer_number)::text, CASE WHEN ((old.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((old.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((old.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((old.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((old.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((old.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((old.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((old.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((old.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, (old.check_document_number)::text));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO cashreceiptapply DO INSTEAD DELETE FROM public.cashrcptitem WHERE ((cashrcptitem.cashrcptitem_cashrcpt_id = public.getcashrcptid((old.customer_number)::text, CASE WHEN ((old.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((old.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((old.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((old.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((old.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((old.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((old.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((old.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((old.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, (old.check_document_number)::text)) AND (cashrcptitem.cashrcptitem_aropen_id = public.getaropenid((old.customer_number)::text, (old.doc_type)::bpchar, (old.doc_number)::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO cashreceiptapplymisc DO INSTEAD DELETE FROM public.cashrcptmisc WHERE ((cashrcptmisc.cashrcptmisc_cashrcpt_id = public.getcashrcptid((old.customer_number)::text, CASE WHEN ((old.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((old.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((old.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((old.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((old.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((old.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((old.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((old.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((old.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, (old.check_document_number)::text)) AND (cashrcptmisc.cashrcptmisc_accnt_id = public.getglaccntid((old.account)::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO contact DO INSTEAD DELETE FROM public.cntct WHERE (cntct.cntct_number = (old.contact_number)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO contactchar DO INSTEAD DELETE FROM public.charass WHERE (((charass.charass_target_type = 'CNTCT'::text) AND (charass.charass_target_id = public.getcntctid(old.contact_number))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'CNTCT'::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO contactcomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO creditmemo DO INSTEAD SELECT public.deletecreditmemo(cmhead.cmhead_id) AS deletecreditmemo FROM public.cmhead WHERE ((cmhead.cmhead_number = old.memo_number) AND (cmhead.cmhead_posted = false));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO creditmemoline DO INSTEAD DELETE FROM public.cmitem WHERE ((cmitem.cmitem_cmhead_id = public.getcmheadid(old.memo_number, false)) AND (cmitem.cmitem_linenumber = old.line_number));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO custchar DO INSTEAD DELETE FROM public.charass WHERE (((charass.charass_target_type = 'C'::text) AND (charass.charass_target_id = public.getcustid((old.customer_number)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'C'::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO custcomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO custcreditcard DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO customer DO INSTEAD DELETE FROM public.custinfo WHERE (custinfo.cust_number = (old.customer_number)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO customertype DO INSTEAD DELETE FROM public.custtype WHERE (custtype.custtype_code = (old.code)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO customertypechar DO INSTEAD DELETE FROM public.charass WHERE (((charass.charass_target_type = 'CT'::text) AND (charass.charass_target_id = public.getcusttypeid((old.customer_type)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'CT'::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO custshipto DO INSTEAD SELECT public.deleteshipto(public.getshiptoid((old.customer_number)::text, (old.shipto_number)::text)) AS deleteshipto;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO custtax DO INSTEAD DELETE FROM public.taxreg WHERE (((taxreg.taxreg_rel_type = 'C'::bpchar) AND (taxreg.taxreg_rel_id = public.getcustid((old.customer_number)::text))) AND (taxreg.taxreg_taxauth_id = public.gettaxauthid((old.tax_authority)::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO employee DO INSTEAD DELETE FROM public.emp WHERE (emp.emp_code = (old.code)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO employeechar DO INSTEAD DELETE FROM public.charass WHERE (((charass.charass_target_type = 'EMP'::text) AND (charass.charass_target_id = public.getempid((old.employee_code)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'EMP'::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO employeecomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO extshipmaint DO INSTEAD DELETE FROM public.shipdata WHERE ((((shipdata.shipdata_cohead_number = (old.so_number)::text) AND (shipdata.shipdata_shiphead_number = (old.shipment_number)::text)) AND (shipdata.shipdata_shipper = (old.shipper)::text)) AND (shipdata.shipdata_cosmisc_packnum_tracknum = (old.package_tracking_number)::text));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO freightpricingscheduleitem DO INSTEAD DELETE FROM public.ipsfreight WHERE (((((((((ipsfreight.ipsfreight_ipshead_id = public.getipsheadid((old.pricing_schedule)::text)) AND (ipsfreight.ipsfreight_qtybreak = old.qty_break)) AND (ipsfreight.ipsfreight_price = old.price)) AND ((ipsfreight.ipsfreight_type)::text = CASE WHEN (old.price_type = 'Flat Rate'::text) THEN 'F'::text WHEN (old.price_type = 'Price Per UOM'::text) THEN 'P'::text ELSE NULL::text END)) AND ((ipsfreight.ipsfreight_warehous_id IS NULL) AND (old.from_site = 'Any'::text))) OR ((ipsfreight.ipsfreight_warehous_id = CASE WHEN (old.from_site = 'Any'::text) THEN 0 ELSE public.getwarehousid(old.from_site, 'All'::text) END) AND ((ipsfreight.ipsfreight_shipzone_id IS NULL) AND (old.to_shipzone = 'Any'::text)))) OR ((ipsfreight.ipsfreight_shipzone_id = CASE WHEN (old.to_shipzone = 'Any'::text) THEN 0 ELSE public.getshipzoneid(old.to_shipzone) END) AND ((ipsfreight.ipsfreight_freightclass_id IS NULL) AND (old.freight_class = 'Any'::text)))) OR ((ipsfreight.ipsfreight_freightclass_id = CASE WHEN (old.freight_class = 'Any'::text) THEN 0 ELSE public.getfreightclassid(old.freight_class) END) AND ((ipsfreight.ipsfreight_shipvia IS NULL) AND (old.ship_via = 'Any'::text)))) OR (ipsfreight.ipsfreight_shipvia = old.ship_via));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO incident DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO incidentchar DO INSTEAD DELETE FROM public.charass WHERE (((charass.charass_target_type = 'INCDT'::text) AND (charass.charass_target_id = public.getincidentid(old.incident_number))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'INCDT'::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO incidentcomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO incidentfile DO INSTEAD DELETE FROM public.url WHERE ((((url.url_source_id = public.getincidentid(old.incident_number)) AND (url.url_source = 'INCDT'::text)) AND (url.url_title = old.title)) AND (url.url_url = old.url));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO incidentimage DO INSTEAD DELETE FROM public.imageass WHERE (((imageass.imageass_source_id = public.getincidentid(old.incident_number)) AND (imageass.imageass_source = 'INCDT'::text)) AND (imageass.imageass_image_id = public.getimageid(old.image_name)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO invoice DO INSTEAD SELECT public.deleteinvoice(invchead.invchead_id) AS deleteinvoice FROM public.invchead WHERE ((invchead.invchead_invcnumber = old.invoice_number) AND (invchead.invchead_posted = false));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO invoiceline DO INSTEAD DELETE FROM public.invcitem WHERE (invcitem.invcitem_invchead_id = (SELECT invchead.invchead_id FROM public.invchead WHERE ((invchead.invchead_invcnumber = old.invoice_number) AND (invchead.invchead_posted = false))));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO item DO INSTEAD SELECT public.deleteitem(public.getitemid((old.item_number)::text)) AS deleteitem;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemalias DO INSTEAD DELETE FROM public.itemalias WHERE ((itemalias.itemalias_item_id = public.getitemid((old.item_number)::text)) AND (itemalias.itemalias_number = old.alias_number));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemchar DO INSTEAD DELETE FROM public.charass WHERE (((charass.charass_target_type = 'I'::text) AND (charass.charass_target_id = public.getitemid((old.item_number)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'I'::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemcomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemcost DO INSTEAD SELECT public.deleteitemcost(public.getitemid((old.item_number)::text), public.getcostelemid((old.costing_element)::text)) AS deleteitemcost;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemfile DO INSTEAD DELETE FROM public.url WHERE ((((url.url_source_id = public.getitemid((old.item_number)::text)) AND (url.url_source = 'I'::text)) AND (url.url_title = old.title)) AND (url.url_url = old.url));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemimage DO INSTEAD DELETE FROM public.imageass WHERE (((imageass.imageass_source_id = public.getitemid((old.item_number)::text)) AND (imageass.imageass_source = 'I'::text)) AND (imageass.imageass_image_id = public.getimageid(old.image_name)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemsite DO INSTEAD SELECT public.deleteitemsite(public.getitemsiteid((old.site)::text, (old.item_number)::text)) AS deleteitemsite;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemsitecomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemsource DO INSTEAD DELETE FROM public.itemsrc WHERE (((((itemsrc.itemsrc_item_id = public.getitemid((old.item_number)::text)) AND (itemsrc.itemsrc_vend_id = public.getvendid((old.vendor)::text))) AND (itemsrc.itemsrc_vend_item_number = old.vendor_item_number)) AND (itemsrc.itemsrc_manuf_name = old.manufacturer_name)) AND (itemsrc.itemsrc_manuf_item_number = old.manufacturer_item_number));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemsourceprice DO INSTEAD DELETE FROM public.itemsrcp WHERE ((itemsrcp.itemsrcp_itemsrc_id = public.getitemsrcid((old.item_number)::text, (old.vendor)::text)) AND (itemsrcp.itemsrcp_qtybreak = old.qty_break));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemsubstitute DO INSTEAD DELETE FROM public.itemsub WHERE ((itemsub.itemsub_parent_item_id = public.getitemid((old.root_item_number)::text)) AND (itemsub.itemsub_sub_item_id = public.getitemid((old.substitute_item_number)::text)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemtaxtype DO INSTEAD DELETE FROM public.itemtax WHERE (((itemtax.itemtax_item_id = public.getitemid((old.item_number)::text)) AND CASE WHEN ((old.tax_zone)::text = 'Any'::text) THEN (itemtax.itemtax_taxzone_id IS NULL) ELSE (itemtax.itemtax_taxzone_id = public.gettaxzoneid((old.tax_zone)::text)) END) AND (itemtax.itemtax_taxtype_id = public.gettaxtypeid(old.tax_type)));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemuomconversion DO INSTEAD SELECT public.deleteitemuomconv(itemuomconv.itemuomconv_id) AS deleteitemuomconv FROM public.itemuomconv WHERE ((itemuomconv.itemuomconv_item_id = public.getitemid((old.item_number)::text)) AND (((itemuomconv.itemuomconv_from_uom_id = public.getuomid((old.uom)::text)) AND (itemuomconv.itemuomconv_to_uom_id = public.getuomid(old.per_uom))) OR ((itemuomconv.itemuomconv_from_uom_id = public.getuomid(old.per_uom)) AND (itemuomconv.itemuomconv_to_uom_id = public.getuomid((old.uom)::text)))));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO journalentry DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO location DO INSTEAD DELETE FROM public.location WHERE ((location.location_warehous_id = public.getwarehousid((old.site)::text, 'ACTIVE'::text)) AND (location.location_name = (old.location)::text));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO misccounttag DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO pricingschedule DO INSTEAD DELETE FROM public.ipshead WHERE ((old.name)::text = ipshead.ipshead_name);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO pricingscheduleassign DO INSTEAD DELETE FROM public.ipsass WHERE ((((((ipsass.ipsass_ipshead_id = public.getipsheadid((old.pricing_schedule)::text)) AND (ipsass.ipsass_cust_id = CASE WHEN ((old.customer_number)::text = 'Any'::text) THEN (-1) ELSE public.getcustid((old.customer_number)::text) END)) AND (ipsass.ipsass_custtype_id = CASE WHEN ((old.customer_type)::text = 'N/A'::text) THEN (-1) ELSE public.getcusttypeid((old.customer_type)::text) END)) AND (ipsass.ipsass_custtype_pattern = (old.customer_type_pattern)::text)) AND (ipsass.ipsass_shipto_id = CASE WHEN ((old.customer_shipto)::text = 'Any'::text) THEN (-1) ELSE public.getshiptoid((old.customer_number)::text, (old.customer_shipto)::text) END)) AND (ipsass.ipsass_shipto_pattern = (old.customer_shipto_pattern)::text));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO pricingscheduleitem DO INSTEAD SELECT CASE WHEN ((old.type)::text = 'Item'::text) THEN public.deleteipsitem(public.getipsitemid((old.pricing_schedule)::text, (old.item_number)::text, old.qty_break, (old.qty_uom)::text, (old.price_uom)::text)) WHEN ((old.type)::text = 'Product Category'::text) THEN public.deleteipsprodcat(public.getipsprodcatid((old.pricing_schedule)::text, (old.product_category)::text, old.qty_break)) ELSE NULL::integer END AS result;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO pricingscheduleitemchar DO INSTEAD DELETE FROM public.ipsitemchar WHERE (((ipsitemchar.ipsitemchar_ipsitem_id = public.getipsitemid((old.pricing_schedule)::text, (old.item_number)::text, old.qty_break, (old.qty_uom)::text, (old.price_uom)::text)) AND (ipsitemchar.ipsitemchar_char_id = public.getcharid((old.characteristic)::text, 'I'::text))) AND (ipsitemchar.ipsitemchar_value = (old.value)::text));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO project DO INSTEAD SELECT public.deleteproject(public.getprjid(old.number)) AS deleteproject;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO projectcomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO prospect DO INSTEAD DELETE FROM public.prospect WHERE (prospect.prospect_number = (old.prospect_number)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO purchaseline DO INSTEAD DELETE FROM public.poitem WHERE (poitem.poitem_id = public.getpoitemid((old.order_number)::text, old.line_number));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO purchaselinechar DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO purchaselinecomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO purchaseorder DO INSTEAD SELECT public.deletepo(pohead.pohead_id) AS deletepo FROM public.pohead WHERE (pohead.pohead_number = (old.order_number)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO purchaseordercomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO quote DO INSTEAD SELECT public.deletequote(quhead.quhead_id, (old.quote_number)::text) AS deletequote FROM public.quhead WHERE (quhead.quhead_number = (old.quote_number)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO quotecomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO quoteline DO INSTEAD DELETE FROM public.quitem WHERE ((quitem.quitem_quhead_id = public.getquoteid(old.quote_number)) AND (quitem.quitem_linenumber = old.line_number));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO quotelinechar DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO quotelinecomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO saleshistory DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO saleslinechar DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO saleslinecomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO salesorder DO INSTEAD SELECT public.deleteso(cohead.cohead_id, (old.order_number)::text) AS deleteso FROM public.cohead WHERE (cohead.cohead_number = (old.order_number)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO salesordercomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO salesrep DO INSTEAD DELETE FROM public.salesrep WHERE (salesrep.salesrep_number = (old.number)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO site DO NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO sitezone DO INSTEAD DELETE FROM public.whsezone WHERE ((whsezone.whsezone_warehous_id = public.getwarehousid((old.site)::text, 'ACTIVE'::text)) AND (whsezone.whsezone_name = (old.name)::text));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO task DO INSTEAD DELETE FROM public.prjtask WHERE ((prjtask.prjtask_prj_id = public.getprjid(old.project_number)) AND (prjtask.prjtask_number = old.number));


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO taskcomment DO INSTEAD NOTHING;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO todo DO INSTEAD SELECT public.deletetodoitem(old.task_number) AS deletetodoitem;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO vendor DO INSTEAD DELETE FROM public.vendinfo WHERE (vendinfo.vend_number = (old.vendor_number)::text);


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO vendoraddress DO INSTEAD SELECT public.deletevendoraddress(public.getvendaddrid((old.vendor_number)::text, (old.vendor_address_number)::text)) AS deletevendoraddress;


--
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO vendortype DO INSTEAD SELECT public.deletevendortype(public.getvendtypeid((old.code)::text)) AS deletevendortype;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO salesline DO INSTEAD SELECT public.insertsalesline(new.*) AS insertsalesline;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO apmemo DO INSTEAD SELECT public.insertapmemo(new.*) AS insertapmemo;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO armemo DO INSTEAD SELECT public.insertarmemo(new.*) AS insertarmemo;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO physinvcount DO INSTEAD SELECT insertphysinvcount(new.*) AS insertphysinvcount;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO account DO INSTEAD INSERT INTO public.crmacct (crmacct_number, crmacct_parent_id, crmacct_name, crmacct_active, crmacct_type, crmacct_cntct_id_1, crmacct_cntct_id_2, crmacct_notes) VALUES (COALESCE(new.account_number, ((public.fetchcrmaccountnumber())::text)::character varying), public.getcrmacctid(new.parent_account), new.account_name, COALESCE(new.active, true), CASE WHEN (new.type = 'Individual'::text) THEN 'I'::text ELSE 'O'::text END, public.savecntct(public.getcntctid(new.primary_contact_number), new.primary_contact_number, public.saveaddr(public.getaddrid(new.primary_contact_address_number), new.primary_contact_address_number, new.primary_contact_address1, new.primary_contact_address2, new.primary_contact_address3, new.primary_contact_city, new.primary_contact_state, new.primary_contact_postalcode, new.primary_contact_country, new.primary_contact_address_change), new.primary_contact_honorific, new.primary_contact_first, new.primary_contact_middle, new.primary_contact_last, new.primary_contact_suffix, new.primary_contact_voice, NULL::text, new.primary_contact_fax, new.primary_contact_email, NULL::text, new.primary_contact_job_title, new.primary_contact_change), public.savecntct(public.getcntctid(new.secondary_contact_number), new.secondary_contact_number, public.saveaddr(public.getaddrid(new.secondary_contact_address_number), new.secondary_contact_address_number, new.secondary_contact_address1, new.secondary_contact_address2, new.secondary_contact_address3, new.secondary_contact_city, new.secondary_contact_state, new.secondary_contact_postalcode, new.secondary_contact_country, new.secondary_contact_address_change), new.secondary_contact_honorific, new.secondary_contact_first, new.secondary_contact_middle, new.secondary_contact_last, new.secondary_contact_suffix, new.secondary_contact_voice, NULL::text, new.secondary_contact_fax, new.secondary_contact_email, NULL::text, new.secondary_contact_job_title, new.secondary_contact_change), new.notes);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO accountchar DO INSTEAD INSERT INTO public.charass (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default) VALUES ('CRMACCT'::text, public.getcrmacctid((new.account_number)::text), public.getcharid((new.characteristic)::text, 'CRMACCT'::text), new.value, false);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO accountcomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'CRMA'::text, public.getcrmacctid((new.account_number)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO accountfile DO INSTEAD INSERT INTO public.url (url_source_id, url_source, url_title, url_url) VALUES (public.getcrmacctid(new.account_number), 'CRMA'::text, new.title, new.url);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO accountimage DO INSTEAD SELECT public.saveimageass('CRMA'::text, public.getcrmacctid(new.account_number), 'M'::bpchar, public.getimageid(new.image_name)) AS saveimageass;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO address DO INSTEAD SELECT public.saveaddr(NULL::integer, (new.address_number)::text, new.address1, new.address2, new.address3, new.city, new.state, new.postal_code, new.country, COALESCE(new.active, true), new.notes, NULL::text) AS saveaddr;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO addresschar DO INSTEAD INSERT INTO public.charass (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default) VALUES ('ADDR'::text, public.getaddrid((new.address_number)::text), public.getcharid((new.characteristic)::text, 'ADDR'::text), new.value, false);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO addresscomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'ADDR'::text, public.getaddrid((new.address_number)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO bom DO INSTEAD SELECT public.savebomhead(public.getitemid((new.item_number)::text), (new.revision)::text, new.revision_date, new.document_number, COALESCE(new.batch_size, (0)::numeric), new.total_qty_per) AS savebomhead;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO bomitem DO INSTEAD SELECT public.createbomitem(COALESCE(new.id, (nextval('public.bomitem_bomitem_id_seq'::regclass))::integer), public.getitemid((new.bom_item_number)::text), public.getitemid(new.item_number), COALESCE(new.sequence_number, (SELECT (max(bomitem.bomitem_seqnumber) + 10) FROM public.bomitem(public.getitemid((new.bom_item_number)::text), COALESCE(public.getrevid('BOM'::text, (new.bom_item_number)::text, (new.bom_revision)::text))) bomitem(bomitem_id, bomitem_parent_item_id, bomitem_seqnumber, bomitem_item_id, bomitem_qtyper, bomitem_scrap, bomitem_status, bomitem_effective, bomitem_expires, bomitem_createwo, bomitem_issuemethod, bomitem_schedatwooper, bomitem_ecn, bomitem_moddate, bomitem_subtype, bomitem_uom_id, bomitem_rev_id, bomitem_booitem_seq_id, bomitem_char_id, bomitem_value, bomitem_notes, bomitem_ref, bomitem_qtyfxd, bomitem_issuewo)), 10), (CASE WHEN (new.issue_method = 'Mixed'::text) THEN 'M'::text WHEN (new.issue_method = 'Push'::text) THEN 'S'::text WHEN (new.issue_method = 'Pull'::text) THEN 'L'::text ELSE public.fetchmetrictext('DefaultWomatlIssueMethod'::text) END)::bpchar, COALESCE(public.getuomid(new.issue_uom), (SELECT item.item_inv_uom_id FROM public.item WHERE (item.item_id = public.getitemid(new.item_number)))), new.qty_per, new.scrap, CASE WHEN (new.effective = 'Always'::text) THEN public.startoftime() ELSE COALESCE((new.effective)::date, public.startoftime()) END, CASE WHEN (new.expires = 'Never'::text) THEN public.endoftime() ELSE COALESCE((new.expires)::date, public.endoftime()) END, COALESCE(new.create_child_wo, false), COALESCE(public.getbooitemseqid((new.bom_item_number)::text, new.used_at), (-1)), COALESCE(new.schedule_at_wo_operation, false), new.ecn_number, (CASE WHEN (new.substitutions = 'No'::text) THEN 'N'::text WHEN (new.substitutions = 'BOM-Defined'::text) THEN 'B'::text ELSE 'I'::text END)::bpchar, COALESCE(public.getrevid('BOM'::text, (new.bom_item_number)::text, (new.bom_revision)::text)), public.getcharid(new.characteristic, 'I'::text), new.value, new.notes, new.reference) AS createbomitem;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO bomitemcomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'BMI'::text, new.bomitem_id, COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO bomitemsubstitute DO INSTEAD INSERT INTO public.bomitemsub (bomitemsub_bomitem_id, bomitemsub_item_id, bomitemsub_uomratio, bomitemsub_rank) VALUES (new.bomitem_id, public.getitemid((new.substitute_item_number)::text), COALESCE(new.sub_parent_uom_ratio, (1)::numeric), COALESCE(new.ranking, 1));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO budget DO INSTEAD INSERT INTO public.budghead (budghead_name, budghead_descrip) VALUES (new.name, new.description);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO budgetentry DO INSTEAD INSERT INTO public.budgitem (budgitem_budghead_id, budgitem_period_id, budgitem_accnt_id, budgitem_amount) VALUES (public.getbudgheadid(new.name), public.getperiodid(new.period_start), public.getglaccntid(new.account), new.amount);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO cashreceipt DO INSTEAD INSERT INTO public.cashrcpt (cashrcpt_cust_id, cashrcpt_number, cashrcpt_amount, cashrcpt_fundstype, cashrcpt_docnumber, cashrcpt_bankaccnt_id, cashrcpt_notes, cashrcpt_distdate, cashrcpt_salescat_id, cashrcpt_curr_id, cashrcpt_usecustdeposit) VALUES (public.getcustid((new.customer_number)::text), (SELECT public.fetchcashrcptnumber() AS fetchcashrcptnumber), COALESCE(new.amount_received, (0)::numeric), CASE WHEN ((new.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((new.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((new.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((new.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((new.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((new.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((new.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((new.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((new.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, COALESCE(new.check_document_number, ''::character varying), public.getbankaccntid(new.post_to), COALESCE(new.notes, ''::text), CASE WHEN (new.distribution_date > ''::text) THEN ((new.distribution_date)::date)::timestamp with time zone ELSE now() END, COALESCE(public.getsalescatid(new.sales_category), (-1)), public.getcurrid((new.currency)::text), CASE WHEN (new.apply_balance_as = 'Customer Deposit'::text) THEN true ELSE false END);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO cashreceiptapply DO INSTEAD INSERT INTO public.cashrcptitem (cashrcptitem_cashrcpt_id, cashrcptitem_aropen_id, cashrcptitem_amount, cashrcptitem_discount) VALUES (public.getcashrcptid((new.customer_number)::text, CASE WHEN ((new.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((new.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((new.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((new.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((new.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((new.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((new.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((new.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((new.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, (new.check_document_number)::text), public.getaropenid((new.customer_number)::text, (new.doc_type)::bpchar, (new.doc_number)::text), COALESCE(new.amount_to_apply, (0)::numeric), COALESCE(new.cashrcptitem_discount, (0)::numeric));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO cashreceiptapplymisc DO INSTEAD INSERT INTO public.cashrcptmisc (cashrcptmisc_cashrcpt_id, cashrcptmisc_accnt_id, cashrcptmisc_amount, cashrcptmisc_notes) VALUES (public.getcashrcptid((new.customer_number)::text, CASE WHEN ((new.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((new.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((new.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((new.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((new.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((new.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((new.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((new.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((new.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, (new.check_document_number)::text), public.getglaccntid((new.account)::text), COALESCE(new.amount_to_distribute, (0)::numeric), COALESCE(new.notes, ''::text));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO contact DO INSTEAD SELECT public.savecntct(NULL::integer, (new.contact_number)::text, public.getcrmacctid(new.crm_account), public.saveaddr(CASE WHEN (NOT (EXISTS (SELECT addr.addr_id FROM public.addr WHERE (addr.addr_number = new.address_number)))) THEN NULL::integer ELSE public.getaddrid(new.address_number) END, new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postal_code, new.country, new.address_change), new.honorific, new.first, new.middle, new.last, new.suffix, new.initials, COALESCE(new.active, true), new.voice, new.alternate, new.fax, new.email, new.web, new.notes, new.job_title, new.contact_change) AS savecntct;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO contactchar DO INSTEAD INSERT INTO public.charass (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default) VALUES ('CNTCT'::text, public.getcntctid(new.contact_number), public.getcharid((new.characteristic)::text, 'CNTCT'::text), new.value, false);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO contactcomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'T'::text, public.getcntctid(new.contact_number), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO creditmemo DO INSTEAD SELECT public.insertcreditmemo(new.*) AS insertcreditmemo;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO creditmemoline DO INSTEAD SELECT public.insertcreditmemoline(new.*) AS insertcreditmemoline;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO custchar DO INSTEAD INSERT INTO public.charass (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default) VALUES ('C'::text, public.getcustid((new.customer_number)::text), public.getcharid((new.characteristic)::text, 'C'::text), new.value, false);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO custcomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'C'::text, public.getcustid((new.customer_number)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO custcreditcard DO INSTEAD SELECT public.insertccard((new.customer_number)::text, new.active, new.credit_card_type, new.credit_card_number, new.name, new.street_address1, new.street_address2, new.city, new.state, new.postal_code, new.country, new.expiration_month, new.expiration_year, new.key) AS insertccard;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO customer DO INSTEAD INSERT INTO public.custinfo (cust_active, cust_custtype_id, cust_salesrep_id, cust_commprcnt, cust_name, cust_creditlmt, cust_creditrating, cust_backorder, cust_partialship, cust_terms_id, cust_discntprcnt, cust_balmethod, cust_ffshipto, cust_shipform_id, cust_shipvia, cust_blanketpos, cust_shipchrg_id, cust_creditstatus, cust_comments, cust_ffbillto, cust_usespos, cust_number, cust_autoupdatestatus, cust_autoholdorders, cust_preferred_warehous_id, cust_curr_id, cust_creditlmt_curr_id, cust_cntct_id, cust_corrcntct_id, cust_taxzone_id, cust_gracedays) VALUES (COALESCE(new.active, true), COALESCE((public.getcusttypeid(new.customer_type))::numeric, public.fetchmetricvalue('DefaultCustType'::text)), COALESCE((public.getsalesrepid(new.sales_rep))::numeric, public.fetchmetricvalue('DefaultSalesRep'::text)), COALESCE((new.commission * 0.01), (SELECT salesrep.salesrep_commission FROM public.salesrep WHERE (salesrep.salesrep_id = public.getsalesrepid(new.sales_rep)))), COALESCE(new.customer_name, ''::text), COALESCE((new.credit_limit)::numeric, public.fetchmetricvalue('SOCreditLimit'::text)), COALESCE(new.credit_rating, public.fetchmetrictext('SOCreditRate'::text)), COALESCE(new.accepts_backorders, public.fetchmetricbool('DefaultBackOrders'::text), false), COALESCE(new.accepts_partial_shipments, public.fetchmetricbool('DefaultPartialShipments'::text), false), COALESCE((public.gettermsid(new.default_terms))::numeric, public.fetchmetricvalue('DefaultTerms'::text)), COALESCE(new.default_discount, (0)::numeric), CASE WHEN (new.balance_method = 'Balance Forward'::text) THEN 'B'::text WHEN (new.balance_method = 'Open Items'::text) THEN 'O'::text ELSE COALESCE(public.fetchmetrictext('DefaultBalanceMethod'::text), 'B'::text) END, COALESCE(new.allow_free_form_shipto, public.fetchmetricbool('DefaultFreeFormShiptos'::text), false), COALESCE((public.getshipformid(new.ship_form))::numeric, public.fetchmetricvalue('DefaultShipFormId'::text)), COALESCE(new.ship_via, public.fetchdefaultshipvia()), COALESCE(new.uses_blanket_pos, false), COALESCE(public.getshipchrgid(new.shipping_charges), (-1)), CASE WHEN (new.credit_status = 'On Credit Warning'::text) THEN 'W'::text WHEN (new.credit_status = 'On Credit Hold'::text) THEN 'H'::text ELSE 'G'::text END, COALESCE(new.notes, ''::text), COALESCE(new.allow_free_form_billto, false), COALESCE(new.uses_purchase_orders, false), COALESCE(upper((new.customer_number)::text), (public.fetchcrmaccountnumber())::text), COALESCE(new.credit_status_exceed_warn, false), COALESCE(new.credit_status_exceed_hold, false), COALESCE(public.getwarehousid(new.preferred_selling_site, 'ACTIVE'::text), (-1)), COALESCE(public.getcurrid((new.default_currency)::text), public.basecurrid()), COALESCE(public.getcurrid((new.credit_limit_currency)::text), public.basecurrid()), public.savecntct(public.getcntctid(new.billing_contact_number, false), new.billing_contact_number, public.saveaddr(public.getaddrid(new.billing_contact_address_number), new.billing_contact_address_number, new.billing_contact_address1, new.billing_contact_address2, new.billing_contact_address3, new.billing_contact_city, new.billing_contact_state, new.billing_contact_postalcode, new.billing_contact_country, new.billing_contact_address_change), new.billing_contact_honorific, new.billing_contact_first, new.billing_contact_middle, new.billing_contact_last, new.billing_contact_suffix, new.billing_contact_voice, new.billing_contact_alternate, new.billing_contact_fax, new.billing_contact_email, new.billing_contact_web, new.billing_contact_job_title, new.billing_contact_change), public.savecntct(public.getcntctid(new.correspond_contact_number, false), new.correspond_contact_number, public.saveaddr(public.getaddrid(new.correspond_contact_address_number), new.correspond_contact_address_number, new.correspond_contact_address1, new.correspond_contact_address2, new.correspond_contact_address3, new.correspond_contact_city, new.correspond_contact_state, new.correspond_contact_postalcode, new.correspond_contact_country, new.correspond_contact_address_change), new.correspond_contact_honorific, new.correspond_contact_first, new.correspond_contact_middle, new.correspond_contact_last, new.correspond_contact_suffix, new.correspond_contact_voice, new.correspond_contact_alternate, new.correspond_contact_fax, new.correspond_contact_email, new.correspond_contact_web, new.correspond_contact_job_title, new.correspond_contact_change), public.gettaxzoneid(new.default_tax_zone), CASE WHEN (COALESCE(new.alternate_grace_days, 0) > 0) THEN new.alternate_grace_days ELSE NULL::integer END);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO customertaxreg DO INSTEAD INSERT INTO public.taxreg (taxreg_rel_id, taxreg_rel_type, taxreg_taxauth_id, taxreg_taxzone_id, taxreg_number, taxreg_effective, taxreg_expires, taxreg_notes) VALUES (public.getcustid((new.customer_number)::text), 'C'::bpchar, public.gettaxauthid((new.tax_authority)::text), (SELECT custinfo.cust_taxzone_id FROM public.custinfo WHERE (custinfo.cust_id = public.getcustid((new.customer_number)::text))), COALESCE(new.registration_number, ''::text), CASE WHEN (new.start_date = 'Always'::text) THEN public.startoftime() ELSE COALESCE((new.start_date)::date, public.startoftime()) END, CASE WHEN (new.end_date = 'Never'::text) THEN public.endoftime() ELSE COALESCE((new.end_date)::date, public.endoftime()) END, new.notes);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO customertype DO INSTEAD INSERT INTO public.custtype (custtype_code, custtype_descrip, custtype_char) VALUES (new.code, COALESCE(new.description, ''::text), COALESCE(new.enable_characteristics_profile, false));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO customertypechar DO INSTEAD INSERT INTO public.charass (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default) VALUES ('CT'::text, public.getcusttypeid((new.customer_type)::text), public.getcharid((new.characteristic)::text, 'CT'::text), new.value, COALESCE(new.is_default, false));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO custshipto DO INSTEAD INSERT INTO public.shiptoinfo (shipto_cust_id, shipto_name, shipto_salesrep_id, shipto_comments, shipto_shipcomments, shipto_shipzone_id, shipto_shipvia, shipto_commission, shipto_shipform_id, shipto_shipchrg_id, shipto_active, shipto_default, shipto_num, shipto_ediprofile_id, shipto_cntct_id, shipto_addr_id, shipto_taxzone_id) VALUES (public.getcustid((new.customer_number)::text), COALESCE(new.name, ''::text), COALESCE(public.getsalesrepid(new.sales_rep), (SELECT custinfo.cust_salesrep_id FROM public.custinfo WHERE (custinfo.cust_id = public.getcustid((new.customer_number)::text)))), COALESCE(new.general_notes, ''::text), COALESCE(new.shipping_notes, ''::text), public.getshipzoneid(new.zone), COALESCE(new.ship_via, (SELECT custinfo.cust_shipvia FROM public.custinfo WHERE (custinfo.cust_id = public.getcustid((new.customer_number)::text)))), COALESCE((new.commission / 100.0), (0)::numeric), COALESCE(public.getshipformid(new.ship_form), (SELECT custinfo.cust_shipform_id FROM public.custinfo WHERE (custinfo.cust_id = public.getcustid((new.customer_number)::text)))), COALESCE(public.getshipchrgid(new.shipping_charges), (SELECT custinfo.cust_shipchrg_id FROM public.custinfo WHERE (custinfo.cust_id = public.getcustid((new.customer_number)::text)))), COALESCE(new.active, true), COALESCE(new.default_flag, false), COALESCE(new.shipto_number, (((SELECT (COALESCE(max((shiptoinfo.shipto_num)::integer), 0) + 1) FROM public.shiptoinfo WHERE ((shiptoinfo.shipto_cust_id = public.getcustid((new.customer_number)::text)) AND (shiptoinfo.shipto_num ~ '^[0-9]*$'::text))))::text)::character varying), CASE WHEN (new.edi_profile = 'No EDI'::text) THEN (-1) WHEN (new.edi_profile = 'Use Customer Master'::text) THEN (-2) ELSE public.getediprofileid(new.edi_profile) END, public.savecntct(public.getcntctid(new.contact_number), new.contact_number, NULL::integer, new.honorific, new.first, new.middle, new.last, new.suffix, new.phone, NULL::text, new.fax, new.email, NULL::text, new.job_title, new.contact_change), public.saveaddr(public.getaddrid(new.address_number), new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postal_code, new.country, new.address_change), COALESCE(public.gettaxzoneid(new.tax_zone), (SELECT custinfo.cust_taxzone_id FROM public.custinfo WHERE (custinfo.cust_id = public.getcustid((new.customer_number)::text)))));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO custtax DO INSTEAD INSERT INTO public.taxreg (taxreg_rel_type, taxreg_rel_id, taxreg_taxauth_id, taxreg_number) VALUES ('C'::bpchar, public.getcustid((new.customer_number)::text), public.gettaxauthid((new.tax_authority)::text), new.registration_number);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO employee DO INSTEAD INSERT INTO public.emp (emp_code, emp_number, emp_active, emp_cntct_id, emp_warehous_id, emp_mgr_emp_id, emp_wage_type, emp_wage, emp_wage_curr_id, emp_wage_period, emp_dept_id, emp_shift_id, emp_image_id, emp_extrate, emp_extrate_period, emp_startdate, emp_notes) VALUES (new.code, new.number, COALESCE(new.active, true), public.savecntct(public.getcntctid(new.contact_number), new.contact_number, public.saveaddr(public.getaddrid(new.address_number), new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postalcode, new.country, new.address_change), new.honorific, new.first, new.middle, new.last, new.suffix, new.voice, new.alternate, new.fax, new.email, new.web, new.job_title, new.contact_change), public.getwarehousid(new.site, 'ALL'::text), (SELECT emp.emp_id FROM public.emp WHERE (emp.emp_code = new.manager_code)), CASE WHEN (new.wage_type = 'Hourly'::text) THEN 'H'::text WHEN (new.wage_type = 'Salaried'::text) THEN 'S'::text ELSE NULL::text END, new.wage, COALESCE(public.getcurrid((new.wage_currency)::text), public.basecurrid()), CASE WHEN (new.wage_period = 'Hour'::text) THEN 'H'::text WHEN (new.wage_period = 'Day'::text) THEN 'D'::text WHEN (new.wage_period = 'Week'::text) THEN 'W'::text WHEN (new.wage_period = 'Biweek'::text) THEN 'BW'::text WHEN (new.wage_period = 'Month'::text) THEN 'M'::text WHEN (new.wage_period = 'Year'::text) THEN 'Y'::text ELSE NULL::text END, public.getdeptid(new.department), public.getshiftid(new.shift), public.getimageid(new.image), new.rate, CASE WHEN (new.billing_period = 'Hour'::text) THEN 'H'::text WHEN (new.billing_period = 'Day'::text) THEN 'D'::text WHEN (new.billing_period = 'Week'::text) THEN 'W'::text WHEN (new.billing_period = 'Biweek'::text) THEN 'BW'::text WHEN (new.billing_period = 'Month'::text) THEN 'M'::text WHEN (new.billing_period = 'Year'::text) THEN 'Y'::text ELSE NULL::text END, new.start_date, COALESCE(new.notes, ''::text));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO employeechar DO INSTEAD INSERT INTO public.charass (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default) VALUES ('EMP'::text, public.getempid((new.employee_code)::text), public.getcharid((new.characteristic)::text, 'EMP'::text), new.value, false);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO employeecomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'EMP'::text, public.getempid((new.code)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid((new.type)::text), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO extshipmaint DO INSTEAD INSERT INTO public.shipdata (shipdata_cohead_number, shipdata_shiphead_number, shipdata_void_ind, shipdata_shipper, shipdata_billing_option, shipdata_weight, shipdata_base_freight, shipdata_base_freight_curr_id, shipdata_total_freight, shipdata_total_freight_curr_id, shipdata_package_type, shipdata_cosmisc_tracknum, shipdata_cosmisc_packnum_tracknum, shipdata_lastupdated) VALUES (new.so_number, new.shipment_number, new.void, new.shipper, new.billing_option, new.weight, new.base_freight, public.getcurrid((new.base_freight_currency)::text), new.total_freight, public.getcurrid((new.total_freight_currency)::text), new.package_type, new.tracking_number, new.package_tracking_number, new.last_updated);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO freightpricingscheduleitem DO INSTEAD INSERT INTO public.ipsfreight (ipsfreight_ipshead_id, ipsfreight_qtybreak, ipsfreight_price, ipsfreight_type, ipsfreight_warehous_id, ipsfreight_shipzone_id, ipsfreight_freightclass_id, ipsfreight_shipvia) VALUES (public.getipsheadid((new.pricing_schedule)::text), new.qty_break, new.price, CASE WHEN (new.price_type = 'Flat Rate'::text) THEN 'F'::text ELSE 'P'::text END, CASE WHEN (new.from_site = 'Any'::text) THEN NULL::integer ELSE public.getwarehousid(new.from_site, 'All'::text) END, CASE WHEN (new.to_shipzone = 'Any'::text) THEN NULL::integer ELSE public.getshipzoneid(new.to_shipzone) END, CASE WHEN (new.freight_class = 'Any'::text) THEN NULL::integer ELSE public.getfreightclassid(new.freight_class) END, CASE WHEN (new.ship_via = 'Any'::text) THEN NULL::text ELSE new.ship_via END);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO glaccount DO INSTEAD INSERT INTO public.accnt (accnt_number, accnt_descrip, accnt_comments, accnt_profit, accnt_sub, accnt_type, accnt_extref, accnt_company, accnt_forwardupdate, accnt_subaccnttype_code) VALUES (COALESCE(new.account_number, ''::character varying), COALESCE(new.description, ''::text), COALESCE(new.notes, ''::text), new.profit_center, new.sub_account, CASE WHEN (new.type = 'Asset'::text) THEN 'A'::text WHEN (new.type = 'Liability'::text) THEN 'L'::text WHEN (new.type = 'Expense'::text) THEN 'E'::text WHEN (new.type = 'Revenue'::text) THEN 'R'::text WHEN (new.type = 'Equity'::text) THEN 'Q'::text ELSE NULL::text END, COALESCE(new.ext_reference, ''::text), new.company, COALESCE(new.forward_update_trial_balances, false), COALESCE(new.sub_type, ''::text));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO incident DO INSTEAD INSERT INTO public.incdt (incdt_number, incdt_crmacct_id, incdt_cntct_id, incdt_summary, incdt_descrip, incdt_item_id, incdt_status, incdt_assigned_username, incdt_incdtcat_id, incdt_incdtseverity_id, incdt_incdtpriority_id, incdt_incdtresolution_id, incdt_lotserial, incdt_ls_id) VALUES (new.incident_number, public.getcrmacctid(new.crm_account), public.savecntct(public.getcntctid(new.contact_number), new.contact_number, NULL::integer, new.honorific, new.first, new.middle, new.last, new.suffix, new.phone, NULL::text, new.fax, new.email, NULL::text, new.job_title, new.contact_change), COALESCE(new.description, ''::text), COALESCE(new.notes, ''::text), public.getitemid(new.item_number), CASE WHEN (new.status = 'New'::text) THEN 'N'::text WHEN (new.status = 'Feedback'::text) THEN 'F'::text WHEN (new.status = 'Confirmed'::text) THEN 'C'::text WHEN (new.status = 'Assigned'::text) THEN 'A'::text WHEN (new.status = 'Resolved'::text) THEN 'R'::text WHEN (new.status = 'Closed'::text) THEN 'L'::text ELSE ''::text END, COALESCE(new.assigned_to, ''::text), public.getincdtcatid(new.category), public.getincdtseverityid(new.severity), public.getincdtpriorityid(new.priority), public.getincdtresolutionid(new.resolution), COALESCE(new.lot_serial_number, ''::text), public.getlotserialid(new.item_number, new.lot_serial_number));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO incidentchar DO INSTEAD INSERT INTO public.charass (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default) VALUES ('INCDT'::text, public.getincidentid(new.incident_number), public.getcharid((new.characteristic)::text, 'INCDT'::text), new.value, false);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO incidentcomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text, comment_public) VALUES (COALESCE(new.date, now()), 'INCDT'::text, public.getincidentid(new.incident_number), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text, COALESCE(new.public, true));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO incidentfile DO INSTEAD INSERT INTO public.url (url_source_id, url_source, url_title, url_url) VALUES (public.getincidentid(new.incident_number), 'INCDT'::text, new.title, new.url);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO incidentimage DO INSTEAD SELECT public.saveimageass('INCDT'::text, public.getincidentid(new.incident_number), 'M'::bpchar, public.getimageid(new.image_name)) AS saveimageass;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO invoice DO INSTEAD SELECT public.insertinvoice(new.*) AS insertinvoice;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO invoiceline DO INSTEAD SELECT public.insertinvoicelineitem(new.*) AS insertinvoicelineitem;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO item DO INSTEAD INSERT INTO public.item (item_number, item_active, item_descrip1, item_descrip2, item_type, item_maxcost, item_classcode_id, item_inv_uom_id, item_picklist, item_fractional, item_config, item_sold, item_prodcat_id, item_exclusive, item_listprice, item_listcost, item_price_uom_id, item_upccode, item_prodweight, item_packweight, item_comments, item_extdescrip) VALUES (upper((new.item_number)::text), COALESCE(new.active, true), COALESCE(new.description1, ''::text), COALESCE(new.description2, ''::text), CASE WHEN (new.item_type = 'Purchased'::text) THEN 'P'::text WHEN (new.item_type = 'Manufactured'::text) THEN 'M'::text WHEN (new.item_type = 'Job'::text) THEN 'J'::text WHEN (new.item_type = 'Kit'::text) THEN 'K'::text WHEN (new.item_type = 'Phantom'::text) THEN 'F'::text WHEN (new.item_type = 'Reference'::text) THEN 'R'::text WHEN (new.item_type = 'Costing'::text) THEN 'S'::text WHEN (new.item_type = 'Tooling'::text) THEN 'T'::text WHEN (new.item_type = 'Outside Process'::text) THEN 'O'::text WHEN (new.item_type = 'Planning'::text) THEN 'L'::text WHEN (new.item_type = 'Breeder'::text) THEN 'B'::text WHEN (new.item_type = 'Co-Product'::text) THEN 'C'::text WHEN (new.item_type = 'By-Product'::text) THEN 'Y'::text ELSE NULL::text END, COALESCE(new.maximum_desired_cost, (0)::numeric), public.getclasscodeid(new.class_code), public.getuomid(new.inventory_uom), COALESCE(new.pick_list_item, true), COALESCE(new.fractional, false), COALESCE(new.configured, false), COALESCE(new.item_is_sold, true), COALESCE(public.getprodcatid(new.product_category), (-1)), COALESCE(new.exclusive, false), COALESCE(new.list_price, (0)::numeric), COALESCE(new.list_cost, (0)::numeric), COALESCE(public.getuomid(new.list_price_uom), public.getuomid(new.inventory_uom)), new.upc_code, COALESCE(new.product_weight, (0)::numeric), COALESCE(new.packaging_weight, (0)::numeric), new.notes, new.ext_description);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemalias DO INSTEAD INSERT INTO public.itemalias (itemalias_item_id, itemalias_number, itemalias_usedescrip, itemalias_descrip1, itemalias_descrip2, itemalias_comments, itemalias_crmacct_id) VALUES (public.getitemid((new.item_number)::text), new.alias_number, COALESCE(new.use_description, false), COALESCE(new.description1, ''::text), COALESCE(new.description2, ''::text), new.comments, public.getcrmacctid(new.crmacct_number));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemchar DO INSTEAD INSERT INTO public.charass (charass_target_type, charass_target_id, charass_char_id, charass_value, charass_default) VALUES ('I'::text, public.getitemid((new.item_number)::text), public.getcharid((new.characteristic)::text, 'I'::text), new.value, COALESCE(new.is_default, false));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemcomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'IS'::text, public.getitemid((new.item_number)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemcost DO INSTEAD SELECT public.insertitemcost(public.getitemid((new.item_number)::text), public.getcostelemid((new.costing_element)::text), public.getcurrid((new.currency)::text), new.actual_cost, new.post_to_standard) AS insertitemcost;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemfile DO INSTEAD INSERT INTO public.url (url_source_id, url_source, url_title, url_url) VALUES (public.getitemid((new.item_number)::text), 'I'::text, new.title, new.url);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemimage DO INSTEAD SELECT public.saveimageass('I'::text, public.getitemid((new.item_number)::text), (CASE WHEN (new.purpose = 'Product Description'::text) THEN 'P'::text WHEN (new.purpose = 'Inventory Description'::text) THEN 'I'::text WHEN (new.purpose = 'Engineering Reference'::text) THEN 'E'::text WHEN (new.purpose = 'Miscellaneous'::text) THEN 'M'::text ELSE 'X'::text END)::bpchar, public.getimageid(new.image_name)) AS saveimageass;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemsite DO INSTEAD INSERT INTO public.itemsite (itemsite_item_id, itemsite_warehous_id, itemsite_active, itemsite_dropship, itemsite_posupply, itemsite_createpr, itemsite_wosupply, itemsite_createwo, itemsite_createsopr, itemsite_createsopo, itemsite_sold, itemsite_soldranking, itemsite_costmethod, itemsite_controlmethod, itemsite_perishable, itemsite_plancode_id, itemsite_costcat_id, itemsite_loccntrl, itemsite_location_id, itemsite_recvlocation_id, itemsite_issuelocation_id, itemsite_location_dist, itemsite_recvlocation_dist, itemsite_issuelocation_dist, itemsite_location, itemsite_location_comments, itemsite_disallowblankwip, itemsite_stocked, itemsite_abcclass, itemsite_autoabcclass, itemsite_cyclecountfreq, itemsite_eventfence, itemsite_useparams, itemsite_reorderlevel, itemsite_ordertoqty, itemsite_minordqty, itemsite_maxordqty, itemsite_multordqty, itemsite_useparamsmanual, itemsite_ordergroup, itemsite_ordergroup_first, itemsite_mps_timefence, itemsite_leadtime, itemsite_safetystock, itemsite_supply_itemsite_id, itemsite_notes, itemsite_qtyonhand, itemsite_warrpurc, itemsite_autoreg, itemsite_freeze, itemsite_value, itemsite_planning_type) VALUES (public.getitemid((new.item_number)::text), public.getwarehousid((new.site)::text, 'ACTIVE'::text), COALESCE(new.active, true), COALESCE(new.dropship, false), COALESCE(new.po_supplied_at_site, false), COALESCE(new.create_prs, false), COALESCE(new.wo_supplied_at_site, false), COALESCE(new.create_wos, false), COALESCE(new.create_soprs, false), COALESCE(new.create_sopos, false), COALESCE(new.sold_from_site, true), COALESCE(new.ranking, 1), CASE WHEN (new.cost_method = 'None'::text) THEN 'N'::text WHEN (new.cost_method = 'Average'::text) THEN 'A'::text WHEN (new.cost_method = 'Standard'::text) THEN 'S'::text WHEN (new.cost_method = 'Job'::text) THEN 'J'::text ELSE NULL::text END, CASE WHEN (new.control_method = 'None'::text) THEN 'N'::text WHEN (new.control_method = 'Regular'::text) THEN 'R'::text WHEN (new.control_method = 'Serial #'::text) THEN 'S'::text WHEN (new.control_method = 'Lot #'::text) THEN 'L'::text ELSE NULL::text END, COALESCE(new.perishable, false), public.getplancodeid(new.planner_code), public.getcostcatid(new.cost_category), COALESCE(new.multiple_location_control, false), COALESCE(public.getlocationid((new.site)::text, new.location), (-1)), COALESCE(public.getlocationid((new.site)::text, new.receive_location), (-1)), COALESCE(public.getlocationid((new.site)::text, new.issue_location), (-1)), COALESCE(new.auto_distr_location, false), COALESCE(new.auto_distr_receive_location, false), COALESCE(new.auto_distr_issue_location, false), COALESCE(new.user_defined_location, ''::text), COALESCE(new.location_comment, ''::text), COALESCE(new.disallow_blank_wip_locations, false), COALESCE(new.stocked, false), COALESCE(new.abc_class, 'A'::bpchar), COALESCE(new.allow_automatic_updates, false), COALESCE(new.cycl_cnt_freq, 0), COALESCE((new.event_fence)::numeric, public.fetchmetricvalue('DefaultEventFence'::text)), COALESCE(new.enforce_order_parameters, false), COALESCE(new.reorder_level, (0)::numeric), COALESCE(new.order_up_to, (0)::numeric), COALESCE(new.minimum_order, (0)::numeric), COALESCE(new.maximum_order, (0)::numeric), COALESCE(new.order_multiple, (0)::numeric), COALESCE(new.enforce_on_manual_orders, false), COALESCE(new.group_mps_mrp_orders, 0), COALESCE(new.first_group, false), COALESCE(new.mps_time_fence, 0), COALESCE(new.lead_time, 0), COALESCE(new.safety_stock, (0)::numeric), CASE WHEN (new.supplied_from_site = 'None'::text) THEN NULL::integer WHEN (new.supplied_from_site = ''::text) THEN NULL::integer ELSE public.getitemsiteid(new.supplied_from_site, (new.item_number)::text) END, COALESCE(new.notes, ''::text), 0, COALESCE(new.require_warranty, false), COALESCE(new.auto_register, false), false, 0, CASE WHEN (new.planning_system = 'None'::text) THEN 'N'::text WHEN (new.planning_system = 'MPS'::text) THEN 'S'::text ELSE 'M'::text END);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemsitecomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'IS'::text, public.getitemsiteid((new.site)::text, (new.item_number)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemsource DO INSTEAD INSERT INTO public.itemsrc (itemsrc_item_id, itemsrc_vend_id, itemsrc_vend_item_number, itemsrc_vend_item_descrip, itemsrc_comments, itemsrc_vend_uom, itemsrc_invvendoruomratio, itemsrc_minordqty, itemsrc_multordqty, itemsrc_leadtime, itemsrc_ranking, itemsrc_active, itemsrc_default, itemsrc_manuf_name, itemsrc_manuf_item_number, itemsrc_manuf_item_descrip, itemsrc_upccode, itemsrc_contrct_id, itemsrc_effective, itemsrc_expires) VALUES (public.getitemid((new.item_number)::text), public.getvendid((new.vendor)::text), new.vendor_item_number, COALESCE(new.vendor_description, ''::text), COALESCE(new.notes, ''::text), new.vendor_uom, new.inventory_vendor_uom_ratio, new.minimum_order, new.order_multiple, new.lead_time, new.vendor_ranking, COALESCE(new.active, true), COALESCE(new.itemsrc_default, true), COALESCE(new.manufacturer_name, ''::text), COALESCE(new.manufacturer_item_number, ''::text), new.manufacturer_description, new.bar_code, public.getcontrctid(new.contract_number), COALESCE(public.getcontrcteffective(new.contract_number), new.effective_date), COALESCE(public.getcontrctexpires(new.contract_number), new.expires_date));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemsourceprice DO INSTEAD INSERT INTO public.itemsrcp (itemsrcp_itemsrc_id, itemsrcp_qtybreak, itemsrcp_price, itemsrcp_curr_id, itemsrcp_updated, itemsrcp_dropship, itemsrcp_warehous_id, itemsrcp_type, itemsrcp_discntprcnt, itemsrcp_fixedamtdiscount) VALUES (public.getitemsrcid((new.item_number)::text, (new.vendor)::text), new.qty_break, new.price_per_unit, public.getcurrid((new.currency)::text), now(), COALESCE(new.dropship_only, false), CASE WHEN (new.pricing_site = 'All'::text) THEN (-1) ELSE COALESCE(public.getwarehousid(new.pricing_site, 'ALL'::text), (-1)) END, CASE WHEN (new.pricing_type = 'Discount'::text) THEN 'D'::text ELSE 'N'::text END, (COALESCE(new.discount_percent, 0.0) / 100.0), new.discount_fixed_amount);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemsubstitute DO INSTEAD INSERT INTO public.itemsub (itemsub_parent_item_id, itemsub_sub_item_id, itemsub_uomratio, itemsub_rank) VALUES (public.getitemid((new.root_item_number)::text), public.getitemid((new.substitute_item_number)::text), COALESCE(new.sub_parent_uom_ratio, (1)::numeric), COALESCE(new.ranking, 1));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemtaxtype DO INSTEAD INSERT INTO public.itemtax (itemtax_item_id, itemtax_taxzone_id, itemtax_taxtype_id) VALUES (public.getitemid((new.item_number)::text), CASE WHEN ((new.tax_zone)::text = 'Any'::text) THEN NULL::integer ELSE public.gettaxzoneid((new.tax_zone)::text) END, public.gettaxtypeid(new.tax_type));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO itemuomconversion DO INSTEAD SELECT public.saveitemuomconv(public.getitemid((new.item_number)::text), COALESCE(public.getuomid((new.uom)::text), (SELECT item.item_inv_uom_id FROM public.item WHERE (item.item_id = public.getitemid((new.item_number)::text)))), COALESCE(new.uom_value, (1)::numeric), COALESCE(public.getuomid(new.per_uom), (SELECT item.item_inv_uom_id FROM public.item WHERE (item.item_id = public.getitemid((new.item_number)::text)))), COALESCE(new.per_uom_value, (1)::numeric), COALESCE(new.fractional, false), public.getuomtypeid(new.selected_types)) AS saveitemuomconv;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO journalentry DO INSTEAD SELECT public.insertgltransaction('G/L'::text, 'JE'::text, new.doc_number, new.notes, public.getglaccntid(new.credit), public.getglaccntid(new.debit), (-1), public.currtobase(public.getcurrid((new.currency)::text), new.amount, new.dist_date), new.dist_date) AS insertgltransaction;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO location DO INSTEAD INSERT INTO public.location (location_warehous_id, location_name, location_descrip, location_restrict, location_netable, location_usable, location_whsezone_id, location_aisle, location_rack, location_bin) VALUES (public.getwarehousid((new.site)::text, 'ACTIVE'::text), COALESCE(new.location, ''::character varying), COALESCE(new.description, ''::text), COALESCE(new.restricted, false), COALESCE(new.netable, true), COALESCE(new.usable, true), public.getwhsezoneid((new.site)::text, new.zone), COALESCE(new.aisle, ''::character varying), COALESCE(new.rack, ''::character varying), COALESCE(new.bin, ''::character varying));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO misccounttag DO INSTEAD SELECT public.postmisccount(public.getitemsiteid(COALESCE(new.site, (SELECT whsinfo.warehous_code FROM public.usrpref, public.whsinfo WHERE (((usrpref.usrpref_username = public.geteffectivextuser()) AND (usrpref.usrpref_name = 'PreferredWarehouse'::text)) AND (whsinfo.warehous_id = (usrpref.usrpref_value)::integer)))), new.item_number), new.quantity, new.comment) AS postmisccount;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO pricingschedule DO INSTEAD INSERT INTO public.ipshead (ipshead_id, ipshead_name, ipshead_descrip, ipshead_effective, ipshead_expires, ipshead_curr_id, ipshead_updated) VALUES (nextval('public.ipshead_ipshead_id_seq'::regclass), new.name, new.description, CASE WHEN (new.effective = 'Always'::text) THEN '1970-01-01'::date ELSE (COALESCE(new.effective, '1970-01-01'::text))::date END, CASE WHEN (new.expires = 'Never'::text) THEN '2100-01-01'::date ELSE (COALESCE(new.expires, '2100-01-01'::text))::date END, COALESCE(public.getcurrid((new.currency)::text), public.basecurrid()), now());


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO pricingscheduleassign DO INSTEAD INSERT INTO public.ipsass (ipsass_ipshead_id, ipsass_cust_id, ipsass_custtype_id, ipsass_custtype_pattern, ipsass_shipto_id, ipsass_shipto_pattern) VALUES (public.getipsheadid((new.pricing_schedule)::text), CASE WHEN ((new.customer_number)::text = 'Any'::text) THEN (-1) ELSE public.getcustid((new.customer_number)::text) END, CASE WHEN ((new.customer_type)::text = 'N/A'::text) THEN (-1) ELSE public.getcusttypeid((new.customer_type)::text) END, new.customer_type_pattern, CASE WHEN (((new.customer_number)::text = 'Any'::text) OR ((new.customer_shipto)::text = 'Any'::text)) THEN (-1) ELSE public.getshiptoid((new.customer_number)::text, (new.customer_shipto)::text) END, new.customer_shipto_pattern);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO pricingscheduleitem DO INSTEAD SELECT CASE WHEN ((new.type)::text = 'Item'::text) THEN public.saveipsitem(NULL::integer, public.getipsheadid((new.pricing_schedule)::text), public.getitemid((new.item_number)::text), COALESCE(new.qty_break, (0)::numeric), COALESCE(new.price, (0)::numeric), public.getuomid((new.qty_uom)::text), public.getuomid((new.price_uom)::text), new.percent, new.fixedamt, CASE new.pricing_type WHEN 'Nominal'::text THEN 'N'::text WHEN 'Discount'::text THEN 'D'::text WHEN 'Markup'::text THEN 'M'::text ELSE '?'::text END) WHEN ((new.type)::text = 'Product Category'::text) THEN public.saveipsprodcat(NULL::integer, public.getipsheadid((new.pricing_schedule)::text), public.getprodcatid((new.product_category)::text), new.qty_break, new.percent, new.fixedamt, CASE new.pricing_type WHEN 'Nominal'::text THEN 'N'::text WHEN 'Discount'::text THEN 'D'::text WHEN 'Markup'::text THEN 'M'::text ELSE '?'::text END) ELSE NULL::integer END AS "case";


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO pricingscheduleitemchar DO INSTEAD INSERT INTO public.ipsitemchar (ipsitemchar_ipsitem_id, ipsitemchar_char_id, ipsitemchar_value, ipsitemchar_price) VALUES (public.getipsitemid((new.pricing_schedule)::text, (new.item_number)::text, new.qty_break, (new.qty_uom)::text, (new.price_uom)::text), public.getcharid((new.characteristic)::text, 'I'::text), new.value, COALESCE(new.price, (0)::numeric));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO project DO INSTEAD INSERT INTO public.prj (prj_number, prj_name, prj_descrip, prj_owner_username, prj_username, prj_so, prj_wo, prj_po, prj_status, prj_due_date, prj_assigned_date, prj_start_date, prj_completed_date) VALUES (new.number, COALESCE(new.name, ''::text), COALESCE(new.description, ''::text), COALESCE(new.owner, public.geteffectivextuser()), COALESCE(new.assigned_to, public.geteffectivextuser()), COALESCE(new.sales_orders, true), COALESCE(new.work_orders, true), COALESCE(new.purchase_orders, true), CASE WHEN (new.status = 'In-Process'::text) THEN 'O'::text WHEN (new.status = 'Completed'::text) THEN 'C'::text ELSE 'P'::text END, new.due, new.assigned, new.started, new.completed);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO projectcomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'J'::text, public.getprjid((new.project_number)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO prospect DO INSTEAD INSERT INTO public.prospect (prospect_number, prospect_name, prospect_active, prospect_cntct_id, prospect_taxzone_id, prospect_salesrep_id, prospect_warehous_id, prospect_comments) VALUES (upper((new.prospect_number)::text), COALESCE(new.prospect_name, ''::text), COALESCE(new.active, true), public.savecntct(public.getcntctid(new.contact_number), new.contact_number, public.saveaddr(public.getaddrid(new.contact_address_number), new.contact_address_number, new.contact_address1, new.contact_address2, new.contact_address3, new.contact_city, new.contact_state, new.contact_postalcode, new.contact_country, new.contact_address_change), new.contact_honorific, new.contact_first, new.contact_middle, new.contact_last, new.contact_suffix, new.contact_voice, new.contact_alternate, new.contact_fax, new.contact_email, new.contact_web, new.contact_job_title, new.contact_change), public.gettaxzoneid(new.default_tax_zone), public.getsalesrepid(new.sales_rep), public.getwarehousid(new.site_code, 'ACTIVE'::text), COALESCE(new.notes, ''::text));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO purchaseline DO INSTEAD INSERT INTO public.poitem (poitem_pohead_id, poitem_linenumber, poitem_duedate, poitem_itemsite_id, poitem_vend_item_descrip, poitem_qty_ordered, poitem_unitprice, poitem_vend_item_number, poitem_manuf_name, poitem_manuf_item_number, poitem_manuf_item_descrip, poitem_comments, poitem_expcat_id, poitem_freight, poitem_prj_id, poitem_bom_rev_id, poitem_boo_rev_id) VALUES (public.getpoheadid((new.order_number)::text), new.line_number, new.due_date, public.getitemsiteid(COALESCE(new.site, (SELECT whsinfo.warehous_code FROM (public.pohead JOIN public.whsinfo ON ((whsinfo.warehous_id = pohead.pohead_warehous_id))) WHERE (pohead.pohead_id = public.getpoheadid((new.order_number)::text))), (SELECT whsinfo.warehous_code FROM public.whsinfo WHERE (whsinfo.warehous_id = public.fetchprefwarehousid()))), new.item_number), new.vendor_description, new.qty_ordered, new.unit_price, new.vend_item_number, new.manufacturer_name, new.manufacturer_item_number, new.manufacturer_description, new.notes, public.getexpcatid(new.expense_category), new.freight, public.getprjid(new.project_number), public.getrevid('BOM'::text, new.item_number, new.bill_of_materials_revision), public.getrevid('BOO'::text, new.item_number, new.bill_of_operations_revision));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO purchaselinechar DO INSTEAD SELECT DISTINCT public.updatecharassignment('PI'::text, poitem.poitem_id, charass.charass_char_id, new.value) AS updatecharassignment FROM public.pohead, public.poitem, public.itemsite, public.item, public.charass, public."char" WHERE (((((((((pohead.pohead_number = (new.order_number)::text) AND (pohead.pohead_id = poitem.poitem_pohead_id)) AND (poitem.poitem_linenumber = new.line_number)) AND (poitem.poitem_itemsite_id = itemsite.itemsite_id)) AND (item.item_id = itemsite.itemsite_item_id)) AND (charass.charass_target_type = 'I'::text)) AND (charass.charass_target_id = item.item_id)) AND ("char".char_id = charass.charass_char_id)) AND ("char".char_name = new.characteristic));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO purchaselinecomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) SELECT COALESCE(new.date, (('now'::text)::date)::timestamp with time zone) AS "coalesce", 'PI', poitem.poitem_id, COALESCE(new.username, public.geteffectivextuser()) AS "coalesce", public.getcmnttypeid(new.type) AS getcmnttypeid, new.text FROM public.poitem, public.pohead WHERE (((pohead.pohead_number = (new.order_number)::text) AND (poitem.poitem_pohead_id = pohead.pohead_id)) AND (poitem.poitem_linenumber = new.line_number));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO purchaseorder DO INSTEAD INSERT INTO public.pohead (pohead_number, pohead_orderdate, pohead_status, pohead_terms_id, pohead_taxzone_id, pohead_warehous_id, pohead_agent_username, pohead_vend_id, pohead_vendaddr_id, pohead_fob, pohead_shipvia, pohead_curr_id, pohead_freight, pohead_comments, pohead_dropship, pohead_vend_cntct_id, pohead_vend_cntct_honorific, pohead_vend_cntct_first_name, pohead_vend_cntct_middle, pohead_vend_cntct_last_name, pohead_vend_cntct_suffix, pohead_vend_cntct_phone, pohead_vend_cntct_title, pohead_vend_cntct_fax, pohead_vend_cntct_email, pohead_vendaddress1, pohead_vendaddress2, pohead_vendaddress3, pohead_vendcity, pohead_vendstate, pohead_vendzipcode, pohead_vendcountry, pohead_shipto_cntct_id, pohead_shipto_cntct_honorific, pohead_shipto_cntct_first_name, pohead_shipto_cntct_middle, pohead_shipto_cntct_last_name, pohead_shipto_cntct_suffix, pohead_shipto_cntct_phone, pohead_shipto_cntct_title, pohead_shipto_cntct_fax, pohead_shipto_cntct_email, pohead_shiptoaddress_id, pohead_shiptoaddress1, pohead_shiptoaddress2, pohead_shiptoaddress3, pohead_shiptocity, pohead_shiptostate, pohead_shiptozipcode, pohead_shiptocountry, pohead_cohead_id) SELECT new.order_number, COALESCE(new.order_date, ('now'::text)::date) AS "coalesce", 'U', COALESCE(public.gettermsid(new.terms), vendinfo.vend_terms_id) AS "coalesce", COALESCE(public.gettaxzoneid(new.tax_zone), vendinfo.vend_taxzone_id) AS "coalesce", COALESCE(public.getwarehousid(new.receiving_site, 'ALL'::text), public.fetchprefwarehousid()) AS "coalesce", COALESCE(new.purchasing_agent, public.geteffectivextuser()) AS "coalesce", public.getvendid(new.vendor_number) AS getvendid, CASE WHEN (new.alt_address = 'MAIN'::text) THEN NULL::integer ELSE public.getvendaddrid(new.vendor_number, new.alt_address) END AS getvendaddrid, COALESCE(new.fob, CASE WHEN (vendinfo.vend_fobsource = 'W'::bpchar) THEN (SELECT whsinfo.warehous_fob FROM public.whsinfo WHERE (whsinfo.warehous_id = COALESCE(public.getwarehousid(new.receiving_site, 'ALL'::text), public.fetchprefwarehousid()))) ELSE vendinfo.vend_fob END) AS "coalesce", COALESCE(new.ship_via, vendinfo.vend_shipvia) AS "coalesce", COALESCE(public.getcurrid((new.currency)::text), vendinfo.vend_curr_id) AS "coalesce", COALESCE(new.freight, (0)::numeric) AS "coalesce", new.notes, COALESCE(new.dropship, false) AS "coalesce", public.getcntctid(new.vend_contact_number) AS getcntctid, COALESCE(new.vend_cntct_honorific, ''::text) AS "coalesce", COALESCE(new.vend_cntct_first_name, ''::text) AS "coalesce", COALESCE(new.vend_cntct_middle, ''::text) AS "coalesce", COALESCE(new.vend_cntct_last_name, ''::text) AS "coalesce", COALESCE(new.vend_cntct_suffix, ''::text) AS "coalesce", COALESCE(new.vend_cntct_phone, ''::text) AS "coalesce", COALESCE(new.vend_cntct_title, ''::text) AS "coalesce", COALESCE(new.vend_cntct_fax, ''::text) AS "coalesce", COALESCE(new.vend_cntct_email, ''::text) AS "coalesce", COALESCE(new.vendaddress1, ''::text) AS "coalesce", COALESCE(new.vendaddress2, ''::text) AS "coalesce", COALESCE(new.vendaddress3, ''::text) AS "coalesce", COALESCE(new.vendcity, ''::text) AS "coalesce", COALESCE(new.vendstate, ''::text) AS "coalesce", COALESCE(new.vendzipcode, ''::text) AS "coalesce", COALESCE(new.vendcountry, ''::text) AS "coalesce", public.getcntctid(new.shipto_contact_number) AS getcntctid, COALESCE(new.shipto_cntct_honorific, ''::text) AS "coalesce", COALESCE(new.shipto_cntct_first_name, ''::text) AS "coalesce", COALESCE(new.shipto_cntct_middle, ''::text) AS "coalesce", COALESCE(new.shipto_cntct_last_name, ''::text) AS "coalesce", COALESCE(new.shipto_cntct_suffix, ''::text) AS "coalesce", COALESCE(new.shipto_cntct_phone, ''::text) AS "coalesce", COALESCE(new.shipto_cntct_title, ''::text) AS "coalesce", COALESCE(new.shipto_cntct_fax, ''::text) AS "coalesce", COALESCE(new.shipto_cntct_email, ''::text) AS "coalesce", public.getaddrid(new.shiptoaddress_number) AS getaddrid, COALESCE(new.shiptoaddress1, ''::text) AS "coalesce", COALESCE(new.shiptoaddress2, ''::text) AS "coalesce", COALESCE(new.shiptoaddress3, ''::text) AS "coalesce", COALESCE(new.shiptocity, ''::text) AS "coalesce", COALESCE(new.shiptostate, ''::text) AS "coalesce", COALESCE(new.shiptozipcode, ''::text) AS "coalesce", COALESCE(new.shiptocountry, ''::text) AS "coalesce", public.getcoheadid(new.sales_order_number) AS getcoheadid FROM public.vendinfo WHERE (vendinfo.vend_id = public.getvendid(new.vendor_number));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO purchaseordercomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, (('now'::text)::date)::timestamp with time zone), 'P'::text, public.getpoheadid((new.order_number)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO quote DO INSTEAD INSERT INTO public.quhead (quhead_number, quhead_cust_id, quhead_custponumber, quhead_quotedate, quhead_warehous_id, quhead_shipto_id, quhead_shiptoname, quhead_shiptoaddress1, quhead_shiptoaddress2, quhead_shiptoaddress3, quhead_salesrep_id, quhead_terms_id, quhead_fob, quhead_shipvia, quhead_shiptocity, quhead_shiptostate, quhead_shiptozipcode, quhead_freight, quhead_misc, quhead_ordercomments, quhead_shipcomments, quhead_shiptophone, quhead_billtoname, quhead_billtoaddress1, quhead_billtoaddress2, quhead_billtoaddress3, quhead_billtocity, quhead_billtostate, quhead_billtozip, quhead_misc_accnt_id, quhead_misc_descrip, quhead_commission, quhead_packdate, quhead_prj_id, quhead_billtocountry, quhead_shiptocountry, quhead_curr_id, quhead_taxzone_id, quhead_taxtype_id, quhead_imported, quhead_expire, quhead_status, quhead_saletype_id, quhead_shipzone_id) VALUES (new.quote_number, public.getcustid(new.customer_number, true), new.cust_po_number, new.quote_date, public.getwarehousid(new.site, 'SHIPPING'::text), public.getshiptoid(new.customer_number, new.shipto_number), new.shipto_name, new.shipto_address1, new.shipto_address2, new.shipto_address3, public.getsalesrepid(new.sales_rep), public.gettermsid(new.terms), new.fob, new.ship_via, new.shipto_city, new.shipto_state, new.shipto_postal_code, new.freight, new.misc_charge, new.order_notes, new.shipping_notes, new.shipto_phone, new.billto_name, new.billto_address1, new.billto_address2, new.billto_address3, new.billto_city, new.billto_state, new.billto_postal_code, public.getglaccntid(new.misc_account_number), new.misc_charge_description, new.commission, new.pack_date, public.getprjid(new.project_number), new.billto_country, new.shipto_country, public.getcurrid((new.currency)::text), public.gettaxzoneid(new.tax_zone), public.gettaxtypeid(new.tax_type), true, new.expire_date, CASE WHEN (new.status = 'Converted'::text) THEN 'C'::text ELSE 'O'::text END, public.getsaletypeid(new.sale_type), public.getshipzoneid(new.shipto_shipzone));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO quotecomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, (('now'::text)::date)::timestamp with time zone), 'Q'::text, public.getquoteid(new.quote_number), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO quoteline DO INSTEAD INSERT INTO public.quitem (quitem_quhead_id, quitem_linenumber, quitem_itemsite_id, quitem_scheddate, quitem_qtyord, quitem_unitcost, quitem_price, quitem_custprice, quitem_memo, quitem_imported, quitem_custpn, quitem_createorder, quitem_order_warehous_id, quitem_item_id, quitem_prcost, quitem_taxtype_id, quitem_qty_uom_id, quitem_qty_invuomratio, quitem_price_uom_id, quitem_price_invuomratio) SELECT public.getquoteid(new.quote_number) AS getquoteid, COALESCE(new.line_number, (SELECT (COALESCE(max(quitem.quitem_linenumber), 0) + 1) FROM public.quitem WHERE (quitem.quitem_quhead_id = public.getquoteid(new.quote_number)))) AS "coalesce", itemsite.itemsite_id, COALESCE(new.scheduled_date, (SELECT min(quitem.quitem_scheddate) AS min FROM public.quitem WHERE (quitem.quitem_quhead_id = public.getquoteid(new.quote_number)))) AS "coalesce", new.qty_ordered, public.stdcost(item.item_id) AS stdcost, COALESCE(new.net_unit_price, public.itemprice(public.getitemid(new.item_number), quhead.quhead_cust_id, quhead.quhead_shipto_id, new.qty_ordered, quhead.quhead_curr_id, quhead.quhead_quotedate)) AS "coalesce", public.itemprice(public.getitemid(new.item_number), quhead.quhead_cust_id, quhead.quhead_shipto_id, new.qty_ordered, quhead.quhead_curr_id, quhead.quhead_quotedate) AS itemprice, COALESCE(new.notes, ''::text) AS "coalesce", true AS bool, new.customer_pn, COALESCE(new.create_order, false) AS "coalesce", COALESCE(public.getwarehousid(new.supplying_site, 'SHIPPING'::text), itemsite.itemsite_warehous_id) AS "coalesce", public.getitemid(new.item_number) AS getitemid, COALESCE(new.overwrite_po_price, (0)::numeric) AS "coalesce", COALESCE(public.gettaxtypeid(new.tax_type), public.getitemtaxtype(itemsite.itemsite_item_id, quhead.quhead_taxzone_id)) AS "coalesce", COALESCE(public.getuomid(new.qty_uom), item.item_inv_uom_id) AS "coalesce", public.itemuomtouomratio(item.item_id, COALESCE(public.getuomid(new.qty_uom), item.item_inv_uom_id), item.item_inv_uom_id) AS itemuomtouomratio, COALESCE(public.getuomid(new.price_uom), item.item_price_uom_id) AS "coalesce", public.itemuomtouomratio(item.item_id, COALESCE(public.getuomid(new.price_uom), item.item_price_uom_id), item.item_price_uom_id) AS itemuomtouomratio FROM public.quhead, public.itemsite, public.item, public.whsinfo WHERE ((quhead.quhead_number = new.quote_number) AND (((((((itemsite.itemsite_warehous_id = whsinfo.warehous_id) AND (itemsite.itemsite_item_id = item.item_id)) AND itemsite.itemsite_active) AND (item.item_number = new.item_number)) AND whsinfo.warehous_active) AND whsinfo.warehous_shipping) AND (whsinfo.warehous_code = COALESCE(new.sold_from_site, (SELECT whsinfo.warehous_code FROM public.usrpref, public.whsinfo WHERE (((usrpref.usrpref_username = public.geteffectivextuser()) AND (usrpref.usrpref_name = 'PreferredWarehouse'::text)) AND (whsinfo.warehous_id = (usrpref.usrpref_value)::integer)))))));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO quotelinechar DO INSTEAD SELECT DISTINCT public.updatecharassignment('QI'::text, quitem.quitem_id, charass.charass_char_id, new.value) AS updatecharassignment FROM public.quhead, public.quitem, public.itemsite, public.item, public.charass, public."char" WHERE (((((((((quhead.quhead_number = new.quote_number) AND (quhead.quhead_id = quitem.quitem_quhead_id)) AND (quitem.quitem_linenumber = new.line_number)) AND (quitem.quitem_itemsite_id = itemsite.itemsite_id)) AND (item.item_id = itemsite.itemsite_item_id)) AND (charass.charass_target_type = 'I'::text)) AND (charass.charass_target_id = item.item_id)) AND ("char".char_id = charass.charass_char_id)) AND ("char".char_name = new.characteristic));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO quotelinecomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, (('now'::text)::date)::timestamp with time zone), 'QI'::text, public.getquotelineitemid(new.quote_number, new.line_number), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO salescredit DO INSTEAD INSERT INTO public.aropenalloc (aropenalloc_aropen_id, aropenalloc_doctype, aropenalloc_doc_id, aropenalloc_amount, aropenalloc_curr_id) VALUES (public.getaropenid(new.customer_number, 'C'::bpchar, new.cm_number), 'S'::bpchar, public.getcoheadid(new.so_number), new.amount, public.getcurrid((new.currency)::text));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO saleshistory DO INSTEAD INSERT INTO public.cohist (cohist_cust_id, cohist_itemsite_id, cohist_shipdate, cohist_shipvia, cohist_ordernumber, cohist_orderdate, cohist_invcnumber, cohist_invcdate, cohist_qtyshipped, cohist_unitprice, cohist_shipto_id, cohist_salesrep_id, cohist_duedate, cohist_imported, cohist_billtoname, cohist_billtoaddress1, cohist_billtoaddress2, cohist_billtoaddress3, cohist_billtocity, cohist_billtostate, cohist_billtozip, cohist_shiptoname, cohist_shiptoaddress1, cohist_shiptoaddress2, cohist_shiptoaddress3, cohist_shiptocity, cohist_shiptostate, cohist_shiptozip, cohist_commission, cohist_commissionpaid, cohist_unitcost, cohist_misc_type, cohist_misc_descrip, cohist_misc_id, cohist_doctype, cohist_promisedate, cohist_ponumber, cohist_curr_id, cohist_sequence, cohist_taxzone_id, cohist_taxtype_id) VALUES (public.getcustid(new.customer_number), public.getitemsiteid(new.site_code, new.item_number), new.ship_date, new.ship_via, new.order_number, new.order_date, new.invoice_number, new.invoice_date, new.quantity_shipped, COALESCE(new.unit_price, (0)::numeric), public.getshiptoid(new.customer_number, new.shipto_number), public.getsalesrepid(new.sales_rep), new.due_date, true, new.billto_name, new.billto_address1, new.billto_address2, new.billto_address3, new.billto_city, new.billto_state, new.billto_zip, new.shipto_name, new.shipto_address1, new.shipto_address2, new.shipto_address3, new.shipto_city, new.shipto_state, new.shipto_zip, COALESCE(new.commission, (0)::numeric), COALESCE(new.commission_paid, false), COALESCE(new.unit_cost, (0)::numeric), CASE WHEN (new.misc_type = 'Misc. Charge'::text) THEN 'M'::text WHEN (new.misc_type = 'Freight'::text) THEN 'F'::text ELSE NULL::text END, new.misc_description, CASE WHEN (new.misc_type = 'Misc. Charge'::text) THEN public.getglaccntid(new.misc_info) ELSE NULL::integer END, CASE WHEN (new.document_type = 'Invoice'::text) THEN 'I'::text WHEN (new.document_type = 'Credit Memo'::text) THEN 'C'::text ELSE NULL::text END, new.promise_date, new.purchase_order_number, COALESCE(public.getcurrid((new.currency)::text), public.basecurrid()), new.gl_sequence, public.gettaxzoneid(new.tax_zone), public.gettaxtypeid(new.tax_type));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO saleslinechar DO INSTEAD SELECT DISTINCT public.updatecharassignment('SI'::text, coitem.coitem_id, charass.charass_char_id, new.value, public.itemcharprice(item.item_id, "char".char_id, new.value, cohead.cohead_cust_id, cohead.cohead_shipto_id, coitem.coitem_qtyord, cohead.cohead_curr_id, cohead.cohead_orderdate)) AS updatecharassignment FROM public.cohead, public.coitem, public.itemsite, public.item, public.charass, public."char" WHERE (((((((((cohead.cohead_number = (new.order_number)::text) AND (cohead.cohead_id = coitem.coitem_cohead_id)) AND (coitem.coitem_id = public.getcoitemid((new.order_number)::text, new.line_number))) AND (coitem.coitem_itemsite_id = itemsite.itemsite_id)) AND (item.item_id = itemsite.itemsite_item_id)) AND (charass.charass_target_type = 'I'::text)) AND (charass.charass_target_id = item.item_id)) AND ("char".char_id = charass.charass_char_id)) AND ("char".char_name = new.characteristic));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO saleslinecomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, (('now'::text)::date)::timestamp with time zone), 'SI'::text, public.getcoitemid((new.order_number)::text, new.line_number), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO salesorder DO INSTEAD INSERT INTO public.cohead (cohead_number, cohead_cust_id, cohead_custponumber, cohead_orderdate, cohead_warehous_id, cohead_shipto_id, cohead_shiptoname, cohead_shiptoaddress1, cohead_shiptoaddress2, cohead_shiptoaddress3, cohead_salesrep_id, cohead_terms_id, cohead_fob, cohead_shipvia, cohead_shiptocity, cohead_shiptostate, cohead_shiptozipcode, cohead_freight, cohead_calcfreight, cohead_misc, cohead_imported, cohead_ordercomments, cohead_shipcomments, cohead_shiptophone, cohead_shipchrg_id, cohead_shipform_id, cohead_billtoname, cohead_billtoaddress1, cohead_billtoaddress2, cohead_billtoaddress3, cohead_billtocity, cohead_billtostate, cohead_billtozipcode, cohead_misc_accnt_id, cohead_misc_descrip, cohead_commission, cohead_holdtype, cohead_packdate, cohead_prj_id, cohead_shipcomplete, cohead_billtocountry, cohead_shiptocountry, cohead_curr_id, cohead_taxzone_id, cohead_shipto_cntct_id, cohead_shipto_cntct_honorific, cohead_shipto_cntct_first_name, cohead_shipto_cntct_middle, cohead_shipto_cntct_last_name, cohead_shipto_cntct_suffix, cohead_shipto_cntct_phone, cohead_shipto_cntct_title, cohead_shipto_cntct_fax, cohead_shipto_cntct_email, cohead_billto_cntct_id, cohead_billto_cntct_honorific, cohead_billto_cntct_first_name, cohead_billto_cntct_middle, cohead_billto_cntct_last_name, cohead_billto_cntct_suffix, cohead_billto_cntct_phone, cohead_billto_cntct_title, cohead_billto_cntct_fax, cohead_billto_cntct_email, cohead_saletype_id, cohead_shipzone_id) SELECT new.order_number, public.getcustid(new.customer_number) AS getcustid, new.cust_po_number, new.order_date, public.getwarehousid(new.site, 'SHIPPING'::text) AS getwarehousid, public.getshiptoid(new.customer_number, new.shipto_number) AS getshiptoid, new.shipto_name, new.shipto_address1, new.shipto_address2, new.shipto_address3, public.getsalesrepid(new.sales_rep) AS getsalesrepid, public.gettermsid(new.terms) AS gettermsid, new.fob, new.ship_via, new.shipto_city, new.shipto_state, new.shipto_postal_code, CASE WHEN COALESCE(new.calculate_freight, public.fetchmetricbool('CalculateFreight'::text)) THEN (0)::numeric ELSE new.freight END AS freight, COALESCE(new.calculate_freight, public.fetchmetricbool('CalculateFreight'::text)) AS "coalesce", new.misc_charge, true AS bool, new.order_notes, new.shipping_notes, new.shipto_phone, public.getshipchrgid(new.shipping_chgs) AS getshipchrgid, public.getshipformid(new.shipping_form) AS getshipformid, new.billto_name, new.billto_address1, new.billto_address2, new.billto_address3, new.billto_city, new.billto_state, new.billto_postal_code, public.getglaccntid(new.misc_account_number) AS getglaccntid, new.misc_charge_description, new.commission, CASE WHEN (new.hold_type = 'Credit'::text) THEN 'C'::text WHEN (new.hold_type = 'Shipping'::text) THEN 'S'::text WHEN (new.hold_type = 'Packing'::text) THEN 'P'::text ELSE 'N'::text END AS "case", new.pack_date, public.getprjid(new.project_number) AS getprjid, new.ship_complete, new.billto_country, new.shipto_country, public.getcurrid((new.currency)::text) AS getcurrid, CASE WHEN (new.tax_zone = 'None'::text) THEN (-1) ELSE public.gettaxzoneid(new.tax_zone) END AS gettaxzoneid, public.getcntctid(new.shipto_contact_number) AS getcntctid, new.shipto_contact_honorific, new.shipto_contact_first, new.shipto_contact_middle, new.shipto_contact_last, new.shipto_contact_suffix, new.shipto_contact_phone, new.shipto_contact_title, new.shipto_contact_fax, new.shipto_contact_email, public.getcntctid(new.billto_contact_number) AS getcntctid, new.billto_contact_name, new.billto_contact_first, new.billto_contact_middle, new.billto_contact_last, new.billto_contact_suffix, new.billto_contact_phone, new.billto_contact_title, new.billto_contct_fax, new.billto_contact_email, public.getsaletypeid(new.sale_type) AS getsaletypeid, public.getshipzoneid(new.shipto_shipzone) AS getshipzoneid FROM public.custinfo WHERE (custinfo.cust_number = new.customer_number);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO salesordercomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, (('now'::text)::date)::timestamp with time zone), 'S'::text, public.getsalesorderid((new.order_number)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO salesrep DO INSTEAD INSERT INTO public.salesrep (salesrep_active, salesrep_number, salesrep_name, salesrep_commission, salesrep_method, salesrep_emp_id) VALUES (COALESCE(new.active, true), COALESCE(new.number, ''::character varying), COALESCE(new.name, ''::text), COALESCE((new.commission_percent * 0.01), (0)::numeric), ''::bpchar, public.getempid(new.employee));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO site DO INSTEAD INSERT INTO public.whsinfo (warehous_code, warehous_descrip, warehous_fob, warehous_active, warehous_counttag_prefix, warehous_counttag_number, warehous_bol_prefix, warehous_bol_number, warehous_shipping, warehous_useslips, warehous_usezones, warehous_aislesize, warehous_aislealpha, warehous_racksize, warehous_rackalpha, warehous_binsize, warehous_binalpha, warehous_locationsize, warehous_locationalpha, warehous_enforcearbl, warehous_default_accnt_id, warehous_shipping_commission, warehous_cntct_id, warehous_addr_id, warehous_taxzone_id, warehous_transit, warehous_shipform_id, warehous_shipvia_id, warehous_shipcomments, warehous_costcat_id, warehous_sitetype_id, warehous_sequence) VALUES (COALESCE(new.code, ''::character varying), COALESCE(new.description, ''::text), CASE WHEN new.inventory_type THEN COALESCE(new.default_fob, ''::text) ELSE ''::text END, COALESCE(new.active, true), CASE WHEN new.inventory_type THEN COALESCE(new.next_count_tag_prefix, ''::text) ELSE ''::text END, CASE WHEN new.inventory_type THEN COALESCE(new.next_count_tag_number, 0) ELSE 0 END, CASE WHEN new.inventory_type THEN COALESCE(new.next_bill_of_lading_prefix, ''::text) ELSE ''::text END, CASE WHEN new.inventory_type THEN COALESCE(new.next_bill_of_lading_number, 0) ELSE 0 END, CASE WHEN new.inventory_type THEN COALESCE(new.shipping_site, false) ELSE false END, CASE WHEN new.inventory_type THEN COALESCE(new.force_the_use_of_count_slips, false) ELSE false END, CASE WHEN new.inventory_type THEN COALESCE(new.force_the_use_of_zones, false) ELSE false END, CASE WHEN new.inventory_type THEN COALESCE(new.aisle_size, 0) ELSE 0 END, CASE WHEN new.inventory_type THEN COALESCE(new.aisle_allow_alpha_characters, false) ELSE false END, CASE WHEN new.inventory_type THEN COALESCE(new.rack_size, 0) ELSE 0 END, CASE WHEN new.inventory_type THEN COALESCE(new.rack_allow_alpha_characters, false) ELSE false END, CASE WHEN new.inventory_type THEN COALESCE(new.bin_size, 0) ELSE 0 END, CASE WHEN new.inventory_type THEN COALESCE(new.bin_allow_alpha_characters, false) ELSE false END, CASE WHEN new.inventory_type THEN COALESCE(new.location_size, 0) ELSE 0 END, CASE WHEN new.inventory_type THEN COALESCE(new.location_allow_alpha_characters, false) ELSE false END, CASE WHEN new.inventory_type THEN COALESCE(new.enforce_arbl_naming_convention, false) ELSE false END, COALESCE(public.getglaccntid(new.post_unassigned_transactions_to), (-1)), CASE WHEN new.inventory_type THEN COALESCE((new.shipping_commission * 0.01), (0)::numeric) ELSE (0)::numeric END, public.savecntct(public.getcntctid(new.contact_number), new.contact_number, NULL::integer, new.honorific, new.first, new.middle, new.last, new.suffix, new.phone, NULL::text, new.fax, new.email, NULL::text, new.job_title, new.contact_change), public.saveaddr(public.getaddrid(new.address_number), new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postal_code, new.country, new.address_change), CASE WHEN new.inventory_type THEN COALESCE(public.gettaxzoneid(new.tax_zone), (-1)) ELSE NULL::integer END, CASE WHEN new.inventory_type THEN false WHEN new.transit_type THEN true ELSE false END, CASE WHEN new.transit_type THEN COALESCE((public.getshipformid(new.default_shipping_form))::numeric, public.fetchmetricvalue('DefaultShipFormId'::text)) ELSE NULL::numeric END, CASE WHEN new.transit_type THEN COALESCE((public.getshipviaid(new.default_ship_via))::numeric, public.fetchmetricvalue('DefaultShipViaId'::text)) ELSE NULL::numeric END, CASE WHEN new.transit_type THEN COALESCE(new.shipping_comments, ''::text) ELSE ''::text END, CASE WHEN new.transit_type THEN COALESCE(public.getcostcatid(new.default_cost_category), (-1)) ELSE NULL::integer END, COALESCE(public.getsitetypeid(new.type), (-1)), COALESCE(new.scheduling_sequence, 0));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO sitezone DO INSTEAD INSERT INTO public.whsezone (whsezone_warehous_id, whsezone_name, whsezone_descrip) VALUES (public.getwarehousid((new.site)::text, 'ACTIVE'::text), COALESCE(new.name, ''::character varying), COALESCE(new.description, ''::text));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO task DO INSTEAD INSERT INTO public.prjtask (prjtask_prj_id, prjtask_number, prjtask_name, prjtask_descrip, prjtask_owner_username, prjtask_username, prjtask_hours_budget, prjtask_hours_actual, prjtask_exp_budget, prjtask_exp_actual, prjtask_status, prjtask_due_date, prjtask_assigned_date, prjtask_start_date, prjtask_completed_date) VALUES (public.getprjid(new.project_number), new.number, COALESCE(new.name, ''::text), COALESCE(new.description, ''::text), COALESCE(new.owner, public.geteffectivextuser()), COALESCE(new.assigned_to, public.geteffectivextuser()), COALESCE(new.hours_budgeted, (0)::numeric), COALESCE(new.hours_actual, (0)::numeric), COALESCE(new.expenses_budgeted, (0)::numeric), COALESCE(new.expenses_actual, (0)::numeric), CASE WHEN (new.status = 'In-Process'::text) THEN 'O'::text WHEN (new.status = 'Completed'::text) THEN 'C'::text ELSE 'P'::text END, new.due, new.assigned, new.started, new.completed);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO taskcomment DO INSTEAD INSERT INTO public.comment (comment_date, comment_source, comment_source_id, comment_user, comment_cmnttype_id, comment_text) VALUES (COALESCE(new.date, now()), 'TA'::text, public.getprjtaskid((new.project_number)::text, (new.task_number)::text), COALESCE(new.username, public.geteffectivextuser()), public.getcmnttypeid(new.type), new.text);


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO todo DO INSTEAD SELECT public.createtodoitem(NULL::integer, new.assigned_to, COALESCE(new.task_name, ''::text), COALESCE(new.description, ''::text), public.getincidentid(new.incident), COALESCE(public.getincdtcrmacctid(new.incident), public.getcrmacctid(new.account)), public.getopheadid(new.opportunity), CASE WHEN (new.date_started > ''::text) THEN (new.date_started)::date ELSE NULL::date END, CASE WHEN (new.date_due > ''::text) THEN (new.date_due)::date ELSE NULL::date END, (CASE WHEN (new.status = 'Pending Input'::text) THEN 'P'::text WHEN (new.status = 'Deferred'::text) THEN 'D'::text ELSE 'N'::text END)::bpchar, CASE WHEN (new.date_assigned > ''::text) THEN (new.date_assigned)::date ELSE NULL::date END, CASE WHEN (new.date_completed > ''::text) THEN (new.date_completed)::date ELSE NULL::date END, public.getincdtpriorityid(new.priority), COALESCE(new.notes, ''::text), new.owner) AS createtodoitem;


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO vendor DO INSTEAD INSERT INTO public.vendinfo (vend_name, vend_lastpurchdate, vend_active, vend_po, vend_comments, vend_pocomments, vend_number, vend_1099, vend_exported, vend_fobsource, vend_fob, vend_terms_id, vend_shipvia, vend_vendtype_id, vend_qualified, vend_ediemail, vend_ediemailbody, vend_edisubject, vend_edifilename, vend_accntnum, vend_emailpodelivery, vend_restrictpurch, vend_edicc, vend_curr_id, vend_cntct1_id, vend_cntct2_id, vend_addr_id, vend_match, vend_taxzone_id, vend_ach_routingnumber, vend_ach_accntnumber, vend_accnt_id, vend_expcat_id, vend_tax_id) VALUES (COALESCE(new.vendor_name, ''::text), NULL::date, COALESCE(new.active, true), COALESCE(new.sells_purchase_order_items, false), COALESCE(new.notes, ''::text), COALESCE(new.po_comments, ''::text), COALESCE(new.vendor_number, ''::character varying), COALESCE(new.receives_1099, false), false, CASE WHEN (new.default_fob = 'Receiving Site'::text) THEN 'W'::text ELSE 'V'::text END, CASE WHEN (new.default_fob = 'Receiving Site'::text) THEN ''::text ELSE new.default_fob END, COALESCE((public.gettermsid(new.default_terms))::numeric, public.fetchmetricvalue('DefaultTerms'::text)), COALESCE(new.ship_via, public.fetchdefaultshipvia()), public.getvendtypeid(new.vendor_type), COALESCE(new.qualified, false), COALESCE(new.po_edi_email, ''::text), COALESCE(new.po_edi_emailbody, ''::text), COALESCE(new.po_edi_subject, ''::text), COALESCE(new.po_edi_filename, ''::text), COALESCE(new.account_number, ''::text), COALESCE(new.allow_email_po_delivery, false), COALESCE(new.may_only_sell_item_source, false), COALESCE(new.po_edi_cc, ''::text), COALESCE(public.getcurrid((new.default_currency)::text), public.basecurrid()), public.savecntct(public.getcntctid(new.contact1_number), new.contact1_number, NULL::integer, new.contact1_honorific, new.contact1_first, new.contact1_middle, new.contact1_last, new.contact1_suffix, new.contact1_voice, new.contact1_alternate, new.contact1_fax, new.contact1_email, new.contact1_web, new.contact1_job_title, new.contact1_change), public.savecntct(public.getcntctid(new.contact2_number), new.contact2_number, NULL::integer, new.contact2_honorific, new.contact2_first, new.contact2_middle, new.contact2_last, new.contact2_suffix, new.contact2_voice, new.contact2_alternate, new.contact2_fax, new.contact2_email, new.contact2_web, new.contact2_job_title, new.contact2_change), public.saveaddr(public.getaddrid(new.address_number), new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postalcode, new.country, new.address_change), COALESCE(new.matching_vo_po_amounts, false), public.gettaxzoneid(new.default_tax_zone), '\x'::bytea, '\x'::bytea, COALESCE(public.getglaccntid(new.default_dist_gl_account), (-1)), COALESCE(public.getexpcatid(new.default_dist_expense_category), (-1)), COALESCE(public.gettaxid(new.default_dist_tax_code), (-1)));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO vendoraddress DO INSTEAD INSERT INTO public.vendaddrinfo (vendaddr_vend_id, vendaddr_code, vendaddr_name, vendaddr_comments, vendaddr_cntct_id, vendaddr_addr_id) VALUES (public.getvendid((new.vendor_number)::text), COALESCE(new.vendor_address_number, ''::character varying), COALESCE(new.vendor_address_name, ''::text), COALESCE(new.notes, ''::text), public.savecntct(public.getcntctid(new.contact_number), new.contact_number, public.saveaddr(public.getaddrid(new.address_number), new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postalcode, new.country, new.address_change), new.contact_honorific, new.contact_first, new.contact_middle, new.contact_last, new.contact_suffix, new.contact_voice, new.contact_alternate, new.contact_fax, new.contact_email, new.contact_web, new.contact_job_title, new.contact_change), public.saveaddr(public.getaddrid(new.address_number), new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postalcode, new.country, new.address_change));


--
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO vendortype DO INSTEAD INSERT INTO public.vendtype (vendtype_code, vendtype_descrip) VALUES (new.code, COALESCE(new.description, ''::text));


--
-- Name: _INSERT_CHAR; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT_CHAR" AS ON INSERT TO purchaseline DO INSTEAD INSERT INTO public.charass (charass_target_type, charass_target_id, charass_char_id, charass_value) SELECT 'PI', poitem.poitem_id, "char".char_id, charass.charass_value FROM public.pohead, public.poitem, public.charass, public."char", public.itemsite, public.item WHERE (((((((((pohead.pohead_number = (new.order_number)::text) AND (poitem.poitem_pohead_id = pohead.pohead_id)) AND (poitem.poitem_linenumber = new.line_number)) AND (itemsite.itemsite_id = poitem.poitem_itemsite_id)) AND (itemsite.itemsite_item_id = item.item_id)) AND (charass.charass_target_type = 'I'::text)) AND (charass.charass_target_id = item.item_id)) AND charass.charass_default) AND ("char".char_id = charass.charass_char_id));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO salesline DO INSTEAD UPDATE public.coitem SET coitem_status = new.status, coitem_scheddate = new.scheduled_date, coitem_promdate = new.promise_date, coitem_qtyord = new.qty_ordered, coitem_qty_uom_id = public.getuomid(new.qty_uom), coitem_qty_invuomratio = public.itemuomtouomratio(item.item_id, public.getuomid(new.qty_uom), item.item_inv_uom_id), coitem_price = new.net_unit_price, coitem_price_uom_id = public.getuomid(new.price_uom), coitem_price_invuomratio = public.itemuomtouomratio(item.item_id, public.getuomid(new.price_uom), item.item_price_uom_id), coitem_memo = new.notes, coitem_order_type = CASE WHEN (((NOT old.create_order) AND new.create_order) AND (item.item_type = 'M'::bpchar)) THEN 'W'::text WHEN ((((NOT old.create_order) AND new.create_order) AND (item.item_type = 'P'::bpchar)) AND itemsite.itemsite_createsopo) THEN 'P'::text WHEN (((NOT old.create_order) AND new.create_order) AND (item.item_type = 'P'::bpchar)) THEN 'R'::text ELSE NULL::text END, coitem_substitute_item_id = public.getitemid(new.substitute_for), coitem_prcost = new.overwrite_po_price, coitem_taxtype_id = CASE WHEN (new.tax_type = 'None'::text) THEN NULL::integer ELSE public.gettaxtypeid(new.tax_type) END, coitem_warranty = new.warranty, coitem_cos_accnt_id = public.getglaccntid(new.alternate_cos_account), coitem_rev_accnt_id = public.getglaccntid(new.alternate_rev_account) FROM (public.item JOIN public.itemsite ON ((item.item_id = itemsite.itemsite_item_id))) WHERE ((((item.item_number = old.item_number) AND (coitem.coitem_cohead_id = public.getcoheadid((old.order_number)::text))) AND (coitem.coitem_id = public.getcoitemid((old.order_number)::text, (old.line_number)::text))) AND (coitem.coitem_subnumber = 0));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO apmemo DO INSTEAD UPDATE public.apopen SET apopen_duedate = new.due_date, apopen_terms_id = public.gettermsid(new.terms), apopen_amount = new.amount, apopen_notes = new.notes WHERE ((apopen.apopen_docnumber = old.document_number) AND ((apopen.apopen_doctype)::text = CASE WHEN (old.document_type = 'Credit Memo'::text) THEN 'C'::text WHEN (old.document_type = 'Debit Memo'::text) THEN 'D'::text ELSE ''::text END));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO armemo DO INSTEAD UPDATE public.aropen SET aropen_duedate = new.due_date, aropen_terms_id = public.gettermsid(new.terms), aropen_salesrep_id = public.getsalesrepid(new.sales_rep), aropen_amount = new.amount, aropen_commission_due = new.commission_due, aropen_notes = new.notes, aropen_rsncode_id = public.getrsnid(new.reason_code) WHERE ((aropen.aropen_docnumber = old.document_number) AND ((aropen.aropen_doctype)::text = CASE WHEN (old.document_type = 'Credit Memo'::text) THEN 'C'::text WHEN (old.document_type = 'Debit Memo'::text) THEN 'D'::text ELSE ''::text END));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO physinvcount DO INSTEAD NOTHING;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO account DO INSTEAD UPDATE public.crmacct SET crmacct_number = new.account_number, crmacct_parent_id = public.getcrmacctid(new.parent_account), crmacct_name = new.account_name, crmacct_active = new.active, crmacct_type = CASE WHEN (new.type = 'Individual'::text) THEN 'I'::text ELSE 'O'::text END, crmacct_cntct_id_1 = public.getcntctid(new.primary_contact_number), crmacct_cntct_id_2 = public.getcntctid(new.secondary_contact_number), crmacct_notes = new.notes WHERE (crmacct.crmacct_number = (old.account_number)::text);


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO accountchar DO INSTEAD UPDATE public.charass SET charass_value = new.value WHERE (((charass.charass_target_type = 'CRMACCT'::text) AND (charass.charass_target_id = public.getcrmacctid((old.account_number)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'CRMACCT'::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO accountcomment DO INSTEAD NOTHING;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO accountfile DO INSTEAD UPDATE public.url SET url_title = new.title, url_url = new.url WHERE ((((url.url_source_id = public.getcrmacctid(old.account_number)) AND (url.url_source = 'CRMA'::text)) AND (url.url_title = old.title)) AND (url.url_url = old.url));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO accountimage DO INSTEAD UPDATE public.imageass SET imageass_image_id = public.getimageid(new.image_name) WHERE (((imageass.imageass_source_id = public.getcrmacctid(old.account_number)) AND (imageass.imageass_source = 'CRMA'::text)) AND (imageass.imageass_image_id = public.getimageid(old.image_name)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO address DO INSTEAD SELECT public.saveaddr(public.getaddrid((new.address_number)::text), (new.address_number)::text, new.address1, new.address2, new.address3, new.city, new.state, new.postal_code, new.country, new.active, new.notes, new.change) AS saveaddr;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO addresschar DO INSTEAD UPDATE public.charass SET charass_value = new.value WHERE (((charass.charass_target_type = 'ADDR'::text) AND (charass.charass_target_id = public.getaddrid((old.address_number)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'ADDR'::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO addresscomment DO INSTEAD NOTHING;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO bom DO INSTEAD SELECT public.savebomhead(public.getitemid((new.item_number)::text), (new.revision)::text, new.revision_date, new.document_number, COALESCE(new.batch_size, (0)::numeric), new.total_qty_per) AS savebomhead;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO bomitem DO INSTEAD UPDATE public.bomitem SET bomitem_issuemethod = CASE WHEN (new.issue_method = 'Mixed'::text) THEN 'M'::text WHEN (new.issue_method = 'Push'::text) THEN 'S'::text WHEN (new.issue_method = 'Pull'::text) THEN 'L'::text ELSE NULL::text END, bomitem_uom_id = public.getuomid(new.issue_uom), bomitem_qtyper = new.qty_per, bomitem_scrap = new.scrap, bomitem_effective = CASE WHEN (new.effective = 'Always'::text) THEN public.startoftime() ELSE (new.effective)::date END, bomitem_expires = CASE WHEN (new.expires = 'Never'::text) THEN public.endoftime() ELSE (new.expires)::date END, bomitem_createwo = new.create_child_wo, bomitem_booitem_seq_id = COALESCE(public.getbooitemseqid((new.bom_item_number)::text, new.used_at), (-1)), bomitem_schedatwooper = new.schedule_at_wo_operation, bomitem_ecn = new.ecn_number, bomitem_subtype = CASE WHEN (new.substitutions = 'No'::text) THEN 'N'::text WHEN (new.substitutions = 'Item-Defined'::text) THEN 'I'::text WHEN (new.substitutions = 'BOM-Defined'::text) THEN 'B'::text ELSE NULL::text END, bomitem_rev_id = public.getrevid('BOM'::text, (new.bom_item_number)::text, (new.bom_revision)::text), bomitem_char_id = public.getcharid(new.characteristic, 'I'::text), bomitem_value = new.value, bomitem_notes = new.notes, bomitem_ref = new.reference WHERE (bomitem.bomitem_id = old.id);


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO bomitemcomment DO INSTEAD NOTHING;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO bomitemsubstitute DO INSTEAD UPDATE public.bomitemsub SET bomitemsub_uomratio = new.sub_parent_uom_ratio, bomitemsub_rank = new.ranking WHERE ((bomitemsub.bomitemsub_bomitem_id = old.bomitem_id) AND (bomitemsub.bomitemsub_item_id = public.getitemid((old.substitute_item_number)::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO budget DO INSTEAD UPDATE public.budghead SET budghead_name = new.name, budghead_descrip = new.description WHERE (budghead.budghead_name = old.name);


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO budgetentry DO INSTEAD UPDATE public.budgitem SET budgitem_amount = new.amount WHERE (((budgitem.budgitem_budghead_id = public.getbudgheadid(old.name)) AND (budgitem.budgitem_period_id = public.getperiodid(old.period_start))) AND (budgitem.budgitem_accnt_id = public.getglaccntid(old.account)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO cashreceipt DO INSTEAD UPDATE public.cashrcpt SET cashrcpt_amount = new.amount_received, cashrcpt_number = new.cashreceipt_number, cashrcpt_fundstype = CASE WHEN ((new.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((new.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((new.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((new.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((new.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((new.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((new.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((new.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((new.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, cashrcpt_docnumber = new.check_document_number, cashrcpt_bankaccnt_id = public.getbankaccntid(new.post_to), cashrcpt_notes = new.notes, cashrcpt_distdate = CASE WHEN (new.distribution_date > ''::text) THEN (new.distribution_date)::date ELSE NULL::date END, cashrcpt_salescat_id = public.getsalescatid(new.sales_category), cashrcpt_curr_id = public.getcurrid((new.currency)::text), cashrcpt_usecustdeposit = CASE WHEN (new.apply_balance_as = 'Customer Deposit'::text) THEN true ELSE false END WHERE (cashrcpt.cashrcpt_id = public.getcashrcptid((old.customer_number)::text, CASE WHEN ((old.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((old.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((old.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((old.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((old.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((old.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((old.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((old.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((old.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, (old.check_document_number)::text));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO cashreceiptapply DO INSTEAD UPDATE public.cashrcptitem SET cashrcptitem_amount = new.amount_to_apply, cashrcptitem_discount = new.cashrcptitem_discount WHERE ((cashrcptitem.cashrcptitem_cashrcpt_id = public.getcashrcptid((old.customer_number)::text, CASE WHEN ((old.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((old.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((old.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((old.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((old.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((old.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((old.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((old.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((old.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, (old.check_document_number)::text)) AND (cashrcptitem.cashrcptitem_aropen_id = public.getaropenid((old.customer_number)::text, (old.doc_type)::bpchar, (old.doc_number)::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO cashreceiptapplymisc DO INSTEAD UPDATE public.cashrcptmisc SET cashrcptmisc_accnt_id = public.getglaccntid((new.account)::text), cashrcptmisc_amount = new.amount_to_distribute, cashrcptmisc_notes = new.notes WHERE ((cashrcptmisc.cashrcptmisc_cashrcpt_id = public.getcashrcptid((old.customer_number)::text, CASE WHEN ((old.funds_type)::text = 'Check'::text) THEN 'C'::text WHEN ((old.funds_type)::text = 'Certified Check'::text) THEN 'T'::text WHEN ((old.funds_type)::text = 'Master Card'::text) THEN 'M'::text WHEN ((old.funds_type)::text = 'Visa'::text) THEN 'V'::text WHEN ((old.funds_type)::text = 'American Express'::text) THEN 'A'::text WHEN ((old.funds_type)::text = 'Discover Card'::text) THEN 'D'::text WHEN ((old.funds_type)::text = 'Other Credit Card'::text) THEN 'R'::text WHEN ((old.funds_type)::text = 'Cash'::text) THEN 'K'::text WHEN ((old.funds_type)::text = 'Wire Transfer'::text) THEN 'W'::text ELSE 'O'::text END, (old.check_document_number)::text)) AND (cashrcptmisc.cashrcptmisc_accnt_id = public.getglaccntid((old.account)::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO contact DO INSTEAD SELECT public.savecntct(public.getcntctid((new.contact_number)::text), (new.contact_number)::text, public.getcrmacctid(new.crm_account), public.saveaddr(public.getaddrid(new.address_number), new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postal_code, new.country, new.address_change), new.honorific, new.first, new.middle, new.last, new.suffix, new.initials, new.active, new.voice, new.alternate, new.fax, new.email, new.web, new.notes, new.job_title, new.contact_change) AS savecntct;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO contactchar DO INSTEAD UPDATE public.charass SET charass_value = new.value WHERE (((charass.charass_target_type = 'CNTCT'::text) AND (charass.charass_target_id = public.getcntctid(old.contact_number))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'CNTCT'::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO contactcomment DO INSTEAD NOTHING;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO creditmemo DO INSTEAD UPDATE public.cmhead SET cmhead_custponumber = new.customer_po_number, cmhead_docdate = new.memo_date, cmhead_shipto_id = COALESCE(public.getshiptoid(new.customer_number, new.shipto_number), (-1)), cmhead_shipto_name = new.shipto_name, cmhead_shipto_address1 = new.shipto_address1, cmhead_shipto_address2 = new.shipto_address2, cmhead_shipto_address3 = new.shipto_address3, cmhead_shipto_city = new.shipto_city, cmhead_shipto_state = new.shipto_state, cmhead_shipto_zipcode = new.shipto_postal_code, cmhead_shipto_country = new.shipto_country, cmhead_salesrep_id = public.getsalesrepid(new.sales_rep), cmhead_freight = COALESCE(new.freight, (0)::numeric), cmhead_misc = COALESCE(new.misc_charge_amount, (0)::numeric), cmhead_comments = new.notes, cmhead_billtoname = new.billto_name, cmhead_billtoaddress1 = new.billto_address1, cmhead_billtoaddress2 = new.billto_address2, cmhead_billtoaddress3 = new.billto_address3, cmhead_billtocity = new.billto_city, cmhead_billtostate = new.billto_state, cmhead_billtozip = new.billto_postal_code, cmhead_billtocountry = new.billto_country, cmhead_hold = COALESCE(new.on_hold, false), cmhead_commission = COALESCE(new.commission, (0)::numeric), cmhead_misc_accnt_id = COALESCE(public.getglaccntid(new.misc_charge_credit_account), (-1)), cmhead_misc_descrip = new.misc_charge_description, cmhead_rsncode_id = (SELECT rsncode.rsncode_id FROM public.rsncode WHERE (rsncode.rsncode_code = new.reason_code)), cmhead_curr_id = COALESCE(public.getcurrid((new.currency)::text), (-1)), cmhead_taxzone_id = public.gettaxzoneid(NULLIF(new.tax_zone, 'None'::text)) WHERE ((cmhead.cmhead_number = old.memo_number) AND (cmhead.cmhead_posted = false));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO creditmemoline DO INSTEAD SELECT public.updatecreditmemoline(new.*, old.*) AS updatecreditmemoline;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO custchar DO INSTEAD UPDATE public.charass SET charass_value = new.value WHERE (((charass.charass_target_type = 'C'::text) AND (charass.charass_target_id = public.getcustid((old.customer_number)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'C'::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO custcomment DO INSTEAD NOTHING;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO custcreditcard DO INSTEAD NOTHING;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO customer DO INSTEAD UPDATE public.custinfo SET cust_active = new.active, cust_custtype_id = public.getcusttypeid(new.customer_type), cust_salesrep_id = public.getsalesrepid(new.sales_rep), cust_commprcnt = (new.commission * 0.01), cust_name = new.customer_name, cust_creditlmt = new.credit_limit, cust_creditrating = new.credit_rating, cust_backorder = new.accepts_backorders, cust_partialship = new.accepts_partial_shipments, cust_terms_id = public.gettermsid(new.default_terms), cust_discntprcnt = new.default_discount, cust_balmethod = CASE WHEN (new.balance_method = 'Balance Forward'::text) THEN 'B'::text WHEN (new.balance_method = 'Open Items'::text) THEN 'O'::text ELSE NULL::text END, cust_ffshipto = new.allow_free_form_shipto, cust_shipform_id = public.getshipformid(new.ship_form), cust_shipvia = new.ship_via, cust_blanketpos = new.uses_blanket_pos, cust_shipchrg_id = COALESCE(public.getshipchrgid(new.shipping_charges), (-1)), cust_creditstatus = CASE WHEN (new.credit_status = 'On Credit Warning'::text) THEN 'W'::text WHEN (new.credit_status = 'On Credit Hold'::text) THEN 'H'::text ELSE 'G'::text END, cust_comments = new.notes, cust_ffbillto = new.allow_free_form_billto, cust_usespos = new.uses_purchase_orders, cust_number = new.customer_number, cust_autoupdatestatus = new.credit_status_exceed_warn, cust_autoholdorders = new.credit_status_exceed_hold, cust_preferred_warehous_id = COALESCE(public.getwarehousid(new.preferred_selling_site, 'ACTIVE'::text), (-1)), cust_curr_id = public.getcurrid((new.default_currency)::text), cust_creditlmt_curr_id = public.getcurrid((new.credit_limit_currency)::text), cust_cntct_id = public.savecntct(public.getcntctid(new.billing_contact_number, false), new.billing_contact_number, public.saveaddr(public.getaddrid(new.billing_contact_address_number), new.billing_contact_address_number, new.billing_contact_address1, new.billing_contact_address2, new.billing_contact_address3, new.billing_contact_city, new.billing_contact_state, new.billing_contact_postalcode, new.billing_contact_country, new.billing_contact_address_change), new.billing_contact_honorific, new.billing_contact_first, new.billing_contact_middle, new.billing_contact_last, new.billing_contact_suffix, new.billing_contact_voice, new.billing_contact_alternate, new.billing_contact_fax, new.billing_contact_email, new.billing_contact_web, new.billing_contact_job_title, new.billing_contact_change), cust_corrcntct_id = public.savecntct(public.getcntctid(new.correspond_contact_number, false), new.correspond_contact_number, public.saveaddr(public.getaddrid(new.correspond_contact_address_number), new.correspond_contact_address_number, new.correspond_contact_address1, new.correspond_contact_address2, new.correspond_contact_address3, new.correspond_contact_city, new.correspond_contact_state, new.correspond_contact_postalcode, new.correspond_contact_country, new.correspond_contact_address_change), new.correspond_contact_honorific, new.correspond_contact_first, new.correspond_contact_middle, new.correspond_contact_last, new.correspond_contact_suffix, new.correspond_contact_voice, new.correspond_contact_alternate, new.correspond_contact_fax, new.correspond_contact_email, new.correspond_contact_web, new.correspond_contact_job_title, new.correspond_contact_change), cust_taxzone_id = public.gettaxzoneid(new.default_tax_zone), cust_gracedays = CASE WHEN (COALESCE(new.alternate_grace_days, 0) > 0) THEN new.alternate_grace_days ELSE NULL::integer END WHERE (custinfo.cust_id = public.getcustid((old.customer_number)::text));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO customertype DO INSTEAD UPDATE public.custtype SET custtype_code = new.code, custtype_descrip = new.description, custtype_char = new.enable_characteristics_profile WHERE (custtype.custtype_code = (old.code)::text);


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO customertypechar DO INSTEAD UPDATE public.charass SET charass_value = new.value, charass_default = new.is_default WHERE (((charass.charass_target_type = 'CT'::text) AND (charass.charass_target_id = public.getcusttypeid((old.customer_type)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'CT'::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO custshipto DO INSTEAD UPDATE public.shiptoinfo SET shipto_cust_id = public.getcustid((new.customer_number)::text), shipto_name = new.name, shipto_salesrep_id = public.getsalesrepid(new.sales_rep), shipto_comments = new.general_notes, shipto_shipcomments = new.shipping_notes, shipto_shipzone_id = public.getshipzoneid(new.zone), shipto_shipvia = new.ship_via, shipto_commission = (new.commission / (100)::numeric), shipto_shipform_id = public.getshipformid(new.ship_form), shipto_shipchrg_id = public.getshipchrgid(new.shipping_charges), shipto_active = new.active, shipto_default = new.default_flag, shipto_num = old.shipto_number, shipto_ediprofile_id = CASE WHEN (new.edi_profile = 'No EDI'::text) THEN (-1) WHEN (new.edi_profile = 'Use Customer Master'::text) THEN (-2) ELSE public.getediprofileid(new.edi_profile) END, shipto_cntct_id = public.savecntct(public.getcntctid(new.contact_number), new.contact_number, NULL::integer, new.honorific, new.first, new.middle, new.last, new.suffix, new.phone, NULL::text, new.fax, new.email, NULL::text, new.job_title, new.contact_change), shipto_addr_id = public.saveaddr(public.getaddrid(new.address_number), new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postal_code, new.country, new.address_change), shipto_taxzone_id = public.gettaxzoneid(new.tax_zone) WHERE (shiptoinfo.shipto_id = public.getshiptoid((old.customer_number)::text, (old.shipto_number)::text));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO custtax DO INSTEAD UPDATE public.taxreg SET taxreg_number = new.registration_number WHERE (((taxreg.taxreg_rel_type = 'C'::bpchar) AND (taxreg.taxreg_rel_id = public.getcustid((old.customer_number)::text))) AND (taxreg.taxreg_taxauth_id = public.gettaxauthid((old.tax_authority)::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO employee DO INSTEAD UPDATE public.emp SET emp_code = new.code, emp_number = new.number, emp_active = new.active, emp_startdate = new.start_date, emp_cntct_id = public.savecntct(public.getcntctid(new.contact_number), new.contact_number, public.saveaddr(public.getaddrid(new.address_number), new.address_number, new.address1, new.address2, new.address3, new.city, new.state, new.postalcode, new.country, new.address_change), new.honorific, new.first, new.middle, new.last, new.suffix, new.voice, new.alternate, new.fax, new.email, new.web, new.job_title, new.contact_change), emp_warehous_id = public.getwarehousid(new.site, 'ALL'::text), emp_mgr_emp_id = (SELECT emp.emp_id FROM public.emp WHERE (emp.emp_code = new.manager_code)), emp_wage_type = CASE WHEN (new.wage_type = 'Hourly'::text) THEN 'H'::text WHEN (new.wage_type = 'Salaried'::text) THEN 'S'::text ELSE NULL::text END, emp_wage = new.wage, emp_wage_curr_id = COALESCE(public.getcurrid((new.wage_currency)::text), public.basecurrid()), emp_wage_period = CASE WHEN (new.wage_period = 'Hour'::text) THEN 'H'::text WHEN (new.wage_period = 'Day'::text) THEN 'D'::text WHEN (new.wage_period = 'Week'::text) THEN 'W'::text WHEN (new.wage_period = 'Biweek'::text) THEN 'BW'::text WHEN (new.wage_period = 'Month'::text) THEN 'M'::text WHEN (new.wage_period = 'Year'::text) THEN 'Y'::text ELSE NULL::text END, emp_dept_id = public.getdeptid(new.department), emp_shift_id = public.getshiftid(new.shift), emp_image_id = public.getimageid(new.image), emp_extrate = new.rate, emp_extrate_period = CASE WHEN (new.billing_period = 'Hour'::text) THEN 'H'::text WHEN (new.billing_period = 'Day'::text) THEN 'D'::text WHEN (new.billing_period = 'Week'::text) THEN 'W'::text WHEN (new.billing_period = 'Biweek'::text) THEN 'BW'::text WHEN (new.billing_period = 'Month'::text) THEN 'M'::text WHEN (new.billing_period = 'Year'::text) THEN 'Y'::text ELSE NULL::text END, emp_notes = COALESCE(new.notes, ''::text) WHERE (emp.emp_code = (old.code)::text);


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO employeechar DO INSTEAD UPDATE public.charass SET charass_value = new.value WHERE (((charass.charass_target_type = 'EMP'::text) AND (charass.charass_target_id = public.getempid((old.employee_code)::text))) AND (charass.charass_char_id = public.getcharid((old.characteristic)::text, 'EMP'::text)));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO employeecomment DO INSTEAD NOTHING;


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO extshipmaint DO INSTEAD UPDATE public.shipdata SET shipdata_cohead_number = new.so_number, shipdata_shiphead_number = new.shipment_number, shipdata_void_ind = new.void, shipdata_shipper = new.shipper, shipdata_billing_option = new.billing_option, shipdata_weight = new.weight, shipdata_base_freight = new.base_freight, shipdata_base_freight_curr_id = public.getcurrid((new.base_freight_currency)::text), shipdata_total_freight = new.total_freight, shipdata_total_freight_curr_id = public.getcurrid((new.total_freight_currency)::text), shipdata_package_type = new.package_type, shipdata_cosmisc_tracknum = new.tracking_number, shipdata_cosmisc_packnum_tracknum = new.package_tracking_number, shipdata_lastupdated = new.last_updated WHERE ((((shipdata.shipdata_cohead_number = (old.so_number)::text) AND (shipdata.shipdata_shiphead_number = (old.shipment_number)::text)) AND (shipdata.shipdata_shipper = (old.shipper)::text)) AND (shipdata.shipdata_cosmisc_packnum_tracknum = (old.package_tracking_number)::text));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO freightpricingscheduleitem DO INSTEAD UPDATE public.ipsfreight SET ipsfreight_ipshead_id = public.getipsheadid((old.pricing_schedule)::text), ipsfreight_qtybreak = new.qty_break, ipsfreight_price = new.price, ipsfreight_type = CASE WHEN (new.price_type = 'Flat Rate'::text) THEN 'F'::text WHEN (new.price_type = 'Price Per UOM'::text) THEN 'P'::text ELSE NULL::text END, ipsfreight_warehous_id = CASE WHEN (new.from_site = 'Any'::text) THEN NULL::integer ELSE public.getwarehousid(new.from_site, 'All'::text) END, ipsfreight_shipzone_id = CASE WHEN (new.to_shipzone = 'Any'::text) THEN NULL::integer ELSE public.getshipzoneid(new.to_shipzone) END, ipsfreight_freightclass_id = CASE WHEN (new.freight_class = 'Any'::text) THEN NULL::integer ELSE public.getfreightclassid(new.freight_class) END, ipsfreight_shipvia = CASE WHEN (new.ship_via = 'Any'::text) THEN NULL::text ELSE new.ship_via END WHERE (((((((((ipsfreight.ipsfreight_ipshead_id = public.getipsheadid((old.pricing_schedule)::text)) AND (ipsfreight.ipsfreight_qtybreak = old.qty_break)) AND (ipsfreight.ipsfreight_price = old.price)) AND ((ipsfreight.ipsfreight_type)::text = CASE WHEN (old.price_type = 'Flat Rate'::text) THEN 'F'::text WHEN (old.price_type = 'Price Per UOM'::text) THEN 'P'::text ELSE NULL::text END)) AND ((ipsfreight.ipsfreight_warehous_id IS NULL) AND (old.from_site = 'Any'::text))) OR ((ipsfreight.ipsfreight_warehous_id = CASE WHEN (old.from_site = 'Any'::text) THEN 0 ELSE public.getwarehousid(old.from_site, 'All'::text) END) AND ((ipsfreight.ipsfreight_shipzone_id IS NULL) AND (old.to_shipzone = 'Any'::text)))) OR ((ipsfreight.ipsfreight_shipzone_id = CASE WHEN (old.to_shipzone = 'Any'::text) THEN 0 ELSE public.getshipzoneid(old.to_shipzone) END) AND ((ipsfreight.ipsfreight_freightclass_id IS NULL) AND (old.freight_class = 'Any'::text)))) OR ((ipsfreight.ipsfreight_freightclass_id = CASE WHEN (old.freight_class = 'Any'::text) THEN 0 ELSE public.getfreightclassid(old.freight_class) END) AND ((ipsfreight.ipsfreight_shipvia IS NULL) AND (old.ship_via = 'Any'::text)))) OR (ipsfreight.ipsfreight_shipvia = old.ship_via));


--
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO glaccount DO INSTEAD UPDATE public.accnt SET accnt_number = new.account_number, accnt_descrip = new.description, accnt_comments = new.notes, accnt_profit = new.profit_center, accnt_sub = new.sub_account, accnt_type = CASE WHEN (new.type = 'Asset'::text) THEN 'A'::text WHEN (new.type = 'Liability'::text) THEN 'L'::text WHEN (new.type = 'Expense'::text) THEN 'E'::text WHEN (new.type = 'Revenue'::text) THEN 'R'::text WHEN (new.type = 'Equity'::text) THEN 'Q'::text ELSE NULL::text END, accnt_extref = new.ext_reference, accnt_company = new.company, accnt_forwardupdate = new.forward_update_trial_balances, accnt_subaccnttype_code = new.sub_type WHERE (accnt.accnt_id = public.getglaccntid((old.company)::text, (old.profit_center)::text, (old.account_number)::text, (old.sub_account)::text));


--
