class Categories(db.Model):
    category_id = db.Column(db.Integer,
                            primary_key=True,
                            nullable=False,
                            unique=True)
    books = db.relationship("Books", backref="category", lazy=False)
    category_name = db.Column(db.String(50))
    image = db.Column(db.String(1500))
    description = db.Column(db.String(1500))
    note = db.Column(db.String(1500))
    delete_at = db.Column(db.DateTime, default=None)
    books = db.relationship('Books', backref="category", lazy=True)

    def serialize(self):
        return {
            "category_id": self.category_id,
            "category_name": self.category_name,
            "note": self.note,
            "description": self.description,
            "delete_at": self.delete_at,
            "image": self.image
        }

    def __repr__(self):
        return f"Category('{self.category_id}','{self.category_name}','{self.note}','{self.description}', '{self.delete_at}')"
Example #2
0
class Book(db.Model):
    id = db.Column(db.String(20), primary_key=True)
    name = db.Column(db.String(20), nullable=False)
    author = db.Column(db.String(120), nullable=False)
    description = db.Column(db.String(60), nullable=False)
    quantity = db.Column(db.Integer, nullable=False)
    total_quantity = db.Column(db.Integer, nullable=False)
Example #3
0
class User(db.Model, UserMixin):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    password_hash = db.Column(db.String(512), nullable=False)
    first_name = db.Column(db.String(64), nullable=False)
    last_name = db.Column(db.String(64), nullable=False)
    email = db.Column(db.String(100), unique=True, index=True)
    is_admin = db.Column(db.Boolean)

    books = db.relationship('Book',
                            secondary='orders',
                            backref=db.backref('users', lazy='select'),
                            lazy='select')

    def __repr__(self):
        return f"<User {self.last_name} {self.first_name}>"

    def __str__(self):
        return f"{self.last_name} {self.first_name} "

    def set_password(self, password):
        self.password_hash = bcrypt.generate_password_hash(password).decode(
            'utf8')

    def is_password_ok(self, password):
        return bcrypt.check_password_hash(self.password_hash, password)
class Suppliers(db.Model):
    supplier_id = db.Column(db.Integer,
                            unique=True,
                            autoincrement=True,
                            primary_key=True,
                            nullable=False)
    contact_name = db.Column(db.String(50), nullable=False)
    address = db.Column(db.String(1500))
    phone = db.Column(db.String(50))
    email = db.Column(db.String(50), nullable=False)
    note = db.Column(db.String(1500))
    delete_at = db.Column(db.DateTime, default=None)
    books = db.relationship('Books', backref='supplier', lazy=True)

    def serialize(self):
        return {
            "supplier_id": self.supplier_id,
            "contact_name": self.contact_name,
            "note": self.note,
            "address": self.address,
            "phone": self.phone,
            "email": self.email,
            "delete_at": self.delete_at
        }

    def __repr__(self):
        return f"Supplier('{self.supplier_id}','{self.contact_name}','{self.note}','{self.address}','{self.phone}'," \
               f"'{self.email}', '{self.delete_at}')"
Example #5
0
class Accounts(db.Model):
    account_id = db.Column(db.Integer,
                           primary_key=True,
                           nullable=False,
                           autoincrement=True,
                           unique=True)
    role_id = db.Column(db.Integer, db.ForeignKey('roles.role_id'))
    account_name = db.Column(db.String(50), nullable=False, unique=True)
    account_password = db.Column(db.String(50), nullable=False)
    note = db.Column(db.String(50))
    delete_at = db.Column(db.DateTime, default=None)
    customers = db.relationship('Customers',
                                backref='account',
                                lazy='subquery')
    employees = db.relationship('Employees',
                                backref='account',
                                lazy='subquery')

    def serialize(self):
        return {
            "account_id": self.account_id,
            "account_name": self.account_name,
            "note": self.note,
            "delete_at": self.delete_at,
            "role": self.role.serialize()
        }

    def __repr__(self):
        return f"Account('{self.account_id}','{self.account_name}','{self.note}', '{self.delete_at}', " \
               f"'{self.role.serialize()}')"
