Exemplo n.º 1
0
    def update(self):
        self.normalize()
        if self.badSetup:
            log(self.ID, "Employee is invalid")
            return
        if not self.exists:
            log(self.ID, "Employee does not exist yet, did you mean to create?")
            return
        _first_name = "first_name='{}'".format(self.first_name)
        _last_name = "last_name='{}'".format(self.last_name)
        _ssn = "ssn='{}'".format(self.ssn)
        _job_title = "job_title='{}'".format(self.job_title)
        _salary_type = "salary_type='{}'".format(self.salary_type)
        _insurancePlan = "insurancePlan='{}'".format(self.insurancePlan)
        _email = "email='{}'".format(self.email)
        _country = "country='{}'".format(self.country)
        _state = "state='{}'".format(self.state)
        _street_name = "street_name='{}'".format(self.street_name)
        _postal_code = "postal_code='{}'".format(self.postal_code)
        _F01k_deduction = "F01k_deduction='{}'".format(self.F01k_deduction)
        _rate = "rate='{}'".format(self.rate)
        _hours = "hours='{}'".format(self.hours)
        DB.execute(
            Query.UPDATE_SINGLE(
                Entity.EMPLOYEE,
                self.e_id,
                _first_name,
                _last_name,
                _ssn,
                _job_title,
                _salary_type,
                _insurancePlan,
                _email,
                _country,
                _state,
                _street_name,
                _postal_code,
                _F01k_deduction,
                _rate,
                _hours,
            )
        )

        # TODO: Only modify tables that actually changed

        DB.execute(Query.DELETE(Relation.HAS, "e_id='{}'".format(self.e_id)))

        DB.execute(Query.DELETE(Multivalue.EMPLOYEE_PHONE, "e_id='{}'".format(self.e_id)))

        DB.execute(Query.DELETE(Multivalue.EMPLOYEE_BENEFIT_SELECTION, "e_id='{}'".format(self.e_id)))

        for d in self.Dependents:
            DB.execute(Query.CREATE(Relation.HAS, self.e_id, d))

        for p in self.PhoneNumbers:
            DB.execute(Query.CREATE(Multivalue.EMPLOYEE_PHONE, self.e_id, p))

        for b in self.Benefits:
            DB.execute(Query.CREATE(Multivalue.EMPLOYEE_BENEFIT_SELECTION, self.e_id, b))
Exemplo n.º 2
0
 def getTaxRate(self):
     self.normalize()
     if self.badSetup:
         log(self.ID, "Employee is invalid")
         return
     if not self.exists:
         log(self.ID, "Employee does not exist yet, did you mean to create?")
         return
     DB.execute(Query.FIND(Entity.STATE, self.state, "tax_rate"))
     return float(DB.result()[0][0])
Exemplo n.º 3
0
    def create(self):  # TODO: use prepared statements instead
        self.normalize()
        if self.badSetup:
            log(self.ID, "Employee is invalid")
            return
        if self.exists:
            log(self.ID, "Employee already created, did you mean to update?")
            return
        DB.execute(
            Query.CREATE(
                Entity.EMPLOYEE,
                self.e_id,
                self.first_name,
                self.last_name,
                self.ssn,
                self.job_title,
                self.salary_type,
                self.insurancePlan,
                self.email,
                self.country,
                self.state,
                self.street_name,
                self.postal_code,
                self.F01k_deduction,
                self.rate,
                self.hours,
            )
        )

        if DB.result():
            log(self.ID, "Created employee {}".format(self.e_id))

        for d in self.Dependents:
            DB.execute(Query.CREATE(Relation.HAS, self.e_id, d))

        for p in self.PhoneNumbers:
            DB.execute(Query.CREATE(Multivalue.EMPLOYEE_PHONE, self.e_id, p))

        for b in self.Benefits:
            DB.execute(Query.CREATE(Multivalue.EMPLOYEE_BENEFIT_SELECTION, self.e_id, b))
Exemplo n.º 4
0
    def create(self):
        self.normalize()
        if self.badSetup:
            log(self.ID, "Dependent is invalid")
            return
        if self.exists:
            log(self.ID, "Dependent already created, did you mean to update?")
            return
        DB.execute(
            Query.CREATE(Entity.DEPENDENT, self.d_id, self.first_name,
                         self.last_name, self.ssn, self.benefitSelection))

        if DB.result():
            log(self.ID, "Created Dependent {}".format(self.d_id))
Exemplo n.º 5
0
def signIn(first_name: str, e_id: str):
    global currentTitle, currentUser, currentEmployee
    """ Sign in given first name and e_id of employee """
    DB.execute(Query.SELECT_WHERE(Entity.EMPLOYEE, "first_name='{}' and e_id='{}'".format(first_name, e_id), "job_title"))
    try:
        currentTitle = DataType.JobTitle(DB.result()[0][0])
        currentUser = first_name
        if currentTitle:
            log(ID, getString())
            currentEmployee = Employee(e_id)
    except IndexError:
        log(ID, "Failed to Sign In")
        currentTitle = None
        currentUser = None
        currentEmployee = None
