DivyaShah2025 commited on
Commit
89014dc
·
verified ·
1 Parent(s): 1a5123b

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +107 -33
app.py CHANGED
@@ -2,37 +2,104 @@ import gradio as gr
2
  from datetime import datetime
3
  from reportlab.pdfgen import canvas
4
  from reportlab.lib.pagesizes import A4
 
5
  import io
6
  import os
7
 
8
- def create_pi_pdf(customer_name, address, gstin, product_name, qty, price_per_unit):
9
- today = datetime.today().strftime("%Y-%m-%d")
10
- total = qty * price_per_unit
11
-
 
 
 
 
 
 
 
12
  buffer = io.BytesIO()
13
  c = canvas.Canvas(buffer, pagesize=A4)
14
- text = c.beginText(50, 800)
15
- text.textLine(f"Consignor: True Vybes, Thane, GSTIN: 27BVOPS7767J2ZF")
16
- text.textLine(f"Consignee: {customer_name}")
17
- text.textLine(f"Address: {address}")
18
- text.textLine(f"GSTIN: {gstin}")
19
- text.textLine(f"Date: {today}")
20
- text.textLine("")
21
- text.textLine(f"Product: {product_name}")
22
- text.textLine(f"Qty: {qty}")
23
- text.textLine(f"Price per unit: {price_per_unit}")
24
- text.textLine(f"Total: {total}")
25
- text.textLine("")
26
- text.textLine("Authorised Signatory")
27
-
28
- c.drawText(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  c.showPage()
30
  c.save()
31
  buffer.seek(0)
32
  return buffer
33
 
34
- def generate_pi(customer_name, address, gstin, product_name, qty, price_per_unit):
35
- pdf_buffer = create_pi_pdf(customer_name, address, gstin, product_name, qty, price_per_unit)
 
36
 
37
  # Create a temporary file
38
  temp_file = "Proforma_Invoice.pdf"
@@ -42,21 +109,28 @@ def generate_pi(customer_name, address, gstin, product_name, qty, price_per_unit
42
  return temp_file
43
 
44
  with gr.Blocks() as demo:
45
- gr.Markdown("# 📄 Proforma Invoice Generator")
46
-
47
- customer_name = gr.Textbox(label="Customer Name")
48
- address = gr.Textbox(label="Address")
49
- gstin = gr.Textbox(label="GSTIN")
50
- product_name = gr.Textbox(label="Product Name")
51
- qty = gr.Number(label="Quantity")
52
- price_per_unit = gr.Number(label="Price per Unit")
53
-
54
- generate_button = gr.Button("Generate PI")
55
- invoice_file = gr.File(label="Download your PI PDF")
 
 
 
 
 
 
 
56
 
57
  generate_button.click(
58
  fn=generate_pi,
59
- inputs=[customer_name, address, gstin, product_name, qty, price_per_unit],
60
  outputs=invoice_file
61
  )
62
 
 
2
  from datetime import datetime
3
  from reportlab.pdfgen import canvas
4
  from reportlab.lib.pagesizes import A4
5
+ from reportlab.lib.units import mm
6
  import io
7
  import os
8
 
9
+ def create_pi_pdf(customer_name, address, gstin, product_code, product_description,
10
+ quantity, price_per_unit, gst_percentage=18):
11
+ # Format today's date
12
+ today = datetime.today().strftime("%d.%m.%Y")
13
+
14
+ # Calculate values
15
+ subtotal = quantity * price_per_unit
16
+ gst_amount = (subtotal * gst_percentage) / 100
17
+ grand_total = subtotal + gst_amount
18
+
19
+ # Create PDF
20
  buffer = io.BytesIO()
21
  c = canvas.Canvas(buffer, pagesize=A4)
22
+ width, height = A4
23
+
24
+ # Header
25
+ c.setFont("Helvetica-Bold", 16)
26
+ c.drawString(50, height-50, "PROFORMA INVOICE")
27
+
28
+ # Consignor Details
29
+ c.setFont("Helvetica", 10)
30
+ c.drawString(50, height-80, "Consignor:")
31
+ c.drawString(120, height-80, "True Vybes")
32
+ c.drawString(50, height-95, "D-1/902, Nilkanth Greens Maple CHS,")
33
+ c.drawString(50, height-110, "GB Road, Manpada,")
34
+ c.drawString(50, height-125, "Thane - 400607")
35
+ c.drawString(50, height-140, f"GSTIN: 27BV0PS7767J2ZF")
36
+
37
+ # Consignee Details
38
+ c.drawString(50, height-170, "Consignee:")
39
+ c.drawString(120, height-170, customer_name)
40
+ c.drawString(50, height-185, address)
41
+ c.drawString(50, height-200, f"GSTIN: {gstin}")
42
+ c.drawString(50, height-215, f"Date: {today}")
43
+
44
+ # Table Header
45
+ c.line(50, height-240, width-50, height-240)
46
+ c.drawString(50, height-250, "Sl.")
47
+ c.drawString(80, height-250, "Description")
48
+ c.drawString(220, height-250, "Code")
49
+ c.drawString(300, height-250, "Qty")
50
+ c.drawString(350, height-250, "Rate/unit")
51
+ c.drawString(430, height-250, "Value")
52
+ c.line(50, height-255, width-50, height-255)
53
+
54
+ # Product Row
55
+ c.drawString(50, height-275, "1")
56
+ c.drawString(80, height-275, product_description)
57
+ c.drawString(220, height-275, product_code)
58
+ c.drawString(300, height-275, str(quantity))
59
+ c.drawString(350, height-275, f"{price_per_unit:.2f}")
60
+ c.drawString(430, height-275, f"{subtotal:.2f}")
61
+
62
+ # Totals
63
+ c.line(300, height-300, width-50, height-300)
64
+ c.drawString(350, height-310, "Total")
65
+ c.drawString(430, height-310, f"{subtotal:.2f}")
66
+
67
+ c.drawString(350, height-330, f"GST @ {gst_percentage}%")
68
+ c.drawString(430, height-330, f"{gst_amount:.2f}")
69
+
70
+ c.line(300, height-340, width-50, height-340)
71
+ c.setFont("Helvetica-Bold", 10)
72
+ c.drawString(350, height-355, "GRAND TOTAL")
73
+ c.drawString(430, height-355, f"{grand_total:.2f}")
74
+ c.setFont("Helvetica", 10)
75
+
76
+ # Bank Details
77
+ c.drawString(50, height-400, "Bank Details For True Vybes")
78
+ c.drawString(50, height-415, "A/C Name: True Vybes")
79
+ c.drawString(50, height-430, "A/C No.: 9747864920")
80
+ c.drawString(50, height-445, "A/C Type: Current")
81
+ c.drawString(50, height-460, "IFSC Code: KKBK0000656")
82
+
83
+ # Terms and Conditions
84
+ c.drawString(50, height-490, "Other terms and conditions:")
85
+ c.drawString(50, height-505, "GST: Extra at actuals")
86
+ c.drawString(50, height-520, "Payment terms: 100% advance against order")
87
+ c.drawString(50, height-535, "Lead Time: 1 to 2 days from the date of confirmed order and receipt of payment")
88
+ c.drawString(50, height-550, "Validity: The validity of this price is 10 days from today")
89
+ c.drawString(50, height-565, "Freight: Extra on To-Pay basis")
90
+
91
+ # Signature
92
+ c.line(width-150, height-600, width-50, height-600)
93
+ c.drawString(width-140, height-615, "Authorised Signatory")
94
+
95
  c.showPage()
96
  c.save()
97
  buffer.seek(0)
98
  return buffer
99
 
100
+ def generate_pi(customer_name, address, gstin, product_code, product_description, quantity, price_per_unit):
101
+ pdf_buffer = create_pi_pdf(customer_name, address, gstin, product_code,
102
+ product_description, quantity, price_per_unit)
103
 
104
  # Create a temporary file
105
  temp_file = "Proforma_Invoice.pdf"
 
109
  return temp_file
110
 
111
  with gr.Blocks() as demo:
112
+ gr.Markdown("# 📄 Proforma Invoice Generator (True Vybes Template)")
113
+
114
+ with gr.Row():
115
+ customer_name = gr.Textbox(label="Customer Name")
116
+ gstin = gr.Textbox(label="GSTIN")
117
+
118
+ address = gr.Textbox(label="Customer Address")
119
+
120
+ with gr.Row():
121
+ product_code = gr.Textbox(label="Product Code", value="TV-CG-102")
122
+ product_description = gr.Textbox(label="Product Description", value="Candle")
123
+
124
+ with gr.Row():
125
+ quantity = gr.Number(label="Quantity", value=500)
126
+ price_per_unit = gr.Number(label="Price per Unit", value=100.00)
127
+
128
+ generate_button = gr.Button("Generate Proforma Invoice")
129
+ invoice_file = gr.File(label="Download your Proforma Invoice")
130
 
131
  generate_button.click(
132
  fn=generate_pi,
133
+ inputs=[customer_name, address, gstin, product_code, product_description, quantity, price_per_unit],
134
  outputs=invoice_file
135
  )
136