def login():
    corpid = request.form['corpId']
    corppass = request.form['corppass']
    sb = EmployeeProfileDAL()
    # EmployeeName = (sb.get_current_employee_Info(corpid))[0][0]
    EmployeeName = corpid
    rowReturn = sb.read_employee()
    loginfailedmsg = "Invalid credentials"
    EmployeeNamefromldap = authenticationldap3(corpid, corppass)
    if EmployeeNamefromldap == "u:CORP\\" + corpid:
        if request.method == 'POST':
            session.pop('user', None)
            if EmployeeNamefromldap:
                session['user'] = request.form['corpId']
                app.logger.info(
                    '-------------------------------------------------------------------------------------'
                )
                app.logger.info('Logged in by: %s', corpid)
                admin_return = Admin()
                if admin_return == "Yes":
                    # return render_template("Dashboard.html", rowTable=rowReturn, **locals())
                    return redirect(url_for("viewTeamfun"))
                else:
                    return render_template("Dashboard.html",
                                           rowTable=rowReturn,
                                           **locals())
    app.logger.error('Failed to login for %s', corpid)
    return render_template("loginV4.html", **locals())
def update_profile():
    # Create cursor
    if 'user' in session:
        sb = EmployeeProfileDAL()
        corpid = session['user']
        # EmployeeName = (sb.get_current_employee_Info(corpid))[0][0]
        EmployeeName = corpid
        employee_id = request.form['employeeId']
        employee_name = request.form['employeeName']
        project_id = request.form['prismId']
        project_name = request.form['projectNameUpdate']
        corpIdM = request.form['corpIdUpdate']
        email = request.form['emailIdUpdate']
        employeeODCStatus = 'Assigned'
        department = request.form['DepartmentUpdate']
        projectList = []
        for value in ReadJson()['project details']:
            projectList.append(value['projectName'])
        employee = Employee(employee_id, employee_name, project_id,
                            project_name, corpIdM, email, department,
                            employeeODCStatus)
        sb.update_employee(employee)
        rowReturn = sb.read_employee()
        sb.c.close()
        print("DataBase is closed")
        # return "Values Submitted to database"
        app.logger.info('%s updated profile details', corpid)
        AdminReturn = Admin()
        if AdminReturn == "Yes":
            return render_template("Dashboard.html",
                                   rowTable=rowReturn,
                                   **locals())
        else:
            return render_template("Dashboard.html",
                                   rowTable=rowReturn,
                                   EmployeeName=EmployeeName,
                                   employee=employee,
                                   projectList=projectList)
    return redirect(url_for('show_data'))
def add_profile():
    if 'user' in session:
        employee_id = request.form['employeeId']
        employee_name = request.form['employeeName']
        project_id = request.form['ProjectID']
        project_name = request.form['ProjectName']
        corpid = session['user']
        email = request.form['Mail']
        corp_idM = request.form['CorpID']
        department = request.form['Department']
        employeeODCStatus = "Assigned"
        sb = EmployeeProfileDAL()
        projectList = []
        for value in ReadJson()['project details']:
            projectList.append(value['projectName'])
        # EmployeeName = (sb.get_current_employee_Info(corpid))
        EmployeeName = corpid
        employee = Employee(employee_id, employee_name, project_id,
                            project_name, corp_idM, email, department,
                            employeeODCStatus)
        sb.add_employee(employee)
        rowReturn = sb.read_employee()
        sb.c.close()
        print("DataBase is closed")
        app.logger.info('%s added by: %s', employee_id, corpid)
        AdminReturn = Admin()
        if AdminReturn == "Yes":
            return render_template("Dashboard.html",
                                   rowTable=rowReturn,
                                   **locals())
        else:
            return render_template("Dashboard.html",
                                   rowTable=rowReturn,
                                   EmployeeName=EmployeeName,
                                   employee=employee,
                                   corpid=corpid,
                                   projectList=projectList)
    return redirect(url_for('show_data'))
