Initialization
```python
invoice = InvoiceGenerator()
# From dictionary
invoice = InvoiceGenerator.from_dict(data)
# From CSV (batch)
invoices = InvoiceGenerator.from_csv("invoices.csv")
```
Company Information
```python
# Basic company info
invoice.set_company(
name="Acme Corporation",
address="123 Business Street\nCity, State 12345"
)
# Full company details
invoice.set_company(
name="Acme Corporation",
address="123 Business Street\nCity, State 12345",
email="billing@acme.com",
phone="+1 (555) 123-4567",
website="www.acme.com",
tax_id="12-3456789"
)
# Add logo
invoice.set_logo("logo.png")
invoice.set_logo("logo.png", width=150) # Specify width in pixels
```
Client Information
```python
# Basic client info
invoice.set_client(
name="John Smith",
address="456 Client Avenue\nTown, State 67890"
)
# Full client details
invoice.set_client(
name="John Smith",
company="Smith Enterprises",
address="456 Client Avenue\nTown, State 67890",
email="john@smithent.com"
)
```
Invoice Details
```python
# Invoice number and dates
invoice.set_invoice_number("INV-2024-001")
invoice.set_date("2024-01-15") # Invoice date
invoice.set_due_date("2024-02-14") # Due date
# Or use days from invoice date
invoice.set_due_days(30) # Due in 30 days
# Currency
invoice.set_currency("USD") # $
invoice.set_currency("EUR") # β¬
invoice.set_currency("GBP") # Β£
invoice.set_currency("$", symbol_only=True) # Custom symbol
```
Line Items
```python
# Add items
invoice.add_item(
description="Consulting Services",
quantity=8,
rate=150.00
)
# With unit
invoice.add_item("Development", 40, 125.00, unit="hours")
# With item-level discount
invoice.add_item("Product", 10, 50.00, discount=10) # 10% discount
# From list
items = [
{"description": "Item 1", "quantity": 2, "rate": 100},
{"description": "Item 2", "quantity": 1, "rate": 250}
]
invoice.add_items(items)
```
Taxes and Discounts
```python
# Add tax
invoice.add_tax("Sales Tax", 8.25) # 8.25%
invoice.add_tax("State Tax", 5.0)
# Compound tax (applied after other taxes)
invoice.add_tax("GST", 10.0, compound=True)
# Discount on subtotal
invoice.set_discount(10) # 10% off
invoice.set_discount(50, is_percentage=False) # $50 off
```
Payment Information
```python
# Payment terms
invoice.set_payment_terms("Net 30")
# Payment instructions
invoice.set_payment_instructions("""
Payment Methods:
- Bank Transfer: Account #12345, Routing #67890
- PayPal: payments@acme.com
- Check payable to: Acme Corporation
""")
# Bank details
invoice.set_bank_details(
bank_name="First National Bank",
account_name="Acme Corporation",
account_number="1234567890",
routing_number="987654321",
swift_code="FNBKUS12"
)
```
Notes and Terms
```python
# Notes (appears on invoice)
invoice.set_notes("Thank you for your business!")
# Terms and conditions
invoice.set_terms("""
- Payment due within 30 days
- Late payments subject to 1.5% monthly interest
- All sales are final
""")
```
Styling
```python
# Color theme
invoice.set_colors(
primary="#2563eb", # Headers, accent
secondary="#64748b", # Secondary text
background="#f8fafc" # Background
)
# Template style
invoice.set_template("modern") # Default
invoice.set_template("classic") # Traditional look
invoice.set_template("minimal") # Clean, minimal
# Font
invoice.set_font("Helvetica") # Default
invoice.set_font("Times")
```
Generation and Export
```python
# Generate invoice
invoice.generate()
# Save to PDF
invoice.save("invoice.pdf")
# Save with custom filename pattern
invoice.save_as("INV-{number}-{client}.pdf")
# Get PDF bytes (for email attachment, etc.)
pdf_bytes = invoice.to_bytes()
```