This is a Python script that automates the process of generating and emailing monthly payslips to employees. It reads data from an Excel file, calculates net salaries, generates PDF payslips, and sends them via email.
- Reads employee data from an Excel file using
pandas - Calculates net salary:
Net Salary = Basic Salary + Allowances - Deductions
- Generates a professional PDF payslip using
fpdf - Emails the payslip to each employee using
smtplib - Uses
.envfor secure email credentials
- Python 3.x
- Required libraries:
- pandas
- fpdf
- openpyxl
- python-dotenv
Install them using:
pip install pandas fpdf openpyxl python-dotenv ๐ Files and Folders . โโโ payslip_generator.py # Main script โโโ employees.xlsx # Input Excel file with employee details โโโ payslips/ # Folder where PDF payslips will be saved โโโ .env # Hidden file for email credentials โโโ README.md # This file
๐ Environment Variables
Create a .env file in the root directory with the following content:
SMTP_SERVER=smtp.yourmail.com
SMTP_PORT=587
EMAIL_USER=[email protected]
EMAIL_PASS=your_email_password_or_app_password
๐งโ๐ผ Excel File Format
The employees.xlsx file should include the following columns:
Employee ID Name Email Basic Salary Allowances Deductions 001 Jane Doe [email protected] 1000 200 100 002 John Smith [email protected] 1200 300 150
Open your terminal in the project folder.
Run the script:
python payslip_generator.py ๐ง Email Details Subject: Your Payslip for This Month
Body:
Dear [Employee Name],
Please find attached your payslip for this month.
Best regards,
Uncommon.org
Attachment: The employeeโs PDF payslip
โ Output
Payslips will be saved in the payslips/ folder.
Each file is named by Employee ID (e.g., 001.pdf).
The PDF includes employee info, salary breakdown, and a professional layout.
๐งโ๐ป Author
Created by Kudzaishe Chikowore For the Python Programming Assignment: Payslip Generator