--
--





--
-- Name: branch; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.branch (
    branch_id integer NOT NULL,
    name text NOT NULL,
    address text,
    code text NOT NULL,
    status integer DEFAULT 1 NOT NULL,
    tel text,
    is_shop boolean DEFAULT false NOT NULL
);


ALTER TABLE public.branch OWNER TO postgres;

--
-- Name: branch_branch_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.branch_branch_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.branch_branch_id_seq OWNER TO postgres;

--
-- Name: branch_branch_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.branch_branch_id_seq OWNED BY public.branch.branch_id;


--
-- Name: invoice; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.invoice (
    invoice_id integer NOT NULL,
    created_date timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    handled_by integer NOT NULL,
    amount_1 numeric,
    amount_payment_method_1 integer,
    amount_2 numeric,
    amount_payment_method_2 integer,
    deposit_1 numeric,
    deposit_payment_method_1 integer,
    deposit_2 numeric,
    deposit_payment_method_2 integer,
    finished_date timestamp without time zone,
    delivery_address text,
    invoice_no text NOT NULL,
    status text NOT NULL,
    remark text,
    discount numeric DEFAULT 0 NOT NULL,
    change numeric DEFAULT 0 NOT NULL,
    grand_total numeric DEFAULT 0 NOT NULL,
    need_retailer_order boolean DEFAULT false NOT NULL,
    need_delivery boolean DEFAULT false NOT NULL
);


ALTER TABLE public.invoice OWNER TO postgres;

--
-- Name: COLUMN invoice.status; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON COLUMN public.invoice.status IS '
D : 落訂
F : 完成
';


--
-- Name: invoice_invoice_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.invoice_invoice_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.invoice_invoice_id_seq OWNER TO postgres;

--
-- Name: invoice_invoice_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.invoice_invoice_id_seq OWNED BY public.invoice.invoice_id;


--
-- Name: invoice_item; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.invoice_item (
    invoice_item_id integer NOT NULL,
    invoice_id integer NOT NULL,
    product_id integer NOT NULL,
    qty numeric DEFAULT 1 NOT NULL,
    unit_price numeric DEFAULT 0 NOT NULL,
    sub_total numeric DEFAULT 0 NOT NULL,
    purchases_type integer NOT NULL,
    discount numeric
);


ALTER TABLE public.invoice_item OWNER TO postgres;

--
-- Name: invoice_item_invoice_item_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.invoice_item_invoice_item_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.invoice_item_invoice_item_id_seq OWNER TO postgres;

--
-- Name: invoice_item_invoice_item_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.invoice_item_invoice_item_id_seq OWNED BY public.invoice_item.invoice_item_id;


--
-- Name: payment_method; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.payment_method (
    payment_method_id integer NOT NULL,
    name text,
    status character varying DEFAULT 1 NOT NULL
);


ALTER TABLE public.payment_method OWNER TO postgres;

--
-- Name: payment_method_payment_method_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.payment_method_payment_method_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.payment_method_payment_method_id_seq OWNER TO postgres;

--
-- Name: payment_method_payment_method_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.payment_method_payment_method_id_seq OWNED BY public.payment_method.payment_method_id;


--
-- Name: product; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.product (
    product_id integer NOT NULL,
    code text NOT NULL,
    name text NOT NULL,
    default_price numeric DEFAULT 0 NOT NULL,
    remark text,
    product_brand_id integer,
    product_type_id integer,
    status integer DEFAULT 1 NOT NULL,
    product_type2_id integer
);


ALTER TABLE public.product OWNER TO postgres;

--
-- Name: product_barcode; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.product_barcode (
    product_barcode_id integer NOT NULL,
    product_id integer NOT NULL,
    barcode text NOT NULL
);


ALTER TABLE public.product_barcode OWNER TO postgres;

--
-- Name: product_barcode_product_barcode_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.product_barcode_product_barcode_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.product_barcode_product_barcode_id_seq OWNER TO postgres;

--
-- Name: product_barcode_product_barcode_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.product_barcode_product_barcode_id_seq OWNED BY public.product_barcode.product_barcode_id;