Exemplo n.º 6
0
 def getInsurnacePlanCost(self):
     self.normalize()
     if self.badSetup:
         log(self.ID, "Employee is invalid")
         return
     if not self.exists:
         log(self.ID, "Employee does not exist yet, did you mean to create?")
         # return
     DB.execute(
         Query.FIND(
             Entity.INSURNACE_PLAN,
             self.insurancePlan,
             "employer_cost_for_family" if len(self.Dependents) > 0 else "employer_cost_for_individual",
         )
     )
     return float(DB.result()[0][0])
Exemplo n.º 7
0
    def __init__(
        self,
        d_id: str = None,
        first_name: str = None,
        last_name: str = None,
        ssn: str = None,
        benefitSelection: DataType.BenefitSelection = None,
    ):
        """ Initialize a new Dependent to be created or updated"""
        self.d_id = d_id
        DB.execute(
            Query.SELECT_WHERE(Entity.DEPENDENT, "d_id='{}'".format(d_id),
                               "*"))
        self.exists = DB.result()
        if self.exists != None:
            if len(self.exists) == 0:
                self.exists = None

        if self.exists and first_name:
            log(
                self.ID,
                "Warning: Dependent already exists but options parameters were still passed"
            )

        if not self.exists:
            if not d_id or not first_name or not last_name or not ssn or not benefitSelection:
                log(self.ID, "Dependent does not exist")
                self.badSetup = True
                self.exists = False
                return
            self.d_id = d_id
            self.first_name = first_name
            self.last_name = last_name
            self.ssn = ssn
            self.benefitSelection = benefitSelection.value
        else:
            log(self.ID, "Dependent found")
            self.exists = self.exists[0]
            self.first_name = self.exists[1]
            self.last_name = self.exists[2]
            self.ssn = self.exists[3]
            self.benefitSelection = self.exists[4]

        self.normalize()

        if self.badSetup:
            return
Exemplo n.º 8
0
 def update(self):
     self.normalize()
     if self.badSetup:
         log(self.ID, "Dependent is invalid")
         return
     if not self.exists:
         log(self.ID,
             "Dependent does not exist yet, did you mean to create?")
         return
     _first_name = "first_name='{}'".format(self.first_name)
     _last_name = "last_name='{}'".format(self.last_name)
     _ssn = "ssn='{}'".format(self.ssn)
     _benefitSelection = "benefitSelection='{}'".format(
         self.benefitSelection)
     DB.execute(
         Query.UPDATE_SINGLE(Entity.DEPENDENT, self.d_id, _first_name,
                             _last_name, _ssn, _benefitSelection))
Exemplo n.º 9
0
def expenseReport():
    repo = ""
    employeeCount = 0
    employeeWages = 0
    bonusCount = 0
    bonuses = 0
    f01k = 0
    social = 0
    premium = 0

    DB.execute(Query.SELECT(Entity.EMPLOYEE, "e_id"))
    for ID in DB.result():
        e = Employee(ID[0])
        wage = e.rate * e.hours
        if e.salary_type == DataType.Salary.SALARY.value:
            wage = e.rate
            bonuses += rnd(0, int(e.rate)) + e.rate % 1
            bonusCount += 1
            social += 0.075 * wage
        employeeWages += wage
        f01k += wage * min(float(e.F01k_deduction) / 100.0, 0.07)
        employeeCount += 1
        premium += e.getInsurnacePlanCost() / 2

    repo += """
---------[ COMPANY EXPENSE REPORT ]---------
    
    Employee Wages @ {} : ${}
    Bonuses @ {} : ${}
    401K Contributions : ${}
    Social Security Contribution @ {} : ${}
    Insurance Premiums : ${}
    
    """.format(employeeCount, employeeWages, bonusCount, bonuses,
               round(f01k, 2), bonusCount, social, premium)

    return repo
