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


--
-- TOC entry 7588 (class 2606 OID 146571471)
-- Dependencies: 787 787 8894
-- Name: state_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7590 (class 2606 OID 146571473)
-- Dependencies: 787 787 787 8894
-- 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);


--
-- TOC entry 7592 (class 2606 OID 146571475)
-- Dependencies: 789 789 8894
-- Name: status_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7594 (class 2606 OID 146571477)
-- Dependencies: 789 789 789 8894
-- 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);


--
-- TOC entry 7596 (class 2606 OID 146571479)
-- Dependencies: 791 791 8894
-- Name: stdjrnl_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7598 (class 2606 OID 146571481)
-- Dependencies: 791 791 8894
-- 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);


--
-- TOC entry 7600 (class 2606 OID 146571483)
-- Dependencies: 793 793 8894
-- Name: stdjrnlgrp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7602 (class 2606 OID 146571485)
-- Dependencies: 793 793 8894
-- 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);


--
-- TOC entry 7604 (class 2606 OID 146571487)
-- Dependencies: 795 795 8894
-- Name: stdjrnlgrpitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7606 (class 2606 OID 146571489)
-- Dependencies: 797 797 8894
-- Name: stdjrnlitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7608 (class 2606 OID 146571491)
-- Dependencies: 799 799 8894
-- Name: subaccnt_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7610 (class 2606 OID 146571493)
-- Dependencies: 799 799 8894
-- 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);


--
-- TOC entry 7613 (class 2606 OID 146571495)
-- Dependencies: 801 801 8894
-- Name: subaccnttype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7125 (class 2606 OID 146571497)
-- Dependencies: 363 363 8894
-- Name: tax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7615 (class 2606 OID 146571499)
-- Dependencies: 804 804 8894
-- Name: taxass_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7617 (class 2606 OID 146571501)
-- Dependencies: 804 804 804 804 8894
-- 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);


--
-- TOC entry 6989 (class 2606 OID 146571503)
-- Dependencies: 284 284 8894
-- Name: taxauth_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6991 (class 2606 OID 146571505)
-- Dependencies: 284 284 8894
-- 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);


--
-- TOC entry 7619 (class 2606 OID 146571507)
-- Dependencies: 807 807 8894
-- Name: taxclass_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7621 (class 2606 OID 146571509)
-- Dependencies: 807 807 8894
-- 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);


--
-- TOC entry 7147 (class 2606 OID 146571511)
-- Dependencies: 377 377 8894
-- Name: taxhist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7623 (class 2606 OID 146571513)
-- Dependencies: 809 809 8894
-- Name: taxrate_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6993 (class 2606 OID 146571515)
-- Dependencies: 285 285 8894
-- Name: taxreg_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6797 (class 2606 OID 146571517)
-- Dependencies: 199 199 8894
-- Name: taxtype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6799 (class 2606 OID 146571519)
-- Dependencies: 199 199 8894
-- 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);


--
-- TOC entry 6879 (class 2606 OID 146571521)
-- Dependencies: 220 220 8894
-- Name: taxzone_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6881 (class 2606 OID 146571523)
-- Dependencies: 220 220 8894
-- 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);


--
-- TOC entry 6837 (class 2606 OID 146571525)
-- Dependencies: 209 209 8894
-- Name: terms_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6839 (class 2606 OID 146571527)
-- Dependencies: 209 209 8894
-- 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);


--
-- TOC entry 6916 (class 2606 OID 146571529)
-- Dependencies: 233 233 8894
-- Name: todoitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7626 (class 2606 OID 146571531)
-- Dependencies: 817 817 8894
-- Name: trialbal_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7193 (class 2606 OID 146571533)
-- Dependencies: 417 417 8894
-- Name: uiform_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7540 (class 2606 OID 146571535)
-- Dependencies: 739 739 8894
-- Name: unq_prjtype_code; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6801 (class 2606 OID 146571537)
-- Dependencies: 200 200 8894
-- Name: uom_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6803 (class 2606 OID 146571539)
-- Dependencies: 200 200 8894
-- 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);


--
-- TOC entry 7628 (class 2606 OID 146571541)
-- Dependencies: 820 820 8894
-- Name: uomconv_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7630 (class 2606 OID 146571543)
-- Dependencies: 822 822 8894
-- Name: uomtype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7632 (class 2606 OID 146571545)
-- Dependencies: 822 822 8894
-- 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);


--
-- TOC entry 6941 (class 2606 OID 146571547)
-- Dependencies: 244 244 8894
-- Name: urlinfo_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7637 (class 2606 OID 146571549)
-- Dependencies: 827 827 8894
-- Name: usr_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7639 (class 2606 OID 146571551)
-- Dependencies: 827 827 8894
-- 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);


--
-- TOC entry 7532 (class 2606 OID 146571553)
-- Dependencies: 732 732 8894
-- Name: usrgrp_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7634 (class 2606 OID 146571555)
-- Dependencies: 825 825 8894
-- Name: usrpref_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7534 (class 2606 OID 146571557)
-- Dependencies: 733 733 8894
-- Name: usrpriv_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6842 (class 2606 OID 146571559)
-- Dependencies: 210 210 8894
-- Name: vend_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7127 (class 2606 OID 146571561)
-- Dependencies: 364 364 8894
-- Name: vendaddr_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6844 (class 2606 OID 146571563)
-- Dependencies: 210 210 8894
-- 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);


--
-- TOC entry 7159 (class 2606 OID 146571565)
-- Dependencies: 393 393 8894
-- Name: vendtype_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7161 (class 2606 OID 146571567)
-- Dependencies: 393 393 8894
-- 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);


--
-- TOC entry 7641 (class 2606 OID 146571569)
-- Dependencies: 837 837 8894
-- Name: vodist_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7643 (class 2606 OID 146571571)
-- Dependencies: 839 839 8894
-- Name: vohead_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7645 (class 2606 OID 146571573)
-- Dependencies: 839 839 8894
-- 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);


--
-- TOC entry 7647 (class 2606 OID 146571575)
-- Dependencies: 841 841 8894
-- Name: voheadtax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7649 (class 2606 OID 146571577)
-- Dependencies: 842 842 8894
-- Name: voitem_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7651 (class 2606 OID 146571579)
-- Dependencies: 844 844 8894
-- Name: voitemtax_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6764 (class 2606 OID 146571581)
-- Dependencies: 193 193 8894
-- Name: warehous_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7096 (class 2606 OID 146571583)
-- Dependencies: 343 343 8894
-- Name: whsezone_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 6766 (class 2606 OID 146571585)
-- Dependencies: 193 193 8894
-- 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);


--
-- TOC entry 7345 (class 2606 OID 146571587)
-- Dependencies: 560 560 8894
-- Name: wo_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7122 (class 2606 OID 146571589)
-- Dependencies: 359 359 8894
-- Name: womatl_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7653 (class 2606 OID 146571591)
-- Dependencies: 850 850 8894
-- Name: womatlpost_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7655 (class 2606 OID 146571593)
-- Dependencies: 852 852 8894
-- Name: womatlvar_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7657 (class 2606 OID 146571595)
-- Dependencies: 855 855 8894
-- Name: xsltmap_name_key; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7659 (class 2606 OID 146571597)
-- Dependencies: 855 855 8894
-- Name: xsltmap_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7661 (class 2606 OID 146571599)
-- Dependencies: 857 857 8894
-- Name: yearperiod_pkey; Type: CONSTRAINT; Schema: public; Owner: admin; Tablespace: 
--

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



--
-- TOC entry 7663 (class 2606 OID 146571601)
-- Dependencies: 859 859 8894
-- Name: pkgcmd_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7665 (class 2606 OID 146571603)
-- Dependencies: 860 860 8894
-- Name: pkgcmdarg_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7667 (class 2606 OID 146571605)
-- Dependencies: 861 861 8894
-- Name: pkgimage_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7669 (class 2606 OID 146571607)
-- Dependencies: 862 862 8894
-- Name: pkgmetasql_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7671 (class 2606 OID 146571609)
-- Dependencies: 863 863 8894
-- Name: pkgpriv_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7673 (class 2606 OID 146571611)
-- Dependencies: 864 864 8894
-- Name: pkgreport_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7675 (class 2606 OID 146571613)
-- Dependencies: 865 865 8894
-- Name: pkgscript_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7677 (class 2606 OID 146571615)
-- Dependencies: 866 866 8894
-- Name: pkguiform_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7679 (class 2606 OID 146571617)
-- Dependencies: 867 867 8894
-- Name: tecustrate_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY tecustrate
    ADD CONSTRAINT tecustrate_pkey PRIMARY KEY (tecustrate_cust_id);


--
-- TOC entry 7681 (class 2606 OID 146571619)
-- Dependencies: 871 871 8894
-- Name: teexp_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teexp
    ADD CONSTRAINT teexp_pkey PRIMARY KEY (teexp_id);


--
-- TOC entry 7683 (class 2606 OID 146571621)
-- Dependencies: 873 873 8894
-- Name: tehead_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY tehead
    ADD CONSTRAINT tehead_pkey PRIMARY KEY (tehead_id);


--
-- TOC entry 7685 (class 2606 OID 146571623)
-- Dependencies: 875 875 8894
-- Name: teitem_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teitem
    ADD CONSTRAINT teitem_pkey PRIMARY KEY (teitem_id);


--
-- TOC entry 7688 (class 2606 OID 146571625)
-- Dependencies: 877 877 8894
-- Name: teprj_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teprj
    ADD CONSTRAINT teprj_pkey PRIMARY KEY (teprj_id);


--
-- TOC entry 7690 (class 2606 OID 146571627)
-- Dependencies: 879 879 8894
-- Name: teprjtask_pkey; Type: CONSTRAINT; Schema: te; Owner: admin; Tablespace: 
--

ALTER TABLE ONLY teprjtask
    ADD CONSTRAINT teprjtask_pkey PRIMARY KEY (teprjtask_id);


--
-- TOC entry 7692 (class 2606 OID 146571629)
-- Dependencies: 879 879 8894
-- 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);



--
-- TOC entry 7694 (class 2606 OID 146571631)
-- Dependencies: 881 881 8894
-- Name: pkgcmd_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7696 (class 2606 OID 146571633)
-- Dependencies: 882 882 8894
-- Name: pkgcmdarg_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7698 (class 2606 OID 146571635)
-- Dependencies: 883 883 8894
-- Name: pkgimage_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7700 (class 2606 OID 146571637)
-- Dependencies: 884 884 8894
-- Name: pkgmetasql_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7702 (class 2606 OID 146571639)
-- Dependencies: 885 885 8894
-- Name: pkgpriv_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7704 (class 2606 OID 146571641)
-- Dependencies: 886 886 8894
-- Name: pkgreport_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7706 (class 2606 OID 146571643)
-- Dependencies: 887 887 8894
-- Name: pkgscript_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

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


--
-- TOC entry 7708 (class 2606 OID 146571645)
-- Dependencies: 888 888 8894
-- Name: pkguiform_pkey; Type: CONSTRAINT; Schema: xtdesktop; Owner: admin; Tablespace: 
--

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



--
-- TOC entry 6956 (class 1259 OID 146571646)
-- Dependencies: 262 262 262 262 8894
-- 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);


--
-- TOC entry 6826 (class 1259 OID 146571647)
-- Dependencies: 207 8894
-- Name: apopen_apopen_open_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX apopen_apopen_open_idx ON apopen USING btree (apopen_open);


--
-- TOC entry 6827 (class 1259 OID 146571648)
-- Dependencies: 207 8894
-- 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);


--
-- TOC entry 7215 (class 1259 OID 146571649)
-- Dependencies: 439 8894
-- 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);


--
-- TOC entry 7222 (class 1259 OID 146571650)
-- Dependencies: 443 8894
-- 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);


--
-- TOC entry 6845 (class 1259 OID 146571651)
-- Dependencies: 212 8894
-- 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);


