class Payments(db.Model): """ this creates the payment model """ __tablename__ = "Payments" id = db.Column(db.String(20), primary_key=True) employee_id = db.Column(db.String(20), db.ForeignKey("Employees.id")) project_number = db.Column(db.Integer) project_name = db.Column(db.String(100)) employee_name = db.Column(db.String(120)) expense_head = db.Column(db.String(255)) rate = db.Column(db.Integer) days = db.Column(db.Integer) total_amount = db.Column(db.Float) file_id = db.Column(db.String(20), db.ForeignKey("Files.id")) advance_amount = db.Column(db.Float) def __init__(self, id, employee_id, project_number, project_name, employee_name, expense_head, rate, days, total_amount, file_id, advance_amount): """initializing inputs for this model""" self.id = id self.employee_id = employee_id, self.project_number = project_number, self.project_name = project_name, self.employee_name = employee_name, self.expense_head = expense_head, self.rate = rate, self.days = days, self.total_amount = total_amount self.file_id = file_id self.advance_amount = advance_amount
class User(db.Model): """ this creates the system users model """ __tablename__ = "Users" id = db.Column(db.String(20), primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True, nullable=False) password = db.Column(db.String(128), nullable=False) companyId = db.Column(db.String(20), db.ForeignKey("Company.id")) role = db.Column(db.String(25), nullable=False) isActive = db.Column(db.String(25), default="False", nullable=False) def __init__(self, id, username, email, password, role, companyId, isActive): """initilize user db values""" self.id = id self.username = username self.email = email self.password = self.hash_password(password) self.companyId = companyId self.role = role self.isActive = isActive def hash_password(self, password): """create a password hash for storage""" password_hash = generate_password_hash(str(password)) return password_hash def compare_password(hashed_password, password): """compare a plain password with its stored hash""" return check_password_hash(hashed_password, str(password))
class Files(db.Model): """this creates the files model""" __tablename__ = "Files" id = db.Column(db.String(20), primary_key=True) companyId = db.Column(db.String(20), db.ForeignKey("Company.id")) projectId = db.Column(db.String(20), db.ForeignKey("Project.id")) fileType = db.Column(db.String(10), nullable=False) fileAmount = db.Column(db.Float, nullable=False) createdBy = db.Column(db.String(20), db.ForeignKey("Users.id")) dateCreated = db.Column(db.Date) authorizedOrRejectedBy = db.Column(db.String(20), db.ForeignKey("Users.id")) dateAuthorizedOrRejected = db.Column(db.Date) fileStatus = db.Column(db.String(25), nullable=False) fileName = db.Column(db.String(100), nullable=False) def __init__( self, id, companyId, projectId, fileType, fileAmount, createdBy, dateCreated, authorizedOrRejectedBy, dateAuthorizedOrRejected, fileStatus, fileName, ): """intilizing files model items""" self.id = id self.companyId = companyId self.projectId = projectId self.fileType = fileType self.fileAmount = fileAmount self.createdBy = createdBy self.dateCreated = dateCreated self.authorizedOrRejectedBy = authorizedOrRejectedBy self.dateAuthorizedOrRejected = dateAuthorizedOrRejected self.fileStatus = fileStatus self.fileName = fileName
class Transactions(db.Model): """ this creates the transactions model """ __tablename__ = "Transactions" id = db.Column(db.String(20), primary_key=True) employeeId = db.Column(db.String(20), db.ForeignKey("Employees.id")) narration = db.Column(db.String(255)) authorizedBy = db.Column(db.String(20), db.ForeignKey("Employees.id")) date = db.Column(db.Date) amount = db.Column(db.Float) def __init__(self, id, employeeId, narration, authorizedby, date, amount): """initializing objects for transactions model""" self.id = id, self.employeeId = employeeId, self.narration = narration, self.authorizedBy = authorizedby, self.date = date, self.amount = amount
class ProjectRegions(db.Model): """ this creates the project regions model """ __tablename__ = "ProjectRegions" id = db.Column(db.String(20), primary_key=True) projectId = db.Column(db.String(20), db.ForeignKey("Project.id")) region = db.Column(db.String(100), nullable=False) def __init__(self, id, projectId, region): """initializing inputs for this model""" self.id = id self.projectId = projectId self.region = region
class ProjectNumber(db.Model): """ create project number or job number """ __tablename__ = "ProjectNumber" id = db.Column(db.String(20), primary_key=True) projectNumber = db.Column(db.Integer, nullable=False) companyId = db.Column(db.String(20), db.ForeignKey("Company.id")) def __init__(self, id, projectNumber, companyId): """initializing inputs for this model""" self.id = id self.projectNumber = projectNumber self.companyId = companyId
class Employees(db.Model): """this creates the employees model""" __tablename__ = "Employees" id = db.Column(db.String(20), primary_key=True) companyId = db.Column(db.String(20), db.ForeignKey("Company.id")) fullname = db.Column(db.String(120), nullable=True) # mobile = db.Column(db.String(12), nullable=False, unique=True) email = db.Column(db.String(120), unique=True) def __init__(self, id, companyId, fullname, email): """initilizing employees model table items""" self.id = id self.companyId = companyId self.fullname = fullname # self.mobile = mobile self.email = email
class Project(db.Model): """ this creates the project model """ __tablename__ = "Project" id = db.Column(db.String(20), primary_key=True) project_name = db.Column(db.String(100), nullable=False, unique=True) projectNumber = db.Column(db.Integer) companyId = db.Column(db.String(20), db.ForeignKey("Company.id")) date_from = db.Column(db.Date) project_status = db.Column(db.String(10), nullable=False) def __init__(self, id, project_name, projectNumber, companyId, date_from, project_status): """initializing inputs for this model""" self.id = id self.project_name = project_name self.projectNumber = projectNumber self.companyId = companyId self.date_from = date_from self.project_status = project_status