Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

END:BUILD: Export requests to excel implemented #103

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Panel de control</h1>

</div>

<!-- Content center -->
Expand Down
12 changes: 10 additions & 2 deletions hiring_module/hiring_app/templates/control_board/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
<h1 class="h3 mb-2 text-gray-800">Solicitudes de contratación</h1>
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3">
<div class="card-header py-3 d-flex justify-content-between align-items-center">
<h6 class="m-0 font-weight-bold text-primary">Listado de solicitudes de contratación</h6>
<button id="export_requests" onclick="redirectToExportRequests()" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i
class="fas fa-download fa-sm text-white-50 mr-2"></i>Exportar</button>
</div>
<div class="card-body">
<div class="table-responsive">
Expand Down Expand Up @@ -56,4 +58,10 @@ <h6 class="m-0 font-weight-bold text-primary">Listado de solicitudes de contrata
</div>
</div>

</div>
</div>

<script>
function redirectToExportRequests() {
window.location.href = "{% url 'hiring_app:export_requests' %}";
}
</script>
2 changes: 2 additions & 0 deletions hiring_module/hiring_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from hiring_app.views.control_board.administrator_user_list_view import AdministratorUserListView
from hiring_app.views.control_board.add_user_view import AddUserView
from hiring_app.views.statistical_registers.statistics_view import StatisticsView
from hiring_app.views.control_board.export_requests_view import ExportRequestsView

app_name = 'hiring_app'

Expand Down Expand Up @@ -43,5 +44,6 @@
path('download_rut/<str:idContract>/',
download_rut_file, name='download_rut'),
path('statistics/', StatisticsView.as_view(), name='statistics'),
path('export_requests/', ExportRequestsView.as_view(), name='export_requests')
]

1 change: 1 addition & 0 deletions hiring_module/hiring_app/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from .control_board.leader_dashboard_view import LeaderDashboardView
from .control_board.manager_dashboard_view import ManagerDashboardView
from .request_hiring.assign_leader import AssignLeaderView
from .control_board.export_requests_view import ExportRequestsView
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.shortcuts import redirect
from django.views import View
from hiring_app.model.user_model import CustomUser
from .utilities import export_requests
class ExportRequestsView(View):

def get(self, request):
return export_requests(self.request.user)
257 changes: 256 additions & 1 deletion hiring_module/hiring_app/views/control_board/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from hiring_app.model.cex_contract_request_model import CEXContractRequest
from hiring_app.model.monitoring_contract_request_model import MonitoringContractRequest
from hiring_app.model.provision_of_services_request_model import ProvisionOfServicesContractRequest
from django.http import HttpResponse
from openpyxl import Workbook

# Decorator to redirect users to the correct dashboard based on their role
def role_redirect(view_func):
Expand Down Expand Up @@ -105,4 +107,257 @@ def get_requests(user):




def export_requests(user):
groups = [group.name for group in user.groups.all()]
requests_CEX = CEXContractRequest.objects.none()
requests_monitoring = MonitoringContractRequest.objects.none()
requests_pos = ProvisionOfServicesContractRequest.objects.none()

if 'admin' in groups:
requests_CEX = CEXContractRequest.objects.all()
requests_monitoring = MonitoringContractRequest.objects.all()
requests_pos = ProvisionOfServicesContractRequest.objects.all()
elif 'leader' in groups:
requests_CEX = CEXContractRequest.objects.filter(leader_assigned_to=user.id)
requests_monitoring = MonitoringContractRequest.objects.filter(leader_assigned_to=user.id)
requests_pos = ProvisionOfServicesContractRequest.objects.filter(leader_assigned_to=user.id)
elif 'manager' in groups:
requests_CEX = CEXContractRequest.objects.filter(manager_assigned_to=user.id)
requests_monitoring = MonitoringContractRequest.objects.filter(manager_assigned_to=user.id)
requests_pos = ProvisionOfServicesContractRequest.objects.filter(manager_assigned_to=user.id)



wb = Workbook()