--
-- TOC entry 6846 (class 1259 OID 146571652)
-- Dependencies: 212 8894
-- Name: aropen_aropen_docnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropen_aropen_docnumber_idx ON aropen USING btree (aropen_docnumber);


--
-- TOC entry 6847 (class 1259 OID 146571653)
-- Dependencies: 212 8894
-- Name: aropen_aropen_doctype_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropen_aropen_doctype_idx ON aropen USING btree (aropen_doctype);


--
-- TOC entry 6848 (class 1259 OID 146571654)
-- Dependencies: 212 8894
-- Name: aropen_aropen_open_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropen_aropen_open_idx ON aropen USING btree (aropen_open);


--
-- TOC entry 6851 (class 1259 OID 146571655)
-- Dependencies: 212 8894
-- Name: aropen_posted_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX aropen_posted_idx ON aropen USING btree (aropen_posted);


--
-- TOC entry 7135 (class 1259 OID 146571656)
-- Dependencies: 374 8894
-- 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);


--
-- TOC entry 7136 (class 1259 OID 146571657)
-- Dependencies: 374 8894
-- 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);


--
-- TOC entry 6806 (class 1259 OID 146571658)
-- Dependencies: 203 8894
-- 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);


--
-- TOC entry 6807 (class 1259 OID 146571659)
-- Dependencies: 203 8894
-- Name: bomitem_effective_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX bomitem_effective_key ON bomitem USING btree (bomitem_effective);


--
-- TOC entry 6808 (class 1259 OID 146571660)
-- Dependencies: 203 8894
-- Name: bomitem_expires_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX bomitem_expires_key ON bomitem USING btree (bomitem_expires);


--
-- TOC entry 6809 (class 1259 OID 146571661)
-- Dependencies: 203 8894
-- 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);


--
-- TOC entry 7247 (class 1259 OID 146571662)
-- Dependencies: 468 8894
-- 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);


--
-- TOC entry 7248 (class 1259 OID 146571663)
-- Dependencies: 468 468 468 8894
-- 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);


--
-- TOC entry 6969 (class 1259 OID 146571664)
-- Dependencies: 269 8894
-- Name: cashrcptitem_aropen_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cashrcptitem_aropen_idx ON cashrcptitem USING btree (cashrcptitem_aropen_id);


--
-- TOC entry 6970 (class 1259 OID 146571665)
-- Dependencies: 269 8894
-- Name: cashrcptitem_cashrcpt_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cashrcptitem_cashrcpt_idx ON cashrcptitem USING btree (cashrcptitem_cashrcpt_id);


--
-- TOC entry 6975 (class 1259 OID 146571666)
-- Dependencies: 278 8894
-- 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);


--
-- TOC entry 7255 (class 1259 OID 146571667)
-- Dependencies: 482 8894
-- 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);


--
-- TOC entry 7256 (class 1259 OID 146571668)
-- Dependencies: 482 8894
-- 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);


--
-- TOC entry 7263 (class 1259 OID 146571669)
-- Dependencies: 486 8894
-- 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);


--
-- TOC entry 7264 (class 1259 OID 146571670)
-- Dependencies: 486 8894
-- 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);


--
-- TOC entry 7265 (class 1259 OID 146571671)
-- Dependencies: 486 8894
-- 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);


--
-- TOC entry 6928 (class 1259 OID 146571672)
-- Dependencies: 237 237 8894
-- 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);


--
-- TOC entry 7206 (class 1259 OID 146571673)
-- Dependencies: 430 8894
-- Name: checkhead_posted_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX checkhead_posted_idx ON checkhead USING btree (checkhead_posted);


--
-- TOC entry 7207 (class 1259 OID 146571674)
-- Dependencies: 430 8894
-- Name: checkhead_replaced_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX checkhead_replaced_idx ON checkhead USING btree (checkhead_replaced);


--
-- TOC entry 7208 (class 1259 OID 146571675)
-- Dependencies: 432 8894
-- 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);


--
-- TOC entry 6871 (class 1259 OID 146571676)
-- Dependencies: 218 8894
-- Name: cmhead_invcnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cmhead_invcnumber_idx ON cmhead USING btree (cmhead_invcnumber);


--
-- TOC entry 6814 (class 1259 OID 146571677)
-- Dependencies: 204 8894
-- Name: cntct_email_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cntct_email_idx ON cntct USING btree (cntct_email);


--
-- TOC entry 6815 (class 1259 OID 146571678)
-- Dependencies: 204 8894
-- Name: cntct_name_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cntct_name_idx ON cntct USING btree (cntct_name);


--
-- TOC entry 7286 (class 1259 OID 146571679)
-- Dependencies: 513 8894
-- Name: cobill_cobmisc_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobill_cobmisc_id ON cobill USING btree (cobill_cobmisc_id);


--
-- TOC entry 7287 (class 1259 OID 146571680)
-- Dependencies: 513 8894
-- Name: cobill_coitem_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobill_coitem_id ON cobill USING btree (cobill_coitem_id);


--
-- TOC entry 7292 (class 1259 OID 146571681)
-- Dependencies: 516 8894
-- Name: cobmisc_cohead_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobmisc_cohead_id ON cobmisc USING btree (cobmisc_cohead_id);


--
-- TOC entry 7295 (class 1259 OID 146571682)
-- Dependencies: 516 8894
-- Name: cobmisc_posted; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cobmisc_posted ON cobmisc USING btree (cobmisc_posted);


--
-- TOC entry 6769 (class 1259 OID 146571683)
-- Dependencies: 195 8894
-- Name: cohead_cohead_status_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohead_cohead_status_idx ON cohead USING btree (cohead_status);


--
-- TOC entry 6770 (class 1259 OID 146571684)
-- Dependencies: 195 8894
-- 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);


--
-- TOC entry 6771 (class 1259 OID 146571685)
-- Dependencies: 195 8894
-- Name: cohead_custponumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohead_custponumber_idx ON cohead USING btree (cohead_custponumber);


--
-- TOC entry 6772 (class 1259 OID 146571686)
-- Dependencies: 195 8894
-- Name: cohead_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX cohead_number_idx ON cohead USING btree (cohead_number);


--
-- TOC entry 6775 (class 1259 OID 146571687)
-- Dependencies: 195 8894
-- Name: cohead_shipto_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohead_shipto_id ON cohead USING btree (cohead_shipto_id);


--
-- TOC entry 7139 (class 1259 OID 146571688)
-- Dependencies: 376 8894
-- Name: cohist_cust_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_cust_id ON cohist USING btree (cohist_cust_id);


--
-- TOC entry 7140 (class 1259 OID 146571689)
-- Dependencies: 376 8894
-- Name: cohist_invcnumber; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_invcnumber ON cohist USING btree (cohist_invcnumber);


--
-- TOC entry 7141 (class 1259 OID 146571690)
-- Dependencies: 376 8894
-- Name: cohist_itemsite_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_itemsite_id ON cohist USING btree (cohist_itemsite_id);


--
-- TOC entry 7144 (class 1259 OID 146571691)
-- Dependencies: 376 8894
-- Name: cohist_shipdate; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_shipdate ON cohist USING btree (cohist_shipdate);


--
-- TOC entry 7145 (class 1259 OID 146571692)
-- Dependencies: 376 8894
-- Name: cohist_shipto_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX cohist_shipto_id ON cohist USING btree (cohist_shipto_id);


--
-- TOC entry 6776 (class 1259 OID 146571693)
-- Dependencies: 196 8894
-- 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);


--
-- TOC entry 6777 (class 1259 OID 146571694)
-- Dependencies: 196 196 196 8894
-- 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);


--
-- TOC entry 6778 (class 1259 OID 146571695)
-- Dependencies: 196 8894
-- Name: coitem_itemsite_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX coitem_itemsite_id ON coitem USING btree (coitem_itemsite_id);


--
-- TOC entry 6779 (class 1259 OID 146571696)
-- Dependencies: 196 8894
-- Name: coitem_linenumber_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX coitem_linenumber_key ON coitem USING btree (coitem_linenumber);


--
-- TOC entry 6782 (class 1259 OID 146571697)
-- Dependencies: 196 8894
-- Name: coitem_status_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX coitem_status_key ON coitem USING btree (coitem_status);


--
-- TOC entry 6933 (class 1259 OID 146571698)
-- Dependencies: 240 240 8894
-- 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);


--
-- TOC entry 7063 (class 1259 OID 146571699)
-- Dependencies: 329 329 8894
-- 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);


--
-- TOC entry 6852 (class 1259 OID 146571700)
-- Dependencies: 213 8894
-- Name: cust_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX cust_number_idx ON custinfo USING btree (cust_number);


--
-- TOC entry 7354 (class 1259 OID 146571701)
-- Dependencies: 567 8894
-- Name: evntlog_dispatched_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX evntlog_dispatched_idx ON evntlog USING btree (evntlog_dispatched);


--
-- TOC entry 7355 (class 1259 OID 146571702)
-- Dependencies: 567 8894
-- Name: evntlog_evntlog_username_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX evntlog_evntlog_username_idx ON evntlog USING btree (evntlog_username);


--
-- TOC entry 7358 (class 1259 OID 146571703)
-- Dependencies: 569 8894
-- 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);


--
-- TOC entry 7361 (class 1259 OID 146571704)
-- Dependencies: 569 8894
-- 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);


--
-- TOC entry 7366 (class 1259 OID 146571705)
-- Dependencies: 575 575 575 8894
-- Name: filter_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX filter_idx ON filter USING btree (filter_screen, filter_username, filter_name);


--
-- TOC entry 7086 (class 1259 OID 146571706)
-- Dependencies: 340 8894
-- 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);


--
-- TOC entry 7087 (class 1259 OID 146571707)
-- Dependencies: 340 8894
-- Name: gltrans_gltrans_date_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX gltrans_gltrans_date_idx ON gltrans USING btree (gltrans_date);


--
-- TOC entry 7088 (class 1259 OID 146571708)
-- Dependencies: 340 8894
-- Name: gltrans_gltrans_journalnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX gltrans_gltrans_journalnumber_idx ON gltrans USING btree (gltrans_journalnumber);


--
-- TOC entry 7091 (class 1259 OID 146571709)
-- Dependencies: 340 8894
-- Name: gltrans_sequence_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX gltrans_sequence_idx ON gltrans USING btree (gltrans_sequence);


--
-- TOC entry 6886 (class 1259 OID 146571710)
-- Dependencies: 224 8894
-- Name: invchead_invchead_ordernumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invchead_invchead_ordernumber_idx ON invchead USING btree (invchead_ordernumber);


--
-- TOC entry 6903 (class 1259 OID 146571711)
-- Dependencies: 229 8894
-- 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);


--
-- TOC entry 6904 (class 1259 OID 146571712)
-- Dependencies: 229 229 8894
-- 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);


--
-- TOC entry 7409 (class 1259 OID 146571713)
-- Dependencies: 619 8894
-- 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);


--
-- TOC entry 7410 (class 1259 OID 146571714)
-- Dependencies: 621 8894
-- 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);


--
-- TOC entry 7411 (class 1259 OID 146571715)
-- Dependencies: 621 8894
-- 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);


--
-- TOC entry 7414 (class 1259 OID 146571716)
-- Dependencies: 623 8894
-- Name: invhist_hasdetail; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_hasdetail ON invhist USING btree (invhist_hasdetail);


--
-- TOC entry 7415 (class 1259 OID 146571717)
-- Dependencies: 623 8894
-- Name: invhist_invhist_ordnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_invhist_ordnumber_idx ON invhist USING btree (invhist_ordnumber);


--
-- TOC entry 7416 (class 1259 OID 146571718)
-- Dependencies: 623 8894
-- Name: invhist_itemsite_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_itemsite_id ON invhist USING btree (invhist_itemsite_id);


--
-- TOC entry 7419 (class 1259 OID 146571719)
-- Dependencies: 623 8894
-- Name: invhist_series; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_series ON invhist USING btree (invhist_series);


