def editEmployeePerfomed(request, employee_id): date_of_birth = convert_to_date(request.POST['dateOfBirth']) joining_date = convert_to_date(request.POST['joiningDate']) emp = get_object_or_404(Employee, pk=employee_id) emp.gender = request.POST['title'] emp.employeeName = request.POST['employeeName'] emp.mobile = request.POST['mobile'] emp.fatherName = request.POST['fatherName'] emp.motherName = request.POST['motherName'] emp.dateOfBirth = date_of_birth emp.bloodGroup = request.POST['bloodGroup'] emp.nationality = request.POST['nationality'] emp.nationalId = request.POST['nationalId'] emp.passportId = request.POST['passportId'] emp.employeeCode = request.POST['employeeCode'] emp.cardId = request.POST['cardId'] emp.joiningDate = joining_date emp.bankName = request.POST['bankName'] emp.bankAccountNo = request.POST['bankAccountNo'] emp.email = request.POST['email'] emp.permanentAddress = request.POST['permanentAddress'] emp.presentAddress = request.POST['presentAddress'] emp.updateUser = request.user.id emp.updateDate = date.today() emp.save() return redirect('hr:viewEmployeeList', 'edited')
def addYearlyHolidayPerfomed(request): startDate = convert_to_date(request.POST['start_date']) endDate = convert_to_date(request.POST['end_date']) dayCount = abs(endDate-startDate).days + 1 try: flagCount = YearlyHoliday.objects.latest('id').id + 1 except ObjectDoesNotExist: flagCount = 1 for days in range(0,dayCount): obj = YearlyHoliday(holidayTitle = request.POST['name'], date = startDate, year = startDate.strftime("%Y"), description = request.POST['comments'], isActive = True, flag = flagCount) obj.save() startDate = startDate + timedelta(days=1) #print(startDate.strftime("%Y")) return HttpResponseRedirect(reverse('holiday:addYearlyHoliday'))
def editEmployee_admin(request, emp_des_id): new_effective_date_start = convert_to_date(request.POST['date']) print(request.POST['isActive']) des_obj = get_object_or_404(EmployeeDesignation, pk=emp_des_id) des_obj.department_id = get_object_or_404(Department, pk=request.POST['departmentId']) des_obj.des_id = get_object_or_404(Designation, pk=request.POST['designationId']) des_obj.location_id = get_object_or_404(Location, pk=request.POST['locationId']) des_obj.supervisor_id = int(request.POST['supervisor']) des_obj.effective_date_start = new_effective_date_start des_obj.updateUser = request.user.id des_obj.updateDate = date.today() des_obj.status = request.POST['status'] des_obj.isActive = request.POST['isActive'] des_obj.save() return HttpResponseRedirect(reverse('hr:editEmployeeDesignationPage'))
def addEmployeeDesignationPerfomed(request): effective_start_date = convert_to_date(request.POST['date']) obj = EmployeeDesignation( employee_id=get_object_or_404(Employee, pk=request.POST['employeeId']), department_id=get_object_or_404(Department, pk=request.POST['departmentId']), des_id=get_object_or_404(Designation, pk=request.POST['designationId']), location_id=get_object_or_404(Location, pk=request.POST['locationId']), effective_date_start=effective_start_date, effective_date_end=datetime.max.date(), supervisor=get_object_or_404(Employee, pk=request.POST['supervisor']), isActive=True, isDelete=False, insertUser=request.user.id, insertDate=date.today(), project='1', status='new') obj.save() return HttpResponseRedirect(reverse('hr:addEmployeeDesignationPage'))
def addWeeklyHolidayPerfomed(request): value = request.POST.getlist('dayName') new_startDate = convert_to_date(request.POST['date']) old_endDate = new_startDate - timedelta(days=1) location = request.POST.getlist('location') print(location) weekday = WeekDays.objects.filter(status = True) for q in weekday: q.status = False q.save() for list in location: query_set = WeeklyHoliday.objects.filter(isActive = True, active_location_id = list) for q in query_set: q.isActive = False q.effectiveEnd = old_endDate q.updateUser = request.user.id q.updateDate = date.today() q.save() for val in value: day = WeekDays.objects.get(dayNum=val) day.status = True day.save() obj = WeeklyHoliday(dayNum = day.dayNum, effectiveFrom = new_startDate, effectiveEnd = datetime.max.date(), dayName = day.dayname, active_location_id = list, isActive = True, insertUser = request.user.id, insertDate = date.today()) obj.save() return HttpResponseRedirect(reverse('holiday:addWeeklyHoliday'))
def addEmployeePerfomed(request): date_of_birth = convert_to_date(request.POST['dateOfBirth']) joining_date = convert_to_date(request.POST['joiningDate']) '''e = Employee(employeeName = request.POST['employeeName'], gender = request.POST['title'], presentAddress = request.POST['presentAddress'], permanentAddress = request.POST['permanentAddress'], fatherName = request.POST['fatherName'], motherName = request.POST['motherName'], email = request.POST['email'], bloodGroup = request.POST['bloodGroup'], nationality = request.POST['nationality'], nationalId = request.POST['nationalId'], joiningDate = joining_date, dateOfBirth = date_of_birth, passportId = request.POST['passportId'], employeeCode = request.POST['employeeCode'], cardId = request.POST['cardId'], bankName = request.POST['bankName'], bankAccountNo = request.POST['bankAccountNo'], mobile = request.POST['mobile'], isActive = True, isDelete = False, insertUser=request.user.id, insertDate=date.today(), project='1') e.save() ''' emp_obj, created = Employee.objects.get_or_create( cardId=request.POST['cardId'], defaults={ 'employeeName': request.POST['employeeName'], 'gender': request.POST['title'], 'presentAddress': request.POST['presentAddress'], 'permanentAddress': request.POST['permanentAddress'], 'fatherName': request.POST['fatherName'], 'motherName': request.POST['motherName'], 'email': request.POST['email'], 'bloodGroup': request.POST['bloodGroup'], 'nationality': request.POST['nationality'], 'nationalId': request.POST['nationalId'], 'joiningDate': joining_date, 'dateOfBirth': date_of_birth, 'passportId': request.POST['passportId'], 'employeeCode': request.POST['employeeCode'], 'bankName': request.POST['bankName'], 'bankAccountNo': request.POST['bankAccountNo'], 'mobile': request.POST['mobile'], 'isActive': True, 'isDelete': False, 'insertUser': request.user.id, 'insertDate': date.today(), 'project': '1' }) if created: if request.POST['date'] != '': effective_start_date = convert_to_date(request.POST['date']) obj = EmployeeDesignation( employee_id=get_object_or_404(Employee, pk=emp_obj.employee_id), department_id=get_object_or_404( Department, pk=request.POST['departmentId']), des_id=get_object_or_404(Designation, pk=request.POST['designationId']), location_id=get_object_or_404(Location, pk=request.POST['locationId']), effective_date_start=effective_start_date, supervisor=get_object_or_404(Employee, pk=request.POST['supervisor']), isActive=True, insertUser=request.user.id, insertDate=date.today(), project='1') obj.save() context = { 'employeeId': emp_obj.employee_id, } #print(e.employee_id) return redirect('hr:addEmployeePage', message=created)
def editEmployeeDesignationPerfomed(request, emp_des_id): new_effective_date_start = convert_to_date(request.POST['date']) old_effective_date_end = new_effective_date_start - timedelta(days=1) reason_status = request.POST['reason'] employee_obj = get_object_or_404(EmployeeDesignation, pk=emp_des_id) #end_date = convert_to_date(request.POST['end_date']) # old_obj, created = EmployeeDesignation.objects.get_or_create(employee_id) if reason_status in ("left", "terminated"): if (LeaveHistory.objects.filter( endorsement='0', endorsed_by_id=employee_obj.employee_id_id, isActive=True).exists() | LeaveHistory.objects.filter( endorsement='3', confirmed_by=employee_obj.employee_id_id, isActive=True).exists()): messages.add_message( request, messages.ERROR, 'THIS EMPLOYEE HAS PENDING APPROVAL ISSUE. CANNOT PERFORM THE CHANGE!!' ) return HttpResponseRedirect( reverse('hr:addEmployeeDesignationPage')) else: try: to_update = EmployeeDesignation.objects.get( emp_des_id=emp_des_id) to_update.effective_date_end = new_effective_date_start to_update.isActive = False to_update.status = reason_status to_update.updateUser = request.user.id to_update.updateDate = date.today() to_update.save() except ObjectDoesNotExist: message = "No object Found" else: des_obj, created = EmployeeDesignation.objects.get_or_create( employee_id=get_object_or_404(Employee, pk=request.POST['hidden_emp_id']), department_id=get_object_or_404(Department, pk=request.POST['departmentId']), des_id=get_object_or_404(Designation, pk=request.POST['designationId']), location_id=get_object_or_404(Location, pk=request.POST['locationId']), effective_date_start=new_effective_date_start, supervisor=get_object_or_404(Employee, pk=request.POST['supervisor']), isActive=True, status=reason_status, defaults={ 'effective_date_end': datetime.max.date(), 'insertUser': request.user.id, 'insertDate': date.today(), 'project': '1', }) if created: obj = get_object_or_404(EmployeeDesignation, pk=emp_des_id) obj.updateUser = request.user.id obj.updateDate = date.today() obj.effective_date_end = old_effective_date_end obj.isActive = False #obj.status = reason_status obj.save() ''' new_emp_des_obj = EmployeeDesignation(employee_id = get_object_or_404(Employee, pk=request.POST['hidden_emp_id']), department_id = get_object_or_404(Department,pk=request.POST['departmentId']), des_id = get_object_or_404(Designation, pk=request.POST['designationId']), location_id = get_object_or_404(Location, pk=request.POST['locationId']), effective_date_start = new_effective_date_start, effective_date_end = datetime.max.date(), supervisor = get_object_or_404(Employee, pk=request.POST['supervisor']), isActive = True, insertUser = request.user.id, insertDate = date.today(), project = '1') new_emp_des_obj.save() ''' return HttpResponseRedirect(reverse('hr:addEmployeeDesignationPage'))