Skip to content

Commit

Permalink
Vacation response letter creation (Not in working)
Browse files Browse the repository at this point in the history
  • Loading branch information
Heibert committed Oct 18, 2024
1 parent 105b5aa commit 20f679c
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ WSGI
*.csv
*.xlsx
*.xl*
# Don't ignore the test files
!INSIGHTSAPI/utils/excels/*.csv
venv
.venv
media/
Expand Down
1 change: 0 additions & 1 deletion INSIGHTSAPI/INSIGHTSAPI/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def test_send_payslip_task(self):
}
payslip = Payslip(**data)
response = send_payslip([payslip])
print(response)
self.assertEqual(response.status_code, 201)


Expand Down
2 changes: 1 addition & 1 deletion INSIGHTSAPI/goals/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_borrado_accepted_with_another_upload(self):
self.test_metas_upload(called=True)
# See if there are goals created
number_goals = Goals.objects.all().count()
self.assertTrue(number_goals > 0)
self.assertTrue(number_goals > 0)
# put accepted to True and accepted_at to now() to Goals
Goals.objects.all().update(accepted=True, accepted_at=timezone.now())
# Read the file again and upload it
Expand Down
16 changes: 10 additions & 6 deletions INSIGHTSAPI/payslip/templates/payslip.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,12 @@ <h3 style="margin: 0">DEDUCCIONES</h3>
${{ payslip.transport_allowance }}
</td>
</tr>
{{ % if payslip.bearing % }}
<tr>
<td>Rodamiento</td>
<td style="border-left: solid 1px #ccc">
${{ payslip.bearing }}
</td>
</tr>
{{ % endif % }}
<tr>
<td>Comision</td>
<td style="border-left: solid 1px #ccc">
Expand Down Expand Up @@ -286,16 +284,22 @@ <h3 style="margin: 0">DEDUCCIONES</h3>
</td>
</tr>
<tr>
<td style="height: 25px"></td>
<td>&#8203;</td> <!-- Empty row to adjust table styles -->
<td
style="border-left: solid 1px #ccc"
></td>
>&#8203;</td> <!-- Empty row to adjust table styles -->
</tr>
<tr>
<td style="height: 22px"></td>
<td>&#8203;</td> <!-- Empty row to adjust table styles -->
<td
style="border-left: solid 1px #ccc"
></td>
>&#8203;</td> <!-- Empty row to adjust table styles -->
</tr>
<tr>
<td>&#8203;</td> <!-- Empty row to adjust table styles -->
<td
style="border-left: solid 1px #ccc"
>&#8203;</td> <!-- Empty row to adjust table styles -->
</tr>
</tbody>
</table>
Expand Down
59 changes: 56 additions & 3 deletions INSIGHTSAPI/vacation/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"""This module contains the model for the vacation request """

import pdfkit
from django.conf import settings
from django.core.mail import EmailMessage, send_mail
from django.db import models
from django.core.mail import send_mail
from users.models import User
from django.template.loader import render_to_string
from django.utils import timezone

from notifications.utils import create_notification
from users.models import User
from vacation.utils import get_return_date
from django.utils import timezone


class VacationRequest(models.Model):
Expand Down Expand Up @@ -144,3 +148,52 @@ def save(self, *args, **kwargs):
self.user,
)
super().save(*args, **kwargs)

def send_approval_email_with_pdf(self):
# Render the vacation request details in a PDF
pdf = self.generate_pdf()

# Create the email message
subject = "Your Vacation Request Has Been Approved"
message = (
f"Dear {self.user.get_full_name()},\n\n"
"Your vacation request from {self.start_date} to {self.end_date} has been approved.\n"
"Please find the attached document with the details of your vacation.\n\n"
"Best regards,\nYour Company"
)

email = EmailMessage(
subject, message, settings.DEFAULT_FROM_EMAIL, [str(self.user.email)]
)

# Attach the generated PDF
email.attach(
filename="vacation_request.pdf", content=pdf, mimetype="application/pdf"
)

# Send the email
email.send()

def generate_pdf(self):
# Create context for the PDF
context = {
"vacation": self,
}

# Render the HTML template to a string
rendered_html = render_to_string("vacation_response.html", context)

# PDF options
options = {
"page-size": "Letter",
"encoding": "UTF-8",
"margin-top": "0mm",
"margin-right": "0mm",
"margin-bottom": "0mm",
"margin-left": "0mm",
}

# Generate the PDF from HTML
pdf = pdfkit.from_string(rendered_html, False, options=options)

return pdf
89 changes: 50 additions & 39 deletions INSIGHTSAPI/vacation/templates/vacation_request.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8" />
Expand All @@ -8,92 +8,103 @@
html,
body {
height: 100%;
margin: -100px 10px 0px 10px;
margin: 0;
padding: 0;
font-family: 'Helvetica Neue', Arial, sans-serif;
color: #333;
line-height: 1.6;
text-align: center;
align-items: center;
font-size: 20px;
background-color: #f0f4f8;
display: flex;
justify-content: center;
align-items: center;
}

#signature-rh {
padding-left: 200px;
.card {
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 40px;
{% comment %} max-width: 600px; {% endcomment %}
height: 90%;
width: 80%;
/* Ensure the card grows vertically when content is too short */
min-height: 300px;
box-sizing: border-box;
}

