-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepository.py
74 lines (64 loc) · 2.59 KB
/
Repository.py
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
import atexit
import sqlite3
from DAO import _Vaccines, _Suppliers, _Clinics, _Logistics
from DTO import Vaccine
class _Repository:
# constructor _Repository
def __init__(self):
self._conn = sqlite3.connect('database.db')
self.vaccines = _Vaccines(self._conn)
self.suppliers = _Suppliers(self._conn)
self.clinics = _Clinics(self._conn)
self.logistics = _Logistics(self._conn)
def _close(self):
self._conn.commit()
self._conn.close()
def create_tables(self):
self._conn.executescript("""
CREATE TABLE vaccines (
id INTEGER PRIMARY KEY,
date DATE NOT NULL,
supplier INTEGER REFERENCES suppliers(id),
quantity INTEGER NOT NULL
);
CREATE TABLE suppliers (
id INTEGER PRIMARY KEY,
name VARCHAR(50) NOT NULL,
logistic INTEGER REFERENCES logistics(id)
);
CREATE TABLE clinics (
id INTEGER PRIMARY KEY,
location VARCHAR(50) NOT NULL,
demand INTEGER NOT NULL,
logistic INTEGER REFERENCES logistics(id)
);
CREATE TABLE logistics (
id INTEGER PRIMARY KEY,
name VARCHAR(50) NOT NULL,
count_sent INTEGER NOT NULL,
count_received INTEGER NOT NULL
);
""")
#process sent order.
def send_shipment(self, line):
_Vaccines.use(self, line[1])
logistic_id = _Clinics.get_vaccines(self, line[0])
_Clinics.use_vaccines(self, line[0], line[1])
_Logistics.send_order(self, logistic_id, line[1])
# process receive order.
def receive_shipment(self, line):
logistic_id = _Suppliers.get_logistics(self, line[0])
supplier_id = _Suppliers.get_supplier(self, line[0])
_Logistics.receive_order(self, logistic_id, line[1])
v_id = _Vaccines.get_next_id(self)
line = [v_id, line[2], supplier_id[0], line[1]]
vaccine = Vaccine(line)
_Vaccines.insert(self, vaccine)
# return summary line.
def summary(self):
total_inventory = _Vaccines.get_total_inventory(self)
total_demand = _Clinics.get_total_demand(self)
total_receive = _Logistics.get_total_receive(self)
total_sent = _Logistics.get_total_sent(self)
output = "{},{},{},{}\n".format(total_inventory[0], total_demand[0], total_receive[0], total_sent[0])
return output