-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpayslip.py
54 lines (40 loc) · 1.78 KB
/
payslip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import openpyxl
import random
class Employee:
def __init__(self, first_name, last_name, job_title, salary):
self.first_name = first_name
self.last_name = last_name
self.job_title = job_title
self.salary = salary
def generate_payslip(self):
payslip = f"First Name: {self.first_name}\nLast Name: {self.last_name}\nJob Title: {self.job_title}\nSalary: {self.salary}"
return payslip
class Company:
def __init__(self, first_name, last_name, name):
self.name = name
self.employees = []
def add_employee(self, employee):
self.employees.append(employee)
def generate_payroll(self, filename):
wb = openpyxl.Workbook()
sheet = wb.active
sheet.title = "Payroll"
sheet.append(["نام", "نام خانوادگی", "شغل", "حقوق($)"])
for employee in self.employees:
sheet.append([
employee.first_name,
employee.last_name,
employee.job_title,
employee.salary,
])
wb.save(filename)
print("لیست کارمندان با دیتای مورد نظر ساخته شد.")
company = Company("University", "Limited", "UniversityLimited")
num_employees = int(input("تعداد کارمندان را وارد کنید: "))
for i in range(num_employees):
first_name = input("نام کارمند را وارد کنید: ")
last_name = input("نام خانوادگی کارمند را وارد کنید: ")
job_title = input("شغل کارمند را وارد کنید: ")
salary = random.randint(3000, 8000)
company.add_employee(Employee(first_name, last_name, job_title, salary))
company.generate_payroll("data.xlsx")