Let’s get started in our journey of creating payment receipts using Python
Introduction
Hello coder, welcome to the codewithrandom blog. In this article, we will Build a payment receipt using Python.
Why creating payment receipts using Python is important?
Creating payment receipts using Python is an important part of any business transaction. It helps in keeping track of the payments received from customers and provides a record for future reference.
In this blog post, we will be discussing how to create payment receipts using Python.
Let’s know how to code a receipt in Python
First knowing the Prerequisites is very important
We need to install the report lab module. You can install these packages in your terminal.
$ pip install reportlab
To Create a payment receipt using Python, we need to perform the following steps:
step 1: imports modules
from reportlab.platypus import SimpleDocTemplate, Table, Paragraph, TableStyle from reportlab.lib import colors from reportlab.lib.pagesizes import A4 from reportlab.lib.styles import getSampleStyleSheet
step 2: Define the Data that we are going to display as tables
DATA = [ [ "Date" , "Name", "Subscription", "Price (Rs.)" ], [ "16/11/2020", "Full Stack Development - Live", "Lifetime", "10,99.00/-", ], [ "16/11/2020", "coding Classes: Live Session", "6 months", "9,999.00/-"], [ "Sub Total", "", "", "208.00/-"], [ "Discount", "", "", "-30.00/-"], [ "Total", "", "", "178.00/-"], ]
step 3: Create a Base Document Template of page size A4 & standard stylesheet defined within Reportlab itself
pdf = SimpleDocTemplate( "receipt.pdf" , pagesize = A4 ) styles = getSampleStyleSheet()
step 4: fetching the style of Top level heading (Heading1)
title_style = styles[ "Heading1" ] # 0: left, 1: center, 2: right title_style.alignment = 1
step 5: Create the paragraph with the heading text and pass the styles of it
title = Paragraph( "Codewithrandom" , title_style )
step 6: Create a Table Style object and in it, define the styles row the tuples that look like coordinates are nothing but rows and columns
style = TableStyle( [ ( "BOX" , ( 0, 0 ), ( -1, -1 ), 1 , colors.black ), ( "GRID" , ( 0, 0 ), ( 4 , 4 ), 1 , colors.black ), ( "BACKGROUND" , ( 0, 0 ), ( 3, 0 ), colors.gray ), ( "TEXTCOLOR" , ( 0, 0 ), ( -1, 0 ), colors.whitesmoke ), ( "ALIGN" , ( 0, 0 ), ( -1, -1 ), "CENTER" ), ( "BACKGROUND" , ( 0 , 1 ) , ( -1 , -1 ), colors.beige ), ] )
step 7: Create a table object and pass the style to it
table = Table( DATA , style = style )
step 8: The final step which builds the actual pdf putting together all the elements
pdf.build([ title , table ])
Here is the Complete Source Code For creating a payment receipts using Python (copy the code and run )👇
# imports module from reportlab.platypus import SimpleDocTemplate, Table, Paragraph, TableStyle from reportlab.lib import colors from reportlab.lib.pagesizes import A4 from reportlab.lib.styles import getSampleStyleSheet DATA = [ [ "Date" , "Name", "Subscription", "Price (Rs.)" ], [ "16/11/2020", "Full Stack Development - Live", "Lifetime", "10,99.00/-", ], [ "16/11/2020", "coding Classes: Live Session", "6 months", "9,999.00/-"], [ "Sub Total", "", "", "208.00/-"], [ "Discount", "", "", "-30.00/-"], [ "Total", "", "", "178.00/-"], ] pdf = SimpleDocTemplate( "receipt.pdf" , pagesize = A4 ) styles = getSampleStyleSheet() title_style = styles[ "Heading1" ] title_style.alignment = 1 title = Paragraph( "Codewithrandom" , title_style ) style = TableStyle( [ ( "BOX" , ( 0, 0 ), ( -1, -1 ), 1 , colors.black ), ( "GRID" , ( 0, 0 ), ( 4 , 4 ), 1 , colors.black ), ( "BACKGROUND" , ( 0, 0 ), ( 3, 0 ), colors.gray ), ( "TEXTCOLOR" , ( 0, 0 ), ( -1, 0 ), colors.whitesmoke ), ( "ALIGN" , ( 0, 0 ), ( -1, -1 ), "CENTER" ), ( "BACKGROUND" , ( 0 , 1 ) , ( -1 , -1 ), colors.beige ), ] ) table = Table( DATA , style = style ) pdf.build([ title , table ])
Output for the project👇👇
Conclusion:
In this blog post, we discussed how to create payment receipts using Python. We used the reportlab library to generate a simple payment receipt. With a few modifications to the code, you can customize the receipt to suit your needs. By automating the process of generating payment receipts, you can save time and ensure accurate record keeping. Hope you enjoyed building with us! Visit our homepage and you get lots of projects💝
If you have any queries related to the project or the concept, feel free to ask in the comment section.
Thank you and keep learning!!
Some FAQs:
ADVERTISEMENT
- Is the above project working and responsive?
Answer – yes!!
ADVERTISEMENT
2. What is the need to create payment receipts using Python?
ADVERTISEMENT
Answer- Creating payment receipts using Python is an important part of any business transaction. It helps in keeping track of the payments received from customers and provides a record for future reference.
ADVERTISEMENT