--
-- Name: product_brand; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.product_brand (
    product_brand_id integer NOT NULL,
    code text,
    name text NOT NULL,
    status integer DEFAULT 1 NOT NULL
);


ALTER TABLE public.product_brand OWNER TO postgres;

--
-- Name: product_brand_product_brand_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.product_brand_product_brand_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.product_brand_product_brand_id_seq OWNER TO postgres;

--
-- Name: product_brand_product_brand_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.product_brand_product_brand_id_seq OWNED BY public.product_brand.product_brand_id;


--
-- Name: product_inventory; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.product_inventory (
    product_inventory_id integer NOT NULL,
    product_id integer NOT NULL,
    branch_id integer NOT NULL,
    qty numeric DEFAULT 0 NOT NULL
);


ALTER TABLE public.product_inventory OWNER TO postgres;

--
-- Name: product_inventory_product_inventory_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.product_inventory_product_inventory_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.product_inventory_product_inventory_id_seq OWNER TO postgres;

--
-- Name: product_inventory_product_inventory_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.product_inventory_product_inventory_id_seq OWNED BY public.product_inventory.product_inventory_id;


--
-- Name: product_product_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.product_product_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.product_product_id_seq OWNER TO postgres;

--
-- Name: product_product_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.product_product_id_seq OWNED BY public.product.product_id;


--
-- Name: product_type; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.product_type (
    product_type_id integer NOT NULL,
    name text NOT NULL,
    status integer DEFAULT 1 NOT NULL
);


ALTER TABLE public.product_type OWNER TO postgres;

--
-- Name: product_type2; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.product_type2 (
    product_type2_id integer NOT NULL,
    code text,
    name text,
    status integer DEFAULT 1 NOT NULL
);


ALTER TABLE public.product_type2 OWNER TO postgres;

--
-- Name: product_type2_product_type2_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.product_type2_product_type2_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.product_type2_product_type2_id_seq OWNER TO postgres;

--
-- Name: product_type2_product_type2_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.product_type2_product_type2_id_seq OWNED BY public.product_type2.product_type2_id;


--
-- Name: product_type_product_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.product_type_product_type_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.product_type_product_type_id_seq OWNER TO postgres;

--
-- Name: product_type_product_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.product_type_product_type_id_seq OWNED BY public.product_type.product_type_id;


--
-- Name: retailer; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.retailer (
    retailer_id integer NOT NULL,
    name text NOT NULL,
    tel text,
    contact_person text,
    status integer DEFAULT 1 NOT NULL,
    remark text,
    code text NOT NULL
);


ALTER TABLE public.retailer OWNER TO postgres;

--
-- Name: retailer_product; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.retailer_product (
    retailer_product_id integer NOT NULL,
    product_id integer NOT NULL,
    default_qty integer DEFAULT 0,
    retailer_id integer NOT NULL,
    default_cost numeric
);


ALTER TABLE public.retailer_product OWNER TO postgres;

--
-- Name: retailer_product_retailer_product_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.retailer_product_retailer_product_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.retailer_product_retailer_product_id_seq OWNER TO postgres;

--
-- Name: retailer_product_retailer_product_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.retailer_product_retailer_product_id_seq OWNED BY public.retailer_product.retailer_product_id;


--
-- Name: retailer_purchase_order; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.retailer_purchase_order (
    retailer_purchase_order_id integer NOT NULL,
    code text NOT NULL,
    retailer_id integer NOT NULL,
    remark text,
    status integer DEFAULT 1 NOT NULL,
    date timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    process_status text DEFAULT 'P'::text NOT NULL,
    total_amount numeric DEFAULT 0 NOT NULL,
    createdby integer NOT NULL,
    branch_id integer NOT NULL,
    tel text,
    contact_person text,
    received_by integer
);


ALTER TABLE public.retailer_purchase_order OWNER TO postgres;

--
-- Name: retailer_purchase_order_product; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.retailer_purchase_order_product (
    retailer_purchase_order_product_id integer NOT NULL,
    retailer_purchase_order_id integer NOT NULL,
    product_id integer NOT NULL,
    cost numeric NOT NULL,
    qty integer NOT NULL
);