Exemplo n.º 10
0
    def __init__(
        self,
        e_id: str,
        first_name: str = None,
        last_name: str = None,
        ssn: str = None,
        job_title: DataType.JobTitle = None,
        salary_type: DataType.Salary = None,
        insurancePlan: str = None,
        email: str = None,
        country: str = None,
        state: str = None,
        street_name: str = None,
        postal_code: int = None,
        F01k_deduction: int = None,
        rate: float = None,
        hours: int = None,
    ):
        """ Initialize a new Employee to be created or updated"""
        self.e_id = e_id
        DB.execute(Query.SELECT_WHERE(Entity.EMPLOYEE, "e_id='{}'".format(e_id), "*"))
        self.exists = DB.result()
        if self.exists != None:
            if len(self.exists) == 0:
                self.exists = None

        if self.exists and first_name:
            log(self.ID, "Warning: Employee already exists but options parameters were still passed")

        if not self.exists:
            if (
                not first_name
                or not last_name
                or not ssn
                or not job_title
                or not salary_type
                or not insurancePlan
                or not email
                or not country
                or not state
                or not street_name
                or not postal_code
                or not F01k_deduction
                or not rate
                or not hours
            ):
                log(self.ID, "Employee does not exist")
                self.badSetup = True
                self.exists = False
                return
            self.first_name = first_name
            self.last_name = last_name
            self.ssn = ssn
            self.job_title = job_title.value
            self.salary_type = salary_type.value
            self.insurancePlan = insurancePlan
            self.email = email
            self.country = country
            self.state = state
            self.street_name = street_name
            self.postal_code = postal_code
            self.F01k_deduction = F01k_deduction
            self.rate = rate
            self.hours = hours
            if type(postal_code) != int or type(F01k_deduction) != int or type(rate) != float or type(hours) != int:
                log(self.ID, "Bad parameter types")
                self.badSetup = True
                self.exists = False
        else:
            log(self.ID, "Employee found")
            self.exists = self.exists[0]
            self.first_name = self.exists[1]
            self.last_name = self.exists[2]
            self.ssn = self.exists[3]
            self.job_title = self.exists[4]
            self.salary_type = self.exists[5]
            self.insurancePlan = self.exists[6]
            self.email = self.exists[7]
            self.country = self.exists[8]
            self.state = self.exists[9]
            self.street_name = self.exists[10]
            self.postal_code = self.exists[11]
            self.F01k_deduction = self.exists[12]
            self.rate = self.exists[13]
            self.hours = self.exists[14]

        self.normalize()

        DB.execute(Query.FIND(Entity.STATE, self.state))
        found = DB.result()
        if not found:
            log(self.ID, "Employee State {} not found".format(self.state))
            self.badSetup = True
            self.exists = False

        DB.execute(Query.FIND(Entity.INSURNACE_PLAN, self.insurancePlan))
        found = DB.result()
        if not found:
            log(self.ID, "Employee State {} not found".format(self.insurancePlan))
            self.badSetup = True
            self.exists = False

        if self.badSetup:
            return

        DB.execute(Query.FIND(Relation.HAS, self.e_id))
        res = DB.result()

        for d in res:
            self.Dependents.add(str(d[1]))

        DB.execute(Query.FIND(Multivalue.EMPLOYEE_PHONE, self.e_id))
        res = DB.result()
        for p in res:
            self.PhoneNumbers.add(str(p[1]))

        DB.execute(Query.FIND(Multivalue.EMPLOYEE_BENEFIT_SELECTION, self.e_id))
        res = DB.result()
        for b in res:
            self.Benefits.add(str(b[1]))
Exemplo n.º 11
0
def checkReport():
    biweeklyReport = ""
    ssn = ""
    biweeklyPay = 0
    stateTax = 0
    federalTax = 0
    socialsPay = 0
    medicarePay = 0
    F01kPay = 0
    insurancePay = 0
    finalPay = 0

    DB.execute(Query.SELECT(Entity.EMPLOYEE, "e_id"))

    # get current employee
    e = Auth.getCurrentEmployee()
    ssn = e.ssn

    if e.salary_type == DataType.Salary.HOURLY.value:
        biweeklyPay = round(e.hours * e.rate, 2)
    else:
        biweeklyPay = round(e.rate / 26, 2)

    sTax = biweeklyPay * e.getTaxRate()
    stateTax = round(sTax, 2)

    if e.rate < 10000:
        fTax = biweeklyPay * 0.01
    elif e.rate < 40000:
        fTax = biweeklyPay * 0.02
    elif e.rate < 85000:
        fTax = biweeklyPay * 0.04
    elif e.rate < 163301:
        fTax = biweeklyPay * 0.06
    elif e.rate < 207351:
        fTax = biweeklyPay * 0.08
    else:
        fTax = biweeklyPay * 0.09

    federalTax = round(fTax, 2)

    # SS
    if e.salary_type == DataType.Salary.HOURLY.value:
        ssPay = biweeklyPay * 0.15
        socialsPay = round(ssPay, 2)
    else:
        ssPay = biweeklyPay * 0.075
        socialsPay = round(ssPay, 2)
        # company pays other 0.075 in their expense report

    # medicare
    mcPay = biweeklyPay * 0.025
    medicarePay = round(mcPay, 2)

    # 401k deduction
    F01kPay = round(biweeklyPay * (e.F01k_deduction / 100), 2)
    # company matched up to 7%

    insurancePay = round(float(e.getInsurnacePlanCost()), 2)
    # here
    finalPay = round(
        biweeklyPay - stateTax - federalTax - socialsPay - medicarePay -
        F01kPay - insurancePay, 2)

    biweeklyReport += """
---------[ BIWEEKLY CHECK REPORT ]---------
    
    SSN : {}
    income no deductions: ${}
    state tax: ${}
    federal tax: ${}
    social security contribution: ${}
    medicare contribution: ${}
    401k contribution: ${}
    insurance cost: ${}
    Final pay: ${}
    """.format(ssn, biweeklyPay, stateTax, federalTax, socialsPay, medicarePay,
               F01kPay, insurancePay, finalPay)

    return biweeklyReport