--
--

\connect - postgres


--
-- TOC entry 2 (OID 17150)
-- Name: master_fpp_values; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE master_fpp_values (
    fpp_code text NOT NULL,
    brn_code text NOT NULL,
    sku text NOT NULL,
    group_code text NOT NULL,
    stktype_code character varying(2),
    supplier_code text,
    mth_sls_qty_01 numeric(16,3),
    mth_sls_qty_02 numeric(16,3),
    mth_sls_qty_03 numeric(16,3),
    mth_sls_qty_04 numeric(16,3),
    mth_sls_qty_05 numeric(16,3),
    mth_sls_qty_06 numeric(16,3),
    mth_sls_qty_07 numeric(16,3),
    mth_sls_qty_08 numeric(16,3),
    mth_sls_qty_09 numeric(16,3),
    mth_sls_qty_10 numeric(16,3),
    mth_sls_qty_11 numeric(16,3),
    mth_sls_qty_12 numeric(16,3),
    qty_on_hand_01 numeric(16,3),
    qty_on_hand_02 numeric(16,3),
    qty_on_hand_03 numeric(16,3),
    qty_on_hand_04 numeric(16,3),
    qty_on_hand_05 numeric(16,3),
    qty_on_hand_06 numeric(16,3),
    qty_on_hand_07 numeric(16,3),
    qty_on_hand_08 numeric(16,3),
    qty_on_hand_09 numeric(16,3),
    qty_on_hand_10 numeric(16,3),
    qty_on_hand_11 numeric(16,3),
    qty_on_hand_12 numeric(16,3),
    mth_sls_cst numeric(16,3),
    mth_sls_disc numeric(16,3),
    mth_sls_nett_excl numeric(16,3),
    mth_qty_on_hand_cst numeric(16,3),
    mth_sls_qty_und numeric(16,3),
    qty_in_goods numeric(16,3),
    mat_sls_qty numeric(16,3),
    ytd_sls_qty numeric(16,3),
    mat_sls_cst numeric(16,3),
    ytd_sls_cst numeric(16,3),
    mat_sls_disc numeric(16,3),
    ytd_sls_disc numeric(16,3),
    mat_sls_nett_excl numeric(16,3),
    ytd_sls_nett_excl numeric(16,3),
    ly_mth_sls_nett_excl numeric(16,3),
    ly_ytd_sls_nett_excl numeric(16,3),
    stk_turn_qty_on_hand_cst numeric(16,3),
    no_mths_history integer DEFAULT 0,
    current_orders integer,
    overdue_orders integer
);


--
-- TOC entry 3 (OID 8022421)
-- Name: master_fpp_values_idx1; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX master_fpp_values_idx1 ON master_fpp_values USING btree (sku);


--
-- TOC entry 4 (OID 8022439)
-- Name: master_fpp_values_idx2; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX master_fpp_values_idx2 ON master_fpp_values USING btree (group_code, brn_code, sku);


--
-- TOC entry 5 (OID 8022440)
-- Name: master_fpp_values_idx3; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX master_fpp_values_idx3 ON master_fpp_values USING btree (fpp_code);


--
-- TOC entry 6 (OID 8022442)
-- Name: master_fpp_values_idx4; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX master_fpp_values_idx4 ON master_fpp_values USING btree (fpp_code, sku);


--
-- TOC entry 7 (OID 8022443)
-- Name: master_fpp_values_idx5; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX master_fpp_values_idx5 ON master_fpp_values USING btree (brn_code);


--
-- TOC entry 8 (OID 8022617)
-- Name: master_fpp_values_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY master_fpp_values
    ADD CONSTRAINT master_fpp_values_pk PRIMARY KEY (fpp_code, brn_code, sku);


--
-- TOC entry 12 (OID 8022619)
-- Name: master_fpp_values_fk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY master_fpp_values
    ADD CONSTRAINT master_fpp_values_fk FOREIGN KEY (group_code, sku) REFERENCES item(group_code, sku) ON UPDATE NO ACTION ON DELETE NO ACTION;


--
-- TOC entry 11 (OID 8022669)
-- Name: master_fpp_values_uidx3; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY master_fpp_values
    ADD CONSTRAINT master_fpp_values_uidx3 UNIQUE (brn_code, fpp_code, sku);


--
-- TOC entry 10 (OID 8022671)
-- Name: master_fpp_values_uidx2; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY master_fpp_values
    ADD CONSTRAINT master_fpp_values_uidx2 UNIQUE (fpp_code, brn_code, sku);


--
-- TOC entry 9 (OID 8022673)
-- Name: master_fpp_values_uidx1; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY master_fpp_values
    ADD CONSTRAINT master_fpp_values_uidx1 UNIQUE (fpp_code, brn_code, sku, group_code);