ALTER TABLE public.retailer_purchase_order_product OWNER TO postgres;

--
-- Name: retailer_purchase_order_produ_retailer_purchase_order_produ_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.retailer_purchase_order_produ_retailer_purchase_order_produ_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.retailer_purchase_order_produ_retailer_purchase_order_produ_seq OWNER TO postgres;

--
-- Name: retailer_purchase_order_produ_retailer_purchase_order_produ_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.retailer_purchase_order_produ_retailer_purchase_order_produ_seq OWNED BY public.retailer_purchase_order_product.retailer_purchase_order_product_id;


--
-- Name: retailer_purchase_order_receive; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.retailer_purchase_order_receive (
    retailer_purchase_order_receive_id integer NOT NULL,
    retailer_purchase_order_id integer NOT NULL,
    retailer_purchase_order_product_id integer NOT NULL,
    qty numeric NOT NULL,
    receive_time time without time zone DEFAULT CURRENT_TIMESTAMP,
    balance numeric NOT NULL
);


ALTER TABLE public.retailer_purchase_order_receive OWNER TO postgres;

--
-- Name: retailer_purchase_order_recei_retailer_purchase_order_recei_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.retailer_purchase_order_recei_retailer_purchase_order_recei_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.retailer_purchase_order_recei_retailer_purchase_order_recei_seq OWNER TO postgres;

--
-- Name: retailer_purchase_order_recei_retailer_purchase_order_recei_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.retailer_purchase_order_recei_retailer_purchase_order_recei_seq OWNED BY public.retailer_purchase_order_receive.retailer_purchase_order_receive_id;


--
-- Name: retailer_purchase_order_retailer_purchase_order_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.retailer_purchase_order_retailer_purchase_order_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.retailer_purchase_order_retailer_purchase_order_id_seq OWNER TO postgres;

--
-- Name: retailer_purchase_order_retailer_purchase_order_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.retailer_purchase_order_retailer_purchase_order_id_seq OWNED BY public.retailer_purchase_order.retailer_purchase_order_id;


--
-- Name: retailer_retailer_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.retailer_retailer_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.retailer_retailer_id_seq OWNER TO postgres;

--
-- Name: retailer_retailer_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.retailer_retailer_id_seq OWNED BY public.retailer.retailer_id;

--
-- Name: user_user_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE public.user_user_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.user_user_id_seq OWNER TO postgres;

--
-- Name: user_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.user_user_id_seq OWNED BY public."user".user_id;


--
-- Name: branch branch_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.branch ALTER COLUMN branch_id SET DEFAULT nextval('public.branch_branch_id_seq'::regclass);


--
-- Name: invoice invoice_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice ALTER COLUMN invoice_id SET DEFAULT nextval('public.invoice_invoice_id_seq'::regclass);


--
-- Name: invoice_item invoice_item_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice_item ALTER COLUMN invoice_item_id SET DEFAULT nextval('public.invoice_item_invoice_item_id_seq'::regclass);


--
-- Name: payment_method payment_method_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.payment_method ALTER COLUMN payment_method_id SET DEFAULT nextval('public.payment_method_payment_method_id_seq'::regclass);


--
-- Name: product product_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product ALTER COLUMN product_id SET DEFAULT nextval('public.product_product_id_seq'::regclass);


--
-- Name: product_barcode product_barcode_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_barcode ALTER COLUMN product_barcode_id SET DEFAULT nextval('public.product_barcode_product_barcode_id_seq'::regclass);


--
-- Name: product_brand product_brand_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_brand ALTER COLUMN product_brand_id SET DEFAULT nextval('public.product_brand_product_brand_id_seq'::regclass);


--
-- Name: product_inventory product_inventory_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_inventory ALTER COLUMN product_inventory_id SET DEFAULT nextval('public.product_inventory_product_inventory_id_seq'::regclass);


--
-- Name: product_type product_type_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_type ALTER COLUMN product_type_id SET DEFAULT nextval('public.product_type_product_type_id_seq'::regclass);


--
-- Name: product_type2 product_type2_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_type2 ALTER COLUMN product_type2_id SET DEFAULT nextval('public.product_type2_product_type2_id_seq'::regclass);


--
-- Name: retailer retailer_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer ALTER COLUMN retailer_id SET DEFAULT nextval('public.retailer_retailer_id_seq'::regclass);


--
-- Name: retailer_product retailer_product_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_product ALTER COLUMN retailer_product_id SET DEFAULT nextval('public.retailer_product_retailer_product_id_seq'::regclass);


--
-- Name: retailer_purchase_order retailer_purchase_order_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order ALTER COLUMN retailer_purchase_order_id SET DEFAULT nextval('public.retailer_purchase_order_retailer_purchase_order_id_seq'::regclass);


--
-- Name: retailer_purchase_order_product retailer_purchase_order_product_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order_product ALTER COLUMN retailer_purchase_order_product_id SET DEFAULT nextval('public.retailer_purchase_order_produ_retailer_purchase_order_produ_seq'::regclass);


--
-- Name: retailer_purchase_order_receive retailer_purchase_order_receive_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order_receive ALTER COLUMN retailer_purchase_order_receive_id SET DEFAULT nextval('public.retailer_purchase_order_recei_retailer_purchase_order_recei_seq'::regclass);


--
-- Data for Name: branch; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.branch (branch_id, name, address, code, status, tel, is_shop) FROM stdin;
1	aa	qq	tt	1	23000000	f
12	ww	\N	qqq	2	\N	f
13	jjj	99	hh	1	\N	f
14	t	\N	tes	1	\N	f
15	123	2	1	1	23	f
16	123	3	123	1	312	f
20	23	323	222	1	12	f
21	123	323	12355	1	123	f
22	12	\N	2323	1	12	f
24	12	\N	6454	1	12	f
27	12	\N	90909090	1	12	f
28	3434	\N	231253	1	334	f
29	main	\N	main	1	\N	t
\.


--
-- Data for Name: invoice; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.invoice (invoice_id, created_date, handled_by, amount_1, amount_payment_method_1, amount_2, amount_payment_method_2, deposit_1, deposit_payment_method_1, deposit_2, deposit_payment_method_2, finished_date, delivery_address, invoice_no, status, remark, discount, change, grand_total, need_retailer_order, need_delivery) FROM stdin;
7	2020-07-19 14:14:37.611992	6	6	1	0	\N	\N	\N	\N	\N	2020-07-19 14:14:37.611992	\N	F00000006	F	remark222	0	1	5	f	f
8	2020-07-19 14:15:31.84687	6	6	1	0	\N	\N	\N	\N	\N	2020-07-19 14:15:31.84687	\N	F00000008	F	remark222	0	1	5	f	f
9	2020-07-19 14:16:53.165646	6	6	1	0	\N	\N	\N	\N	\N	2020-07-19 14:16:53.165646	\N	F00000009	F	remark222	0	1	5	f	f
10	2020-07-19 14:22:36.809439	6	6	1	0	\N	\N	\N	\N	\N	2020-07-19 14:22:36.809439	\N	F00000010	F	remark222	0	1	5	f	f
11	2020-07-19 14:26:00.69846	6	6	1	0	\N	\N	\N	\N	\N	2020-07-19 14:26:00.69846	\N	F00000011	F	remark222	0	1	5	f	f
12	2020-07-19 14:26:49.349126	6	6	1	0	\N	\N	\N	\N	\N	2020-07-19 14:26:49.349126	\N	F00000012	F	remark222	0	1	5	f	f
13	2020-07-19 15:38:05.477847	6	6	1	0	\N	\N	\N	\N	\N	2020-07-19 15:38:05.477847	\N	F00000013	F	remark222	0	1	5	f	f
14	2020-07-19 16:58:26.793643	6	5	1	0	\N	\N	\N	\N	\N	2020-07-19 16:58:26.793643	\N	F00000014	F		0	0	5	f	f
15	2020-07-19 16:59:38.03154	6	35.9	1	0	\N	\N	\N	\N	\N	2020-07-19 16:59:38.03154	\N	F00000015	F		0	0	35.9	f	f
16	2020-07-19 17:00:05.855813	6	16.9	1	0	\N	\N	\N	\N	\N	\N		D00000016	D		0	0	16.9	f	f
17	2020-07-19 21:13:33.791269	6	180	1	0	\N	\N	\N	\N	\N	2020-07-19 21:13:33.791269	\N	F00000017	F	testrrr	0	2	178	f	f
18	2020-07-19 21:46:53.922644	6	\N	\N	\N	\N	2	1	1	\N	2020-07-19 21:46:53.922644	\N	F00000018	F		0	0	5	f	f
19	2020-07-19 21:59:41.518513	6	\N	\N	\N	\N	14	1	1	2	\N	12123	D00000019	D		0	0	16	t	f
\.


--
-- Data for Name: invoice_item; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.invoice_item (invoice_item_id, invoice_id, product_id, qty, unit_price, sub_total, purchases_type, discount) FROM stdin;
2	7	21	1	5	5	0	\N
3	8	21	1	5	5	0	\N
4	9	21	1	5	5	0	\N
5	10	21	1	5	5	0	\N
6	11	21	1	5	5	0	\N
7	12	21	1	5	5	0	\N
8	13	21	1	5	5	0	\N
9	14	21	1	5	5	0	\N
10	15	21	5	5	25	0	\N
11	15	23	1	11.89	10.9	0	1
12	16	21	1	5	5	1	\N
13	16	23	1	11.89	11.9	0	\N
14	17	36	1	2	2	0	\N
15	17	37	1	3	3	0	\N
16	17	39	1	4	4	0	\N
17	17	45	1	5	5	0	\N
18	17	35	1	123	123	0	\N
19	17	21	1	5	5	0	\N
20	17	28	1	11	11	0	\N
21	17	25	1	25	25	0	\N
22	18	45	1	5	5	0	\N
23	19	28	1	11	11	2	\N
24	19	21	1	5	5	0	\N
\.


--
-- Data for Name: payment_method; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.payment_method (payment_method_id, name, status) FROM stdin;
1	現金	1
2	VISA	1
3	MasterCard	1
\.


--
-- Data for Name: product; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.product (product_id, code, name, default_price, remark, product_brand_id, product_type_id, status, product_type2_id) FROM stdin;
19	fgb	cvb	345	123	1	1	2	\N
22	qw	qwe1e123	9.9	\N	\N	\N	2	\N
21	test	test	5	\N	39	4	1	7
23	qwr	qwrqwerqwe	11.89	\N	\N	4	1	7
25	fg1212412412b	testgg3474 5346 3456457345734583457345	25	\N	\N	4	1	\N
28	123	123	11	\N	\N	\N	1	\N
35	test123	test123	123	\N	\N	\N	1	\N
36	test2	test2	2	\N	\N	\N	1	\N
37	test3	test3	3	\N	\N	\N	1	\N
39	test4	test5	4	\N	\N	\N	1	\N
45	test5555	test5	5	\N	\N	\N	1	\N
\.


--
-- Data for Name: product_barcode; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.product_barcode (product_barcode_id, product_id, barcode) FROM stdin;
9	19	346345
10	19	123
11	21	124
14	21	125
15	21	11
\.


--
-- Data for Name: product_brand; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.product_brand (product_brand_id, code, name, status) FROM stdin;
2	\N	LG	1
5	\N	Xbox	1
1	\N	Sony	1
39	\N	6	1
41	\N	34	1
42	\N	test	1
\.


--
-- Data for Name: product_inventory; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.product_inventory (product_inventory_id, product_id, branch_id, qty) FROM stdin;
2	23	1	2
6	22	1	5
10	22	13	0
11	22	14	0
24	21	1	0
5	21	13	2
26	21	14	0
27	21	15	0
28	21	16	0
29	21	20	0
30	21	21	0
31	21	22	0
32	21	24	0
33	21	27	0
34	21	28	0
42	23	29	-2
45	36	29	-1
46	37	29	-1
47	39	29	-1
49	35	29	-1
52	25	29	-1
48	45	29	-2
51	28	29	-2
35	21	29	-9
\.


