homepage修改

This commit is contained in:
li.kai 2024-06-21 00:45:59 +08:00
parent ce164e6812
commit 7df7e538d6
3 changed files with 273 additions and 237 deletions

View File

@ -22,9 +22,12 @@ from application.accounts.forms import EmailAuthenticationForm
from application.accounts.models import AccountProfile from application.accounts.models import AccountProfile
from application.accounts.viewmodels import UserPermissionItem from application.accounts.viewmodels import UserPermissionItem
from application.hrm_mgnt.models import AnnualLeaveRecord from application.hrm_mgnt.models import AnnualLeaveRecord
from application.hrm_mgnt.models import EmployeeAttendanceRecord
from application.hrm_mgnt.models import EmployeeInformation from application.hrm_mgnt.models import EmployeeInformation
from application.perf_mgnt.models import EmployeePerformanceTarget from application.perf_mgnt.models import EmployeePerformanceTarget
from application.pjt_mgnt.models import ProjectLedger 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.auth import custom_permission_required
from common.utils.page_helper import paginate_query_and_assign_numbers 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.'}) return JsonResponse({'success': False, 'message': 'An error occurred during group deletion.'})
import pdb
@login_required @login_required
@custom_permission_required('auth.view_user') @custom_permission_required('auth.view_user')
def user_homepage_view(request): def user_homepage_view(request):
@ -580,17 +585,50 @@ def user_homepage_view(request):
# 查询人员基本信息表中的转正日期、岗位 # 查询人员基本信息表中的转正日期、岗位
account_profile = AccountProfile.objects.get(user=request.user) account_profile = AccountProfile.objects.get(user=request.user)
employee_information = account_profile.employee_information 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得到完成率 # 查询员工业绩目标表的sales_target和项目台账的关于这个人今年状态为已完成所有项目的标的金额用标的金额除以目标表的sales_target得到完成率
try: try:
employee_performance = EmployeePerformanceTarget.objects.get(name=employee_information.name) employee_performance = EmployeePerformanceTarget.objects.get(name=employee_information.name)
@ -598,18 +636,30 @@ def user_homepage_view(request):
except EmployeePerformanceTarget.DoesNotExist: except EmployeePerformanceTarget.DoesNotExist:
performance_target = 0 performance_target = 0
# 获取今年的日期范围 start_date = f"{current_day.year}-01-01"
current_year = now().year end_date = f"{current_day.year}-12-31"
start_date = f"{current_year}-01-01"
end_date = f"{current_year}-12-31"
try: 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( # ongoing_projects = ProjectLedger.objects.filter(
Q(project_leader=employee_information.name) | Q(project_members__contains=employee_information.name), # Q(project_leader=employee_information.name) | Q(project_members__contains=employee_information.name),
project_status='进行中', # project_status='进行中',
end_date__range=[start_date, end_date] # end_date__range=[start_date, end_date]
).distinct() # ).distinct()
# 查询今年已完成的项目 # 查询今年已完成的项目
completed_projects = ProjectLedger.objects.filter( completed_projects = ProjectLedger.objects.filter(
@ -618,45 +668,40 @@ def user_homepage_view(request):
end_date__range=[start_date, end_date] end_date__range=[start_date, end_date]
).distinct() ).distinct()
ongoing_project_count = ongoing_projects.count() # ongoing_project_count = ongoing_projects.count()
completed_project_count = completed_projects.count() # completed_project_count = completed_projects.count()
total_project_count = ongoing_project_count + completed_project_count # total_project_count = ongoing_project_count + completed_project_count
# 计算项目完成率 # 计算项目完成率
if total_project_count > 0: # if total_project_count > 0:
project_completion_rate = (completed_project_count / total_project_count) * 100 # project_completion_rate = (completed_project_count / total_project_count) * 100
else: # else:
project_completion_rate = 0 # project_completion_rate = 0
# 计算已完成项目的总标的金额 # 计算已完成项目的总标的金额
total_completed_amount = completed_projects.aggregate(Sum('contract_amount'))['contract_amount__sum'] or 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: if performance_target > 0:
completion_rate = (total_completed_amount / performance_target) * 100 completion_rate = (total_completed_amount / performance_target) * 100
else: else:
completion_rate = 0 completion_rate = 0
context = { context = {
'name': employee_information.name, 'employee_information': employee_information,
'postion': employee_information.position, 'attendance_status_str': attendance_status_str,
'on_duty_days': on_duty_days, 'on_duty_days': on_duty_days,
'status': employee_information.status, 'mobiles': mobiles,
'remaining_annual_leave': remaining_annual_leave, 'accounts': accounts,
'used_annual_leave': used_annual_leave, 'all_project_count': all_project_count,
'performance_target': performance_target, 'performance_target': performance_target,
'total_completed_amount': total_completed_amount, 'completion_rate': round(completion_rate, 2),
'completion_rate': completion_rate, 'recent_project': recent_project
'completed_project_count': completed_project_count,
'ongoing_project_count': ongoing_project_count,
'total_project_count': total_project_count,
'project_completion_rate': project_completion_rate,
} }
except AccountProfile.DoesNotExist: except AccountProfile.DoesNotExist:
context = { context = {

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 KiB

View File

@ -23,9 +23,9 @@
<h5 class="m-b-10">个人中心</h5> <h5 class="m-b-10">个人中心</h5>
</div> </div>
<ul class="breadcrumb"> <ul class="breadcrumb">
<li class="breadcrumb-item"><a href="index.html"><i <li class="breadcrumb-item"><a href="#"><i
class="feather icon-home"></i></a></li> class="feather icon-home"></i></a></li>
<li class="breadcrumb-item"><a href="#!">个人中心</a></li> <li class="breadcrumb-item"><a href="#">个人中心</a></li>
</ul> </ul>
</div> </div>
</div> </div>
@ -35,201 +35,150 @@
<!-- [ Main Content ] start --> <!-- [ Main Content ] start -->
<div class="row"> <div class="row">
<div class="col-md-4 mb-4"> <div class="col-sm-12 col-md-12 mb-12">
<div class="card statustic-card h-100"> <div class="card text-white bg-info">
<div class="card-body text-center">
<h3>{{ name }}</h3>
<p>{{ postion }}</p>
<div class="row mt-5">
<div class="col text-center">
<h4>{{ on_duty_days }}天</h4>
<span>{{ status }}</span>
</div>
<div class="col text-center">
<h4>{{ used_annual_leave }}天</h4>
<span>已用年假</span>
</div>
<div class="col text-center">
<h4>{{ remaining_annual_leave }}天</h4>
<span>剩余年假</span>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-4 mb-4">
<div class="card statustic-card h-100">
<div class="card-header borderless pb-0">
<h5>我的业绩目标</h5>
</div>
<div class="card-body text-center">
<span class="d-block text-c-blue f-36">{{ completion_rate }}</span>
<p class="m-b-0">业绩目标完成率</p>
<div class="progress">
<div class="progress-bar bg-c-blue"
style="width: {{ total_completed_amount }}"></div>
</div>
</div>
<div class="card-footer bg-c-blue border-0">
<h6 class="text-white m-b-0">
本年已完成项目收入: {{ total_completed_amount }}元</h6>
</div>
</div>
</div>
<div class="col-md-4 mb-4">
<div class="card statustic-card h-100">
<div class="card-header borderless pb-0">
<h5>我的项目</h5>
</div>
<div class="card-body text-center">
<span class="d-block text-c-green f-36">{{ ongoing_project_count }}个</span>
<p class="m-b-0">正在进行的项目数量</p>
<div class="progress">
<div class="progress-bar bg-c-green"
style="width:{{ project_completion_rate }}"></div>
</div>
</div>
<div class="card-footer bg-c-green border-0">
<h6 class="text-white m-b-0">
今年已完成的项目数量: {{ completed_project_count }}个</h6>
</div>
</div>
</div>
<div class="row d-flex align-items-stretch">
<div class="col-xl-4 col-md-6">
<div class="card latest-update-card update-card h-100">
<div class="card-header">
<h5>系统通知</h5>
</div>
<div class="new-scroll" style="height:350px;position:relative;">
<div class="card-body"> <div class="card-body">
<div class="latest-update-box"> <div class="d-flex align-items-baseline">
<p class="card-title text-white mb-0" style="font-size: 2.5rem;">{{ employee_information.name }}</p>
<div class="row p-t-20 p-b-30"> <p class="mb-0 ml-3" style="margin-left: 50px; font-size: 1.3rem;"> 在职 {{ on_duty_days }} 天</p>
<div class="col-auto text-end update-meta">
<i class="feather icon-bell bg-c-blue update-icon"></i>
</div> </div>
<div class="col p-l-5"> <div class="d-flex align-items-baseline">
<a href="#!"> <p class="mb-0" style="font-size: 1.25rem;">{{ employee_information.primary_department|default:"星环集团" }} - {{ employee_information.secondary_department|default:"" }} - {{ employee_information.position|default:"" }}</p>
<h6 class="m-0">端午节放假通知</h6> <p class="mb-0" style="margin-left: auto; font-size: 1.25rem;">本月考勤: 【
</a> {% if attendance_status_str == '正常'%}
<p class="m-b-0">2024/06/07 11:40 AM</p> {{attendance_status_str}}
{% else %}
<a style="color:white" href="{% url 'attd_rec_list' %}">{{attendance_status_str}}</a>
{% endif %}
</p>
</div>
<div class="d-flex align-items-baseline mt-2 mb-0">
{% if mobiles %}
<p class="mb-0" style="font-size: 1rem;">在用手机:{{ mobiles }}</p>
{% endif %}
{% if accounts %}
{% if mobiles %}
<p class="mb-0" style="margin-left: 30px; font-size: 1rem;">在管账号:{{accounts}}</p>
{% else %}
<p class="mb-0" style="font-size: 1rem;">在管账号:{{accounts}}</p>
{% endif %}
{% endif %}
</div> </div>
</div> </div>
<div class="row p-b-30">
<div class="col-auto text-end update-meta">
<i class="feather icon-bell bg-c-blue update-icon"></i>
</div>
<div class="col p-l-5">
<a href="#!">
<h6 class="m-0">儿童节活动通知</h6>
</a>
<p class="m-b-0">2024/06/01 11:40 AM</p>
</div> </div>
</div> </div>
<div class="row p-b-30">
<div class="col-auto text-end update-meta">
<i class="feather icon-file f-w-600 bg-c-yellow update-icon"></i>
</div> </div>
<div class="col p-l-5"> {% if all_project_count > 0 %}
<a href="#!">
<h6 class="m-0">更新报销明细</h6>
</a>
<p class="m-b-0">2024/05/27 9:00 AM</p>
</div>
</div>
<div class="row p-b-30">
<div class="col-auto text-end update-meta">
<i class="feather icon-file bg-c-yellow update-icon"></i>
</div>
<div class="col p-l-5">
<a href="#!">
<h6 class="m-0">上传发票通知</h6>
</a>
<p class="m-b-0">2024/05/25 9:00 AM</p>
</div>
</div>
<div class="row p-b-30">
<div class="col-auto text-end update-meta">
<i class="feather icon-check-circle f-w-600 bg-c-green update-icon"></i>
</div>
<div class="col p-l-5">
<a href="#!">
<h6 class="m-0">外贸出口项目完成</h6>
</a>
<p class="m-b-0">2024/4/28 9:00 AM</p>
</div>
</div>
<div class="row"> <div class="row">
<div class="col-auto text-end update-meta"> <div class="col-md-4 col-xl-4">
<i class="feather icon-alert-triangle f-w-600 bg-c-red update-icon"></i> <div class="card table-card widget-purple-card bg-c-yellow">
<div class="row-table">
<div class="col-sm-3 card-body-big">
<i class="feather icon-star-on"></i>
</div> </div>
<div class="col p-l-5"> <div class="col-sm-9 ms-3">
<a href="#!"> <h4><a href="{% url 'proj_ledger_list' %}" style="color:white">{{all_project_count}}</a></h4>
<h6 class="m-0">库存不足提醒</h6> <h6>我的项目</h6>
</a>
<p class="m-b-0">2024/4/28 9:00 AM</p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="col-md-4 col-xl-4">
<div class="card table-card widget-purple-card bg-c-green">
<div class="row-table">
<div class="col-sm-3 card-body-big">
<i class="feather icon-heart-on"></i>
</div>
<div class="col-sm-9 ms-3">
<h4>{{completion_rate}}%</h4>
<h6>年度目标完成率</h6>
<div class="progress" style="height:6px;width: 80%;">
<div class="progress-bar progress-c-blue" role="progressbar"
style="width:{{completion_rate}}%;height:6px;"
aria-valuemin="0" aria-valuemax="100">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-4 col-xl-4">
<div class="card table-card widget-purple-card bg-c-purple">
<div class="row-table">
<div class="col-sm-3 card-body-big">
<i class="feather icon-award"></i>
</div>
<div class="col-sm-9 ms-3">
<h4>{{performance_target}}</h4>
<h6>年度目标金额(元)</h6>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="col-xl-8 col-md-6"> <div class="card">
<div class="card user-list table-card h-100">
<div class="card-header"> <div class="card-header">
<h5>项目协作动态</h5> <h3>近期项目</h3>
</div> </div>
<div class="card-body pb-0"> <div class="card-body">
<div class="table-responsive"> <table class="table table-hover m-b-0" style="font-size: 1.2rem;">
<div class="user-scroll ps ps--active-y"
style="height:430px;position:relative;">
<table class="table table-hover m-0">
<thead> <thead>
<tr> <tr>
<th>姓名</th> <th style="font-size: 1.05rem;">项目状态</th>
<th>操作/项目</th> <th style="font-size: 1.05rem;">项目名称</th>
<th>时间</th> <th style="font-size: 1.05rem;">开始时间</th>
<th style="font-size: 1.05rem;">合同金额</th>
<th style="font-size: 1.05rem;">当前回款</th>
<th style="font-size: 1.05rem;">回款比例</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for project in recent_project %}
<tr> <tr>
<td>张三</td> {% if project.project_status == '进行中'%}
<td> <td><span class="badge text-bg-info">进行中</span></td>
<h6 class="mb-1"><span {% elif project.project_status == '暂停'%}
class="text-c-green">新增项目</span> <td><span class="badge text-bg-secondary">暂停</span></td>
老挝贸易项目 {% elif project.project_status == '待收款'%}
</h6> <td><span class="badge text-bg-warning">待收款</span></td>
{% elif project.project_status == '完成'%}
<td><span class="badge text-bg-success">完成</span></td>
{% endif %}
<td style="max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">{{project.project_name}}</td>
<td>{{project.start_date}}</td>
<td>{{project.contract_amount}}</td>
<td>{{project.repayment_amount}}</td>
<td>{{project.repayment_per}}%
<div class="progress mt-1" style="height:4px;">
<div class="progress-bar bg-primary rounded"
role="progressbar" style="width: {{project.repayment_per}}%;"
aria-valuemin="0"
aria-valuemax="100"></div>
</div>
</td> </td>
<td>2024/06/01 11:40 AM</td>
</tr> </tr>
{% endfor %}
</tbody> </tbody>
</table> </table>
<div class="ps__rail-x" style="left: 0px; bottom: 0px;">
<div class="ps__thumb-x" tabindex="0"
style="left: 0px; width: 0px;"></div>
</div> </div>
<div class="ps__rail-y" </div>
style="top: 0px; height: 430px; right: 0px;"> {% else %}
<div class="ps__thumb-y" tabindex="0" <div class="col-xl-12 col-md-12">
style="top: 0px; height: 351px;"></div> <div class="card-body">
<div class="image-container">
<img src="{% static 'images/homepage-astronomy-1280.jpg' %}" alt="advance-1"/>
<div class="overlay"></div>
<div class="text">
<p style="font-size: 6rem;">星环</p>
<p style="font-size: 3rem;">看见更远的自己,看见更远的将来</p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> {% endif %}
</div>
</div>
</div>
<!-- [ Main Content ] end --> <!-- [ Main Content ] end -->
</div> </div>
</div> </div>
@ -248,5 +197,47 @@
.h-100 { .h-100 {
height: 100%; height: 100%;
} }
.image-container {
position: relative;
width: 100%;
max-width: 100%;
}
.image-container img {
width: 100%;
height: 700px;
}
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(69, 69, 69, 0.7);
}
.text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
color: white;
width: 80%; /* 调整文本容器宽度 */
font-size: 5rem;
}
.text h2 {
margin-bottom: 20px;
}
.text p {
margin-bottom: 0;
}
</style> </style>
<!-- <link rel="stylesheet" href="{% static 'css/pages/gallery.css' %}"> -->
{% endblock %} {% endblock %}