invoice-pdf-lib 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
File without changes
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: invoice_pdf_lib
3
+ Version: 0.1.0
4
+ Summary: A Python library for exporting data to pdf file and generate invoice number.
5
+ Author-email: Pooja <x23389401@student.ncirl.ie>
6
+ License: MIT
7
+ Keywords: pdf,export,invoice
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Education
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: Microsoft :: Windows :: Windows 10
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Requires-Python: >=3.6
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: reportlab>=4.0.0
19
+ Requires-Dist: xhtml2pdf>=0.2.0
20
+ Requires-Dist: requests>=2.28.0
21
+ Dynamic: license-file
File without changes
@@ -0,0 +1,24 @@
1
+ """
2
+ FoodDash Invoice Generator
3
+ A simple package for generating invoice numbers and PDF invoices
4
+ """
5
+
6
+ from .pdf_invoice import (
7
+ generate_invoice_number,
8
+ create_invoice_pdf,
9
+ get_invoice_number_from_lambda,
10
+ render_to_pdf,
11
+ download_invoice
12
+ )
13
+
14
+ __all__ = [
15
+ 'generate_invoice_number',
16
+ 'create_invoice_pdf',
17
+ 'get_invoice_number_from_lambda',
18
+ 'render_to_pdf',
19
+ 'download_invoice'
20
+ ]
21
+
22
+ __version__ = '1.0.0'
23
+ __author__ = 'FoodDash Team'
24
+ __description__ = 'Simple invoice generator for FoodDash'
@@ -0,0 +1,230 @@
1
+ """
2
+ Simple Invoice Generator for FoodDash
3
+ Generates invoice numbers and creates PDF invoices
4
+ """
5
+
6
+ import io
7
+ import json
8
+ import random
9
+ import string
10
+ from datetime import datetime
11
+ from reportlab.lib import colors
12
+ from reportlab.lib.pagesizes import letter, A4
13
+ from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer
14
+ from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
15
+ from reportlab.lib.units import inch
16
+ from reportlab.lib.enums import TA_CENTER, TA_RIGHT
17
+ from reportlab.pdfgen import canvas
18
+ import requests
19
+
20
+ def generate_invoice_number():
21
+ """
22
+ Generate a unique invoice number
23
+ Format: INV-YYYYMMDD-XXXXX
24
+ Example: INV-20250115-00123
25
+ """
26
+ date_part = datetime.now().strftime('%Y%m%d')
27
+ random_part = ''.join(random.choices(string.digits, k=5))
28
+ invoice_number = f"INV-{date_part}-{random_part}"
29
+ return invoice_number
30
+
31
+
32
+ def create_invoice_pdf(data):
33
+ """
34
+ Create a PDF invoice from data
35
+ data should be a dictionary with:
36
+ - invoice_no: str
37
+ - order_date: str
38
+ - customer_name: str
39
+ - customer_email: str
40
+ - customer_mobile: str
41
+ - shipment_address: str
42
+ - order_status: str
43
+ - product_name: str
44
+ - product_price: float
45
+ - product_description: str
46
+ """
47
+
48
+ # Create a buffer for the PDF
49
+ buffer = io.BytesIO()
50
+
51
+ # Create the PDF document
52
+ doc = SimpleDocTemplate(
53
+ buffer,
54
+ pagesize=A4,
55
+ rightMargin=72,
56
+ leftMargin=72,
57
+ topMargin=72,
58
+ bottomMargin=72
59
+ )
60
+
61
+ # Story (content) for the PDF
62
+ story = []
63
+
64
+ # Styles
65
+ styles = getSampleStyleSheet()
66
+
67
+ # Custom styles
68
+ title_style = ParagraphStyle(
69
+ 'CustomTitle',
70
+ parent=styles['Heading1'],
71
+ fontSize=24,
72
+ textColor=colors.HexColor('#FF6B35'),
73
+ alignment=TA_CENTER,
74
+ spaceAfter=30
75
+ )
76
+
77
+ heading_style = ParagraphStyle(
78
+ 'CustomHeading',
79
+ parent=styles['Heading2'],
80
+ fontSize=14,
81
+ textColor=colors.HexColor('#2d3436'),
82
+ spaceAfter=10
83
+ )
84
+
85
+ normal_style = ParagraphStyle(
86
+ 'CustomNormal',
87
+ parent=styles['Normal'],
88
+ fontSize=10,
89
+ textColor=colors.HexColor('#4a5568'),
90
+ spaceAfter=6
91
+ )
92
+
93
+ # Header
94
+ story.append(Paragraph("🍕 FoodDash", title_style))
95
+ story.append(Paragraph("Order Invoice", ParagraphStyle(
96
+ 'SubTitle',
97
+ parent=styles['Heading2'],
98
+ fontSize=16,
99
+ alignment=TA_CENTER,
100
+ textColor=colors.HexColor('#2d3436'),
101
+ spaceAfter=20
102
+ )))
103
+
104
+ # Invoice details table
105
+ invoice_data = [
106
+ ['Invoice Number:', data.get('invoice_no', 'N/A')],
107
+ ['Date:', data.get('order_date', datetime.now().strftime('%Y-%m-%d %H:%M'))],
108
+ ['Status:', data.get('order_status', 'Pending')],
109
+ ]
110
+
111
+ invoice_table = Table(invoice_data, colWidths=[1.5*inch, 3*inch])
112
+ invoice_table.setStyle(TableStyle([
113
+ ('FONTNAME', (0, 0), (-1, -1), 'Helvetica'),
114
+ ('FONTSIZE', (0, 0), (-1, -1), 10),
115
+ ('TEXTCOLOR', (0, 0), (0, -1), colors.HexColor('#4a5568')),
116
+ ('TEXTCOLOR', (1, 0), (1, -1), colors.HexColor('#2d3436')),
117
+ ('ALIGN', (0, 0), (0, -1), 'RIGHT'),
118
+ ('ALIGN', (1, 0), (1, -1), 'LEFT'),
119
+ ('BOTTOMPADDING', (0, 0), (-1, -1), 6),
120
+ ('TOPPADDING', (0, 0), (-1, -1), 6),
121
+ ]))
122
+ story.append(invoice_table)
123
+ story.append(Spacer(1, 20))
124
+
125
+ # Customer details section
126
+ story.append(Paragraph("Customer Details", heading_style))
127
+ customer_data = [
128
+ ['Name:', data.get('customer_name', 'N/A')],
129
+ ['Email:', data.get('customer_email', 'N/A')],
130
+ ['Mobile:', data.get('customer_mobile', 'N/A')],
131
+ ['Address:', data.get('shipment_address', 'N/A')],
132
+ ]
133
+
134
+ customer_table = Table(customer_data, colWidths=[1.5*inch, 3*inch])
135
+ customer_table.setStyle(TableStyle([
136
+ ('FONTNAME', (0, 0), (-1, -1), 'Helvetica'),
137
+ ('FONTSIZE', (0, 0), (-1, -1), 9),
138
+ ('TEXTCOLOR', (0, 0), (0, -1), colors.HexColor('#4a5568')),
139
+ ('TEXTCOLOR', (1, 0), (1, -1), colors.HexColor('#2d3436')),
140
+ ('ALIGN', (0, 0), (0, -1), 'RIGHT'),
141
+ ('ALIGN', (1, 0), (1, -1), 'LEFT'),
142
+ ('BOTTOMPADDING', (0, 0), (-1, -1), 4),
143
+ ('TOPPADDING', (0, 0), (-1, -1), 4),
144
+ ]))
145
+ story.append(customer_table)
146
+ story.append(Spacer(1, 20))
147
+
148
+ # Product details section
149
+ story.append(Paragraph("Order Details", heading_style))
150
+
151
+ # Product table header
152
+ product_data = [
153
+ ['Product Name', 'Description', 'Price'],
154
+ [
155
+ data.get('product_name', 'N/A'),
156
+ data.get('product_description', 'N/A')[:50],
157
+ f"${data.get('product_price', '0.00')}"
158
+ ],
159
+ ]
160
+
161
+ product_table = Table(product_data, colWidths=[1.5*inch, 2.5*inch, 1*inch])
162
+ product_table.setStyle(TableStyle([
163
+ ('FONTNAME', (0, 0), (-1, -1), 'Helvetica-Bold'),
164
+ ('FONTSIZE', (0, 0), (-1, -1), 10),
165
+ ('BACKGROUND', (0, 0), (-1, 0), colors.HexColor('#FF6B35')),
166
+ ('TEXTCOLOR', (0, 0), (-1, 0), colors.white),
167
+ ('ALIGN', (0, 0), (-1, -1), 'CENTER'),
168
+ ('VALIGN', (0, 0), (-1, -1), 'MIDDLE'),
169
+ ('GRID', (0, 0), (-1, -1), 1, colors.HexColor('#e2e8f0')),
170
+ ('BACKGROUND', (0, 1), (-1, -1), colors.HexColor('#f7fafc')),
171
+ ('TEXTCOLOR', (0, 1), (-1, -1), colors.HexColor('#2d3436')),
172
+ ('TOPPADDING', (0, 0), (-1, -1), 8),
173
+ ('BOTTOMPADDING', (0, 0), (-1, -1), 8),
174
+ ]))
175
+ story.append(product_table)
176
+ story.append(Spacer(1, 20))
177
+
178
+ # Total amount
179
+ total_style = ParagraphStyle(
180
+ 'TotalStyle',
181
+ parent=styles['Heading2'],
182
+ fontSize=16,
183
+ textColor=colors.HexColor('#FF6B35'),
184
+ alignment=TA_RIGHT,
185
+ spaceAfter=20
186
+ )
187
+ story.append(Paragraph(f"Total Amount: ${data.get('product_price', '0.00')}", total_style))
188
+
189
+ # Footer
190
+ footer_style = ParagraphStyle(
191
+ 'FooterStyle',
192
+ parent=styles['Normal'],
193
+ fontSize=8,
194
+ textColor=colors.HexColor('#a0aec0'),
195
+ alignment=TA_CENTER,
196
+ spaceBefore=30
197
+ )
198
+ story.append(Paragraph("Thank you for choosing FoodDash!", footer_style))
199
+ story.append(Paragraph("This is a system-generated invoice.", footer_style))
200
+
201
+ # Build the PDF
202
+ doc.build(story)
203
+
204
+ # Get the PDF content
205
+ pdf_content = buffer.getvalue()
206
+ buffer.close()
207
+
208
+ return pdf_content
209
+
210
+
211
+ def get_invoice_number_from_lambda():
212
+ """
213
+ Get invoice number from AWS Lambda API
214
+ If fails, generate a local invoice number
215
+ """
216
+ try:
217
+ # Your Lambda URL
218
+ lambda_url = "https://8gn82qr48j.execute-api.us-east-1.amazonaws.com/deploy-stage/invoice_no"
219
+ response = requests.get(lambda_url, timeout=10)
220
+ if response.status_code == 200:
221
+ outer_data = response.json()
222
+ body = json.loads(outer_data.get("body", "{}"))
223
+ invoice_number = body.get("invoice_number")
224
+ if invoice_number:
225
+ return invoice_number
226
+ except Exception as e:
227
+ print(f"Error fetching invoice from Lambda: {e}")
228
+
229
+ # Fallback: generate local invoice number
230
+ return generate_invoice_number()
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: invoice_pdf_lib
3
+ Version: 0.1.0
4
+ Summary: A Python library for exporting data to pdf file and generate invoice number.
5
+ Author-email: Pooja <x23389401@student.ncirl.ie>
6
+ License: MIT
7
+ Keywords: pdf,export,invoice
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Education
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: Microsoft :: Windows :: Windows 10
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Requires-Python: >=3.6
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: reportlab>=4.0.0
19
+ Requires-Dist: xhtml2pdf>=0.2.0
20
+ Requires-Dist: requests>=2.28.0
21
+ Dynamic: license-file
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ invoice_pdf_lib/__init__.py
6
+ invoice_pdf_lib/pdf_invoice.py
7
+ invoice_pdf_lib.egg-info/PKG-INFO
8
+ invoice_pdf_lib.egg-info/SOURCES.txt
9
+ invoice_pdf_lib.egg-info/dependency_links.txt
10
+ invoice_pdf_lib.egg-info/requires.txt
11
+ invoice_pdf_lib.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ reportlab>=4.0.0
2
+ xhtml2pdf>=0.2.0
3
+ requests>=2.28.0
@@ -0,0 +1 @@
1
+ invoice_pdf_lib
@@ -0,0 +1,30 @@
1
+
2
+ [build-system]
3
+ requires = ["setuptools>=61.0.0", "wheel"]
4
+ build-backend = "setuptools.build_meta"
5
+
6
+ [project]
7
+ name = "invoice_pdf_lib"
8
+ version = "0.1.0"
9
+ description = "A Python library for exporting data to pdf file and generate invoice number."
10
+ readme = {file = "README.md", content-type = "text/markdown"}
11
+ authors = [
12
+ {name = "Pooja", email = "x23389401@student.ncirl.ie"}
13
+ ]
14
+ license = {text = "MIT"}
15
+ keywords = ["pdf","export","invoice"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Education",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Operating System :: Microsoft :: Windows :: Windows 10",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ ]
25
+ requires-python = ">=3.6"
26
+ dependencies = [
27
+ "reportlab>=4.0.0",
28
+ "xhtml2pdf>=0.2.0",
29
+ "requests>=2.28.0",
30
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+