From cd0f4a1fbb59bf6f015ff931c5c4573314f4bf61 Mon Sep 17 00:00:00 2001 From: nataly Date: Wed, 29 May 2024 15:18:38 +0300 Subject: [PATCH] New changes. --- .../add/__pycache__/views.cpython-312.pyc | Bin 8335 -> 12211 bytes osinaweb/billing/add/urls.py | 3 +- osinaweb/billing/add/views.py | 111 ++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/osinaweb/billing/add/__pycache__/views.cpython-312.pyc b/osinaweb/billing/add/__pycache__/views.cpython-312.pyc index 11a293a8ba16b3a2b168dffdc234fb90f095f157..78b9ab59d7c4a27386c23539a9ab76bbdf6a7ddb 100644 GIT binary patch delta 5062 zcmai2Yit|G5k5Xekra?@BI(SMM^Vaa z01bC%XLo02cjueal_yssuFsm9>2{^rBRwNgts2FY_ZJXwik?(4gc94aQ1P#_2)o%NsyA!p#kZnW8sS$f~ zZaX%q86j+$k#!^ML1sZ_0v2|W9oX(g)`yHnVi&eH!r{>E$7oQacA~;&KS&s4vI`i; zaq5`I8SIC)=HLY(0`Wl)$s-^cTnRY#84QDJG1$72aJo!>3`*EgS$MS4Zd0$ats%5u zvz<-LQbLqv%`EVW7&cWDABQpWGxam}pkYMyy7%vWh$=r-Ri**ataDOKfv{80oj7B2 zTr|tmM1b)g^)2_{-f>i@kIKU+p#DCIt*3x#4&5A##m`VoEg4h)>+bVDfg1KCt{K5A zM8fK*C)i8_(TIVdL*y8!9a}l=IRjx>`PkcO$kBVT8&}(hY(KEDqwdruQF;g&J!pD} zQ`kKWOf$>;MX_?I_bKLpQxXc*E(-(JWG&pU3#uL}XT-4n&V_jp@O|Gn2EL;~9Q2E+&){@QTPYxQY!K zjc>!&TUWp2{{oz$U+oNbSzdq%udCz1t6)(vxWnY8VWPU!wxDWl9~z*3(HDIRH~2ZS z)5uN$gQs!^+o-hEqviwc>SDVmN8|Y%4%9sy>~8jj90Zx>q?e@XPQ?{`sG12*w9cuf zic{mb47G`F{5^(gZnd#v#}jlb`e>S93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)Cze4)2y5N*>(uEUiHJv?t zZ03yAPUe>?=7KYiuLw@iDIo&Zw{`98d5_$X8C0@jHZ!1}#ejRl$~;s?#d5g2(b*OD z$5|@obABl?-kaORwehPyN0*!@xIl0k0pHI>S`+E^uy~p7tyhcr^4L|UQr6?H$}I3a zv6|o4nt_3XNReTlnw9$8+GvQSA6x9HGU8Ur9pD5x3(7JKo-{?SZ*+n+9KkI+g5Wl1 z1>GJcXnYo3NsS8S4|!xhYdq}x6URt=?!VPBgbv_Ce0&IG#p1v^wSdMu@pxc3IEpL1 zSKQD2b3SQ1`BKR!SFczL2AJ1t7MMk#zczlgJflD(0n`P)3+SMiEkLJmQvZhbU?#P) cIR%U8Q}AcM5%0%z5gLD@ee(sCd4<_O0h`4?q5uE@ diff --git a/osinaweb/billing/add/urls.py b/osinaweb/billing/add/urls.py index 97dc4702..e3be8608 100644 --- a/osinaweb/billing/add/urls.py +++ b/osinaweb/billing/add/urls.py @@ -7,7 +7,8 @@ urlpatterns = [ path('service', views.add_service, name='addservice'), path('order//', views.add_order, name='addorder'), - + path('invoice-pdf//', views.add_invoice_pdf, name='addinvoice'), + path('payment-pdf//', views.add_payment_pdf, name='addpayment'), path('service///', views.add_service_in_order, name='addserviceinorder'), diff --git a/osinaweb/billing/add/views.py b/osinaweb/billing/add/views.py index 1c79925c..628aabe3 100644 --- a/osinaweb/billing/add/views.py +++ b/osinaweb/billing/add/views.py @@ -8,6 +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 @@ -212,6 +213,116 @@ 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}
{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