--
-- TOC entry 7420 (class 1259 OID 146571720)
-- Dependencies: 623 8894
-- Name: invhist_transdate; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_transdate ON invhist USING btree (invhist_transdate);


--
-- TOC entry 7421 (class 1259 OID 146571721)
-- Dependencies: 623 8894
-- Name: invhist_transtype; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX invhist_transtype ON invhist USING btree (invhist_transtype);


--
-- TOC entry 7101 (class 1259 OID 146571722)
-- Dependencies: 349 8894
-- 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);


--
-- TOC entry 6747 (class 1259 OID 146571723)
-- Dependencies: 191 8894
-- Name: item_classcode_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX item_classcode_id ON item USING btree (item_classcode_id);


--
-- TOC entry 6750 (class 1259 OID 146571724)
-- Dependencies: 191 8894
-- Name: item_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX item_number_idx ON item USING btree (item_number);


--
-- TOC entry 6753 (class 1259 OID 146571725)
-- Dependencies: 191 8894
-- 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);


--
-- TOC entry 6754 (class 1259 OID 146571726)
-- Dependencies: 191 8894
-- Name: item_upccode_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX item_upccode_idx ON item USING btree (item_upccode);


--
-- TOC entry 7051 (class 1259 OID 146571727)
-- Dependencies: 321 8894
-- 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);


--
-- TOC entry 7052 (class 1259 OID 146571728)
-- Dependencies: 321 321 321 8894
-- 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);


--
-- TOC entry 7436 (class 1259 OID 146571729)
-- Dependencies: 649 8894
-- Name: itemloc_itemsite_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemloc_itemsite_idx ON itemloc USING btree (itemloc_itemsite_id);


--
-- TOC entry 7437 (class 1259 OID 146571730)
-- Dependencies: 649 8894
-- Name: itemloc_location_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemloc_location_idx ON itemloc USING btree (itemloc_location_id);


--
-- TOC entry 6755 (class 1259 OID 146571731)
-- Dependencies: 192 8894
-- Name: itemsite_active_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX itemsite_active_key ON itemsite USING btree (itemsite_active);


--
-- TOC entry 6756 (class 1259 OID 146571732)
-- Dependencies: 192 8894
-- 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);


--
-- TOC entry 6757 (class 1259 OID 146571733)
-- Dependencies: 192 192 8894
-- 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);


--
-- TOC entry 6760 (class 1259 OID 146571734)
-- Dependencies: 192 8894
-- 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);


--
-- TOC entry 6761 (class 1259 OID 146571735)
-- Dependencies: 192 8894
-- 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);


--
-- TOC entry 7070 (class 1259 OID 146571736)
-- Dependencies: 330 8894
-- 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);


--
-- TOC entry 7071 (class 1259 OID 146571737)
-- Dependencies: 332 8894
-- 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);


--
-- TOC entry 7078 (class 1259 OID 146571738)
-- Dependencies: 334 8894
-- 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);


--
-- TOC entry 7081 (class 1259 OID 146571739)
-- Dependencies: 334 8894
-- 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);


--
-- TOC entry 7094 (class 1259 OID 146571740)
-- Dependencies: 342 8894
-- Name: location_warehous_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX location_warehous_idx ON location USING btree (location_warehous_id);


--
-- TOC entry 7502 (class 1259 OID 146571741)
-- Dependencies: 708 8894
-- 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);


--
-- TOC entry 7503 (class 1259 OID 146571742)
-- Dependencies: 708 8894
-- 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);


--
-- TOC entry 7506 (class 1259 OID 146571743)
-- Dependencies: 709 8894
-- 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);


--
-- TOC entry 7507 (class 1259 OID 146571744)
-- Dependencies: 709 8894
-- 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);


--
-- TOC entry 6787 (class 1259 OID 146571745)
-- Dependencies: 197 8894
-- Name: pohead_pohead_status_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX pohead_pohead_status_idx ON pohead USING btree (pohead_status);


--
-- TOC entry 6788 (class 1259 OID 146571746)
-- Dependencies: 198 8894
-- 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);


--
-- TOC entry 6789 (class 1259 OID 146571747)
-- Dependencies: 198 198 198 8894
-- 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);


--
-- TOC entry 6792 (class 1259 OID 146571748)
-- Dependencies: 198 8894
-- 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);


--
-- TOC entry 6795 (class 1259 OID 146571749)
-- Dependencies: 198 8894
-- Name: poitem_status_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX poitem_status_key ON poitem USING btree (poitem_status);


--
-- TOC entry 7178 (class 1259 OID 146571750)
-- Dependencies: 408 8894
-- Name: priv_name_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX priv_name_idx ON priv USING btree (priv_name);


--
-- TOC entry 7134 (class 1259 OID 146571751)
-- Dependencies: 370 8894
-- 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);


--
-- TOC entry 7518 (class 1259 OID 146571752)
-- Dependencies: 721 721 8894
-- 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);


--
-- TOC entry 7183 (class 1259 OID 146571753)
-- Dependencies: 411 411 8894
-- 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);


--
-- TOC entry 7325 (class 1259 OID 146571754)
-- Dependencies: 540 8894
-- 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);


--
-- TOC entry 7326 (class 1259 OID 146571755)
-- Dependencies: 540 8894
-- 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);


--
-- TOC entry 7006 (class 1259 OID 146571756)
-- Dependencies: 297 8894
-- 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);


--
-- TOC entry 7573 (class 1259 OID 146571757)
-- Dependencies: 771 8894
-- 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);


--
-- TOC entry 7574 (class 1259 OID 146571758)
-- Dependencies: 771 8894
-- 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);


--
-- TOC entry 7302 (class 1259 OID 146571759)
-- Dependencies: 526 8894
-- 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);


--
-- TOC entry 7307 (class 1259 OID 146571760)
-- Dependencies: 526 8894
-- Name: shiphead_shipped_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX shiphead_shipped_idx ON shiphead USING btree (shiphead_shipped);


--
-- TOC entry 7308 (class 1259 OID 146571761)
-- Dependencies: 527 8894
-- 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);


--
-- TOC entry 7309 (class 1259 OID 146571762)
-- Dependencies: 527 8894
-- 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);


--
-- TOC entry 7312 (class 1259 OID 146571763)
-- Dependencies: 527 8894
-- 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);


--
-- TOC entry 7579 (class 1259 OID 146571764)
-- Dependencies: 781 8894
-- Name: sltrans_sequence_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX sltrans_sequence_idx ON sltrans USING btree (sltrans_sequence);


--
-- TOC entry 7580 (class 1259 OID 146571765)
-- Dependencies: 781 8894
-- 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);


--
-- TOC entry 7581 (class 1259 OID 146571766)
-- Dependencies: 781 8894
-- Name: sltrans_sltrans_date_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX sltrans_sltrans_date_idx ON sltrans USING btree (sltrans_date);


--
-- TOC entry 7582 (class 1259 OID 146571767)
-- Dependencies: 781 8894
-- Name: sltrans_sltrans_journalnumber_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX sltrans_sltrans_journalnumber_idx ON sltrans USING btree (sltrans_journalnumber);


--
-- TOC entry 7611 (class 1259 OID 146571768)
-- Dependencies: 801 8894
-- Name: subaccnttype_code_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX subaccnttype_code_idx ON subaccnttype USING btree (subaccnttype_code);


--
-- TOC entry 6917 (class 1259 OID 146571769)
-- Dependencies: 233 8894
-- Name: todoitem_todoitem_username_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX todoitem_todoitem_username_idx ON todoitem USING btree (todoitem_username);


--
-- TOC entry 7624 (class 1259 OID 146571770)
-- Dependencies: 817 817 8894
-- 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);


--
-- TOC entry 7635 (class 1259 OID 146571771)
-- Dependencies: 825 8894
-- Name: usrpref_userpref_name_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX usrpref_userpref_name_idx ON usrpref USING btree (usrpref_name);


--
-- TOC entry 6840 (class 1259 OID 146571772)
-- Dependencies: 210 8894
-- Name: vend_number_idx; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE UNIQUE INDEX vend_number_idx ON vendinfo USING btree (vend_number);


--
-- TOC entry 6762 (class 1259 OID 146571773)
-- Dependencies: 193 8894
-- Name: warehous_code_key; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX warehous_code_key ON whsinfo USING btree (warehous_code bpchar_ops);


--
-- TOC entry 7341 (class 1259 OID 146571774)
-- Dependencies: 560 8894
-- Name: wo_duedate; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_duedate ON wo USING btree (wo_duedate);


--
-- TOC entry 7342 (class 1259 OID 146571775)
-- Dependencies: 560 8894
-- Name: wo_itemsite_id; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_itemsite_id ON wo USING btree (wo_itemsite_id);


--
-- TOC entry 7343 (class 1259 OID 146571776)
-- Dependencies: 560 8894
-- Name: wo_ordtype; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_ordtype ON wo USING btree (wo_ordtype);


--
-- TOC entry 7346 (class 1259 OID 146571777)
-- Dependencies: 560 8894
-- Name: wo_startdate; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_startdate ON wo USING btree (wo_startdate);


--
-- TOC entry 7347 (class 1259 OID 146571778)
-- Dependencies: 560 8894
-- Name: wo_status; Type: INDEX; Schema: public; Owner: admin; Tablespace: 
--

CREATE INDEX wo_status ON wo USING btree (wo_status);


--
-- TOC entry 7120 (class 1259 OID 146571779)
-- Dependencies: 359 8894
-- 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);


--
-- TOC entry 7123 (class 1259 OID 146571780)
-- Dependencies: 359 8894
-- 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);



--
-- TOC entry 7686 (class 1259 OID 146571781)
-- Dependencies: 875 8894
-- 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);



--
-- TOC entry 8597 (class 2618 OID 146571782)
-- Dependencies: 201 201 201 196 196 196 1672 201 8894
-- 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));


--
-- TOC entry 8598 (class 2618 OID 146571783)
-- Dependencies: 211 211 211 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO apmemo DO INSTEAD NOTHING;


--
-- TOC entry 8599 (class 2618 OID 146571784)
-- Dependencies: 217 217 217 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO armemo DO INSTEAD NOTHING;


--
-- TOC entry 8600 (class 2618 OID 146571785)
-- Dependencies: 194 194 194 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO physinvcount DO INSTEAD NOTHING;


--
-- TOC entry 8601 (class 2618 OID 146571786)
-- Dependencies: 235 235 205 235 8894
-- 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);


--
-- TOC entry 8602 (class 2618 OID 146571787)
-- Dependencies: 238 238 238 237 237 237 1680 1665 238 8894
-- 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)));


--
-- TOC entry 8603 (class 2618 OID 146571788)
-- Dependencies: 241 241 241 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO accountcomment DO INSTEAD NOTHING;


--
-- TOC entry 8604 (class 2618 OID 146571789)
-- Dependencies: 246 246 246 246 245 245 245 245 1680 246 8894
-- 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));


--
-- TOC entry 8605 (class 2618 OID 146571790)
-- Dependencies: 250 250 250 249 249 249 1702 1680 250 8894
-- 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)));


--
-- TOC entry 8606 (class 2618 OID 146571791)
-- Dependencies: 251 251 1658 1400 251 8894
-- 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;


--
-- TOC entry 8607 (class 2618 OID 146571792)
-- Dependencies: 252 252 252 237 237 237 1665 1658 252 8894
-- 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)));


--
-- TOC entry 8608 (class 2618 OID 146571793)
-- Dependencies: 253 253 253 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO addresscomment DO INSTEAD NOTHING;


--
-- TOC entry 8609 (class 2618 OID 146571794)
-- Dependencies: 255 255 1714 1404 255 8894
-- 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;


--
-- TOC entry 8610 (class 2618 OID 146571795)
-- Dependencies: 256 256 203 1545 256 8894
-- 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));


