diff --git a/osinaweb/billing/add/__pycache__/views.cpython-312.pyc b/osinaweb/billing/add/__pycache__/views.cpython-312.pyc index 66eb6500..a9c7844f 100644 Binary files a/osinaweb/billing/add/__pycache__/views.cpython-312.pyc and b/osinaweb/billing/add/__pycache__/views.cpython-312.pyc differ diff --git a/osinaweb/billing/add/views.py b/osinaweb/billing/add/views.py index 0e2d4384..5d552753 100644 --- a/osinaweb/billing/add/views.py +++ b/osinaweb/billing/add/views.py @@ -272,6 +272,56 @@ def add_invoice_pdf(request, order_id): +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}
{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 + + +