def list_all_users():
    if 'user' in session:
        sb = EmployeeProfileDAL()
        corpid = session['user']
        # EmployeeName = (sb.get_current_employee_Info(corpid))[0][0]
        EmployeeName = corpid
        row_return = sb.read_employee()
        projectList = []

        for value in ReadJson()['project details']:
            projectList.append(value['projectName'])
        app.logger.info('Employee Details page viewed by : %s', corpid)
        AdminReturn = Admin()
        if AdminReturn == "Yes":
            return render_template("Dashboard.html",
                                   rowTable=row_return,
                                   **locals())
        else:
            return render_template("Dashboard.html",
                                   rowTable=row_return,
                                   EmployeeName=EmployeeName,
                                   corpid=corpid,
                                   projectList=projectList)
    return redirect(url_for('show_login'))
def gettingOtherDeductionsInfo(month, year):
    numOfDays = calendar.monthrange(year, int(month))
    startDate = "1-" + str(month) + "-" + str(year)
    endDate = str(numOfDays[1]) + "-" + str(month) + "-" + str(year)
    otherDeductions = []
    for value in ReadJson()['OtherDeductions']:
        otherDeductions.append(value['PaymentRecovery'])
        otherDeductions.append(value['Amount'])
        otherDeductions.append(value['PaymentRecoveryTowards'])
        otherDeductions.append(value['LetterToBeIssued'])
        otherDeductions.append(value['ApprovalAttached'])
        otherDeductions.append(value['NameOftheAttachment'])
        otherDeductions.append(value['ApproverName'])
        otherDeductions.append(value['RemarksReason'])
        otherDeductions.append(value['TypeOfDeduction'])
        otherDeductions.append(value['MinimumWorkDays'])

    # print(numOfDays[1])
    numOfDaysCfCurrentMonth = numOfDays[1]
    sb = EmployeeProfileDAL()
    # EmployeeName = (sb.get_current_employee_Info(corpid))[0][0]

    employee_list = sb.read_employee()
    employeeStatusListView = []
    for employee in employee_list:
        employeeWorkStatus = []
        counterForOn = 0
        dateArray = dateArrayMethod(year, int(month))
        for i in range(numOfDaysCfCurrentMonth):
            if dateArray[i][-3:] == 'Sat' or dateArray[i][-3:] == 'Sun':
                test = " "
            else:
                counterForOn += 1

        employee_leave_list = sb.read_leaves_type(employee[6], month, year)
        if employee_leave_list is not None:
            counterForFullDay = 0
            counterForHalfDay = 0
            for leave in employee_leave_list:
                numOfDays = calendar.monthrange(year, int(month))
                numOfDaysCfCurrentMonth = numOfDays[1]
                leave_date = str(leave[0])
                leave_type = leave[1]
                leavedate = leave_date.split('/')
                if leave_type == '1':
                    counterForFullDay += 1  #full day leave
                else:
                    counterForHalfDay += 1  #half day leave
        totalDayOfFullDays = counterForFullDay
        totalDayOfHalfDays = counterForHalfDay
        totalhoursofWork = 0
        totalhoursofWork = (counterForOn * 8 -
                            (counterForFullDay * 8 + counterForHalfDay * 4))
        print("Total work hours = %d" % totalhoursofWork)
        print("OtherDeductions[9]= %d" % int(otherDeductions[9]))
        if (totalhoursofWork <
            (int(otherDeductions[9]) * 8)):  #if work days is less than 7 days
            print("inside continue")
            continue
        else:
            employeeWorkStatus.append(str(employee[1]))
            employeeWorkStatus.append(otherDeductions[0])
            employeeWorkStatus.append(employee[2])
            employeeWorkStatus.append(otherDeductions[1])
            employeeWorkStatus.append(startDate)
            employeeWorkStatus.append(endDate)
            employeeWorkStatus.append(otherDeductions[2])
            employeeWorkStatus.append(otherDeductions[3])
            employeeWorkStatus.append(otherDeductions[4])
            employeeWorkStatus.append(otherDeductions[5])
            employeeWorkStatus.append(otherDeductions[6])
            employeeWorkStatus.append(otherDeductions[7])
            employeeStatusListView.append(employeeWorkStatus)
    return employeeStatusListView