--
-- TOC entry 8611 (class 2618 OID 146571796)
-- Dependencies: 257 257 257 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO bomitemcomment DO INSTEAD NOTHING;


--
-- TOC entry 8612 (class 2618 OID 146571797)
-- Dependencies: 259 259 259 258 258 1714 259 8894
-- 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)));


--
-- TOC entry 8613 (class 2618 OID 146571798)
-- Dependencies: 261 261 260 261 8894
-- 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);


--
-- TOC entry 8614 (class 2618 OID 146571799)
-- Dependencies: 265 265 265 265 263 263 263 1730 1700 1663 265 8894
-- 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)));


--
-- TOC entry 8615 (class 2618 OID 146571800)
-- Dependencies: 268 268 268 268 267 1664 1409 268 8894
-- 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));


--
-- TOC entry 8616 (class 2618 OID 146571802)
-- Dependencies: 270 270 270 270 270 270 269 269 1664 1660 270 8894
-- 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)));


--
-- TOC entry 8617 (class 2618 OID 146571804)
-- Dependencies: 272 272 272 272 272 271 271 1700 1664 272 8894
-- 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)));


--
-- TOC entry 8618 (class 2618 OID 146571806)
-- Dependencies: 273 273 204 273 8894
-- 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);


--
-- TOC entry 8619 (class 2618 OID 146571807)
-- Dependencies: 274 274 274 237 237 237 1670 1665 274 8894
-- 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)));


--
-- TOC entry 8620 (class 2618 OID 146571808)
-- Dependencies: 275 275 275 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO contactcomment DO INSTEAD NOTHING;


--
-- TOC entry 8621 (class 2618 OID 146571809)
-- Dependencies: 221 221 218 218 218 1414 221 8894
-- 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));


--
-- TOC entry 8622 (class 2618 OID 146571810)
-- Dependencies: 223 223 223 222 222 1668 223 8894
-- 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));


--
-- TOC entry 8623 (class 2618 OID 146571811)
-- Dependencies: 276 276 276 237 237 237 1682 1665 276 8894
-- 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)));


--
-- TOC entry 8624 (class 2618 OID 146571812)
-- Dependencies: 277 277 277 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO custcomment DO INSTEAD NOTHING;


--
-- TOC entry 8625 (class 2618 OID 146571813)
-- Dependencies: 279 279 279 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO custcreditcard DO INSTEAD NOTHING;


--
-- TOC entry 8626 (class 2618 OID 146571814)
-- Dependencies: 283 283 213 283 8894
-- 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);


--
-- TOC entry 8627 (class 2618 OID 146571816)
-- Dependencies: 287 287 280 287 8894
-- 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);


--
-- TOC entry 8628 (class 2618 OID 146571817)
-- Dependencies: 288 288 288 237 237 237 1686 1665 288 8894
-- 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)));


--
-- TOC entry 8629 (class 2618 OID 146571818)
-- Dependencies: 289 289 289 1756 1456 289 8894
-- 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;


--
-- TOC entry 8630 (class 2618 OID 146571819)
-- Dependencies: 290 290 290 285 285 285 1765 1682 290 8894
-- 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)));


--
-- TOC entry 8631 (class 2618 OID 146571820)
-- Dependencies: 294 294 292 294 8894
-- 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);


--
-- TOC entry 8632 (class 2618 OID 146571821)
-- Dependencies: 295 295 295 237 237 237 1690 1665 295 8894
-- 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)));


--
-- TOC entry 8633 (class 2618 OID 146571822)
-- Dependencies: 296 296 296 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO employeecomment DO INSTEAD NOTHING;


--
-- TOC entry 8634 (class 2618 OID 146571823)
-- Dependencies: 298 298 298 298 298 297 297 297 297 298 8894
-- 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));


--
-- TOC entry 8635 (class 2618 OID 146571824)
-- Dependencies: 302 302 302 302 302 302 302 302 302 300 300 300 300 300 300 300 300 1780 1759 1684 1697 302 8894
-- 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));


--
-- TOC entry 8636 (class 2618 OID 146571826)
-- Dependencies: 308 308 308 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO incident DO INSTEAD NOTHING;


--
-- TOC entry 8637 (class 2618 OID 146571827)
-- Dependencies: 309 309 309 237 237 237 1708 1665 309 8894
-- 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)));


--
-- TOC entry 8638 (class 2618 OID 146571828)
-- Dependencies: 310 310 310 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO incidentcomment DO INSTEAD NOTHING;


--
-- TOC entry 8639 (class 2618 OID 146571829)
-- Dependencies: 311 311 311 311 245 245 245 245 1708 311 8894
-- 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));


--
-- TOC entry 8640 (class 2618 OID 146571830)
-- Dependencies: 312 312 312 249 249 249 1708 1702 312 8894
-- 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)));


--
-- TOC entry 8641 (class 2618 OID 146571831)
-- Dependencies: 228 228 224 224 224 1423 228 8894
-- 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));


--
-- TOC entry 8642 (class 2618 OID 146571832)
-- Dependencies: 230 230 229 224 224 224 230 8894
-- 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))));


--
-- TOC entry 8643 (class 2618 OID 146571833)
-- Dependencies: 315 315 1714 1426 315 8894
-- 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;


--
-- TOC entry 8644 (class 2618 OID 146571834)
-- Dependencies: 317 317 317 316 316 1714 317 8894
-- 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));


--
-- TOC entry 8645 (class 2618 OID 146571835)
-- Dependencies: 318 318 318 237 237 237 1714 1665 318 8894
-- 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)));


--
-- TOC entry 8646 (class 2618 OID 146571836)
-- Dependencies: 319 319 319 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemcomment DO INSTEAD NOTHING;


--
-- TOC entry 8647 (class 2618 OID 146571837)
-- Dependencies: 322 322 322 1714 1679 1427 322 8894
-- 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;


--
-- TOC entry 8648 (class 2618 OID 146571838)
-- Dependencies: 323 323 323 323 245 245 245 245 1714 323 8894
-- 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));


--
-- TOC entry 8649 (class 2618 OID 146571839)
-- Dependencies: 324 324 324 249 249 249 1714 1702 324 8894
-- 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)));


--
-- TOC entry 8650 (class 2618 OID 146571840)
-- Dependencies: 327 327 327 1716 1428 327 8894
-- 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;


--
-- TOC entry 8651 (class 2618 OID 146571841)
-- Dependencies: 328 328 328 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO itemsitecomment DO INSTEAD NOTHING;


--
-- TOC entry 8652 (class 2618 OID 146571842)
-- Dependencies: 331 331 331 331 331 331 330 330 330 330 330 1778 1714 331 8894
-- 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));


--
-- TOC entry 8653 (class 2618 OID 146571843)
-- Dependencies: 333 333 333 333 332 332 1718 333 8894
-- 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));


--
-- TOC entry 8654 (class 2618 OID 146571844)
-- Dependencies: 335 335 335 334 334 1714 335 8894
-- 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)));


--
-- TOC entry 8655 (class 2618 OID 146571845)
-- Dependencies: 337 337 337 337 336 336 336 1768 1767 1714 337 8894
-- 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)));


--
-- TOC entry 8656 (class 2618 OID 146571846)
-- Dependencies: 339 339 339 339 338 338 338 338 1771 1714 1430 339 8894
-- 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)))));


--
-- TOC entry 8657 (class 2618 OID 146571847)
-- Dependencies: 341 341 341 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO journalentry DO INSTEAD NOTHING;


--
-- TOC entry 8658 (class 2618 OID 146571848)
-- Dependencies: 344 344 344 342 342 1780 344 8894
-- 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));


--
-- TOC entry 8659 (class 2618 OID 146571849)
-- Dependencies: 345 345 345 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO misccounttag DO INSTEAD NOTHING;


--
-- TOC entry 8660 (class 2618 OID 146571850)
-- Dependencies: 346 346 301 346 8894
-- 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);


--
-- TOC entry 8661 (class 2618 OID 146571851)
-- Dependencies: 348 348 348 348 348 348 348 347 347 347 347 347 347 1756 1684 1686 1682 348 8894
-- 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));


--
-- TOC entry 8662 (class 2618 OID 146571852)
-- Dependencies: 350 350 350 350 350 350 350 350 1713 1712 1425 1424 350 8894
-- 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;


--
-- TOC entry 8663 (class 2618 OID 146571853)
-- Dependencies: 352 352 352 352 352 352 352 352 351 351 351 1712 1665 352 8894
-- 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));


--
-- TOC entry 8664 (class 2618 OID 146571854)
-- Dependencies: 353 353 1736 1444 353 8894
-- 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;


--
-- TOC entry 8665 (class 2618 OID 146571855)
-- Dependencies: 354 354 354 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO projectcomment DO INSTEAD NOTHING;


--
-- TOC entry 8666 (class 2618 OID 146571856)
-- Dependencies: 357 357 356 357 8894
-- 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);


--
-- TOC entry 8667 (class 2618 OID 146571857)
-- Dependencies: 360 360 360 198 1734 360 8894
-- 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));


--
-- TOC entry 8668 (class 2618 OID 146571858)
-- Dependencies: 361 361 361 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO purchaselinechar DO INSTEAD NOTHING;


--
-- TOC entry 8669 (class 2618 OID 146571859)
-- Dependencies: 362 362 362 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO purchaselinecomment DO INSTEAD NOTHING;


--
-- TOC entry 8670 (class 2618 OID 146571860)
-- Dependencies: 365 365 197 197 1438 365 8894
-- 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);


--
-- TOC entry 8671 (class 2618 OID 146571861)
-- Dependencies: 366 366 366 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO purchaseordercomment DO INSTEAD NOTHING;


--
-- TOC entry 8672 (class 2618 OID 146571862)
-- Dependencies: 368 368 367 367 1447 368 8894
-- 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);


--
-- TOC entry 8673 (class 2618 OID 146571863)
-- Dependencies: 369 369 369 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO quotecomment DO INSTEAD NOTHING;


--
-- TOC entry 8674 (class 2618 OID 146571864)
-- Dependencies: 371 371 371 370 370 1720 371 8894
-- 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));


--
-- TOC entry 8675 (class 2618 OID 146571865)
-- Dependencies: 372 372 372 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO quotelinechar DO INSTEAD NOTHING;


--
-- TOC entry 8676 (class 2618 OID 146571866)
-- Dependencies: 373 373 373 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO quotelinecomment DO INSTEAD NOTHING;


--
-- TOC entry 8677 (class 2618 OID 146571867)
-- Dependencies: 380 380 380 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO saleshistory DO INSTEAD NOTHING;


--
-- TOC entry 8678 (class 2618 OID 146571868)
-- Dependencies: 381 381 381 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO saleslinechar DO INSTEAD NOTHING;


--
-- TOC entry 8679 (class 2618 OID 146571869)
-- Dependencies: 382 382 382 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO saleslinecomment DO INSTEAD NOTHING;


--
-- TOC entry 8680 (class 2618 OID 146571870)
-- Dependencies: 383 383 195 195 1458 383 8894
-- 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);


--
-- TOC entry 8681 (class 2618 OID 146571872)
-- Dependencies: 384 384 384 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO salesordercomment DO INSTEAD NOTHING;


--
-- TOC entry 8682 (class 2618 OID 146571873)
-- Dependencies: 385 385 216 385 8894
-- 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);


--
-- TOC entry 8683 (class 2618 OID 146571874)
-- Dependencies: 388 388 388 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO site DO NOTHING;


--
-- TOC entry 8684 (class 2618 OID 146571875)
-- Dependencies: 389 389 389 343 343 1780 389 8894
-- 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));


--
-- TOC entry 8685 (class 2618 OID 146571876)
-- Dependencies: 390 390 390 232 232 1736 390 8894
-- 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));


--
-- TOC entry 8686 (class 2618 OID 146571877)
-- Dependencies: 391 391 391 8894
-- Name: _DELETE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_DELETE" AS ON DELETE TO taskcomment DO INSTEAD NOTHING;