.header {
margin-top: 80px;
margin-bottom: 40px;
margin-bottom: 30px;
text-align: center;
}

.header h1 {
margin: 0;
font-size: 28px;
color: #0056b3;
font-size: 40px;
color: #2c3e50;
letter-spacing: 1px;
}

.content {
text-align: left;
font-size: 20px;
}

.signature {
margin-top: 200px;
text-align: center;
margin-top: 40px;
text-align: left;
}

.signature p {
margin: 5px 0;
text-align: left;
}

.footer {
margin-top: 20px;
font-size: 14px;
text-align: center;
color: #777;
color: #7f8c8d;
}

.highlight {
color: #3498db;
font-weight: bold;
}

.date {
color: #7f8c8d;
font-style: italic;
}
</style>
</head>

<body>
<div class="card">
<div class="header">
<h1>Solicitud de Vacaciones</h1>
</div>
<div class="content">
<p>{{ vacation.created_at|date }}</p>
<br />
<p class="date">{{ vacation.created_at|date }}</p>
<p>Estimado (a) Gestión Humana</p>
<p>CYC SERVICES S.A.S.</p>
<p>Ref. Solicitud de vacaciones disfrutadas</p>
<br />
<p><strong>Ref. Solicitud de vacaciones disfrutadas</strong></p>
<p>
Por la presente le solicito se me conceda {{
vacation.duration }} días de mi periodo vacacional
comprendido para el año {{ vacation.start_date|date:"Y" }}.
Por la presente le solicito se me conceda <span class="highlight">{{ vacation.duration }} días</span> de mi periodo vacacional
comprendido para el año <span class="highlight">{{ vacation.start_date|date:"Y" }}</span>.
</p>
<p>
Los días tomados serán a partir del {{ vacation.start_date
}} hasta el día {{ vacation.end_date }}, para retomar a mis
labores el día {{ vacation.return_date }}.
Los días tomados serán a partir del <span class="highlight">{{ vacation.start_date }}</span> hasta el día <span class="highlight">{{ vacation.end_date }}</span>,
para retomar a mis labores el día <span class="highlight">{{ vacation.return_date }}</span>.
</p>
<p>Quedo agradecido(a) ante su pronta respuesta.</p>
<div class="signature">
<p>Atentamente,</p>
<p><strong>{{ vacation.user }}</strong></p>
<p>{{ vacation.user.job_position }}</p>
</div>
<!-- <div class="signature-line">
<table>
<td>
_____________________________________<br>
GARZON NAVAS CESAR ALBERTO <br>
<i>Gerente General</i>
</td>
<td id="signature-rh">
_____________________________________<br>
PINZON MARTINEZ JEANNETH OTILIA<br>
<i>Gerente de Gestión Humana</i>
</td>
</table>
</div> -->
</div>
{% comment %} <div class="footer">
<p>Este documento es generado automáticamente. No requiere firma ni sello.</p>
</div> {% endcomment %}
</div>
</body>
</html>
Loading

0 comments on commit 20f679c

Please sign in to comment.