from django.http import JsonResponse from django.shortcuts import render, get_object_or_404, redirect from django.urls import reverse from application.hrm_mgnt.forms import EmployeeInformationForm from application.hrm_mgnt.models import * from common.utils.page_helper import paginate_query_and_assign_numbers def pst_list_view(request): # 声明查询集 query_set = Position.objects.filter().order_by('-position_id') # 获取查询参数 position_name = request.GET.get('position_name', '') # 根据提供的参数进行筛选 if request.GET.get('position_name', ''): query_set = query_set.filter(position_name__icontains=request.GET.get('position_name', '')) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&position_name={}' + format(position_name) # 准备上下文 context = { 'items': items, 'list_key': 'position_id', 'filters': [{"type": "text", "id": "position_name", "name": "position_name", "label": "岗位名称", "placeholder": "请输入岗位名称"}], 'form_action_url': 'pst_list', 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "岗位表", "name": "pst_list"}], 'query_params': query_params, 'table_columns': [{"header": "岗位名称", "field": "position_name"}, {"header": "岗位描述", "field": "position_description"}, {"header": "操作", "field": "actions"}], 'show_modify_button': True, 'show_add_button': True, 'show_download_button': True, 'show_upload_button': True, } return render(request, 'hrm_mgnt/pst_list.html', context) def rk_list_view(request): # 声明查询集 query_set = Rank.objects.filter().order_by('-rank_id') # 获取查询参数 rank_name = request.GET.get('rank_name', '') # 根据提供的参数进行筛选 if request.GET.get('rank_name', ''): query_set = query_set.filter(rank_name__icontains=request.GET.get('rank_name', '')) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&rank_name={}' + format(rank_name) # 准备上下文 context = { 'items': items, 'list_key': 'rank_id', 'filters': [{"type": "text", "id": "rank_name", "name": "rank_name", "label": "职级名称", "placeholder": "请输入职级名称"}], 'form_action_url': 'rk_list', 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "职级表", "name": "rk_list"}], 'query_params': query_params, 'table_columns': [{"header": "职级名称", "field": "rank_name"}, {"header": "职级描述", "field": "rank_description"}, {"header": "操作", "field": "actions"}], 'show_modify_button': True, 'show_add_button': True, 'show_download_button': True, 'show_upload_button': True, } return render(request, 'hrm_mgnt/rk_list.html', context) def attd_rec_list_view(request): # 声明查询集 query_set = EmployeeAttendanceRecord.objects.filter().order_by('-record_id') # 获取查询参数 employee = request.GET.get('employee', '') year_month = request.GET.get('year_month', '') primary_department = request.GET.get('primary_department', '') # 根据提供的参数进行筛选 if request.GET.get('employee', ''): query_set = query_set.filter(employee__icontains=request.GET.get('employee', '')) if request.GET.get('year_month', ''): query_set = query_set.filter(year_month__icontains=request.GET.get('year_month', '')) if request.GET.get('primary_department', ''): query_set = query_set.filter(primary_department__icontains=request.GET.get('primary_department', '')) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&employee={}' + format(employee) + '&year_month={}' + format( year_month) + '&primary_department={}' + format(primary_department) # 准备上下文 context = { 'items': items, 'list_key': 'record_id', 'filters': [ {"type": "text", "id": "employee", "name": "employee", "label": "员工", "placeholder": "请输入员工姓名"}, {"type": "month", "id": "year_month", "name": "year_month", "label": "年月"}, {"type": "select", "id": "primary_department", "name": "primary_department", "label": "一级部门", "options": [{"value": "天信", "display": "天信"}, {"value": "混改", "display": "混改"}, {"value": "艾力芬特", "display": "艾力芬特"}, {"value": "星河", "display": "星河"}, {"value": "星海", "display": "星海"}]}], 'form_action_url': 'attd_rec_list', 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "员工考勤记录表", "name": "attd_rec_list"}], 'query_params': query_params, 'table_columns': [{"header": "员工", "field": "employee"}, {"header": "年月", "field": "year_month"}, {"header": "迟到", "field": "late"}, {"header": "早退", "field": "early_leave"}, {"header": "旷工", "field": "absenteeism"}, {"header": "年假", "field": "annual_leave"}, {"header": "事假", "field": "personal_leave"}, {"header": "病假", "field": "sick_leave"}, {"header": "操作", "field": "actions"}], 'show_modify_button': True, 'show_add_button': True, 'show_download_button': True, 'show_upload_button': True, } return render(request, 'hrm_mgnt/attd_rec_list.html', context) def alv_list_view(request): # 声明查询集 query_set = AnnualLeaveRecord.objects.filter().order_by('-record_id') # 获取查询参数 employee_name = request.GET.get('employee_name', '') year = request.GET.get('year', '') # 根据提供的参数进行筛选 if request.GET.get('employee_name', ''): query_set = query_set.filter(employee_name__icontains=request.GET.get('employee_name', '')) if request.GET.get('year', ''): query_set = query_set.filter(year__icontains=request.GET.get('year', '')) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&employee_name={}' + format(employee_name) + '&year={}' + format(year) # 准备上下文 context = { 'items': items, 'list_key': 'record_id', 'filters': [{"type": "text", "id": "employee_name", "name": "employee_name", "label": "姓名", "placeholder": "请输入姓名"}, {"type": "select", "id": "year", "name": "year", "label": "年度", "options": [{"value": "2024", "display": "2024"}, {"value": "2023", "display": "2023"}, {"value": "2022", "display": "2022"}, {"value": "2021", "display": "2021"}, {"value": "2020", "display": "2020"}]}], 'form_action_url': 'alv_list', 'breadcrumb_list': [{"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "年假使用记录", "name": "alv_list"}], 'query_params': query_params, 'table_columns': [{"header": "年份", "field": "year"}, {"header": "姓名", "field": "employee_name"}, {"header": "一级部门", "field": "primary_department"}, {"header": "年假天数", "field": "total_annual_leave"}, {"header": "已请年假数", "field": "used_annual_leave"}, {"header": "剩余年假数", "field": "remaining_annual_leave"}, {"header": "操作", "field": "actions"}], 'show_modify_button': True, 'show_add_button': True, 'show_download_button': True, 'show_upload_button': True, } return render(request, 'hrm_mgnt/alv_list.html', context) def emp_list_view(request): # 声明查询集 query_set = EmployeeInformation.objects.filter().order_by('-employee_id') # 获取查询参数 name = request.GET.get('name', '') department = request.GET.get('department', '') # 根据提供的参数进行筛选 if name: query_set = query_set.filter(name__icontains=name) if department: query_set = query_set.filter(department=request.GET.get('department', '')) # 对查询结果进行分页,每页10条记录 items = paginate_query_and_assign_numbers( request=request, queryset=query_set, per_page=10 ) # 构建上下文查询参数字符串 query_params = '&name={}'.format(name) + '&department={}'.format(department) # Excel上传模板 template_name = "人力资源管理-人员基本信息-Excel上传模板.xlsx" # 构建上下文 context = { "model_config": "hrm_mgnt.EmployeeInformation", "items": items, "breadcrumb_list": [ {"title": "首页", "name": "index"}, {"title": "人力资源管理", "name": "index"}, {"title": "人员基本信息表", "name": "emt_list"} ], "filters": [ { "type": "text", "id": "name", "name": "name", "label": "姓名", "placeholder": "请输入姓名" }, { "type": "select", "id": "department", "name": "department", "label": "一级部门", "options": [ {"value": "天信", "display": "天信"}, {"value": "混改", "display": "混改"}, {"value": "艾力芬特", "display": "艾力芬特"}, {"value": "星河", "display": "星河"}, {"value": "星海", "display": "星海"} ] } ], "excel_upload_config": { "template_url": reverse("download_template", kwargs={'template_name': template_name}), "parse_url": reverse("common_excel_parse"), "save_url": reverse("save_excel_table_data"), "fields_preview_config": { "name": {"type": "text", "width": "180px"}, "id_number": {"type": "text", "width": "220px"}, "gender": {"type": "text", "width": "100px"}, "birthday": {"type": "date", "width": "110px"}, "age": {"type": "text", "width": "80px"}, "height": {"type": "text", "width": "100px"}, "weight": {"type": "text", "width": "100px"}, "blood_type": {"type": "text", "width": "80px"}, "ethnicity": {"type": "text", "width": "180px"}, "domicile": {"type": "text", "width": "220px"}, "marital_status": {"type": "text", "width": "120px"}, "political_affiliation": {"type": "text", "width": "120px"}, "entry_date": {"type": "date", "width": "110px"}, "regularization_date": {"type": "date", "width": "110px"}, "departure_date": {"type": "date", "width": "110px"}, "employment_type": {"type": "text", "width": "100px"}, "status": {"type": "text", "width": "80px"}, "primary_department": {"type": "text", "width": "180px"}, "secondary_department": {"type": "text", "width": "180px"}, "position": {"type": "text", "width": "180px"}, "grade": {"type": "text", "width": "120px"}, "contract_end_date": {"type": "date", "width": "110px"}, "mobile_number": {"type": "text", "width": "150px"}, "email": {"type": "text", "width": "200px"}, "mailing_address": {"type": "text", "width": "280px"}, "emergency_contact": {"type": "text", "width": "150px"}, "relation_with_contact": {"type": "text", "width": "150px"}, "emergency_contact_phone": {"type": "text", "width": "150px"}, "education": {"type": "text", "width": "100px"}, "undergraduate_school": {"type": "text", "width": "220px"}, "graduate_school": {"type": "text", "width": "220px"}, "major": {"type": "text", "width": "220px"}, "technical_title": {"type": "text", "width": "180px"}, "base_salary": {"type": "text", "width": "120px"}, "salary_account_number": {"type": "text", "width": "220px"}, "bank_of_salary_account": {"type": "text", "width": "220px"}, "resignation_type": {"type": "text", "width": "120px"}, "resignation_reason": {"type": "textarea", "width": "300px"} } }, "query_params": query_params, "form_action_url": "emp_list", "modify_url": reverse("emp_list_modify"), "add_url": reverse("emp_list_add"), "delete_url": reverse("emp_list_delete"), } return render(request, 'hrm_mgnt/emp_list.html', context) def emp_list_add(request): if request.method == 'POST': data = { 'name': request.POST.get('name'), 'id_number': request.POST.get('id_number'), 'gender': request.POST.get('gender'), 'birthday': request.POST.get('birthday'), 'age': request.POST.get('age'), 'height': request.POST.get('height'), 'weight': request.POST.get('weight'), 'blood_type': request.POST.get('blood_type'), 'ethnicity': request.POST.get('ethnicity'), 'domicile': request.POST.get('domicile'), 'marital_status': request.POST.get('marital_status'), 'political_affiliation': request.POST.get('political_affiliation'), 'entry_date': request.POST.get('entry_date'), 'regularization_date': request.POST.get('regularization_date'), 'departure_date': request.POST.get('departure_date'), 'employment_type': request.POST.get('employment_type'), 'status': request.POST.get('status'), 'primary_department': request.POST.get('primary_department'), 'secondary_department': request.POST.get('secondary_department'), 'position': request.POST.get('position'), 'grade': request.POST.get('grade'), 'contract_end_date': request.POST.get('contract_end_date'), 'mobile_number': request.POST.get('mobile_number'), 'email': request.POST.get('email'), 'mailing_address': request.POST.get('mailing_address'), 'emergency_contact': request.POST.get('emergency_contact'), 'relation_with_contact': request.POST.get('relation_with_contact'), 'emergency_contact_phone': request.POST.get('emergency_contact_phone'), 'education': request.POST.get('education'), 'undergraduate_school': request.POST.get('undergraduate_school'), 'graduate_school': request.POST.get('graduate_school'), 'major': request.POST.get('major'), 'technical_title': request.POST.get('technical_title'), 'base_salary': request.POST.get('base_salary'), 'salary_account_number': request.POST.get('salary_account_number'), 'bank_of_salary_account': request.POST.get('bank_of_salary_account'), 'resignation_type': request.POST.get('resignation_type'), 'resignation_reason': request.POST.get('resignation_reason') } EmployeeInformation.objects.create(**data) return JsonResponse({"message": "添加成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def emp_list_modify(request): if request.method == 'POST': employee_id = request.POST.get('employee_id') data = { 'name': request.POST.get('name'), 'id_number': request.POST.get('id_number'), 'gender': request.POST.get('gender'), 'birthday': request.POST.get('birthday'), 'age': request.POST.get('age'), 'height': request.POST.get('height'), 'weight': request.POST.get('weight'), 'blood_type': request.POST.get('blood_type'), 'ethnicity': request.POST.get('ethnicity'), 'domicile': request.POST.get('domicile'), 'marital_status': request.POST.get('marital_status'), 'political_affiliation': request.POST.get('political_affiliation'), 'entry_date': request.POST.get('entry_date'), 'regularization_date': request.POST.get('regularization_date'), 'departure_date': request.POST.get('departure_date'), 'employment_type': request.POST.get('employment_type'), 'status': request.POST.get('status'), 'primary_department': request.POST.get('primary_department'), 'secondary_department': request.POST.get('secondary_department'), 'position': request.POST.get('position'), 'grade': request.POST.get('grade'), 'contract_end_date': request.POST.get('contract_end_date'), 'mobile_number': request.POST.get('mobile_number'), 'email': request.POST.get('email'), 'mailing_address': request.POST.get('mailing_address'), 'emergency_contact': request.POST.get('emergency_contact'), 'relation_with_contact': request.POST.get('relation_with_contact'), 'emergency_contact_phone': request.POST.get('emergency_contact_phone'), 'education': request.POST.get('education'), 'undergraduate_school': request.POST.get('undergraduate_school'), 'graduate_school': request.POST.get('graduate_school'), 'major': request.POST.get('major'), 'technical_title': request.POST.get('technical_title'), 'base_salary': request.POST.get('base_salary'), 'salary_account_number': request.POST.get('salary_account_number'), 'bank_of_salary_account': request.POST.get('bank_of_salary_account'), 'resignation_type': request.POST.get('resignation_type'), 'resignation_reason': request.POST.get('resignation_reason') } EmployeeInformation.objects.filter(employee_id=employee_id).update(**data) return JsonResponse({"message": "修改成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def emp_list_delete(request): if request.method == 'GET': employee_id = request.GET.get('employee_id') EmployeeInformation.objects.filter(employee_id=employee_id).delete() return JsonResponse({"message": "删除成功"}) return JsonResponse({"message": "无效的请求方法"}, status=405) def employee_form_view(request, pk=None): if pk: employee = get_object_or_404(EmployeeInformation, pk=pk) form = EmployeeInformationForm(request.POST or None, instance=employee) form_title = '修改人员基本信息' else: form = EmployeeInformationForm(request.POST or None) form_title = '添加人员基本信息' if request.method == 'POST' and form.is_valid(): form.save() return redirect('employee_list') # 假设有一个员工列表视图 fields = [field.verbose_name for field in EmployeeInformation._meta.fields] return render(request, 'add_edit_modal.html', { 'form': form, 'form_title': form_title, 'fields': fields })