-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculateSalary.py
250 lines (196 loc) · 9.47 KB
/
CalculateSalary.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
from PySide.QtGui import QWidget, QApplication, QPushButton, QLabel,\
QLineEdit, QComboBox, QHBoxLayout, QFormLayout, QVBoxLayout, QMessageBox, QFrame, QFileDialog, QSpinBox, QGroupBox
from datetime import datetime
from CustomClasses import Designation, Salary
from DatabaseManager import Database
from CustomWidgets import SearchBox, ValueBox
from ShowMySqlError import ShowMysqlError
class CalculateSalaryWidget(QWidget):
"""A PySide widget which provides GUI for selecting employee and calculating salary for a month & year
Tis contains boxes for month and year input. Enter the month and year of salary to be calculated here. This is
initially automatically set to present month and year.
Also contains a ``SearchBox`` for selecting name of employee who's salary needs to be calculated. Selecting the name
automatically loads IDs of all employees with that name (in case multiple employees have exact same name) in
a dropdown box (``QComboBox``). After selecting the required ID from there, the employee info
is automatically loaded.
The allowances and deductions are loaded in ``ValueBoxes`` and hence may be edited if required.
After selecting everything, user needs to click 'calculate' button. This creates a ``Salary`` object from
available info. The actual salary calculation takes place inside ``Salary`` class. This salary object is then
passed to ``ShowPaySlipWidget`` which shows the final result and has option to confirm the calculation and print
the payslip.
Note:
To automatically call functions on GUI interaction such as button click, PySide Signal and Slots are used.
visit http://zetcode.com/gui/pysidetutorial/eventsandsignals/ for more on PySide Signal and Slots.
See Also:
- :py:mod:`SearchBox <CustomWidgets.searchBox.SearchBox>` widget from CustomWidgets
- :py:mod:`ValueBox <CustomWidgets.valueBox.ValueBox>` widget from CustomWidgets
- :py:mod:`Salary <CustomClasses.Salary.Salary>` class from CustomClasses
- :py:mod:`ShowPaySlipWidget <ShowPaySlip.ShowPaySlipWidget>`
"""
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.__parent = parent
self.title = "Calculate Salary"
self.__desig = None
self.__emp = None
t = datetime.now()
self.month = QComboBox()
self.month.addItems(["JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE",
"JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"])
self.month.setCurrentIndex(t.month - 1)
self.year = QSpinBox()
self.year.setRange(1900, 3000)
self.year.setValue(t.year)
self.name = SearchBox(self)
self.name.setPlaceholderText("Enter Name")
self.nameList = []
self.nameList = Database.getdb().getEmployeeNameList()
self.name.setList(self.nameList)
self.id = QComboBox()
self.designation = QLineEdit()
self.designation.setReadOnly(True)
self.originalPay = QLineEdit()
self.originalPay.setReadOnly(True)
self.gradePay = QLineEdit()
self.gradePay.setReadOnly(True)
self.DOJ = QLineEdit()
self.DOJ.setReadOnly(True)
self.pan = QLineEdit()
self.pan.setReadOnly(True)
self.presentPay = QLineEdit()
self.presentPay.setReadOnly(True)
self.da_percent = ValueBox()
self.hra_percent = ValueBox()
self.ta_percent = ValueBox()
self.it_percent = ValueBox()
self.pt_percent = ValueBox()
self.name.editTextChanged.connect(self.clearInfo)
self.bttnCalculate = QPushButton("Calculate")
self.bttnCalculate.clicked.connect(self.calculate)
self.bttnCancel = QPushButton("Back")
self.bttnCancel.clicked.connect(self.goBack)
self.bttnCalculate.setObjectName("OkButton")
self.bttnCancel.setObjectName("CancelButton")
self.name.returnPressed.connect(self.setIDList)
self.id.currentIndexChanged.connect(lambda: self.loadInfo(self.id.currentText()))
self.setupUI()
def calculate(self):
"""Automatically called on clicking calculate button"""
if self.__emp is None:
QMessageBox(QMessageBox.Information, "Error", "Please select an employee!", parent=self).exec_()
else:
if self.__parent is not None:
self.__desig = Designation(self.__desig.designation,
self.da_percent.text(),
self.hra_percent.text(),
self.ta_percent.text(),
self.it_percent.text(),
self.pt_percent.text())
salary = Salary(self.__emp, self.__desig, self.month.currentText(), self.year.text())
self.__parent.gotoPage("Result", salary)
def clearInfo(self):
"""Clears the contents of all input/display boxes"""
self.id.setCurrentIndex(-1)
self.designation.clear()
self.originalPay.clear()
self.gradePay.clear()
self.DOJ.clear()
self.pan.clear()
self.da_percent.clear()
self.hra_percent.clear()
self.ta_percent.clear()
self.it_percent.clear()
self.pt_percent.clear()
self.__desig = None
self.__emp = None
def loadInfo(self, id):
"""Loads info for given ID in the GUI boxes. This automatically called on selecting an ID from GUI
Args:
id (str): ID of employee who's info needs to be loaded
"""
print "id =", id, "...", len(id)
if id != '':
self.__emp = Database.getdb().getEmployeeInfo(id)
self.designation.setText(self.__emp.designation)
self.originalPay.setText(str(self.__emp.originalPay))
self.gradePay.setText(str(self.__emp.gradePay))
self.DOJ.setText(self.__emp.getStrDate())
self.pan.setText(self.__emp.pan)
self.__desig = Database.getdb().getDesignationInfo(self.__emp.designation)
self.da_percent.setText(str(self.__desig.da))
self.hra_percent.setText(str(self.__desig.hra))
self.ta_percent.setText(str(self.__desig.ta))
self.it_percent.setText(str(self.__desig.it))
self.pt_percent.setText(str(self.__desig.pt))
def setIDList(self, name):
"""Loads IDs of all employees with given name into the ID dropdown box
This function is automatically called after selecting a name from the GUI
Args:
name (str): Name of employee
"""
self.id.clear()
self.id.addItems(Database.getdb().getIdListForName(name))
def goBack(self):
if self.__parent is not None:
self.__parent.goBack()
def setupUI(self):
"""Arranges GUI elements inside the widget properly"""
paneLayout = QHBoxLayout()
paneLayout.setContentsMargins(0, 0, 0, 0)
leftPane = QFrame()
leftPane.setObjectName("leftPane")
leftPaneLayout = QVBoxLayout()
leftPaneLayout.setContentsMargins(20, 20, 20, 10)
heading = QLabel("Select Employee: ")
heading.setObjectName("heading")
leftPaneLayout.addWidget(heading)
leftPaneLayout.addSpacing(10)
datelayout = QHBoxLayout()
datelayout.addWidget(QLabel("Salary for month of "))
datelayout.addWidget(self.month)
datelayout.addWidget(self.year)
datelayout.addStretch()
leftPaneLayout.addLayout(datelayout)
leftForm = QFormLayout()
leftForm.setSpacing(10)
leftForm.addRow(QLabel("Name"), self.name)
leftForm.addRow(QLabel("ID No."), self.id)
leftPaneLayout.addLayout(leftForm)
leftPaneLayout.addStretch()
leftPane.setLayout(leftPaneLayout)
paneLayout.addWidget(leftPane)
layout = QVBoxLayout()
layout.setContentsMargins(20, 20, 20, 10)
form = QFormLayout()
form.setSpacing(10)
form.addRow(QLabel("Designation"), self.designation)
form.addRow(QLabel("Original Pay"), self.originalPay)
form.addRow(QLabel("Original Pay Grade"), self.gradePay)
form.addRow(QLabel("Date of joining"), self.DOJ)
form.addRow(QLabel("Pan No."), self.pan)
infoGroup = QGroupBox("Basic Info")
infoGroup.setLayout(form)
layout.addWidget(infoGroup)
leftForm = QFormLayout()
leftForm.addRow(QLabel("Dearness Allowance (%)"), self.da_percent)
leftForm.addRow(QLabel("Housing Rent Allowance (%)"),self.hra_percent)
leftForm.addRow(QLabel("Transport Allowance (%)"), self.ta_percent)
leftGroup = QGroupBox("Allowances")
leftGroup.setLayout(leftForm)
rightForm = QFormLayout()
rightForm.addRow(QLabel("Income Tax (%)"), self.it_percent)
rightForm.addRow(QLabel("Profession Tax (%)"), self.pt_percent)
rightGroup = QGroupBox("Deductions")
rightGroup.setLayout(rightForm)
table = QHBoxLayout()
table.addWidget(leftGroup)
table.addWidget(rightGroup)
layout.addLayout(table)
layout.addStretch()
bttnLayout = QHBoxLayout()
bttnLayout.addStretch()
bttnLayout.addWidget(self.bttnCancel)
bttnLayout.addWidget(self.bttnCalculate)
layout.addLayout(bttnLayout)
paneLayout.addLayout(layout)
self.setLayout(paneLayout)