ws1 = wb.active
ws1.title = "Solicitudes de Contratación"

headers = [
"ID",
"Start Date",
"Completion Date",
"Estimated Completion Date",
"Current State Start",
"State",
"Manager Assigned To",
"Leader Assigned To",
"Created By",
]

ws1.append(headers)

for request in (list(requests_CEX) + list(requests_monitoring) + list(requests_pos)):
row_data = [
str(request.id),
request.start_date.strftime('%Y-%m-%d'),
request.completion_date.strftime('%Y-%m-%d %H:%M:%S') if request.completion_date else None,
request.estimated_completion_date.strftime('%Y-%m-%d') if request.estimated_completion_date else None,
request.current_state_start.strftime('%Y-%m-%d %H:%M:%S'),
request.state,
f'{request.manager_assigned_to.first_name} {request.manager_assigned_to.last_name}' if request.manager_assigned_to else 'sin asignar',
f'{request.leader_assigned_to.first_name} {request.leader_assigned_to.last_name}' if request.leader_assigned_to else 'sin asignar',
f'{request.created_by.first_name} {request.created_by.last_name}' if request.created_by else 'sin asignar',
]
ws1.append(row_data)


ws2 = wb.create_sheet(title="CEX")

headers = [
"ID",
"Start Date",
"Completion Date",
"Estimated Completion Date",
"Current State Start",
"State",
"Manager Assigned To",
"Leader Assigned To",
"Created By",
"Hiree Full Name",
"Hiree ID",
"Hiree Cellphone",
"Hiree Email",
"Cenco",
"Request Motive",
"Banking Entity",
"Bank Account Type",
"Bank Account Number",
"EPS",
"Pension Fund",
"ARL",
"Contract Value",
"Charge Account",
"RUT"
]
ws2.append(headers)

for cex_request in requests_CEX:
row_data = [
str(cex_request.id),
cex_request.start_date.strftime('%Y-%m-%d'),
cex_request.completion_date.strftime('%Y-%m-%d %H:%M:%S') if cex_request.completion_date else None,
cex_request.estimated_completion_date.strftime('%Y-%m-%d') if cex_request.estimated_completion_date else None,
cex_request.current_state_start.strftime('%Y-%m-%d %H:%M:%S'),
cex_request.state,
f'{cex_request.manager_assigned_to.first_name} {cex_request.manager_assigned_to.last_name}' if cex_request.manager_assigned_to else 'sin asignar',
f'{cex_request.leader_assigned_to.first_name} {cex_request.leader_assigned_to.last_name}' if cex_request.leader_assigned_to else 'sin asignar',
f'{cex_request.created_by.first_name} {cex_request.created_by.last_name}' if cex_request.created_by else 'sin asignar',
cex_request.hiree_full_name,
cex_request.hiree_id,
cex_request.hiree_cellphone,
cex_request.hiree_email,
cex_request.cenco,
cex_request.request_motive,
cex_request.banking_entity,
cex_request.bank_account_type,
cex_request.bank_account_number,
cex_request.eps,
cex_request.pension_fund,
cex_request.arl,
cex_request.contract_value,
cex_request.charge_account,
cex_request.rut.url if cex_request.rut else ""
]
ws2.append(row_data)

ws3 = wb.create_sheet(title="Monitorías")

headers = [
"ID",
"Start Date",
"Completion Date",
"Estimated Completion Date",
"Current State Start",
"State",
"Manager Assigned To",
"Leader Assigned To",
"Created By",
"Cenco",
"Has Money in Cenco",
"Cenco Manager",
"Monitoring Type",
"Student Code",
"Student Full Name",
"Student ID",
"Student Email",
"Student Cellphone",
"Daviplata",
"Course or Project",
"Monitoring Description",
"Weekly Hours",
"Total Value to Pay",
"Is Unique Payment"
]
ws3.append(headers)

