Skip to content

weston273/Payslip_generator

Repository files navigation

Payslip Generator

📄 Payslip Generation & Email Automation

This Python project automates the payroll process by:

Reading employee data from an Excel file (employees.xlsx)

Generating PDF payslips for each employee

Sending the payslips to employees via email

All sensitive credentials are securely stored in a .env file.

🧰 Technologies Used

pandas — For reading Excel data

reportlab — For generating PDF documents

smtplib & email.mime — For composing and sending emails

python-dotenv — For loading environment variables from .env

📦 Required Files

employees.xlsx — Contains employee data (ID, Name, Email, Salary, Allowances, Deductions)

.env — Stores sensitive email credentials

generate_payslip.py — Logic to generate payslips

send_email.py — Main script to process employees and send payslips

📄 How the Scripts Work

🧾 generate_payslip.py

This file defines the function create_payslip() which:

Accepts employee_Id, name, salary, allowances, and deductions

Calculates Net Pay: Net Pay = Salary + Allowances - Deductions

Uses reportlab to create a clean and professional payslip

Saves it as payslip_<Employee_Name>.pdf

📬 send_email.py

This is the main script that ties everything together.

  1. Load Environment Variables

from dotenv import load_dotenv load_dotenv()

Retrieves EMAIL and EMAIL_PASSWORD from .env

  1. Read Excel File

df = pd.read_excel("employees.xlsx")

Reads employee details into a DataFrame

  1. Generate Payslips

for index, row in df.iterrows(): create_payslip(...)

  1. Iterates through each row to generate a PDF payslip

Send Emails

def send_email(to_email, subject, body, attachment_path):

Composes an email with the payslip attached

Sends it using Gmail SMTP with TLS encryption

🧪 Example .env File

EMAIL=[email protected] EMAIL_PASSWORD=your_app_specific_password

⚠️ Never push this file to GitHub. Always add .env to your .gitignore.

🚀 Step-by-Step Instructions

  1. Set Up Project

git clone cd payslip python -m venv my_venv source my_venv/bin/activate # or my_venv\Scripts\activate on Windows pip install -r requirements.txt

  1. Create .env file

EMAIL=[email protected] EMAIL_PASSWORD=your_app_specific_password

  1. Prepare employees.xlsx Ensure this file has columns:

Employee ID | Name | Email | Basic Salary | Allowances | Deductions

  1. Run the Script

python send_email.py

✅ Sample Output

✅ Saved: payslip_Tinotenda_Hove.pdf ✅ Email sent successfully to [email protected]

  1. ⚠️ Error Handling

If Excel file is missing, a clear error is shown and script exits

If payslip cannot be generated, that employee is skipped

If file attachment fails, email is not sent

If credentials are wrong or missing, script fails securely

Automate payroll efficiently, securely, and with style! 💼📧

Nyanzvi_zw

Payslip_generator

Payslip_generator

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages