-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.sql
162 lines (144 loc) · 4.33 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
CREATE TABLE property_type (
id bigserial primary key,
name VARCHAR(40) not null
);
CREATE TABLE company (
id bigserial primary key,
name text,
phone text
);
CREATE TABLE property (
id bigserial primary key,
type_id integer REFERENCES property_type (id),
company_id integer REFERENCES company (id),
address_street text not null,
address_city text not null,
address_state text not null,
address_zip text not null,
index_number text
);
CREATE TABLE property_unit (
id bigserial primary key,
property_id integer REFERENCES property (id),
name text,
is_building boolean default false
);
CREATE TABLE rental_price (
id bigserial primary key,
unit_id integer REFERENCES property_unit (id),
price money,
time timestamp
);
CREATE TABLE property_tax (
id bigserial primary key,
property_id integer REFERENCES property (id),
description text,
amount money,
pay_date date default CURRENT_DATE
);
CREATE TABLE work_order (
id bigserial primary key,
company_id integer REFERENCES company (id),
unit_id integer REFERENCES property_unit (id),
description text not null,
estimation money,
assignee_name text,
assignee_phone text,
assignee_email text,
status text,
scheduled_date date,
start_date date,
end_date date
);
CREATE TABLE vendor (
id bigserial primary key,
company_id integer REFERENCES company (id),
category text not null,
name text,
phone text,
email text,
note text
);
CREATE TABLE expense_type (
id bigserial primary key,
name text not null
);
CREATE TABLE expense (
id bigserial primary key,
unit_id integer REFERENCES property_unit (id),
pay_to text,
type_id integer REFERENCES expense_type (id),
description text,
amount money,
pay_time timestamp default CURRENT_TIMESTAMP,
file text
);
CREATE TABLE work_order_expense (
id bigserial primary key,
work_id integer REFERENCES work_order (id),
expense_id integer REFERENCES expense (id)
);
CREATE TABLE tenant (
id bigserial primary key,
unit_id integer REFERENCES property_unit (id),
company_id integer REFERENCES company (id),
firstname text not null,
lastname text,
phone text,
email text,
lease_start date,
lease_end date
);
CREATE TABLE rental_income (
id bigserial primary key,
tenant_id integer REFERENCES tenant (id),
method text,
reference text,
amount money,
time timestamp
);
CREATE TABLE login_user (
id bigserial primary key,
company_id integer REFERENCES company (id),
email text not null UNIQUE, -- username
password text not null,
firstname text,
lastname text,
phone text,
is_admin boolean default false,
is_manager boolean default false
);
CREATE TABLE import_statement_config (
id bigserial primary key,
company_id integer REFERENCES company (id),
filter_column_number integer not null,
filter_keyword text,
date_column_number integer not null,
date_format text,
pay_to_column_number integer,
amount_column_number integer not null,
category_column_number integer,
description_column_number integer
);
-- IMPORT BASIC APPLICATION DATA
INSERT INTO expense_type (name) VALUES ('Advertising');
INSERT INTO expense_type (name) VALUES ('Auto and Travel');
INSERT INTO expense_type (name) VALUES ('Cleaning and Maintenance');
INSERT INTO expense_type (name) VALUES ('Commissions');
INSERT INTO expense_type (name) VALUES ('Insurance');
INSERT INTO expense_type (name) VALUES ('Legal and other professional fees');
INSERT INTO expense_type (name) VALUES ('Management fees');
INSERT INTO expense_type (name) VALUES ('Mortgate interest paid to banks, etc');
INSERT INTO expense_type (name) VALUES ('Others');
INSERT INTO expense_type (name) VALUES ('Repairs');
INSERT INTO expense_type (name) VALUES ('Supplies');
INSERT INTO expense_type (name) VALUES ('Taxes');
INSERT INTO expense_type (name) VALUES ('Utilities');
INSERT INTO property_type (name) VALUES ('single');
INSERT INTO property_type (name) VALUES ('multi');
INSERT INTO property_type (name) VALUES ('condo');
INSERT INTO property_type (name) VALUES ('apartment');
INSERT INTO company(name) VALUES ('base company');
CREATE EXTENSION pgcrypto;
INSERT INTO login_user(company_id, email, password, is_admin, is_manager) VALUES (1, 'email', crypt('password', gen_salt('bf')), true, true);
--- SELECT id, company_id, email, phone, is_admin, is_manager FROM login_user WHERE email='email' AND password = crypt('password-to-test',password);