for monitoring_request in requests_monitoring:
row_data = [
str(monitoring_request.id),
monitoring_request.start_date.strftime('%Y-%m-%d'),
monitoring_request.completion_date.strftime('%Y-%m-%d %H:%M:%S') if monitoring_request.completion_date else None,
monitoring_request.estimated_completion_date.strftime('%Y-%m-%d') if monitoring_request.estimated_completion_date else None,
monitoring_request.current_state_start.strftime('%Y-%m-%d %H:%M:%S'),
monitoring_request.state,
f'{monitoring_request.manager_assigned_to.first_name} {monitoring_request.manager_assigned_to.last_name}' if monitoring_request.manager_assigned_to else 'sin asignar',
f'{monitoring_request.leader_assigned_to.first_name} {monitoring_request.leader_assigned_to.last_name}' if monitoring_request.leader_assigned_to else 'sin asignar',
f'{monitoring_request.created_by.first_name} {monitoring_request.created_by.last_name}' if monitoring_request.created_by else 'sin asignar',
monitoring_request.cenco,
monitoring_request.has_money_in_cenco,
monitoring_request.cenco_manager,
monitoring_request.monitoring_type,
monitoring_request.student_code,
monitoring_request.student_full_name,
monitoring_request.student_id,
monitoring_request.student_email,
monitoring_request.student_cellphone,
monitoring_request.daviplata,
monitoring_request.course_or_proyect,
monitoring_request.monitoring_description,
monitoring_request.weekly_hours,
monitoring_request.total_value_to_pay,
monitoring_request.is_unique_payment
]
ws3.append(row_data)

ws4 = wb.create_sheet(title="Honorarios")

headers = [
"ID",
"Start Date",
"Completion Date",
"Estimated Completion Date",
"Current State Start",
"State",
"Manager Assigned To",
"Leader Assigned To",
"Created By",
"Hiree Full Name",
"Hiree ID",
"Hiree Cellphone",
"Hiree Email",
"Cenco",
"Request Motive",
"Banking Entity",
"Bank Account Type",
"Bank Account Number",
"EPS",
"Pension Fund",
"ARL",
"Contract Value",
"Charge Account",
"RUT",
"Course Name",
"Period",
"Group",
"Intensity",
"Total Hours",
"Course Code",
"Students Quantity",
"Additional Hours"
]

ws4.append(headers)

for post_request in requests_pos:
row_data = [
str(post_request.id),
post_request.start_date.strftime('%Y-%m-%d'),
post_request.completion_date.strftime('%Y-%m-%d %H:%M:%S') if post_request.completion_date else None,
post_request.estimated_completion_date.strftime('%Y-%m-%d') if post_request.estimated_completion_date else None,
post_request.current_state_start.strftime('%Y-%m-%d %H:%M:%S'),
post_request.state,
f'{post_request.manager_assigned_to.first_name} {post_request.manager_assigned_to.last_name}' if post_request.manager_assigned_to else 'sin asignar',
f'{post_request.leader_assigned_to.first_name} {post_request.leader_assigned_to.last_name}' if post_request.leader_assigned_to else 'sin asignar',
f'{post_request.created_by.first_name} {post_request.created_by.last_name}' if post_request.created_by else 'sin asignar',
post_request.hiree_full_name,
post_request.hiree_id,
post_request.hiree_cellphone,
post_request.hiree_email,
post_request.cenco,
post_request.request_motive,
post_request.banking_entity,
post_request.bank_account_type,
post_request.bank_account_number,
post_request.eps,
post_request.pension_fund,
post_request.arl,
post_request.contract_value,
post_request.charge_account,
post_request.rut.url if post_request.rut else "",
post_request.course_name,
post_request.period,
post_request.group,
post_request.intensity,
post_request.total_hours,
post_request.course_code,
post_request.students_quantity,
post_request.additional_hours
]
ws4.append(row_data)

response = HttpResponse(content_type='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename="solicitudes.xlsx"'
wb.save(response)

return response
1 change: 1 addition & 0 deletions hiring_module/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ six == 1.16.0
sqlparse == 0.4.3
tzdata == 2022.7
selenium
openpyxl
Loading