--
-- Data for Name: product_type; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.product_type (product_type_id, name, status) FROM stdin;
4	SmartPhone	1
1	Battery	2
23	Fan	1
31	Battery	1
\.


--
-- Data for Name: product_type2; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.product_type2 (product_type2_id, code, name, status) FROM stdin;
7	\N	1hp	1
\.


--
-- Data for Name: retailer; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.retailer (retailer_id, name, tel, contact_person, status, remark, code) FROM stdin;
12	test	23000000	tom	1	re	tttt
15	T			1		test
13	123	qwe123		1		ttt
\.


--
-- Data for Name: retailer_product; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.retailer_product (retailer_product_id, product_id, default_qty, retailer_id, default_cost) FROM stdin;
14	23	5	12	50
15	19	\N	12	10
16	21	2	13	20
\.


--
-- Data for Name: retailer_purchase_order; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.retailer_purchase_order (retailer_purchase_order_id, code, retailer_id, remark, status, date, process_status, total_amount, createdby, branch_id, tel, contact_person, received_by) FROM stdin;
2	hh-0000	12	RRRR	1	2019-04-03 23:20:18.171823	P	250	1	13	23000000	tom	\N
3	hh-0001	12		1	2019-04-03 23:23:27.595745	P	20	1	13	23000000	tom	\N
1	test	12	test_rtt	1	2019-04-02 23:37:05.815333	F	220	1	13	23000000	Tony	1
4	hh-0000	12	222	1	2019-06-13 19:27:19.480204	F	250	1	13	23000000	tom	1
5	tes-0000	12		1	2020-04-26 17:59:08.705388	P	250	6	14	23000000	tom	\N
6	hh-0001	13	remark2	1	2020-04-26 18:00:24.841967	P	40	6	13	qwe123	tom	\N
7	hh-0000	13	remark	1	2020-06-10 16:06:12.774094	P	40	6	13	qwe123	tom	\N
8	tt-202006100001	12	remark	1	2020-06-10 16:31:47.276592	P	250	6	1	23000000	tom	\N
9	tt-202006100001	12	remark	1	2020-06-10 16:31:51.163672	P	250	6	1	23000000	tom	\N
10	tt-202006100001	12	remark	1	2020-06-10 16:31:52.216915	P	250	6	1	23000000	tom	\N
11	hh-202006100004	13	remark	1	2020-06-10 16:42:12.892204	F	40	6	13	qwe123	tom	6
\.


--
-- Data for Name: retailer_purchase_order_product; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.retailer_purchase_order_product (retailer_purchase_order_product_id, retailer_purchase_order_id, product_id, cost, qty) FROM stdin;
37	1	19	22	4
38	1	22	33	4
39	2	23	50	5
40	3	19	10	2
41	4	23	50	5
42	5	23	50	5
45	6	21	20	2
46	7	21	20	2
47	8	23	50	5
48	9	23	50	5
49	10	23	50	5
50	11	21	20	2
\.


--
-- Data for Name: retailer_purchase_order_receive; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.retailer_purchase_order_receive (retailer_purchase_order_receive_id, retailer_purchase_order_id, retailer_purchase_order_product_id, qty, receive_time, balance) FROM stdin;
17	1	37	3	18:35:10.4394	3
18	1	38	2	18:35:10.4394	2
19	4	41	4	19:27:53.430414	4
21	11	50	2	16:48:54.060735	2
\.



--
-- Name: branch branch_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.branch
    ADD CONSTRAINT branch_pk PRIMARY KEY (branch_id);


--
-- Name: invoice_item invoice_item_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice_item
    ADD CONSTRAINT invoice_item_pk PRIMARY KEY (invoice_item_id);


--
-- Name: invoice invoice_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice
    ADD CONSTRAINT invoice_pk PRIMARY KEY (invoice_id);


--
-- Name: payment_method payment_method_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.payment_method
    ADD CONSTRAINT payment_method_pk PRIMARY KEY (payment_method_id);


