New changes.

main
nataly 12 months ago
parent 2453f3b80f
commit a0d2093550

@ -7,8 +7,7 @@ urlpatterns = [
path('service', views.add_service, name='addservice'),
path('order/<int:customer_id>/', views.add_order, name='addorder'),
path('invoice-pdf/<int:order_id>/', views.add_invoice_pdf, name='addinvoice'),
path('payment-pdf/<int:order_id>/', views.add_payment_pdf, name='addpayment'),
path('service/<int:service_id>/<int:order_id>/', views.add_service_in_order, name='addserviceinorder'),

@ -8,7 +8,7 @@ import os
from osinacore.decorators import *
from django.core.files.base import ContentFile
from django.db.models import Q
from weasyprint import HTML, CSS
@ -218,116 +218,6 @@ def add_payment_comment_modal(request):
def add_invoice_pdf(request, order_id):
order = get_object_or_404(Order, id=order_id)
current_year = str(timezone.now().year)[-2:]
last_invoice = Invoice.objects.all().last()
if last_invoice:
last_invoice_number = int(last_invoice.invoice_number.split('-')[1].split('+')[0])
new_invoice_number = f"$0{current_year}-{last_invoice_number + 1}"
else:
new_invoice_number = f"$0{current_year}-1425"
invoice = Invoice.objects.create(
invoice_number = new_invoice_number,
order=order,
date_created=datetime.now(),
)
template = get_template('details_templates/invoice-details.html')
context = {'order': order}
html_string = template.render(context)
# Define the CSS string with Poppins font
css_string = '''
@font-face {
font-family: 'Poppins';
src: url('path_to_poppins_font_file.ttf') format('truetype'); /* Update the path to the font file */
}
body {
font-family: 'Poppins', sans-serif; /* Use Poppins font for the entire document */
}
/* Your existing CSS styles */
/* Add or modify styles as needed */
'''
# Generate PDF
pdf = HTML(string=html_string).write_pdf(
stylesheets=[
CSS(string=css_string),
CSS(string='@page { margin: 30px; }')
],
presentational_hints=True
)
filename = f'invoice_{invoice.invoice_number}.pdf'
pdf_content = ContentFile(pdf)
invoice.pdf.save(filename, pdf_content, save=True)
# Return PDF
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="my_pdf.pdf"'
return response
def add_payment_pdf(request, order_id):
order = get_object_or_404(Order, id=order_id)
payments = OrderPayment.objects.filter(order = order)
paid_amount = OrderPayment.objects.filter(order=order, date_paid__isnull=False).aggregate(total_paid=Sum('amount'))['total_paid'] or 0
cart_total = order.get_cart_total
remaining_amount = cart_total - paid_amount
invoice = order.invoice
# Render both invoice and payment details templates to HTML
invoice_template = get_template('details_templates/invoice-details.html')
payment_template = get_template('details_templates/payment-details.html')
invoice_html = invoice_template.render({'order': order})
payment_html = payment_template.render({'order': order, 'payments':payments, 'remaining_amount':remaining_amount,})
# Combine the HTML content of both templates
combined_html = f"{invoice_html}<div style='page-break-before: always;'></div>{payment_html}"
# Define CSS
css_string = '''
@font-face {
font-family: 'Poppins';
src: url('path_to_poppins_font_file.ttf') format('truetype'); /* Update the path to the font file */
}
body {
font-family: 'Poppins', sans-serif; /* Use Poppins font for the entire document */
}
/* Your existing CSS styles */
/* Add or modify styles as needed */
'''
# Generate PDF
pdf = HTML(string=combined_html).write_pdf(
stylesheets=[
CSS(string=css_string),
CSS(string='@page { margin: 30px; }')
],
presentational_hints=True
)
# Return PDF
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="my_pdf.pdf"'
return response

@ -1,28 +1,32 @@
{% extends "customer_main.html" %}
{%load static%}
{% block content %}
<div class="w-full px-5 s:px-9 flex flex-col gap-3">
<div class="w-full bg-white rounded-md h-fit shadow-md p-5">
<div class="w-full h-fit flex flex-col gap-2 bg-gray-100 shadow-md rounded-md px-3 py-3">
<p class="text-secondosiblue text-[20px]">Ticket <span class="font-semibold">#{{ticket.ticket_number}}</span></p>
<p class="text-secondosiblue text-[20px]">Ticket <span
class="font-semibold">#{{ticket.ticket_number}}</span></p>
{% if last_ticket_status.status == 'Open' %}
<div class="flex justify-start items-center gap-1">
<div class="w-[16px] h-[16px] rounded-full bg-green-200 shadow-md"></div>
<p class="text-secondosiblue font-light">Opened by {{last_ticket_status.added_by.first_name}} at {{last_ticket_status.date_added}}</p>
<p class="text-secondosiblue font-light">Opened by {{last_ticket_status.added_by.first_name}} at
{{last_ticket_status.date_added}}</p>
</div>
{% elif last_ticket_status.status == 'Working On' %}
<div class="flex justify-start items-center gap-1">
<div class="w-[16px] h-[16px] rounded-full bg-yellow-200 shadow-md"></div>
<p class="text-secondosiblue font-light">Updated to 'Working On' by {{last_ticket_status.added_by.first_name}} at {{last_ticket_status.date_added}}</p>
<p class="text-secondosiblue font-light">Updated to 'Working On' by
{{last_ticket_status.added_by.first_name}} at {{last_ticket_status.date_added}}</p>
</div>
{% elif last_ticket_status.status == 'Closed' %}
<div class="flex justify-start items-center gap-1">
<div class="w-[16px] h-[16px] rounded-full bg-red-200 shadow-md"></div>
<p class="text-secondosiblue font-light">Closed by {{last_ticket_status.added_by.first_name}} at {{last_ticket_status.date_added}}</p>
<p class="text-secondosiblue font-light">Closed by {{last_ticket_status.added_by.first_name}} at
{{last_ticket_status.date_added}}</p>
</div>
{% endif %}
@ -35,18 +39,21 @@
{% if ticket.ticketattachment_set.all %}
<div class="w-full flex flex-wrap justify-end items-center gap-3">
<a>
<div class="flex items-center gap-1 text-secondosiblue hover:text-gray-500 duration-300 cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4 text-secondosiblue">
<path stroke-linecap="round" stroke-linejoin="round" d="m18.375 12.739-7.693 7.693a4.5 4.5 0 0 1-6.364-6.364l10.94-10.94A3 3 0 1 1 19.5 7.372L8.552 18.32m.009-.01-.01.01m5.699-9.941-7.81 7.81a1.5 1.5 0 0 0 2.112 2.13" />
</svg>
<div
class="flex items-center gap-1 text-secondosiblue hover:text-gray-500 duration-300 cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-4 h-4 text-secondosiblue">
<path stroke-linecap="round" stroke-linejoin="round"
d="m18.375 12.739-7.693 7.693a4.5 4.5 0 0 1-6.364-6.364l10.94-10.94A3 3 0 1 1 19.5 7.372L8.552 18.32m.009-.01-.01.01m5.699-9.941-7.81 7.81a1.5 1.5 0 0 0 2.112 2.13" />
</svg>
{% for file in ticket.ticketattachment_set.all %}
<a href="{{file.file.url}}">{{ file.file }}{% if not forloop.last %}, {% endif %}</a>
{% endfor %}
<a href="{{file.file.url}}">{{ file.file }}{% if not forloop.last %}, {% endif %}</a>
{% endfor %}
</div>
</a>
</div>
{% endif %}
</div>
@ -101,22 +108,23 @@
</svg>
</div>
<div class="w-full bg-white p-5 flex flex-col gap-3 reply">
<p class="text-gray-500 font-light leading-8 text-[15px]">
{{update.description}}
</p>
<div class="w-full bg-white p-5 flex flex-col gap-3 reply default-css">
{{update.description | safe }}
{% if update.ticketattachment_set.all %}
<div class="w-full flex flex-wrap justify-end items-center gap-3">
<a>
<div class="flex items-center gap-1 text-secondosiblue hover:text-gray-500 duration-300 cursor-pointer text-sm">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-4 h-4 text-secondosiblue">
<path stroke-linecap="round" stroke-linejoin="round" d="m18.375 12.739-7.693 7.693a4.5 4.5 0 0 1-6.364-6.364l10.94-10.94A3 3 0 1 1 19.5 7.372L8.552 18.32m.009-.01-.01.01m5.699-9.941-7.81 7.81a1.5 1.5 0 0 0 2.112 2.13" />
</svg>
{% for file in update.ticketattachment_set.all %}
<a href="{{file.file.url}}">{{ file.file }}{% if not forloop.last %}, {% endif %}</a>
{% endfor %}
<div
class="flex items-center gap-1 text-secondosiblue hover:text-gray-500 duration-300 cursor-pointer text-sm">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke-width="1.5" stroke="currentColor" class="w-4 h-4 text-secondosiblue">
<path stroke-linecap="round" stroke-linejoin="round"
d="m18.375 12.739-7.693 7.693a4.5 4.5 0 0 1-6.364-6.364l10.94-10.94A3 3 0 1 1 19.5 7.372L8.552 18.32m.009-.01-.01.01m5.699-9.941-7.81 7.81a1.5 1.5 0 0 0 2.112 2.13" />
</svg>
{% for file in update.ticketattachment_set.all %}
<a href="{{file.file.url}}">{{ file.file }}{% if not forloop.last %}, {% endif %}</a>
{% endfor %}
</div>
</a>
</div>
@ -131,21 +139,24 @@
<div class="flex justify-start items-center gap-2">
<a href="{% url 'customeraddticketupdatereaction' 'Happy' update.id %}">
<div class="w-fit h-fit rounded-full {% if update.last_customer_reaction == 'Happy' %} border-2 border-secondosiblue {% endif %}">
<div
class="w-fit h-fit rounded-full {% if update.last_customer_reaction == 'Happy' %} border-2 border-secondosiblue {% endif %}">
<img src="{% static 'images/icons/happy-icon.png' %}"
class="w-[30px] h-[30px] rounded-full cursor-pointer hover:scale-105 duration-300 transition-transform">
</div>
</a>
<a href="{% url 'customeraddticketupdatereaction' 'Indifferent' update.id %}">
<div class="w-fit h-fit rounded-full {% if update.last_customer_reaction == 'Indifferent' %} border-2 border-secondosiblue {% endif %}">
<div
class="w-fit h-fit rounded-full {% if update.last_customer_reaction == 'Indifferent' %} border-2 border-secondosiblue {% endif %}">
<img src="{% static 'images/icons/neutral-icon.png' %}"
class="w-[30px] h-[30px] rounded-full cursor-pointer hover:scale-105 duration-300 transition-transform">
</div>
</a>
<a href="{% url 'customeraddticketupdatereaction' 'Sad' update.id %}">
<div class="w-fit h-fit rounded-full {% if update.last_customer_reaction == 'Sad' %} border-2 border-secondosiblue {% endif %}">
<div
class="w-fit h-fit rounded-full {% if update.last_customer_reaction == 'Sad' %} border-2 border-secondosiblue {% endif %}">
<img src="{% static 'images/icons/unhappy-icon.png' %}"
class="w-[30px] h-[30px] rounded-full cursor-pointer hover:scale-105 duration-300 transition-transform">
</div>
@ -192,10 +203,9 @@
<div class="w-full flex flex-col gap-3">
<textarea name="description"
<textarea name="description" rows="8"
class="w-full bg-white px-3 py-3 border border-gray-200 rounded-md outline-none text-gray-500 resize-none"
rows="8" placeholder="Add Comment..."></textarea>
placeholder="Add Comment..." required></textarea>
<div class="w-full flex flex-col s:flex-row justify-end items-center gap-3">
<div
@ -226,6 +236,10 @@
<!---------------------- JS SCRIPTS -------------------->
<script>
CKEDITOR.replace('description');
</script>
<script type="text/javascript" src="{% static 'js/customer_dashboard/ticket-details.js' %}"></script>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save