diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3180d04..0000000 --- a/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.vscode/ -assets/node_modules/ - -.DS_Store -*.sqlite3 -*.pyc diff --git a/requirements.txt b/requirements.txt index 6c924df..b42a731 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ six==1.12.0 sqlparse==0.3.0 webencodings==0.5.1 xhtml2pdf==0.2.3 +WeasyPrint==50 diff --git a/salaries/views.py b/salaries/views.py index 74e3083..70d09fa 100644 --- a/salaries/views.py +++ b/salaries/views.py @@ -5,24 +5,24 @@ from django.template import loader, Context from django.views.generic import View from django.utils.text import slugify - -from easy_pdf.rendering import render_to_pdf -from .models import Salary - +from .models import Salary, TimeRecord +from weasyprint import HTML, CSS +from django.template.loader import render_to_string +from .admin import SalaryAdmin class SendPayslip(View): """ send payslip to email """ def get(self, *args, **kwargs): - #payroll = get_object_or_404(Salary, **kwargs) + + salary = get_object_or_404(Salary, **kwargs) + time_record = TimeRecord.objects.filter(salary=salary) + html = render_to_string('emails/payslip.html',{'salary': salary, 'time_record': time_record}) + pdf = HTML(string=html).write_pdf() - pdf = render_to_pdf( - 'emails/payslip.html', - {} - ) html_content = "

payslip is attached

" - msg = EmailMultiAlternatives("Swiftkind Payroll", "payslip is attached", settings.DEFAULT_FROM_EMAIL, ['earvin@swiftkind.com']) + msg = EmailMultiAlternatives("Swiftkind Payroll", "payslip is attached", settings.DEFAULT_FROM_EMAIL, ['erykestabillo@gmail.com']) msg.attach_alternative(html_content, "text/html") msg.attach('payslip.pdf', pdf, 'application/pdf') msg.send() @@ -34,8 +34,11 @@ class DownloadPayslip(View): """ download payslip """ def get(self, *args, **kwargs): + salary = get_object_or_404(Salary, **kwargs) - pdf = render_to_pdf('emails/payslip.html', {'salary': salary}) + time_record = TimeRecord.objects.filter(salary=salary) + html = render_to_string('emails/payslip.html',{'salary': salary, 'time_record': time_record}) + pdf = HTML(string=html).write_pdf() filename = slugify(f"{salary.user.get_full_name()} {salary.period}") diff --git a/templates/emails/payslip.html b/templates/emails/payslip.html index 6d70e64..599833d 100644 --- a/templates/emails/payslip.html +++ b/templates/emails/payslip.html @@ -1,59 +1,312 @@ -{% load static %} + + + + + + + + +
-
-
- -

Swiftkind Software

+
+
+

Swiftkind Softwares

+

Philippines

-
-

Payslip

-

#1234567

+
+

INVOICE

+

Invoice# SWKD-00001

+

Balance Due

+

PHP{{ salary.net }}

-
-
-

{{ salary.user.get_full_name }}

-

Software Developer

-

earvin@swiftkind.com

+
+
+

Bill To

+

{{ salary.user.get_full_name }}

-
-

Pay period

-

July 1-15, 2019

+
+ + + + + + + + + + + + + + + + + + + +
Invoice Date:{{ salary.date_sent }}
Terms:Due on Receipt
Due Date:{{ salary.date_due }}
P.O.#:SWKD-00001
-
-
-

Base Salary

-

P12,000

-
-
-
-
Less
-
-
    -
  • - SSS - 480.00 -
  • -
  • - Philhealth - 480.00 -
  • -
-
-
-
Total Deductions:
-

P600.00

-
-
-
+
+ + + + + + + + + + + + + + + + + + + {% for deduction in salary.deductions.all %} + + + + + + + + {% endfor %} + + {% if salary.total_late > 0 %} + + + + + + {% endif %} + + + {% if salary.total_absent > 0 %} + + + + + + {% endif %} + + + + + + + + + + + + + + + + + + + + + + + + + +
#Item & DescriptionQtyRateAmount
Basic Salary Period {{ salary.period }}1.001.00{{ salary.base_amount }}
{{ deduction.name }}1.00-{{ deduction.total }}-{{ deduction.total }}
Late Deduction1.00-{{ salary.total_late }}-{{ salary.total_late }}
Absent Deduction1.00-{{ salary.total_absent }}-{{ salary.total_absent }}
Sub TotalPHP{{ salary.net }}
TotalPHP{{ salary.net }}
Balance DuePHP{{ salary.net }}
- - \ No newline at end of file +
+ \ No newline at end of file