--
-- Name: product_brand product_brand_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_brand
    ADD CONSTRAINT product_brand_pkey PRIMARY KEY (product_brand_id);


--
-- Name: product_inventory product_inventory_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_inventory
    ADD CONSTRAINT product_inventory_pk PRIMARY KEY (product_inventory_id);


--
-- Name: product product_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product
    ADD CONSTRAINT product_pkey PRIMARY KEY (product_id);


--
-- Name: product_type2 product_type2_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_type2
    ADD CONSTRAINT product_type2_pk PRIMARY KEY (product_type2_id);


--
-- Name: product_type product_type_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_type
    ADD CONSTRAINT product_type_pkey PRIMARY KEY (product_type_id);


--
-- Name: retailer retailer_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer
    ADD CONSTRAINT retailer_pk PRIMARY KEY (retailer_id);


--
-- Name: retailer_product retailer_product_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_product
    ADD CONSTRAINT retailer_product_pk PRIMARY KEY (retailer_product_id);


--
-- Name: retailer_purchase_order retailer_purchase_order_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order
    ADD CONSTRAINT retailer_purchase_order_pk PRIMARY KEY (retailer_purchase_order_id);


--
-- Name: retailer_purchase_order_product retailer_purchase_order_product_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order_product
    ADD CONSTRAINT retailer_purchase_order_product_pk PRIMARY KEY (retailer_purchase_order_product_id);


--
-- Name: retailer_purchase_order_receive retailer_purchase_order_receive_pk; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order_receive
    ADD CONSTRAINT retailer_purchase_order_receive_pk PRIMARY KEY (retailer_purchase_order_receive_id);


--
-- Name: branch_code_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX branch_code_idx ON public.branch USING btree (code) WHERE (status <> 2);


--
-- Name: brand_code_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX brand_code_idx ON public.product_brand USING btree (code) WHERE (status <> 2);


--
-- Name: brand_name_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX brand_name_idx ON public.product_brand USING btree (name) WHERE (status <> 2);


--
-- Name: invoice_created_date_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX invoice_created_date_idx ON public.invoice USING btree (created_date);


--
-- Name: product_barcode_barcode_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX product_barcode_barcode_idx ON public.product_barcode USING btree (barcode);


--
-- Name: product_brand_all_key; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX product_brand_all_key ON public.product_brand USING btree (product_brand_id);


--
-- Name: product_code_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX product_code_idx ON public.product USING btree (code) WHERE (status <> 2);


--
-- Name: product_inventory_product_id_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX product_inventory_product_id_idx ON public.product_inventory USING btree (product_id, branch_id);


--
-- Name: product_type2_name_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX product_type2_name_idx ON public.product_type2 USING btree (name) WHERE (status <> 2);


--
-- Name: product_type_all_key; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX product_type_all_key ON public.product_type USING btree (product_type_id);


--
-- Name: product_type_name_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX product_type_name_idx ON public.product_type USING btree (name) WHERE (status <> 2);


--
-- Name: retailer_code_ukey; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX retailer_code_ukey ON public.retailer USING btree (code) WHERE (status <> 2);


--
-- Name: invoice_item invoice_item_invoice_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice_item
    ADD CONSTRAINT invoice_item_invoice_fk FOREIGN KEY (invoice_id) REFERENCES public.invoice(invoice_id);


--
-- Name: invoice_item invoice_item_product_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice_item
    ADD CONSTRAINT invoice_item_product_fk FOREIGN KEY (product_id) REFERENCES public.product(product_id);


--
-- Name: invoice invoice_payment_method_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice
    ADD CONSTRAINT invoice_payment_method_fk FOREIGN KEY (amount_payment_method_1) REFERENCES public.payment_method(payment_method_id);


--
-- Name: invoice invoice_payment_method_fk_1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice
    ADD CONSTRAINT invoice_payment_method_fk_1 FOREIGN KEY (amount_payment_method_2) REFERENCES public.payment_method(payment_method_id);


