0% found this document useful (0 votes)
322 views49 pages

Payroll Calculator & Database Code

This Python program is a payroll management system that allows users to: 1. Add employee details like name, designation, salary etc to a database table 2. Set DA and HRA rates in a separate database table 3. Enter monthly salary details like days worked, allowances for each employee 4. Calculate salary components like basic pay, HRA, PF etc and save to a CSV file The program provides an interactive menu to choose these payroll processing options.

Uploaded by

1106006 HOS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
322 views49 pages

Payroll Calculator & Database Code

This Python program is a payroll management system that allows users to: 1. Add employee details like name, designation, salary etc to a database table 2. Set DA and HRA rates in a separate database table 3. Enter monthly salary details like days worked, allowances for each employee 4. Calculate salary components like basic pay, HRA, PF etc and save to a CSV file The program provides an interactive menu to choose these payroll processing options.

Uploaded by

1106006 HOS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 49

SOURCE CODE

user = str
end = "0"
hours = round(40,2)
print("One Stop Shop Payroll
Calculator")
while user != end:
print()

user = input("Please enter your name or type '0' to


quit: ") if user == end:

print("End of Report")
else:
hours = (float(input("Please enter hours worked:
", )))

payrate =(float(input("Please enter your payrate:


$", ))) if hours < 40:
print("Employee's name: ", user)
print("Overtime hours: 0")
print("Overtime Pay: $0.00")
regularpay = round(hours * payrate,

2)
print("Gross Pay: $", regularpay)
elif hours > 40:
overtimehours = round(hours - 40.00,2)

print("Overtime hours: ",


overtimehours)

print("Employee's name: ", user) regularpay =


round(hours *
payrate,2)
overtimerate = round(payrate * 1.5,
2)

overtimepay = round(overtimehours *
overtimerate)

grosspay =
round(regularpay+overtimepay,2)
print("Regular Pay: $", regularpay)

print("Overtime Pay:
$",overtimepay)
print("Gross Pay: $", grosspay)

Output :--

One Stop Shop Payroll Calculator

Please enter your name or type '0' to quit: Brandon

Please enter hours worked: 50


Please enter your payrate: $10
Overtime hours: 10.0
Employee's name: Brandon
Regular Pay: $ 500.0
Overtime Pay: $ 150
Gross Pay: $ 650.0
Please enter your name or type '0' to quit: Brandon

Please enter hours worked: 30


Please enter your payrate: $10
Employee's name: Brandon
Overtime hours: 0
Overtime Pay: $0.00

Gross Pay: $ 300.0

Please enter your name or type '0' to quit: 0

End of Report
Employee's name: 0
Overtime hours: 0
Overtime Pay: $0.00

Gross Pay: $ 300.


Payroll source code

1. Def main():
2. hours = float(input('How many hours did you
work: '))
3. while hours < 8 or hours > 86:
4. print ("Error- Hours must be at least 8 and less
than 86")
5. hours = float(input('re-enter hours worked: '))

6. rate= float(input('What is your hourly rate? '))


7. while rate < 7 or rate > 50:
9. print ("Error- Pay rate must be at least $7.00 and
less than $50.00")
10. rate = float(input('re-enter your hourly rate: '))
11.
12. if hours <= 40:
13. print (" Payroll Information")
14. print ("Pay rate
$",format(rate,'7.2f'))
15. print ("Regular Hours ", format
(hours, '2.0f'))
16. print ("Overtime Hours 0")
17. print ("Regular pay $", format
(hours*rate, '7.2f'))
18. print ("Overtime pay $ 0.00")
19. print ("Total pay: $", format
(hours*rate, '7.2f'))
20. else:
21. Other course = hours - 40
22.
23.
24. Other pay = other course * (rate * 1.5)
25. Regular pay = 40 * rate
26.
27. print (" Payroll Information")
28. print ("Pay rate $", format
(rate,'7.2f'))
29. print ("Regular Hours ", format
(hours, '2.0f'))
30. print ("Overtime Hours ", format
(other course, '2.0f'))
31. print ("Regular pay $", format
(hours*rate, '7.2f'))
32. print ("Overtime pay $", format
(other pay, '7.2f'))
33. print ("Total pay: $", format
(regularpay+otpay,'7.2f'))
34.
35. main()
Output

1.How many hours did you work: 50

2. What is your hourly rate? 8


3.
4. Payroll Information
5.
6.
7.Pay rate $ 8.00
8.Regular Hours 50
9.Overtime Hours 10
10. Regular pay $ 400.00
11. Overtime pay $ 120.00
12. Total pay: $ 440.00
TIME TABLE GENERATOR

SQL Commands:

create database payroll;

USE PAYROLL;

CREATE TABLE EMP(ECODE INT(6) PRIMARY KEY, FNAME VARCHAR(20) NOT NULL, LNAME VARCHAR(20)
NOT NULL,

DESIG CHAR(15) NOT NULL, LEVEL INT(2)NOT NULL, GENDER CHAR DEFAULT 'M', DOB DATE, DOJ DATE, MOB

VARCHAR(11), PAN CHAR(10), ACNO VARCHAR(15), IFSC CHAR(11),BASIC INT(6), TA INT(4),


HRAYN CHAR,NPSYN CHAR);
CREATE TABLE PAY(YEAR INT(4), MONTH INT(2), ECODE INT(6), NODAYS INT(2) NOT NULL, DA INT(6),

DATA INT(5), HRA INT(5), NPS_M INT(5), OTHER_ALLW INT(5), GROSS INT(6), ITAX INT(6), NPS_O INT(5),

GPF INT(5) DEFAULT 0, LCFEE INT(5), ODEDUCT INT(5), TOT_DEDUC INT(7), NETSAL INT(7), PRIMARY

KEY(YEAR, MONTH, ECODE), FOREIGN KEY (ECODE) REFERENCES EMP(ECODE));

CREATE TABLE SETTER(DAP INT(3), HRAP INT(2)); INSERT INTO SETTER VALUES (9, 8);
Python Code:

from sqlalchemy import create_engine

import pandas as pd

import datetime

import subprocess
cnx =

create_engine('mysql+pymysql://root:123@localhost:3306/payroll').connec t()

def emp_entry():
ec = eval(input("Enter employee code : "))

fn = input("Enter First Name of Employee: ")

ln = input("Enter Last Name of Employee: ")

dg = input("Enter Designation : ")

ge=input("Enter Gender : ")


db = input("Enter Date of Birth : ")

dj = input("Enter Date of Joining : ")

mb =input("Enter Mobile Number : ")

pn =input("Enter PAN Number : ")


ac= input("Enter Bank Account Number: ")
fc = input("Enter IFSC code of Bank Account : ")

sl = eval(input("Enter Pay Level : "))

bs=eval(input("Enter Basic Salary: "))

ta=eval(input("Enter Transport Allowance : "))

hr=input("Enter employee is Eligible for HRA Y/N : ")


np=input("Enter employee is Eligible for NPS Y/N : ")

data = [[ec, fn, ln, dg, sl, ge, db, dj, mb, pn, ac, fc,bs,ta,hr,np]]

df = pd.DataFrame(data,columns=['ecode','fname', 'lname', 'desig', 'level',


'gender','dob','doj','mob','pan','acno','ifsc','basic','ta','hrayn','np syn'])

df.to_sql(name = 'emp', con = cnx, if_exists = 'append', index = False)

def per_setter() :
dap=eval(input("Enter DA Percentage : "))

hrp=eval(input("Enter HRA Percentage: "))

data = [[dap,hrp]]

df = pd.DataFrame(data,columns=['dap','hrap'])
df.to_sql(name = 'setter', con = cnx, if_exists = 'replace', index = False)
def salary_entry():

while True:

try:

y = eval(input("Enter the salary year (press enter for current year otherwise input new year:

str(datetime.datetime.today().strftime('%Y'))))
except:

y = str(datetime.datetime.today().strftime('%Y'))

break
while True:

try:

m = eval(input("Enter the salary month (press enter for current month otherwise input new mon

+ str(datetime.datetime.today().strftime('%m')))) except: m =

str(datetime.datetime.today().strftime('%m'))
break

sql="select * from emp "

df=pd.read_sql(sql,cnx)
print("enter salary details for the " + str(m) + "/" + str(y))
lec=[]

llevel=[]

lec = df["ECODE"]

l1=[]

ly = []
lm = []

allw = []

deduc = []

lfee = []
it = []

for x in df["ECODE"]:

print("Employee Code : " + str(x) + "\n")

l1.append(eval(input("Enter No of days worked : ")))

allw.append(eval(input("Enter other allowance (or 0): ")))


deduc.append(eval(input("Enter other deductions (or 0): ")))

it.append(eval(input("Enter income tax to be deducted (or 0): ")))

lfee.append(eval(input("Enter other License fee (or 0): ")))

ly.append(y)
lm.append(m)

sql="select * from pay"

df1=pd.read_sql(sql,cnx)

df1["YEAR"] = ly

df1["MONTH"] = lm
df1["ECODE"] = lec
df1["NODAYS"] = l1

df1 = pd.merge(df,df1,on='ECODE')

df1["BASIC"] = df1["BASIC"]/30 * df1["NODAYS"]


df1["DA"] = df1["BASIC"] * DP/100

df1["DATA"] = df1["TA"] * DP /100

df1["HRA"] = df1["TA"] * HP /100

df1["NPS_M"] = (df1["BASIC"] + df1["DA"] ) * 10 /100 df1["OTHER_ALLW"] =


allw

df1["GROSS"] = df1["BASIC"] + df1["DA"] + df1["DATA"] + df1["HRA"] +


df1["NPS_M"] + df1["OTHER_ALLW"]

df1["NPS_O"] = df1["NPS_M"]
df1["GPF"] = df1["BASIC"] * 6/100

df1["LCFEE"] = lfee
df1["ITAX"] = it

df1["ODEDUCT"] = deduc

df1["TOTAL_DEDUC"] = df1["ITAX"] + df1["NPS_M"] + df1["NPS_O"] + df1["GPF"] +


df1["ODEDUCT"] + df1["LCFEE"]

df1["NETSAL"] = df1["GROSS"] - df1["TOTAL_DEDUC"]


df1.to_csv('C:\Payroll\SALARY.csv', mode = 'w')
def Date_operations():

= datetime.datetime.today().strftime('%Y-%m-%d') print(x)

def Sdf_show():
df = pd.read_csv('c:\payroll\salary.csv')

print(df)

def Show_Rates():

sql = "select * from setter"


df = pd.read_sql(sql, cnx)

print(df)

def Show_EMP():
sql = "select * from EMP"

df = pd.read_sql(sql, cnx)

print(df)
def Salary_show():

subprocess.call('C:\Program Files\Microsoft Office\Office15\excel c:\payroll\salary.csv')


DP=0

HP=0

sql="select * from setter"

df=pd.read_sql(sql,cnx)
DP = df["dap"][0]

HP = df["hrap"][0]

while (True):

print("1 : Add EMPOYEE DETAILS")


print("2 : SHOW EMPOYEE DETAILS")

print("3 : FIX DA AND HRA RATES")


print("4 : SHOW CURRENT DA AND HRA RATES")

print("5 : PAYBILL ENTRY ")

print("6 : SHOW PAYBILL")

print("7 : SHOW PAYBILL (CSV FILE IN EXCEL)")

print("8 : Exit")
choice = int(input("Please Select An Above Option: "))

if(choice == 1):

emp_entry()

elif (choice==2):
Show_EMP()

elif (choice==3):

per_setter()

elif (choice==4):

Show_Rates()
elif (choice==5):

salary_entry()

elif (choice == 6):

Sdf_show()
elif (choice == 7):

Salary_show()

elif (choice == 8):

break

else:

print(" Wrong choice. ..... )

You might also like