Example #6
0
class Orders(db.Model):
    order_id = db.Column(db.Integer,
                         unique=True,
                         autoincrement=True,
                         primary_key=True,
                         nullable=False)
    customer_id = db.Column(db.Integer, db.ForeignKey('customers.customer_id'))
    employee_id = db.Column(db.Integer, db.ForeignKey('employees.employee_id'))
    order_date = db.Column(db.DateTime)
    total = db.Column(db.Float)
    type = db.Column(db.String(50))
    note = db.Column(db.String(1500))
    delete_at = db.Column(db.DateTime, default=None)
    orderdetails = db.relationship('Orderdetails', backref="order", lazy=True)

    def serialize(self):
        return {
            "order_id": self.order_id,
            "customer": self.customer.serialize(),
            "note": self.note,
            "employee": self.employee.serialize(),
            "order_date": self.order_date,
            "total": self.order_date,
            "type": self.type,
            "delete_at": self.delete_at
        }

    def __repr__(self):
        return f"Order('{self.order_id}', '{self.customer.serialize()}', '{self.employee.serialize()}','{self.note}', '{self.order_date}', '{self.total}', " \
               f"'{self.type}', '{self.delete_at}')"
class Books(db.Model):
    book_id = db.Column(db.Integer,
                        autoincrement=True,
                        nullable=False,
                        primary_key=True,
                        unique=True)
    book_name = db.Column(db.String(150), nullable=False)
    supplier_id = db.Column(db.Integer, db.ForeignKey('suppliers.supplier_id'))
    category_id = db.Column(db.Integer,
                            db.ForeignKey('categories.category_id'))
    author_id = db.Column(db.Integer, db.ForeignKey('authors.author_id'))
    old_amount = db.Column(db.Integer)
    new_amount = db.Column(db.Integer)
    image = db.Column(db.String(1000))
    page_number = db.Column(db.Integer)
    description = db.Column(db.TEXT(16383))
    cost_price = db.Column(db.Float)
    retail_price = db.Column(db.Float)
    discount = db.Column(db.Float, default=0.0)
    ranking = db.Column(db.String(50))
    rate_star = db.Column(db.Float, name="rate_star", default=0)
    rate_count = db.Column(db.Integer, name="rate_count", default=0)
    delete_at = db.Column(db.DateTime, default=None)
    note = db.Column(db.String(1500))
    comments = db.relationship('Comments', backref='book', lazy=True)
    order_details = db.relationship('Orderdetails', backref='book', lazy=True)
    borrow_ticket_details = db.relationship('Borrowticketdetails',
                                            backref='book',
                                            lazy=True)

    def serialize(self):
        return {
            "book_id": self.book_id,
            "book_name": self.book_name,
            "note": self.note,
            "supplier":
            self.supplier.serialize() if self.supplier != None else None,
            "category":
            self.category.serialize() if self.category != None else None,
            "author": self.author.serialize() if self.author != None else None,
            "old_amount": self.old_amount,
            "new_amount": self.new_amount,
            "image": self.image,
            "page_number": self.page_number,
            "description": self.description,
            "cost_price": self.cost_price,
            "retail_price": self.retail_price,
            "discount": self.discount,
            "ranking": self.ranking,
            "rate_star": self.rate_star,
            "rate_count": self.rate_count,
            "delete_at": self.delete_at
        }

    def __repr__(self):
        return f"('book_id':{self.book_id},'book_name': {self.book_name},'note : {self.note},'supplier': {self.supplier.serialize()},'category': {self.category.serialize()}, " \
               f"'author': {self.author.serialize()},'old_amount': {self.old_amount},'new_amount': {self.new_amount},'image': {self.image},'page_number': {self.page_number}, " \
               f"'description ':{self.description},'cost_price': {self.cost_price},'retail_price': {self.retail_price},'discount': {self.discount},'ranking': {self.ranking})"
Example #8
0
class Request(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(120), nullable=False)
    title = db.Column(db.String(1000), nullable=False, unique=False)
    timestamp = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

    def __repr__(self):
        return f("User('{self.email}', '{self.title}', )")
Example #9
0
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    email = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)
    usertype = db.Column(db.String(20), nullable=False)

    def __repr__(self):
        return f"User('{self.username}', '{self.email}')"
