星环
+看见更远的自己,看见更远的将来
+diff --git a/application/accounts/views.py b/application/accounts/views.py index 036517a..1939e24 100644 --- a/application/accounts/views.py +++ b/application/accounts/views.py @@ -22,9 +22,12 @@ from application.accounts.forms import EmailAuthenticationForm from application.accounts.models import AccountProfile from application.accounts.viewmodels import UserPermissionItem from application.hrm_mgnt.models import AnnualLeaveRecord +from application.hrm_mgnt.models import EmployeeAttendanceRecord from application.hrm_mgnt.models import EmployeeInformation from application.perf_mgnt.models import EmployeePerformanceTarget from application.pjt_mgnt.models import ProjectLedger +from application.rsc_mgnt.models import CompanyMobilePhoneUsageRegistry +from application.opa_mgnt.models import SocialMediaAccountRegistration from common.auth import custom_permission_required from common.utils.page_helper import paginate_query_and_assign_numbers @@ -570,6 +573,8 @@ def delete_group(request, group_id): return JsonResponse({'success': False, 'message': 'An error occurred during group deletion.'}) +import pdb + @login_required @custom_permission_required('auth.view_user') def user_homepage_view(request): @@ -580,36 +585,81 @@ def user_homepage_view(request): # 查询人员基本信息表中的转正日期、岗位 account_profile = AccountProfile.objects.get(user=request.user) employee_information = account_profile.employee_information - # 计算在职天数,用今天减去employee_information.entry_date - on_duty_days = (date.today() - employee_information.entry_date).days - # 查询年假使用表中的年假剩余天数 - try: - annual_leave_records = AnnualLeaveRecord.objects.get(employee_name__icontains=employee_information.name) - remaining_annual_leave = annual_leave_records.remaining_annual_leave - used_annual_leave = annual_leave_records.used_annual_leave - except AnnualLeaveRecord.DoesNotExist: - remaining_annual_leave = 0 - used_annual_leave = 0 + current_day = date.today() + current_year_month = f"{current_day.year}-{current_day.month:0>2d}-01" + + # 计算在职天数,用今天减去employee_information.entry_date + on_duty_days = (current_day - employee_information.entry_date).days + + # 查看当月考勤情况 + try: + attendance_record = EmployeeAttendanceRecord.objects.get(employee=employee_information.name, year_month=current_year_month) + attendance_abnormal = attendance_record.late + attendance_record.early_leave + attendance_record.absenteeism + attendance_reason = attendance_record.annual_leave + attendance_record.personal_leave + attendance_record.sick_leave + except: + attendance_abnormal = 0 + attendance_reason = 0 + if attendance_abnormal == 0 and attendance_reason == 0: + attendance_status_str = '正常' + else: + attendance_status = [] + if attendance_abnormal > 0: + attendance_status.append(f"异常 {attendance_abnormal} 次") + if attendance_reason > 0: + attendance_status.append(f"请假 {attendance_abnormal} 次") + attendance_status_str = ';'.join(attendance_status) + + # 在用手机 + company_mobies = CompanyMobilePhoneUsageRegistry.objects.filter(current_user=employee_information.name) + if company_mobies.count() > 0: + mobiles = ';'.join([i.mobile_number for i in company_mobies]) + else: + mobiles = None + + # 在管账号 + socail_accounts = SocialMediaAccountRegistration.objects.filter(operator=employee_information.name) + if socail_accounts.count() > 0: + accounts = ';'.join([i.platform + ' - ' + i.account_name for i in socail_accounts]) + else: + accounts = None + + # 业绩达成率 + # 1. 找总数 + # 2. 找年度目标 + # 3. 找年完成率 + # 4. 找近期 # 查询员工业绩目标表的sales_target,和项目台账的关于这个人今年状态为已完成所有项目的标的金额,用标的金额除以目标表的sales_target得到完成率 try: employee_performance = EmployeePerformanceTarget.objects.get(name=employee_information.name) performance_target = employee_performance.sales_target except EmployeePerformanceTarget.DoesNotExist: performance_target = 0 - - # 获取今年的日期范围 - current_year = now().year - start_date = f"{current_year}-01-01" - end_date = f"{current_year}-12-31" + + start_date = f"{current_day.year}-01-01" + end_date = f"{current_day.year}-12-31" try: + recent_project = ProjectLedger.objects.filter( + Q(project_leader=employee_information.name) | Q(project_members__contains=employee_information.name) + ).distinct().order_by('-start_date') + + all_project_count = recent_project.count() + recent_project = recent_project[:5] + + for i in recent_project: + try: + i.repayment_per = round(i.repayment_amount / i.contract_amount * 100, 2) + except: + i.repayment_per = 0 + + # 查询今年进行中的项目 - ongoing_projects = ProjectLedger.objects.filter( - Q(project_leader=employee_information.name) | Q(project_members__contains=employee_information.name), - project_status='进行中', - end_date__range=[start_date, end_date] - ).distinct() + # ongoing_projects = ProjectLedger.objects.filter( + # Q(project_leader=employee_information.name) | Q(project_members__contains=employee_information.name), + # project_status='进行中', + # end_date__range=[start_date, end_date] + # ).distinct() # 查询今年已完成的项目 completed_projects = ProjectLedger.objects.filter( @@ -618,45 +668,40 @@ def user_homepage_view(request): end_date__range=[start_date, end_date] ).distinct() - ongoing_project_count = ongoing_projects.count() - completed_project_count = completed_projects.count() - total_project_count = ongoing_project_count + completed_project_count + # ongoing_project_count = ongoing_projects.count() + # completed_project_count = completed_projects.count() + # total_project_count = ongoing_project_count + completed_project_count # 计算项目完成率 - if total_project_count > 0: - project_completion_rate = (completed_project_count / total_project_count) * 100 - else: - project_completion_rate = 0 + # if total_project_count > 0: + # project_completion_rate = (completed_project_count / total_project_count) * 100 + # else: + # project_completion_rate = 0 # 计算已完成项目的总标的金额 total_completed_amount = completed_projects.aggregate(Sum('contract_amount'))['contract_amount__sum'] or 0 - except ProjectLedger.DoesNotExist: - total_completed_amount = 0 - completed_project_count = 0 - total_project_count = 0 - project_completion_rate = 0 - ongoing_project_count = 0 - # 计算完成率 + except ProjectLedger.DoesNotExist: + all_project_count = 0 + total_completed_amount = 0 + recent_project = None + + # 计算金额完成率 if performance_target > 0: completion_rate = (total_completed_amount / performance_target) * 100 else: completion_rate = 0 context = { - 'name': employee_information.name, - 'postion': employee_information.position, + 'employee_information': employee_information, + 'attendance_status_str': attendance_status_str, 'on_duty_days': on_duty_days, - 'status': employee_information.status, - 'remaining_annual_leave': remaining_annual_leave, - 'used_annual_leave': used_annual_leave, + 'mobiles': mobiles, + 'accounts': accounts, + 'all_project_count': all_project_count, 'performance_target': performance_target, - 'total_completed_amount': total_completed_amount, - 'completion_rate': completion_rate, - 'completed_project_count': completed_project_count, - 'ongoing_project_count': ongoing_project_count, - 'total_project_count': total_project_count, - 'project_completion_rate': project_completion_rate, + 'completion_rate': round(completion_rate, 2), + 'recent_project': recent_project } except AccountProfile.DoesNotExist: context = { diff --git a/static/images/homepage-astronomy-1280.jpg b/static/images/homepage-astronomy-1280.jpg new file mode 100644 index 0000000..8b04c30 Binary files /dev/null and b/static/images/homepage-astronomy-1280.jpg differ diff --git a/templates/user_homepage.html b/templates/user_homepage.html index 006ad9b..8dd67f5 100644 --- a/templates/user_homepage.html +++ b/templates/user_homepage.html @@ -23,9 +23,9 @@
{{ postion }}
-{{ employee_information.name }}
+在职 {{ on_duty_days }} 天
+{{ employee_information.primary_department|default:"星环集团" }} - {{ employee_information.secondary_department|default:"" }} - {{ employee_information.position|default:"" }}
+本月考勤: 【 + {% if attendance_status_str == '正常'%} + {{attendance_status_str}} + {% else %} + {{attendance_status_str}} + {% endif %} + 】 +
+在用手机:{{ mobiles }}
+ {% endif %} + {% if accounts %} + {% if mobiles %} +在管账号:{{accounts}}
+ {% else %} +在管账号:{{accounts}}
+ {% endif %} + {% endif %}业绩目标完成率
-正在进行的项目数量
-2024/06/07 11:40 AM
-2024/06/01 11:40 AM
-2024/05/27 9:00 AM
-2024/05/25 9:00 AM
-2024/4/28 9:00 AM
-2024/4/28 9:00 AM
-姓名 | -操作/项目 | -时间 | -
---|---|---|
张三 | -
- 新增项目: - 老挝贸易项目 -- |
- 2024/06/01 11:40 AM | -
项目状态 | +项目名称 | +开始时间 | +合同金额 | +当前回款 | +回款比例 | +||
---|---|---|---|---|---|---|---|
进行中 | + {% elif project.project_status == '暂停'%} +暂停 | + {% elif project.project_status == '待收款'%} +待收款 | + {% elif project.project_status == '完成'%} +完成 | + {% endif %} + + +{{project.start_date}} | +{{project.contract_amount}} | +{{project.repayment_amount}} | +{{project.repayment_per}}%
+
+
+
+ |
+
星环
+看见更远的自己,看见更远的将来
+