--
-- TOC entry 8687 (class 2618 OID 146571878)
-- Dependencies: 392 392 1468 392 8894
-- 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;


--
-- TOC entry 8688 (class 2618 OID 146571879)
-- Dependencies: 394 394 210 394 8894
-- 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);


--
-- TOC entry 8689 (class 2618 OID 146571880)
-- Dependencies: 395 395 395 1777 1479 395 8894
-- 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;


--
-- TOC entry 8690 (class 2618 OID 146571881)
-- Dependencies: 396 396 1779 1480 396 8894
-- 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;


--
-- TOC entry 8691 (class 2618 OID 146571882)
-- Dependencies: 201 201 1832 201 8894
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO salesline DO INSTEAD SELECT public.insertsalesline(new.*) AS insertsalesline;


--
-- TOC entry 8692 (class 2618 OID 146571883)
-- Dependencies: 211 211 1813 211 8894
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO apmemo DO INSTEAD SELECT public.insertapmemo(new.*) AS insertapmemo;


--
-- TOC entry 8693 (class 2618 OID 146571884)
-- Dependencies: 217 217 1814 217 8894
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO armemo DO INSTEAD SELECT public.insertarmemo(new.*) AS insertarmemo;


--
-- TOC entry 8694 (class 2618 OID 146571885)
-- Dependencies: 194 194 906 194 8894
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO physinvcount DO INSTEAD SELECT insertphysinvcount(new.*) AS insertphysinvcount;


--
-- TOC entry 8695 (class 2618 OID 146571886)
-- Dependencies: 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 235 205 2162 2158 1680 1670 1658 1537 235 8894
-- 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);


--
-- TOC entry 8696 (class 2618 OID 146571888)
-- Dependencies: 238 238 238 238 237 1680 1665 238 8894
-- 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);


--
-- TOC entry 8697 (class 2618 OID 146571889)
-- Dependencies: 241 241 241 241 241 241 240 1680 1669 910 241 8894
-- 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);


--
-- TOC entry 8698 (class 2618 OID 146571890)
-- Dependencies: 246 246 246 246 245 1680 246 8894
-- 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);


--
-- TOC entry 8699 (class 2618 OID 146571891)
-- Dependencies: 250 250 250 2165 1702 1680 250 8894
-- 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;


--
-- TOC entry 8700 (class 2618 OID 146571892)
-- Dependencies: 251 251 251 251 251 251 251 251 251 251 251 2157 251 8894
-- 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;


--
-- TOC entry 8701 (class 2618 OID 146571893)
-- Dependencies: 252 252 252 252 237 1665 1658 252 8894
-- 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);


--
-- TOC entry 8702 (class 2618 OID 146571894)
-- Dependencies: 253 253 253 253 253 253 240 1669 1658 910 253 8894
-- 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);


--
-- TOC entry 8703 (class 2618 OID 146571895)
-- Dependencies: 255 255 255 255 255 255 255 2160 1714 255 8894
-- 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;


--
-- TOC entry 8704 (class 2618 OID 146571897)
-- Dependencies: 256 467 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 191 191 2233 1771 1742 1714 1665 1650 1546 1519 1311 1148 256 8894
-- 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;


--
-- TOC entry 8705 (class 2618 OID 146571899)
-- Dependencies: 257 257 257 257 257 257 240 1669 910 257 8894
-- 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);


--
-- TOC entry 8706 (class 2618 OID 146571900)
-- Dependencies: 259 259 259 259 259 258 1714 259 8894
-- 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));


--
-- TOC entry 8707 (class 2618 OID 146571901)
-- Dependencies: 261 261 261 260 261 8894
-- 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);


--
-- TOC entry 8708 (class 2618 OID 146571902)
-- Dependencies: 265 265 265 265 265 263 1730 1700 1663 265 8894
-- 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);


--
-- TOC entry 8709 (class 2618 OID 146571903)
-- Dependencies: 268 268 268 268 268 268 268 268 268 268 268 267 1744 1682 1681 1661 1535 268 8894
-- 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);


--
-- TOC entry 8710 (class 2618 OID 146571905)
-- Dependencies: 270 270 270 270 270 270 270 270 269 1664 1660 270 8894
-- 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));


--
-- TOC entry 8711 (class 2618 OID 146571907)
-- Dependencies: 272 272 272 272 272 272 272 271 1700 1664 272 8894
-- 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));


--
-- TOC entry 8712 (class 2618 OID 146571909)
-- Dependencies: 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 2161 2158 1680 1658 273 8894
-- 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(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, COALESCE(new.active, true), new.voice, new.alternate, new.fax, new.email, new.web, new.notes, new.job_title, new.contact_change) AS savecntct;


--
-- TOC entry 8713 (class 2618 OID 146571910)
-- Dependencies: 274 274 274 274 237 1670 1665 274 8894
-- 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);


--
-- TOC entry 8714 (class 2618 OID 146571911)
-- Dependencies: 275 275 275 275 275 275 240 1670 1669 910 275 8894
-- 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);


--
-- TOC entry 8715 (class 2618 OID 146571912)
-- Dependencies: 221 221 1816 221 8894
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO creditmemo DO INSTEAD SELECT public.insertcreditmemo(new.*) AS insertcreditmemo;


--
-- TOC entry 8716 (class 2618 OID 146571913)
-- Dependencies: 223 223 1817 223 8894
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO creditmemoline DO INSTEAD SELECT public.insertcreditmemoline(new.*) AS insertcreditmemoline;


--
-- TOC entry 8717 (class 2618 OID 146571914)
-- Dependencies: 276 276 276 276 237 1682 1665 276 8894
-- 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);


--
-- TOC entry 8718 (class 2618 OID 146571915)
-- Dependencies: 277 277 277 277 277 277 240 1682 1669 910 277 8894
-- 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);


--
-- TOC entry 8719 (class 2618 OID 146571916)
-- Dependencies: 279 279 279 279 279 279 279 279 279 279 279 279 279 279 279 1815 279 8894
-- 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;


--
-- TOC entry 8720 (class 2618 OID 146571917)
-- Dependencies: 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 216 216 213 2162 2158 1780 1769 1768 1754 1753 1749 1686 1681 1671 1658 1547 1546 1545 1539 1537 907 283 8894
-- 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);


--
-- TOC entry 8721 (class 2618 OID 146571919)
-- Dependencies: 286 286 286 286 286 286 286 285 213 213 2233 1765 1682 1519 286 8894
-- 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);


--
-- TOC entry 8722 (class 2618 OID 146571921)
-- Dependencies: 287 287 287 287 280 287 8894
-- 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));


--
-- TOC entry 8723 (class 2618 OID 146571922)
-- Dependencies: 288 288 288 288 288 237 1686 1665 288 8894
-- 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));


--
-- TOC entry 8724 (class 2618 OID 146571923)
-- Dependencies: 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 219 219 213 213 213 213 213 213 2162 2158 1768 1759 1754 1753 1749 1688 1682 1670 1658 289 8894
-- 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)))));


--
-- TOC entry 8725 (class 2618 OID 146571925)
-- Dependencies: 290 290 290 290 285 1765 1682 290 8894
-- 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);


--
-- TOC entry 8726 (class 2618 OID 146571926)
-- Dependencies: 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 292 292 2162 2158 1780 1752 1702 1687 1681 1670 1658 907 294 8894
-- 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));


--
-- TOC entry 8727 (class 2618 OID 146571928)
-- Dependencies: 295 295 295 295 237 1690 1665 295 8894
-- 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);


--
-- TOC entry 8728 (class 2618 OID 146571929)
-- Dependencies: 296 296 296 296 296 296 240 1690 1669 910 296 8894
-- 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);


--
-- TOC entry 8729 (class 2618 OID 146571930)
-- Dependencies: 298 298 298 298 298 298 298 298 298 298 298 298 298 298 298 297 1681 298 8894
-- 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);


--
-- TOC entry 8730 (class 2618 OID 146571931)
-- Dependencies: 302 302 302 302 302 302 302 302 302 300 1780 1759 1684 1697 302 8894
-- 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);


--
-- TOC entry 8731 (class 2618 OID 146571932)
-- Dependencies: 303 303 303 303 303 303 303 303 303 303 303 262 303 8894
-- 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));


--
-- TOC entry 8732 (class 2618 OID 146571934)
-- Dependencies: 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 206 2162 1721 1714 1707 1706 1705 1703 1680 1670 308 8894
-- 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));


--
-- TOC entry 8733 (class 2618 OID 146571936)
-- Dependencies: 309 309 309 309 237 1708 1665 309 8894
-- 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);


--
-- TOC entry 8734 (class 2618 OID 146571937)
-- Dependencies: 310 310 310 310 310 310 310 240 1708 1669 910 310 8894
-- 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));


--
-- TOC entry 8735 (class 2618 OID 146571938)
-- Dependencies: 311 311 311 311 245 1708 311 8894
-- 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);


--
-- TOC entry 8736 (class 2618 OID 146571939)
-- Dependencies: 312 312 312 2165 1708 1702 312 8894
-- 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;


--
-- TOC entry 8737 (class 2618 OID 146571940)
-- Dependencies: 228 228 1829 228 8894
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO invoice DO INSTEAD SELECT public.insertinvoice(new.*) AS insertinvoice;


--
-- TOC entry 8738 (class 2618 OID 146571941)
-- Dependencies: 230 230 1830 230 8894
-- Name: _INSERT; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_INSERT" AS ON INSERT TO invoiceline DO INSTEAD SELECT public.insertinvoicelineitem(new.*) AS insertinvoicelineitem;


--
-- TOC entry 8739 (class 2618 OID 146571942)
-- Dependencies: 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 191 1771 1738 1666 315 8894
-- 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);


--
-- TOC entry 8740 (class 2618 OID 146571944)
-- Dependencies: 317 317 317 317 317 317 317 316 1714 317 8894
-- 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) 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);


--
-- TOC entry 8741 (class 2618 OID 146571945)
-- Dependencies: 318 318 318 318 318 237 1714 1665 318 8894
-- 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));


--
-- TOC entry 8742 (class 2618 OID 146571946)
-- Dependencies: 319 319 319 319 319 319 240 1714 1669 910 319 8894
-- 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);


--
-- TOC entry 8743 (class 2618 OID 146571947)
-- Dependencies: 322 322 322 322 322 322 1831 1714 1681 1679 322 8894
-- 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;


--
-- TOC entry 8744 (class 2618 OID 146571948)
-- Dependencies: 323 323 323 323 245 1714 323 8894
-- 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);


--
-- TOC entry 8745 (class 2618 OID 146571949)
-- Dependencies: 324 324 324 324 2165 1714 1702 324 8894
-- 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;


--
-- TOC entry 8746 (class 2618 OID 146571950)
-- Dependencies: 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 192 1780 1732 1693 1716 1714 1678 1547 327 8894
-- 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);


--
-- TOC entry 8747 (class 2618 OID 146571952)
-- Dependencies: 328 328 328 328 328 328 328 240 1716 1669 910 328 8894
-- 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);


--
-- TOC entry 8748 (class 2618 OID 146571953)
-- Dependencies: 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 330 1778 1714 1677 1676 1675 331 8894
-- 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));


--
-- TOC entry 8749 (class 2618 OID 146571955)
-- Dependencies: 333 333 333 333 333 333 333 333 333 333 333 332 1780 1718 1681 333 8894
-- 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);


--
-- TOC entry 8750 (class 2618 OID 146571957)
-- Dependencies: 335 335 335 335 335 334 1714 335 8894
-- 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));


--
-- TOC entry 8751 (class 2618 OID 146571958)
-- Dependencies: 337 337 337 337 336 1768 1767 1714 337 8894
-- 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));


--
-- TOC entry 8752 (class 2618 OID 146571959)
-- Dependencies: 339 339 339 339 339 339 339 339 191 191 2172 1774 1771 1714 339 8894
-- 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;


