--
--

\connect - alpha_dba


--
-- TOC entry 2 (OID 17290)
-- Name: impr_out; Type: TABLE; Schema: public; Owner: alpha_dba
--

CREATE TABLE impr_out (
    impo_sid integer DEFAULT nextval('SEQ_IMPR_OUT_IMPO_SID'::text) NOT NULL,
    impo_crt_erg_errand integer NOT NULL,
    impo_crt_erg_ord_number smallint NOT NULL,
    impo_crt_used_cdt integer NOT NULL,
    impo_store_note_in integer NOT NULL,
    impo_ord_number_in smallint NOT NULL,
    impo_quantity numeric(17,3) NOT NULL
);



ALTER TABLE ONLY impr_out
    ADD CONSTRAINT impr_out_pk PRIMARY KEY (impo_sid);




CREATE TABLE impr_out_waste (
    impow_sid integer DEFAULT nextval('SEQ_IMPR_OUT_WASTE_IMPOW_SID'::text) NOT NULL,
    impow_crt_erg_errand integer NOT NULL,
    impow_crt_erg_ord_number smallint NOT NULL,
    impow_crt_used_cdt integer NOT NULL,
    impow_store_note_in integer NOT NULL,
    impow_ord_number_in smallint NOT NULL,
    impow_quantity numeric(17,3) NOT NULL,
    impow_iwnog_impr_note_out integer
);


--
-- TOC entry 3 (OID 17300)
-- Name: impr_out_waste_pk; Type: CONSTRAINT; Schema: public; Owner: alpha_dba
--

ALTER TABLE ONLY impr_out_waste
    ADD CONSTRAINT impr_out_waste_pk PRIMARY KEY (impow_sid);



CREATE TABLE impr_waste_note_out_goods (
    iwnog_impr_note_out integer NOT NULL,
    iwnog_store_note_in integer NOT NULL,
    iwnog_ord_number_in smallint NOT NULL,
    iwnog_cg_number smallint,
    iwnog_quantity numeric(15,3) NOT NULL,
    iwnog_price numeric(15,3)
);




ALTER TABLE ONLY impr_waste_note_out_goods
    ADD CONSTRAINT impr_waste_note_out_goods_pk PRIMARY KEY (iwnog_impr_note_out, iwnog_store_note_in, iwnog_ord_number_in);


CREATE TABLE store_note_in (
    sni_sid integer NOT NULL,
    sni_number integer NOT NULL,
    sni_store integer,
    sni_inv_number character(20),
    sni_inv_date date,
    sni_currency integer,
    sni_sender_id integer,
    sni_receiver_id integer,
    sni_num_rows smallint,
    sni_sender character varying(250),
    sni_receiver character varying(250),
    sni_type_doc integer NOT NULL,
    sni_transport numeric(12,0),
    sni_impr_permit integer
);


--
-- TOC entry 3 (OID 17548)
-- Name: store_note_in_pk; Type: CONSTRAINT; Schema: public; Owner: alpha_dba
--

ALTER TABLE ONLY store_note_in
    ADD CONSTRAINT store_note_in_pk PRIMARY KEY (sni_sid);


CREATE TABLE store_note_in_goods (
    snig_store_note_in integer NOT NULL,
    snig_ord_number_in smallint NOT NULL,
    snig_commodity integer NOT NULL,
    snig_trf_code character(10),
    snig_measure integer,
    snig_quantity numeric(15,3) NOT NULL,
    snig_used_quantity numeric(15,3) NOT NULL,
    snig_weight numeric(15,3),
    snig_price numeric(15,3),
    snig_price_lv numeric(17,3),
    snig_state integer,
    snig_cg_45 numeric(12,0),
    snig_tax_1 numeric(12,0),
    snig_tax_2 numeric(12,0),
    snig_tax_3 numeric(12,0),
    snig_tax_4 numeric(12,0),
    snig_tax_4_code character(1),
    snig_cg_number smallint,
    snig_description character varying(100),
    snig_transport numeric(15,3)
);


--
-- TOC entry 3 (OID 17556)
-- Name: store_note_in_goods_pk; Type: CONSTRAINT; Schema: public; Owner: alpha_dba
--

ALTER TABLE ONLY store_note_in_goods
    ADD CONSTRAINT store_note_in_goods_pk PRIMARY KEY (snig_store_note_in, snig_ord_number_in);




CREATE TABLE commodity (
    cdt_sid integer NOT NULL,
    cdt_trf_code character(10),
    cdt_measure integer,
    cdt_state integer,
    cdt_weight numeric(15,3),
    cdt_price numeric(15,3),
    cdt_currency integer,
    cdt_part_number character varying(50),
    cdt_description character varying(100),
    cdt_prefer character(1)
);


--
-- TOC entry 4 (OID 723727)
-- Name: i_cdt_part_number; Type: INDEX; Schema: public; Owner: alpha_dba
--

CREATE UNIQUE INDEX i_cdt_part_number ON commodity USING btree (cdt_part_number);


--
-- TOC entry 3 (OID 17076)
-- Name: commodity_pk; Type: CONSTRAINT; Schema: public; Owner: alpha_dba
--