def gettingInfo(month, year):
    #corpid=session['user']
    numOfDays = calendar.monthrange(year, int(month))
    numOfDaysCfCurrentMonth = numOfDays[1]
    sb = EmployeeProfileDAL()
    employee_list = sb.read_employee()
    employeeStatusListView = []
    HolidayList = []
    HolidayMonth = []
    HolidayDates = []
    listOfDays = list(range(1, numOfDaysCfCurrentMonth + 1))
    # get the current month
    # get the month from holiday
    # and compare
    dateArray = dateArrayMethod(year, int(month))
    i = 0
    for value in ReadJson()['waters holidays']:
        HolidayList.append(value['date'].split("/"))
        HolidayMonth.append(HolidayList[i][1])
        # filter out the dates of relevent month
        if month in HolidayMonth:
            if HolidayList[i][1] == month:
                HolidayDates.append(int(HolidayList[i][0]))
                # getHolidayDates
        i = i + 1

    for employee in employee_list:
        employeeWorkStatus = []
        counterForOn = 0
        # employeeWorkStatus.append(str(employee[7]))
        employeeWorkStatus.append(str(employee[0]))
        employeeWorkStatus.append(str(employee[1]))
        employeeWorkStatus.append(employee[2])
        employeeWorkStatus.append(employee[3])
        employeeWorkStatus.append(employee[4])
        employeeWorkStatus.append(" ")
        employeeWorkStatus.append(" ")
        employeeWorkStatus.append(" ")
        employeeWorkStatus.append(" ")

        for i in range(numOfDaysCfCurrentMonth):
            if dateArray[i][-3:] == 'Sat' or dateArray[i][-3:] == 'Sun' or (
                    i + 1 in HolidayDates):
                employeeWorkStatus.append(" ")
            else:
                employeeWorkStatus.append("Present")
                counterForOn += 1

        employee_leave_list = sb.read_leaves_type(employee[6], month, year)
        if employee_leave_list is not None:
            counterForFullDay = 0
            counterForHalfDay = 0
            for leave in employee_leave_list:
                numOfDays = calendar.monthrange(year, int(month))
                numOfDaysCfCurrentMonth = numOfDays[1]
                leave_date = str(leave[0])
                leave_type = leave[1]
                leavedate = leave_date.split('/')
                if leave_type == '1':
                    employeeWorkStatus[int(leavedate[0]) + 8] = 'FullDayLeave'
                    counterForFullDay += 1
                elif leave_type == '2':
                    employeeWorkStatus[int(leavedate[0]) + 8] = 'HalfDayLeave'
                    counterForHalfDay += 1
                elif leave_type == '3':
                    employeeWorkStatus[int(leavedate[0]) + 8] = 'Non-WIPL'
                    # counterForHalfDay += 1

        totalDayOfFullDays = counterForFullDay
        totalDayOfHalfDays = counterForHalfDay
        totalhoursofWork = (counterForOn * 8 -
                            (counterForFullDay * 8 + counterForHalfDay * 4)
                            )  #+ (len(HolidayDates)*8)))
        employeeWorkStatus.append(" ")
        employeeWorkStatus.append(str(totalDayOfFullDays))
        employeeWorkStatus.append(str(totalDayOfHalfDays))
        employeeWorkStatus[7] = str(totalhoursofWork)
        employeeWorkStatus[5] = str(round(21.85 * totalhoursofWork, 1))
        employeeWorkStatus[6] = str(21.85)
        employeeStatusListView.append(employeeWorkStatus)
    return employeeStatusListView