--
-- TOC entry 8753 (class 2618 OID 146571960)
-- Dependencies: 341 341 341 341 341 341 341 341 1820 1700 1681 1384 341 8894
-- 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;


--
-- TOC entry 8754 (class 2618 OID 146571961)
-- Dependencies: 344 344 344 344 344 344 344 344 344 344 342 1781 1780 344 8894
-- 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_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), public.getwhsezoneid((new.site)::text, new.zone), COALESCE(new.aisle, ''::character varying), COALESCE(new.rack, ''::character varying), COALESCE(new.bin, ''::character varying));


--
-- TOC entry 8755 (class 2618 OID 146571962)
-- Dependencies: 345 825 825 825 345 345 345 345 193 193 2030 1716 910 345 8894
-- 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;


--
-- TOC entry 8756 (class 2618 OID 146571963)
-- Dependencies: 346 632 346 346 346 346 346 301 1681 907 346 8894
-- 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());


--
-- TOC entry 8757 (class 2618 OID 146571964)
-- Dependencies: 348 348 348 348 348 348 348 347 1756 1684 1686 1682 348 8894
-- 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);


--
-- TOC entry 8758 (class 2618 OID 146571965)
-- Dependencies: 350 350 350 350 350 350 350 350 350 350 350 350 2164 2167 1771 1738 1714 1684 350 8894
-- 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";


--
-- TOC entry 8759 (class 2618 OID 146571967)
-- Dependencies: 352 352 352 352 352 352 352 352 352 351 1712 1665 352 8894
-- 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));


--
-- TOC entry 8760 (class 2618 OID 146571968)
-- Dependencies: 353 353 353 353 353 353 353 353 353 353 353 353 353 353 225 910 353 8894
-- 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);


--
-- TOC entry 8761 (class 2618 OID 146571970)
-- Dependencies: 354 354 354 354 354 354 240 1736 1669 910 354 8894
-- 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);


--
-- TOC entry 8762 (class 2618 OID 146571971)
-- Dependencies: 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 357 356 2162 2158 1780 1768 1749 1670 1658 357 8894
-- 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));


--
-- TOC entry 8763 (class 2618 OID 146571973)
-- Dependencies: 360 360 360 360 360 360 360 360 360 360 360 360 360 360 360 360 360 360 360 198 197 197 193 193 1742 1736 1733 1716 1691 1551 360 8894
-- 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));


--
-- TOC entry 8764 (class 2618 OID 146571975)
-- Dependencies: 361 361 361 361 361 237 237 237 236 236 198 198 198 198 197 197 192 192 191 2281 361 8894
-- 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));


--
-- TOC entry 8765 (class 2618 OID 146571977)
-- Dependencies: 362 362 362 362 362 362 362 240 198 198 198 197 197 1669 910 362 8894
-- 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));


--
-- TOC entry 8766 (class 2618 OID 146571979)
-- Dependencies: 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 365 210 210 210 210 210 210 210 197 193 193 1780 1778 1777 1769 1768 1681 1672 1670 1658 1551 910 365 8894
-- 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));


--
-- TOC entry 8767 (class 2618 OID 146571981)
-- Dependencies: 366 366 366 366 366 366 240 1733 1669 910 366 8894
-- 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);


--
-- TOC entry 8768 (class 2618 OID 146571982)
-- Dependencies: 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 368 367 1780 1769 1768 1767 1759 1756 1751 1749 1736 1700 1683 1681 368 8894
-- 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));


--
-- TOC entry 8769 (class 2618 OID 146571984)
-- Dependencies: 369 369 369 369 369 369 240 1720 1669 910 369 8894
-- 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);


--
-- TOC entry 8770 (class 2618 OID 146571985)
-- Dependencies: 371 825 825 825 371 371 371 371 371 371 371 371 371 371 371 371 371 371 371 370 370 370 367 367 367 367 367 367 193 193 193 193 192 192 192 192 191 191 191 191 2234 1902 1888 1780 1771 1767 1720 1714 911 910 371 8894
-- 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)))))));


--
-- TOC entry 8771 (class 2618 OID 146571987)
-- Dependencies: 372 372 372 372 372 370 370 370 370 367 367 237 237 237 236 236 192 192 191 2281 372 8894
-- 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));


--
-- TOC entry 8772 (class 2618 OID 146571989)
-- Dependencies: 373 373 373 373 373 373 373 240 1740 1669 910 373 8894
-- 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);


--
-- TOC entry 8773 (class 2618 OID 146571990)
-- Dependencies: 375 375 375 375 375 375 374 1681 1672 1660 375 8894
-- 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));


--
-- TOC entry 8774 (class 2618 OID 146571991)
-- Dependencies: 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 376 1768 1767 1756 1749 1716 1700 1682 1681 907 380 8894
-- 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));


--
-- TOC entry 8775 (class 2618 OID 146571993)
-- Dependencies: 381 381 381 381 381 237 237 237 236 236 196 196 196 196 195 195 195 195 195 195 192 192 191 2282 1876 1674 381 8894
-- 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));


--
-- TOC entry 8776 (class 2618 OID 146571995)
-- Dependencies: 382 382 382 382 382 382 382 240 1674 1669 910 382 8894
-- 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);


--
-- TOC entry 8777 (class 2618 OID 146571996)
-- Dependencies: 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 383 213 195 1780 1769 1768 1759 1756 1754 1753 1751 1749 1736 1700 1682 1681 1670 1545 383 8894
-- 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);


--
-- TOC entry 8778 (class 2618 OID 146571998)
-- Dependencies: 384 384 384 384 384 384 240 1748 1669 910 384 8894
-- 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);


--
-- TOC entry 8779 (class 2618 OID 146571999)
-- Dependencies: 385 385 385 385 385 385 216 1690 385 8894
-- 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));


--
-- TOC entry 8780 (class 2618 OID 146572000)
-- Dependencies: 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 388 193 2162 2158 1768 1760 1758 1754 1700 1678 1670 1658 1547 388 8894
-- 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));


--
-- TOC entry 8781 (class 2618 OID 146572002)
-- Dependencies: 389 389 389 389 343 1780 389 8894
-- 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));


--
-- TOC entry 8782 (class 2618 OID 146572003)
-- Dependencies: 390 390 390 390 390 390 390 390 390 390 390 390 390 390 390 390 232 1736 910 390 8894
-- 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);


--
-- TOC entry 8783 (class 2618 OID 146572005)
-- Dependencies: 391 391 391 391 391 391 391 240 1737 1669 910 391 8894
-- 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);


--
-- TOC entry 8784 (class 2618 OID 146572006)
-- Dependencies: 392 392 392 392 392 392 392 392 392 392 392 392 392 392 392 1724 1708 1705 1704 1680 1350 392 8894
-- 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;


--
-- TOC entry 8785 (class 2618 OID 146572008)
-- Dependencies: 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 394 210 2162 2158 1779 1769 1768 1766 1700 1691 1681 1670 1658 1547 1539 907 394 8894
-- 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)));


--
-- TOC entry 8786 (class 2618 OID 146572010)
-- Dependencies: 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 395 364 2162 2158 1778 1670 1658 395 8894
-- 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));


--
-- TOC entry 8787 (class 2618 OID 146572012)
-- Dependencies: 396 396 396 393 396 8894
-- 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));


--
-- TOC entry 8788 (class 2618 OID 146572013)
-- Dependencies: 360 360 360 237 237 237 237 237 236 198 198 198 198 197 197 192 192 191 360 8894
-- 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));


--
-- TOC entry 8789 (class 2618 OID 146572015)
-- Dependencies: 201 201 201 201 201 201 201 201 201 201 201 201 201 201 201 201 201 201 201 196 196 196 192 192 191 191 191 191 191 1902 1771 1767 1714 1700 1674 1672 201 8894
-- 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));


--
-- TOC entry 8790 (class 2618 OID 146572017)
-- Dependencies: 211 211 211 211 211 211 211 207 207 1769 211 8894
-- 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));


--
-- TOC entry 8791 (class 2618 OID 146572018)
-- Dependencies: 217 217 217 217 217 217 217 217 217 217 212 212 1769 1749 1743 217 8894
-- 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));


--
-- TOC entry 8792 (class 2618 OID 146572020)
-- Dependencies: 194 194 194 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO physinvcount DO INSTEAD NOTHING;


--
-- TOC entry 8793 (class 2618 OID 146572021)
-- Dependencies: 235 235 235 235 235 235 235 235 235 205 1680 1670 235 8894
-- 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);


--
-- TOC entry 8794 (class 2618 OID 146572023)
-- Dependencies: 238 238 238 238 237 237 237 1680 1665 238 8894
-- 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)));


--
-- TOC entry 8795 (class 2618 OID 146572024)
-- Dependencies: 241 241 241 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO accountcomment DO INSTEAD NOTHING;


--
-- TOC entry 8796 (class 2618 OID 146572025)
-- Dependencies: 246 246 246 246 245 245 245 245 1680 246 8894
-- 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));


--
-- TOC entry 8797 (class 2618 OID 146572026)
-- Dependencies: 250 250 250 249 249 249 1702 1680 250 8894
-- 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)));


--
-- TOC entry 8798 (class 2618 OID 146572027)
-- Dependencies: 251 251 251 251 251 251 251 251 251 251 251 251 2157 1658 251 8894
-- 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;


--
-- TOC entry 8799 (class 2618 OID 146572028)
-- Dependencies: 252 252 252 252 237 237 237 1665 1658 252 8894
-- 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)));


--
-- TOC entry 8800 (class 2618 OID 146572029)
-- Dependencies: 253 253 253 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO addresscomment DO INSTEAD NOTHING;


--
-- TOC entry 8801 (class 2618 OID 146572030)
-- Dependencies: 255 255 255 255 255 255 255 2160 1714 255 8894
-- 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;


--
-- TOC entry 8802 (class 2618 OID 146572031)
-- Dependencies: 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 256 203 2233 1771 1742 1665 1650 1519 256 8894
-- 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);


--
-- TOC entry 8803 (class 2618 OID 146572033)
-- Dependencies: 257 257 257 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO bomitemcomment DO INSTEAD NOTHING;


--
-- TOC entry 8804 (class 2618 OID 146572034)
-- Dependencies: 259 259 259 259 259 258 258 1714 259 8894
-- 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)));


--
-- TOC entry 8805 (class 2618 OID 146572035)
-- Dependencies: 261 261 261 260 261 8894
-- 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);


--
-- TOC entry 8806 (class 2618 OID 146572036)
-- Dependencies: 265 265 265 265 265 263 263 263 1730 1700 1663 265 8894
-- 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)));


--
-- TOC entry 8807 (class 2618 OID 146572037)
-- Dependencies: 268 268 268 268 268 268 268 268 268 268 268 268 267 1744 1681 1664 1661 268 8894
-- 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));


--
-- TOC entry 8808 (class 2618 OID 146572039)
-- Dependencies: 270 270 270 270 270 270 270 270 269 269 1664 1660 270 8894
-- 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)));


--
-- TOC entry 8809 (class 2618 OID 146572041)
-- Dependencies: 272 272 272 272 272 272 272 271 271 1700 1664 272 8894
-- 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)));


--
-- TOC entry 8810 (class 2618 OID 146572043)
-- Dependencies: 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 273 2161 2158 1680 1670 1658 273 8894
-- 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;


--
-- TOC entry 8811 (class 2618 OID 146572044)
-- Dependencies: 274 274 274 274 237 237 237 1670 1665 274 8894
-- 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)));


--
-- TOC entry 8812 (class 2618 OID 146572045)
-- Dependencies: 275 275 275 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO contactcomment DO INSTEAD NOTHING;


--
-- TOC entry 8813 (class 2618 OID 146572046)
-- Dependencies: 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 221 218 218 214 214 1768 1756 1749 1700 1681 221 8894
-- 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));


--
-- TOC entry 8814 (class 2618 OID 146572048)
-- Dependencies: 223 223 2287 223 8894
-- 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;