--
-- Name: invoice invoice_payment_method_fk_2; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice
    ADD CONSTRAINT invoice_payment_method_fk_2 FOREIGN KEY (deposit_payment_method_1) REFERENCES public.payment_method(payment_method_id);


--
-- Name: invoice invoice_payment_method_fk_3; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.invoice
    ADD CONSTRAINT invoice_payment_method_fk_3 FOREIGN KEY (deposit_payment_method_2) REFERENCES public.payment_method(payment_method_id);


--
-- Name: product_barcode product_barcode_product_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_barcode
    ADD CONSTRAINT product_barcode_product_fk FOREIGN KEY (product_id) REFERENCES public.product(product_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: product_inventory product_inventory_branch_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_inventory
    ADD CONSTRAINT product_inventory_branch_fk FOREIGN KEY (branch_id) REFERENCES public.branch(branch_id);


--
-- Name: product_inventory product_inventory_product_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product_inventory
    ADD CONSTRAINT product_inventory_product_fk FOREIGN KEY (product_id) REFERENCES public.product(product_id);


--
-- Name: product product_product_brand_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product
    ADD CONSTRAINT product_product_brand_id_fkey FOREIGN KEY (product_brand_id) REFERENCES public.product_brand(product_brand_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: product product_product_type2_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product
    ADD CONSTRAINT product_product_type2_fk FOREIGN KEY (product_type2_id) REFERENCES public.product_type2(product_type2_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: product product_product_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.product
    ADD CONSTRAINT product_product_type_id_fkey FOREIGN KEY (product_type_id) REFERENCES public.product_type(product_type_id) ON UPDATE CASCADE ON DELETE CASCADE;


--
-- Name: retailer_product retailer_product_product_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_product
    ADD CONSTRAINT retailer_product_product_fk FOREIGN KEY (product_id) REFERENCES public.product(product_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: retailer_product retailer_product_retailer_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_product
    ADD CONSTRAINT retailer_product_retailer_fk FOREIGN KEY (retailer_id) REFERENCES public.retailer(retailer_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: retailer_purchase_order retailer_purchase_order_branch_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order
    ADD CONSTRAINT retailer_purchase_order_branch_fk FOREIGN KEY (branch_id) REFERENCES public.branch(branch_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: retailer_purchase_order_product retailer_purchase_order_product_product_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order_product
    ADD CONSTRAINT retailer_purchase_order_product_product_fk FOREIGN KEY (product_id) REFERENCES public.product(product_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: retailer_purchase_order_product retailer_purchase_order_product_retailer_purchase_order_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order_product
    ADD CONSTRAINT retailer_purchase_order_product_retailer_purchase_order_fk FOREIGN KEY (retailer_purchase_order_id) REFERENCES public.retailer_purchase_order(retailer_purchase_order_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: retailer_purchase_order_receive retailer_purchase_order_receive_retailer_purchase_order_fk_1; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order_receive
    ADD CONSTRAINT retailer_purchase_order_receive_retailer_purchase_order_fk_1 FOREIGN KEY (retailer_purchase_order_id) REFERENCES public.retailer_purchase_order(retailer_purchase_order_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: retailer_purchase_order_receive retailer_purchase_order_receive_retailer_purchase_order_product; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order_receive
    ADD CONSTRAINT retailer_purchase_order_receive_retailer_purchase_order_product FOREIGN KEY (retailer_purchase_order_product_id) REFERENCES public.retailer_purchase_order_product(retailer_purchase_order_product_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: retailer_purchase_order retailer_purchase_order_receiver_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order
    ADD CONSTRAINT retailer_purchase_order_receiver_fk FOREIGN KEY (received_by) REFERENCES public."user"(user_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: retailer_purchase_order retailer_purchase_order_retailer_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order
    ADD CONSTRAINT retailer_purchase_order_retailer_fk FOREIGN KEY (retailer_id) REFERENCES public.retailer(retailer_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- Name: retailer_purchase_order retailer_purchase_order_user_fk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.retailer_purchase_order
    ADD CONSTRAINT retailer_purchase_order_user_fk FOREIGN KEY (createdby) REFERENCES public."user"(user_id) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
--