ALTER TABLE ONLY commodity
    ADD CONSTRAINT commodity_pk PRIMARY KEY (cdt_sid);


CREATE TABLE md_header (
    md_id integer DEFAULT nextval('SEQ_MD_HEADER_MD_ID'::text) NOT NULL,
    md_cust_house integer NOT NULL,
    md_number integer NOT NULL,
    md_number_tranzit integer,
    md_date date NOT NULL,
    md_type_doc integer NOT NULL,
    md_sub_type_doc character(1),
    md_type_input character(1),
    md_regime integer,
    md_clerk integer,
    md_client integer,
    md_status character(1),
    md_cancel_date date,
    md_cancel_clerk integer,
    md_cancel_order integer,
    md_cancel_note character varying(250),
    md_dest_custom integer,
    md_end_date date,
    md_sell1_1 integer,
    md_sell1_3 character(1),
    md_sell2 character varying(200),
    md_sell2_id integer,
    md_sell2_egn character varying(10),
    md_sell2_state integer,
    md_sell2_passprt character varying(20),
    md_sell3_1 smallint,
    md_sell3_2 smallint,
    md_sell4 smallint,
    md_sell5 smallint,
    md_sell6 integer,
    md_sell7 character varying(20),
    md_sell8 character varying(200),
    md_sell8_id integer,
    md_sell8_egn character varying(10),
    md_sell8_state integer,
    md_sell8_passprt character varying(20),
    md_sell9_1 integer,
    md_sell9_2 character varying(200),
    md_sell10 integer,
    md_sell11 integer,
    md_sell12 integer,
    md_sell13 integer,
    md_sell14 character varying(200),
    md_sell14_id integer,
    md_sell14_egn character varying(10),
    md_sell14_state integer,
    md_sell14_passprt character varying(20),
    md_sell14_agent character varying(20),
    md_sell14_reprsnt character varying(20),
    md_sell15_1 integer,
    md_sell15_2 integer,
    md_sell16 integer,
    md_sell17_1 integer,
    md_sell17_2 integer,
    md_sell18_1 character varying(40),
    md_sell18_2 integer,
    md_sell18_3 character varying(20),
    md_sell19 character(1),
    md_sell20_1 integer,
    md_sell20_2 integer,
    md_sell20_3 character varying(20),
    md_sell21_1 character varying(40),
    md_sell21_2 integer,
    md_sell21_3 character varying(20),
    md_sell22_1 numeric(12,0),
    md_sell22_2 integer,
    md_sell23 numeric(12,6),
    md_sell24_1 integer,
    md_sell25 integer,
    md_sell26 integer,
    md_sell27 integer,
    md_sell28 character varying(200),
    md_sell29_1 integer,
    md_sell29_2 date,
    md_sell30 character varying(20),
    md_sell48_1 character(1),
    md_sell48_2 date,
    md_sell49_1 integer,
    md_sell49_2 integer,
    md_sell50_1 character varying(200),
    md_sell50_1_id integer,
    md_sell50_1_egn character varying(10),
    md_sell50_2_1 character varying(40),
    md_sell50_2_2 character(1),
    md_sell50_3_1 character varying(20),
    md_sell50_3_2 date,
    md_sell51_1 character varying(10),
    md_sell51_2 character varying(10),
    md_sell51_3 character varying(10),
    md_sell51_4 character varying(10),
    md_sell52 character varying(50),
    md_sell52_1 integer,
    md_sell53_1 character varying(50),
    md_sell53_2 integer,
    md_sell54_1_1 integer,
    md_sell54_1_2 date,
    md_sell54_3 character varying(100),
    md_sell54_4 character(1),
    md_sell_b character varying(200),
    md_sell_c character varying(200),
    md_sell_d_1 character varying(40),
    md_sell_d_2 character varying(10),
    md_sell_d_3 character varying(40),
    md_sell_d_4 date,
    md_sell48_term character varying(3),
    md_sell9_bank_code character varying(8),
    md_sell9_bank_name character varying(50),
    md_sell9_bank_account character varying(10),
    md_sell28_bank_code character varying(8),
    md_sell28_bank_name character varying(50),
    md_sell28_bank_account character varying(10),
    md_sell54_egn character varying(10),
    md_sell2_tuda character varying(20),
    md_sell2_ds character varying(20),
    md_sell8_tuda character varying(20),
    md_sell8_ds character varying(20),
    md_tuda_id integer,
    md_ds_id integer,
    md_sell18_1_1 character varying(250),
    md_sell18_1_2 character varying(250),
    md_sell21_1_1 character varying(250),
    md_sell21_1_2 character varying(250),
    md_full_save character(1),
    md_sni_sid integer,
    md_sno_sid integer,
    md_custom_number integer,
    md_custom_date date,
    md_sell50_state integer,
    md_sell50_passprt character varying(20),
    md_ino_sid integer,
    md_iwno_sid integer
);

ALTER TABLE ONLY md_header
    ADD CONSTRAINT md_header_pk PRIMARY KEY (md_id);

	