--
-- TOC entry 8815 (class 2618 OID 146572049)
-- Dependencies: 276 276 276 276 237 237 237 1682 1665 276 8894
-- 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)));


--
-- TOC entry 8816 (class 2618 OID 146572050)
-- Dependencies: 277 277 277 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO custcomment DO INSTEAD NOTHING;


--
-- TOC entry 8817 (class 2618 OID 146572051)
-- Dependencies: 279 279 279 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO custcreditcard DO INSTEAD NOTHING;


--
-- TOC entry 8818 (class 2618 OID 146572052)
-- Dependencies: 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 283 213 2162 2158 1780 1769 1768 1754 1753 1749 1686 1682 1681 1671 1658 283 8894
-- 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));


--
-- TOC entry 8819 (class 2618 OID 146572054)
-- Dependencies: 287 287 287 287 280 287 8894
-- 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);


--
-- TOC entry 8820 (class 2618 OID 146572055)
-- Dependencies: 288 288 288 288 288 237 237 237 1686 1665 288 8894
-- 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)));


--
-- TOC entry 8821 (class 2618 OID 146572056)
-- Dependencies: 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 219 2162 2158 1768 1759 1756 1754 1753 1749 1688 1682 1670 1658 289 8894
-- 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));


--
-- TOC entry 8822 (class 2618 OID 146572058)
-- Dependencies: 290 290 290 290 285 285 285 1765 1682 290 8894
-- 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)));


--
-- TOC entry 8823 (class 2618 OID 146572059)
-- Dependencies: 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 294 292 292 2162 2158 1780 1752 1702 1687 1681 1670 1658 907 294 8894
-- 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);


--
-- TOC entry 8824 (class 2618 OID 146572061)
-- Dependencies: 295 295 295 295 237 237 237 1690 1665 295 8894
-- 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)));


--
-- TOC entry 8825 (class 2618 OID 146572062)
-- Dependencies: 296 296 296 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO employeecomment DO INSTEAD NOTHING;


--
-- TOC entry 8826 (class 2618 OID 146572063)
-- Dependencies: 298 298 298 298 298 298 298 298 298 298 298 298 298 298 298 297 297 297 297 1681 298 8894
-- 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));


--
-- TOC entry 8827 (class 2618 OID 146572064)
-- Dependencies: 302 302 302 302 302 302 302 302 302 300 300 300 300 300 300 300 300 1780 1759 1684 1697 302 8894
-- 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));


--
-- TOC entry 8828 (class 2618 OID 146572066)
-- Dependencies: 303 303 303 303 303 303 303 303 303 303 303 262 1701 303 8894
-- 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));


--
-- TOC entry 8829 (class 2618 OID 146572068)
-- Dependencies: 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 308 206 2162 1721 1714 1708 1707 1706 1705 1703 1680 1670 308 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO incident DO INSTEAD UPDATE public.incdt SET incdt_crmacct_id = public.getcrmacctid(new.crm_account), incdt_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), incdt_descrip = new.notes, incdt_summary = new.description, incdt_item_id = public.getitemid(new.item_number), incdt_status = 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 NULL::text END, incdt_assigned_username = new.assigned_to, incdt_incdtcat_id = public.getincdtcatid(new.category), incdt_incdtseverity_id = public.getincdtseverityid(new.severity), incdt_incdtpriority_id = public.getincdtpriorityid(new.priority), incdt_incdtresolution_id = public.getincdtresolutionid(new.resolution), incdt_lotserial = new.lot_serial_number, incdt_ls_id = public.getlotserialid(new.item_number, new.lot_serial_number) WHERE (incdt.incdt_id = public.getincidentid(old.incident_number));


--
-- TOC entry 8830 (class 2618 OID 146572070)
-- Dependencies: 309 309 309 309 237 237 237 1708 1665 309 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO incidentchar DO INSTEAD UPDATE public.charass SET charass_value = new.value 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)));


--
-- TOC entry 8831 (class 2618 OID 146572071)
-- Dependencies: 310 310 310 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO incidentcomment DO INSTEAD NOTHING;


--
-- TOC entry 8832 (class 2618 OID 146572072)
-- Dependencies: 311 311 311 311 245 245 245 245 1708 311 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO incidentfile DO INSTEAD UPDATE public.url SET url_title = new.title, url_url = new.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));


--
-- TOC entry 8833 (class 2618 OID 146572073)
-- Dependencies: 312 312 312 249 249 249 1708 1702 312 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO incidentimage DO INSTEAD UPDATE public.imageass SET imageass_image_id = public.getimageid(new.image_name) 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)));


--
-- TOC entry 8834 (class 2618 OID 146572074)
-- Dependencies: 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 228 224 224 1769 1768 1759 1756 1751 1749 1736 1700 1682 1681 228 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO invoice DO INSTEAD UPDATE public.invchead SET invchead_invcnumber = old.invoice_number, invchead_ordernumber = new.order_number, invchead_invcdate = new.invoice_date, invchead_shipdate = new.ship_date, invchead_orderdate = new.order_date, invchead_salesrep_id = public.getsalesrepid(new.sales_rep), invchead_commission = new.commission, invchead_taxzone_id = public.gettaxzoneid(NULLIF(new.tax_zone, 'None'::text)), invchead_terms_id = public.gettermsid(new.terms), invchead_cust_id = (SELECT public.getcustid(new.customer_number) AS getcustid), invchead_billto_name = new.billto_name, invchead_billto_address1 = new.billto_address1, invchead_billto_address2 = new.billto_address2, invchead_billto_address3 = new.billto_address3, invchead_billto_city = new.billto_city, invchead_billto_state = new.billto_state, invchead_billto_zipcode = new.billto_postal_code, invchead_billto_country = new.billto_country, invchead_billto_phone = new.billto_phone, invchead_shipto_id = COALESCE(public.getshiptoid(new.customer_number, new.shipto_number), (-1)), invchead_shipto_name = new.shipto_name, invchead_shipto_address1 = new.shipto_address1, invchead_shipto_address2 = new.shipto_address2, invchead_shipto_address3 = new.shipto_address3, invchead_shipto_city = new.shipto_city, invchead_shipto_state = new.shipto_state, invchead_shipto_zipcode = new.shipto_postal_code, invchead_shipto_country = new.shipto_country, invchead_shipto_phone = new.shipto_phone, invchead_ponumber = new.po_number, invchead_shipvia = new.ship_via, invchead_prj_id = COALESCE(public.getprjid(new.project_number), (-1)), invchead_fob = new.fob, invchead_misc_descrip = new.misc_charge_description, invchead_misc_amount = new.misc_charge, invchead_misc_accnt_id = COALESCE(public.getglaccntid(new.misc_charge_account_number), (-1)), invchead_freight = new.freight, invchead_curr_id = COALESCE(public.getcurrid((new.currency)::text), (-1)), invchead_payment = new.payment, invchead_notes = new.notes, invchead_saletype_id = public.getsaletypeid(new.sale_type), invchead_shipzone_id = public.getshipzoneid(new.shipto_shipzone) WHERE ((invchead.invchead_invcnumber = old.invoice_number) AND (invchead.invchead_posted = false));


--
-- TOC entry 8835 (class 2618 OID 146572076)
-- Dependencies: 230 230 2291 230 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO invoiceline DO INSTEAD SELECT public.updateinvoicelineitem(new.*, old.*) AS updateinvoicelineitem;


--
-- TOC entry 8836 (class 2618 OID 146572077)
-- Dependencies: 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 315 191 1771 1738 1714 1666 315 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO item DO INSTEAD UPDATE public.item SET item_active = new.active, item_descrip1 = new.description1, item_descrip2 = new.description2, item_type = 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, item_maxcost = new.maximum_desired_cost, item_classcode_id = public.getclasscodeid(new.class_code), item_inv_uom_id = public.getuomid(new.inventory_uom), item_picklist = new.pick_list_item, item_fractional = new.fractional, item_config = new.configured, item_sold = new.item_is_sold, item_prodcat_id = COALESCE(public.getprodcatid(new.product_category), (-1)), item_exclusive = new.exclusive, item_listprice = new.list_price, item_listcost = new.list_cost, item_price_uom_id = public.getuomid(new.list_price_uom), item_upccode = new.upc_code, item_prodweight = new.product_weight, item_packweight = new.packaging_weight, item_comments = new.notes, item_extdescrip = new.ext_description WHERE (item.item_id = public.getitemid((old.item_number)::text));


--
-- TOC entry 8837 (class 2618 OID 146572079)
-- Dependencies: 317 317 317 317 317 317 317 316 316 1714 317 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemalias DO INSTEAD UPDATE public.itemalias SET itemalias_number = new.alias_number, itemalias_usedescrip = new.use_description, itemalias_descrip1 = new.description1, itemalias_descrip2 = new.description2, itemalias_comments = new.comments WHERE ((itemalias.itemalias_item_id = public.getitemid((old.item_number)::text)) AND (itemalias.itemalias_number = old.alias_number));


--
-- TOC entry 8838 (class 2618 OID 146572080)
-- Dependencies: 318 318 318 318 318 237 237 237 1714 1665 318 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemchar DO INSTEAD UPDATE public.charass SET charass_value = new.value, charass_default = new.is_default 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)));


--
-- TOC entry 8839 (class 2618 OID 146572081)
-- Dependencies: 319 319 319 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemcomment DO INSTEAD NOTHING;


--
-- TOC entry 8840 (class 2618 OID 146572082)
-- Dependencies: 322 322 322 322 322 322 2292 1714 1681 1679 322 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemcost DO INSTEAD SELECT public.updateitemcost(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 updateitemcost;


--
-- TOC entry 8841 (class 2618 OID 146572083)
-- Dependencies: 323 323 323 323 245 245 245 245 1714 323 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemfile DO INSTEAD UPDATE public.url SET url_title = new.title, url_url = new.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));


--
-- TOC entry 8842 (class 2618 OID 146572084)
-- Dependencies: 324 324 324 324 2165 1714 1702 324 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE 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;


--
-- TOC entry 8843 (class 2618 OID 146572085)
-- Dependencies: 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 327 192 1732 1693 1716 1678 327 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemsite DO INSTEAD UPDATE public.itemsite SET itemsite_active = new.active, itemsite_dropship = new.dropship, itemsite_posupply = new.po_supplied_at_site, itemsite_createpr = new.create_prs, itemsite_wosupply = new.wo_supplied_at_site, itemsite_createwo = new.create_wos, itemsite_createsopr = new.create_soprs, itemsite_createsopo = new.create_sopos, itemsite_sold = new.sold_from_site, itemsite_soldranking = new.ranking, itemsite_costmethod = 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, itemsite_controlmethod = 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, itemsite_perishable = new.perishable, itemsite_plancode_id = public.getplancodeid(new.planner_code), itemsite_costcat_id = public.getcostcatid(new.cost_category), itemsite_loccntrl = new.multiple_location_control, itemsite_location_id = CASE WHEN (new.location = 'N/A'::text) THEN (-1) ELSE public.getlocationid((new.site)::text, new.location) END, itemsite_recvlocation_id = CASE WHEN (new.receive_location = 'N/A'::text) THEN (-1) ELSE public.getlocationid((new.site)::text, new.receive_location) END, itemsite_issuelocation_id = CASE WHEN (new.issue_location = 'N/A'::text) THEN (-1) ELSE public.getlocationid((new.site)::text, new.issue_location) END, itemsite_location_dist = new.auto_distr_location, itemsite_recvlocation_dist = new.auto_distr_receive_location, itemsite_issuelocation_dist = new.auto_distr_issue_location, itemsite_location = new.user_defined_location, itemsite_location_comments = new.user_defined_location, itemsite_disallowblankwip = new.disallow_blank_wip_locations, itemsite_stocked = new.stocked, itemsite_abcclass = new.abc_class, itemsite_autoabcclass = new.allow_automatic_updates, itemsite_cyclecountfreq = new.cycl_cnt_freq, itemsite_eventfence = new.event_fence, itemsite_useparams = new.enforce_order_parameters, itemsite_reorderlevel = new.reorder_level, itemsite_ordertoqty = new.order_up_to, itemsite_minordqty = new.minimum_order, itemsite_maxordqty = new.maximum_order, itemsite_multordqty = new.order_multiple, itemsite_useparamsmanual = new.enforce_on_manual_orders, itemsite_ordergroup = new.group_mps_mrp_orders, itemsite_ordergroup_first = new.first_group, itemsite_mps_timefence = new.mps_time_fence, itemsite_leadtime = new.lead_time, itemsite_safetystock = new.safety_stock, itemsite_supply_itemsite_id = 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, itemsite_notes = new.notes, itemsite_warrpurc = new.require_warranty, itemsite_autoreg = new.auto_register, itemsite_planning_type = CASE WHEN (new.planning_system = 'None'::text) THEN 'N'::text WHEN (new.planning_system = 'MPS'::text) THEN 'S'::text ELSE 'M'::text END WHERE (itemsite.itemsite_id = public.getitemsiteid((old.site)::text, (old.item_number)::text));