Example #10
0
class Book(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    genre = db.Column(db.String(200), nullable=False)
    title = db.Column(db.String(200), nullable=False)
    author = db.Column(db.String(100), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    def __repr__(self):
        return f"Book('{self.genre}', '{self.title}')"
Example #11
0
class Member(db.Model):
    id = db.Column(db.String(20), primary_key=True)
    name = db.Column(db.String(20), nullable=False)
    address = db.Column(db.String(120), nullable=False)
    balance = db.Column(db.Integer, nullable=True, default=0)
    books = db.relationship('Book',
                            secondary=books,
                            lazy='subquery',
                            backref=db.backref('members', lazy=True))
Example #12
0
class Author(db.Model):
    id = db.Column(db.Integer,
                   primary_key=True)

    name = db.Column(db.String(45),
                     nullable=False)

    surname = db.Column(db.String(45),
                     nullable=False)
Example #13
0
class Book(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    summary = db.Column(db.String(250), nullable=False)
    author = relationship('Author',
                          secondary=assoc_author_book,
                          backref='book')

    def __repr__(self):
        return self.name
Example #14
0
class Transaction(db.Model):
    id = db.Column(db.String(20), primary_key=True)
    member_id = db.Column(db.String(20),
                          db.ForeignKey('member.id'),
                          nullable=False)
    book_id = db.Column(db.String(20),
                        db.ForeignKey('book.id'),
                        nullable=False)
    date_issued = db.Column(db.DateTime, nullable=False)
    date_returned = db.Column(db.DateTime)
Example #15
0
class Employees(db.Model):
    employee_id = db.Column(db.Integer,
                            autoincrement=True,
                            primary_key=True,
                            nullable=False,
                            unique=True)
    account_id = db.Column(db.Integer,
                           db.ForeignKey('accounts.account_id'),
                           unique=True)
    last_name = db.Column(db.String(50), nullable=False)
    first_name = db.Column(db.String(50), nullable=False)
    phone = db.Column(db.String(50), nullable=False, unique=True)
    email = db.Column(db.String(50), nullable=False, unique=True)
    birth_date = db.Column(db.DateTime)
    hire_date = db.Column(db.DateTime)
    province_id = db.Column(db.String(50), name="province_id")
    district_id = db.Column(db.String(50), name="district_id")
    ward_id = db.Column(db.String(50), name="ward_id")
    address = db.Column(db.String(1500))
    gender = db.Column(db.Boolean)
    image = db.Column(db.String(1500))
    basic_rate = db.Column(db.Float)
    note = db.Column(db.String(1500))
    delete_at = db.Column(db.DateTime, default=None)
    orders = db.relationship('Orders', backref='employee', lazy=True)
    borrow_tickets = db.relationship('Borrowtickets',
                                     backref='employee',
                                     lazy=True)

    def serialize(self):
        return {
            "employee_id": self.employee_id,
            "note": self.note,
            "account":
            self.account.serialize() if self.account != None else None,
            "last_name": self.last_name,
            "first_name": self.first_name,
            "phone": self.phone,
            "birth_day": self.birth_date,
            "provinceId": self.province_id,
            "districtId": self.district_id,
            "wardId": self.ward_id,
            "address": self.address,
            "gender": self.gender,
            "image": self.image,
            "basic_rate": self.basic_rate,
            "delete_at": self.delete_at,
            "email": self.email,
            "hire_date": self.hire_date
        }

    def __repr__(self):
        return f"Employee('{self.employee_id}','','{self.note}','{self.account.serialize()}','{self.first_name}'" \
               f",'{self.last_name}','{self.phone}','{self.birth_date}','{self.address}','{self.gender}','{self.image}'" \
               f",'{self.basic_rate}', '{self.delete_at}', '{self.hire_date}', '{self.email}')"
Example #16
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String())
    barcode = db.Column(db.String())
    membertype = db.Column(db.String())

    def to_json(self):
        return {
            "id": self.id,
            "name": self.name,
            "barcode": self.barcode,
            "memberType": self.membertype,
        }
Example #17
0
class Book(db.Model):
    id = db.Column(db.Integer, primary_key=True)

    title = db.Column(db.String(45), nullable=False)

    annotation = db.Column(db.String(1000), nullable=False)

    year = db.Column(db.Integer, nullable=False)

    author_id = db.Column(db.Integer, db.ForeignKey('author.id'))

    rubric_id = db.Column(db.Integer, db.ForeignKey('rubric.id'))

    press_id = db.Column(db.Integer, db.ForeignKey('press.id'))
Example #18
0
class Book(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String())
    isbn = db.Column(db.String())

    def to_json(self, entities=False):
        if not entities:
            return {"title": self.title, "isbn": self.isbn, "id": self.id}
        else:
            return {
                "id": self.id,
                "title": self.title,
                "isbn": self.isbn,
                "authors": [a.name for a in self.authors],
            }
Example #19
0
class Borrowtickets(db.Model):
    borrow_ticket_id = db.Column(db.Integer,
                                 autoincrement=True,
                                 primary_key=True,
                                 nullable=False,
                                 unique=True)
    customer_id = db.Column(db.Integer, db.ForeignKey('customers.customer_id'))
    employee_id = db.Column(db.Integer, db.ForeignKey('employees.employee_id'))
    quantity = db.Column(db.Integer)
    borrow_date = db.Column(db.DateTime)
    appointment_date = db.Column(db.DateTime)
    return_date = db.Column(db.DateTime)
    status = db.Column(db.String(20))
    delete_at = db.Column(db.DateTime, default=None)
    note = db.Column(db.String(1500))
    borrow_ticket_detail = db.relationship('Borrowticketdetails',
                                           backref='borrowticket',
                                           lazy=True)

    def serialize(self):
        return {
            "borrow_ticket_id":
            self.borrow_ticket_id,
            "customer":
            self.customer.serialize() if self.customer != None else None,
            "note":
            self.note,
            "employee":
            self.employee.serialize() if self.employee != None else None,
            "quantity":
            self.quantity,
            "borrow_date":
            self.borrow_date,
            "appointment_date":
            self.appointment_date,
            "return_date":
            self.return_date,
            "status":
            self.status,
            "delete_at":
            self.delete_at,
            "borrow_ticket_details":
            ConvertModelListToDictList(self.borrow_ticket_detail)
        }

    def __repr__(self):
        return f"Borrowticket('{self.borrow_ticket_id}','{self.customer.serialize()}','{self.note}','{self.employee.serialize()}'," \
               f"'{self.quantity}','{self.borrow_date}','{self.appointment_date}','{self.return_date}','{self.status}', '{self.delete_at}')"
Example #20
0
class Schedules(db.Model):
    schedule_id = db.Column(db.Integer,
                            unique=True,
                            primary_key=True,
                            autoincrement=True,
                            nullable=False)
    employee_id = db.Column(db.Integer, db.ForeignKey('employees.employee_id'))
    date = db.Column(db.DateTime)
    time_from = db.Column(db.DateTime)
    time_to = db.Column(db.DateTime)
    actual_hours = db.Column(db.Float)
    expected_hours = db.Column(db.Float)
    salary = db.Column(db.Float)
    delete_at = db.Column(db.DateTime, default=None)
    note = db.Column(db.String(1500))

    def serialize(self):
        return {
            "id": self.schedule_id,
            "employee": self.employee.serialize(),
            "date": self.date,
            "time_from": self.time_from,
            "time_to": self.time_to,
            "note": self.note,
            "actual_hours": self.actual_hours,
            "expected_hours": self.expected_hours,
            "salary": self.salary,
            "delete_at": self.delete_at
        }

    def __repr__(self):
        return f"Schedule('{self.schedule_id}','{self.employee.serialize()}','{self.date}','{self.time_from}','{self.time_to}'," \
               f"'{self.note}','{self.actual_hours}','{self.expected_hours}','{self.salary}', '{self.delete_at}')"
Example #21
0
class Books(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(length=150), nullable=False, unique=True)
    author = db.Column(db.String(length=50), nullable=False, unique=False)
    fee = db.Column(db.Integer(), nullable=False)
    count = db.Column(db.Integer(), nullable=False, default=1)
    owned = db.Column(db.Integer(), db.ForeignKey('member.id'))

    def __init__(self, name, author, fee, count):
        self.name = name
        self.author = author
        self.fee = fee
        self.count = count

    def __repr__(self):
        return f'Books {self.name}'
Example #22
0
class Author(db.Model):
    __tablename__ = 'authors'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    first_name = db.Column(db.String(64), nullable=False)
    middle_name = db.Column(db.String(64))
    last_name = db.Column(db.String(64), nullable=False)
    books = db.relationship('Book',
                            backref='author',
                            cascade='all, delete-orphan',
                            lazy='select')

    def __repr__(self):
        return f"<Author {self.last_name} {self.first_name[0]}. {self.middle_name[0]}.>"

    def __str__(self):
        return f"{self.last_name} {self.first_name[0]}. {self.middle_name[0]}."
Example #23
0
class Orderdetails(db.Model):
    order_id = db.Column(db.Integer,
                         db.ForeignKey('orders.order_id'),
                         primary_key=True)
    book_id = db.Column(db.Integer,
                        db.ForeignKey('books.book_id'),
                        primary_key=True)
    retail_price = db.Column(db.Float)
    quantity = db.Column(db.Integer)
    discount = db.Column(db.Float)
    total = db.Column(db.Float)
    note = db.Column(db.String(1500))
    delete_at = db.Column(db.DateTime, default=None)

    def serialize(self):
        return {
            "book": self.book.serialize() if self.book != None else None,
            "order_id": self.order_id,
            "note": self.note,
            "retail_price": self.retail_price,
            "quantity": self.quantity,
            "discount": self.discount,
            "total": self.total,
            "delete_at": self.delete_at
        }

    def __repr__(self):
        return f"Orderdetail('{self.order.serialize()}','{self.note}','{self.retail_price}','{self.quantity}'," \
               f"'{self.discount}','{self.note}', {self.delete_at})"
Example #24
0
class Messages(db.Model):
    message_id = db.Column(db.Integer,
                           autoincrement=True,
                           primary_key=True,
                           nullable=False,
                           unique=True)
    conversation_id = db.Column(db.Integer,
                                db.ForeignKey('conversations.conversation_id'),
                                nullable=False)
    content = db.Column(db.String(2000))
    created_at = db.Column(db.DateTime)
    deleted_at = db.Column(db.DateTime)
    account_id = db.Column(db.Integer,
                           db.ForeignKey('accounts.account_id'),
                           nullable=False)

    def serialize(self):
        return {
            'message_id': self.message_id,
            'conversation_id': self.conversation_id,
            'content': self.content,
            'created_at': self.created_at,
            'account_id': self.account_id,
            'deleted_at': self.deleted_at,
        }
Example #25
0
class Conversations(db.Model):
    conversation_id = db.Column(db.Integer,
                                autoincrement=True,
                                primary_key=True,
                                nullable=False,
                                unique=True)
    customer_account_id = db.Column(db.Integer,
                                    db.ForeignKey('accounts.account_id'),
                                    primary_key=True,
                                    nullable=False,
                                    unique=True)
    messages = db.relationship('Messages', backref='conversation', lazy=True)
    created_at = db.Column(
        db.DateTime)  #Ngay khi tạo tài khoản customer thành công
    updated_at = db.Column(db.DateTime)  #Ngay khi tin nhắn gần nhất được gửi
    last_message = db.Column(db.String(2000))
    is_read = db.Column(db.Boolean)

    def serialize(self):
        return {
            'conversation_id': self.conversation_id,
            'customer_account_id': self.customer_account_id,
            'created_at': self.created_at,
            'updated_at': self.updated_at,
            'last_message': self.last_message,
            'account':
            self.account.serialize() if self.account != None else None,
            'is_read': self.is_read
        }
Example #26
0
class Member(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(length=30), nullable=False, unique=True)
    rent = db.Column(db.Integer(), nullable=True, default=0)
    books = db.relationship('Books', backref='owned_book', lazy=True)

    def __init__(self, name, rent):
        self.name = name
        self.rent = rent
Example #27
0
class District(db.Model):
    id = db.Column(db.String(10), nullable=False)
    code = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50))
    provinceId = db.Column(db.String(50), name="province_id")

    def __init__(self, id, name, provinceId) -> None:
        self.id = id
        self.name = name
        self.provinceId = provinceId
        super().__init__()

    def serialize(self):
        return {
            "id": self.id,
            "name": self.name,
            "provinceId": self.provinceId,
        }
Example #28
0
class Province(db.Model):
    id = db.Column(db.String(10), nullable=False)
    code = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50))
    region = db.Column(db.String(50), name="region")

    def __init__(self, id, name, region) -> None:
        self.id = id
        self.name = name
        self.region = region
        super().__init__()

    def serialize(self):
        return {
            "id": self.id,
            "name": self.name,
            "region": self.region,
        }
Example #29
0
class Borrow(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    date_posted = db.Column(db.DateTime(60),
                            nullable=False,
                            default=datetime.utcnow)

    #video 4 minute 17:30 to explains the making of databases

    def __repr__(self):
        return f"Borrow('{self.title}','{self.DatePosted}')"
Example #30
0
class Book(db.Model):
    __tablename__ = 'books'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(120), nullable=False)
    author_id = db.Column(db.Integer, db.ForeignKey('authors.id'))

    def __repr__(self):
        return f"<Book {self.title}>"

    def __str__(self):
        return f"{self.title}"