--
-- TOC entry 8844 (class 2618 OID 146572087)
-- Dependencies: 328 328 328 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemsitecomment DO INSTEAD NOTHING;


--
-- TOC entry 8845 (class 2618 OID 146572088)
-- Dependencies: 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 331 330 330 330 330 330 1778 1714 1677 1676 1675 331 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemsource DO INSTEAD UPDATE public.itemsrc SET itemsrc_vend_item_number = new.vendor_item_number, itemsrc_vend_item_descrip = new.vendor_description, itemsrc_comments = new.notes, itemsrc_vend_uom = new.vendor_uom, itemsrc_invvendoruomratio = new.inventory_vendor_uom_ratio, itemsrc_minordqty = new.minimum_order, itemsrc_multordqty = new.order_multiple, itemsrc_leadtime = new.lead_time, itemsrc_ranking = new.vendor_ranking, itemsrc_active = new.active, itemsrc_default = new.itemsrc_default, itemsrc_manuf_name = new.manufacturer_name, itemsrc_manuf_item_number = new.manufacturer_item_number, itemsrc_manuf_item_descrip = new.manufacturer_description, itemsrc_upccode = new.bar_code, itemsrc_contrct_id = public.getcontrctid(new.contract_number), itemsrc_effective = COALESCE(public.getcontrcteffective(new.contract_number), new.effective_date), itemsrc_expires = COALESCE(public.getcontrctexpires(new.contract_number), new.expires_date) 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));


--
-- TOC entry 8846 (class 2618 OID 146572090)
-- Dependencies: 333 333 333 333 333 333 333 333 333 333 333 332 332 1780 1718 1681 333 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemsourceprice DO INSTEAD UPDATE public.itemsrcp SET itemsrcp_qtybreak = new.qty_break, itemsrcp_price = new.price_per_unit, itemsrcp_updated = now(), itemsrcp_curr_id = public.getcurrid((new.currency)::text), itemsrcp_dropship = COALESCE(new.dropship_only, false), itemsrcp_warehous_id = CASE WHEN (new.pricing_site = 'All'::text) THEN (-1) ELSE COALESCE(public.getwarehousid(new.pricing_site, 'ALL'::text), (-1)) END, itemsrcp_type = CASE WHEN (new.pricing_type = 'Discount'::text) THEN 'D'::text ELSE 'N'::text END, itemsrcp_discntprcnt = (COALESCE(new.discount_percent, 0.0) / 100.0), itemsrcp_fixedamtdiscount = new.discount_fixed_amount WHERE ((itemsrcp.itemsrcp_itemsrc_id = public.getitemsrcid((old.item_number)::text, (new.vendor)::text)) AND (itemsrcp.itemsrcp_qtybreak = old.qty_break));


--
-- TOC entry 8847 (class 2618 OID 146572092)
-- Dependencies: 335 335 335 335 335 334 334 1714 335 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemsubstitute DO INSTEAD UPDATE public.itemsub SET itemsub_uomratio = new.sub_parent_uom_ratio, itemsub_rank = new.ranking 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)));


--
-- TOC entry 8848 (class 2618 OID 146572093)
-- Dependencies: 337 337 337 337 336 336 336 1768 1767 1714 337 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO itemtaxtype DO INSTEAD UPDATE public.itemtax SET itemtax_taxzone_id = CASE WHEN ((new.tax_zone)::text = 'Any'::text) THEN NULL::integer ELSE public.gettaxzoneid((new.tax_zone)::text) END, itemtax_taxtype_id = public.gettaxtypeid(new.tax_type) 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)));


--
-- TOC entry 8849 (class 2618 OID 146572094)
-- Dependencies: 339 339 339 339 339 339 339 339 191 191 2172 1774 1771 1714 339 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE 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;


--
-- TOC entry 8850 (class 2618 OID 146572095)
-- Dependencies: 341 341 341 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO journalentry DO INSTEAD NOTHING;


--
-- TOC entry 8851 (class 2618 OID 146572096)
-- Dependencies: 344 344 344 344 344 344 344 344 344 344 342 342 1781 1780 344 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO location DO INSTEAD UPDATE public.location SET location_name = new.location, location_descrip = new.description, location_restrict = new.restricted, location_netable = new.netable, location_whsezone_id = public.getwhsezoneid((new.site)::text, new.zone), location_aisle = new.aisle, location_rack = new.rack, location_bin = new.bin WHERE ((location.location_warehous_id = public.getwarehousid((old.site)::text, 'ACTIVE'::text)) AND (location.location_name = (old.location)::text));


--
-- TOC entry 8852 (class 2618 OID 146572097)
-- Dependencies: 345 345 345 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO misccounttag DO INSTEAD NOTHING;


--
-- TOC entry 8853 (class 2618 OID 146572098)
-- Dependencies: 346 349 349 346 346 346 346 346 301 1684 1681 907 346 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO pricingschedule DO INSTEAD UPDATE public.ipshead SET ipshead_descrip = new.description, ipshead_effective = CASE WHEN (new.effective = 'Always'::text) THEN '1970-01-01'::date ELSE (new.effective)::date END, ipshead_expires = CASE WHEN (new.expires = 'Never'::text) THEN '2100-01-01'::date ELSE (new.expires)::date END, ipshead_updated = now(), ipshead_curr_id = CASE WHEN (SELECT (count(ipsiteminfo.ipsitem_id) = 0) FROM public.ipsiteminfo WHERE (ipsiteminfo.ipsitem_ipshead_id = public.getipsheadid((old.name)::text))) THEN COALESCE(public.getcurrid((new.currency)::text), public.basecurrid()) ELSE public.getcurrid((old.currency)::text) END WHERE (ipshead.ipshead_name = (old.name)::text);


--
-- TOC entry 8854 (class 2618 OID 146572100)
-- Dependencies: 348 348 348 348 348 348 348 347 347 347 347 347 347 1756 1684 1686 1682 348 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO pricingscheduleassign DO INSTEAD UPDATE public.ipsass SET ipsass_ipshead_id = public.getipsheadid((new.pricing_schedule)::text), ipsass_cust_id = CASE WHEN ((new.customer_number)::text = 'Any'::text) THEN (-1) ELSE public.getcustid((new.customer_number)::text) END, ipsass_custtype_id = CASE WHEN ((new.customer_type)::text = 'N/A'::text) THEN (-1) ELSE public.getcusttypeid((new.customer_type)::text) END, ipsass_custtype_pattern = new.customer_type_pattern, ipsass_shipto_id = 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, ipsass_shipto_pattern = new.customer_shipto_pattern 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));


--
-- TOC entry 8855 (class 2618 OID 146572102)
-- Dependencies: 350 350 350 350 350 350 350 350 350 350 350 350 2164 2167 1771 1738 1714 1713 1712 1684 350 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO pricingscheduleitem DO INSTEAD SELECT CASE WHEN ((old.type)::text = 'Item'::text) THEN public.saveipsitem(public.getipsitemid((old.pricing_schedule)::text, (old.item_number)::text, old.qty_break, (old.qty_uom)::text, (old.price_uom)::text), public.getipsheadid((new.pricing_schedule)::text), public.getitemid((new.item_number)::text), new.qty_break, new.price, 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 ((old.type)::text = 'Product Category'::text) THEN public.saveipsprodcat(public.getipsprodcatid((old.pricing_schedule)::text, (old.product_category)::text, old.qty_break), 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 result;


--
-- TOC entry 8856 (class 2618 OID 146572104)
-- Dependencies: 352 352 352 352 352 352 352 352 352 351 351 351 1712 1665 352 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO pricingscheduleitemchar DO INSTEAD UPDATE public.ipsitemchar SET ipsitemchar_price = new.price 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));


--
-- TOC entry 8857 (class 2618 OID 146572105)
-- Dependencies: 353 353 353 353 353 353 353 353 353 353 353 353 353 353 225 353 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO project DO INSTEAD UPDATE public.prj SET prj_name = new.name, prj_descrip = new.description, prj_owner_username = new.owner, prj_username = new.assigned_to, prj_so = new.sales_orders, prj_wo = new.work_orders, prj_po = new.purchase_orders, prj_status = CASE WHEN (new.status = 'In-Process'::text) THEN 'O'::text WHEN (new.status = 'Completed'::text) THEN 'C'::text ELSE 'P'::text END, prj_due_date = new.due, prj_assigned_date = new.assigned, prj_start_date = new.started, prj_completed_date = new.completed WHERE (prj.prj_number = old.number);


--
-- TOC entry 8858 (class 2618 OID 146572106)
-- Dependencies: 354 354 354 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO projectcomment DO INSTEAD NOTHING;


--
-- TOC entry 8859 (class 2618 OID 146572107)
-- Dependencies: 357 357 357 357 357 357 357 357 357 356 1780 1768 1749 1739 1670 357 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO prospect DO INSTEAD UPDATE public.prospect SET prospect_number = upper((new.prospect_number)::text), prospect_name = new.prospect_name, prospect_active = new.active, prospect_cntct_id = public.getcntctid(new.contact_number), prospect_taxzone_id = public.gettaxzoneid(new.default_tax_zone), prospect_salesrep_id = public.getsalesrepid(new.sales_rep), prospect_warehous_id = public.getwarehousid(new.site_code, 'ACTIVE'::text), prospect_comments = new.notes WHERE (prospect.prospect_id = public.getprospectid((old.prospect_number)::text));


--
-- TOC entry 8860 (class 2618 OID 146572108)
-- Dependencies: 360 360 360 360 360 360 360 360 360 360 360 360 360 360 360 360 360 198 1742 1736 1734 360 8894
-- Name: _UPDATE; Type: RULE; Schema: api; Owner: admin
--

CREATE RULE "_UPDATE" AS ON UPDATE TO purchaseline DO INSTEAD UPDATE public.poitem SET poitem_duedate = new.due_date, poitem_qty_ordered = new.qty_ordered, poitem_unitprice = new.unit_price, poitem_vend_item_number = new.vend_item_number, poitem_vend_item_descrip = new.vendor_description, poitem_manuf_name = new.manufacturer_name, poitem_manuf_item_number = new.manufacturer_item_number, poitem_manuf_item_descrip = new.manufacturer_description, poitem_comments = new.notes, poitem_freight = new.freight, poitem_prj_id = public.getprjid(new.project_number), poitem_bom_rev_id = public.getrevid('BOM'::text, old.item_number, new.bill_of_materials_revision), poitem_boo_rev_id = public.getrevid('BOO'::text, old.item_number, new.bill_of_operations_revision) WHERE (poitem.poitem_id = public.getpoitemid((old.order_number)::text, old.line_number));


--
-- TOC entry 8861 (class 2618 OID 146572110)
-- Dependencies: 361 361 361 361 361 237 237 237 236 236 198 198 198 198 197 197 192 192 191 2281 361 8894
