Employee and applicant frontend and backend

This commit is contained in:
2025-02-13 09:11:26 +01:00
parent bfd1d0974d
commit 80bd2c9be2
8 changed files with 165 additions and 25 deletions

View File

@@ -103,18 +103,21 @@ ColumnLayout
var new_applicant var new_applicant
if (radio.children[0].checked) if (radio.children[0].checked)
{ {
// Ein Bewerber
new_applicant = JsLib.parseForm(personalData) new_applicant = JsLib.parseForm(personalData)
// business_model.addApplicant(new_business, 0) employee_model.addEmployee(new_applicant, false)
// appLoader.source = "EmployeeTable.qml" // appLoader.source = "EmployeeTable.qml"
console.log(JSON.stringify (new_applicant)) // console.log(JSON.stringify (new_applicant))
} }
else else
{ {
// Ein Mitarbeiter
// console.log(personalData, bankAccount, nationalInsurance, applicantVarious) // console.log(personalData, bankAccount, nationalInsurance, applicantVarious)
new_applicant = JsLib.parseForm(personalData, bankAccount, nationalInsurance, applicantVarious) new_applicant = JsLib.parseForm(personalData, bankAccount, nationalInsurance, applicantVarious)
employee_model.addEmployee(new_applicant, true)
// var new_contact = JsLib.addApplicant(addContactLayout) // var new_contact = JsLib.addApplicant(addContactLayout)
// contact_model.addContact(new_contact) // contact_model.addContact(new_contact)
console.log(JSON.stringify (new_applicant)) // console.log(JSON.stringify (new_applicant))
} }
} }
} }

View File

@@ -71,40 +71,56 @@ Item
{ {
id: horizontalHeader id: horizontalHeader
Layout.fillWidth: true Layout.fillWidth: true
syncView: testTable syncView: appliEmpTable
implicitHeight: 40
visible: false
movableColumns: true //@disable-check M16
} }
TableView TableView
{ {
id: testTable id: appliEmpTable
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
columnSpacing: 1 columnSpacing: 1
rowSpacing: 2 rowSpacing: 2
model: business_model model: employee_model
selectionBehavior: TableView.SelectRows selectionBehavior: TableView.SelectRows
ScrollBar.vertical: ScrollBar
{
policy: appliEmpTable.contentHeight > appliEmpTable.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff
}
selectionModel: ItemSelectionModel selectionModel: ItemSelectionModel
{
id: selModel
{ model: appliEmpTable.model
id: selModel }
model: testTable.model
}
delegate:Rectangle delegate:Rectangle
{ {
required property bool selected required property bool selected
required property bool current required property bool current
implicitWidth: 200 //implicitWidth: 200
implicitHeight: 25 implicitHeight: 25
color: selected? "lightblue": palette.base color: selected
? palette.highlight //palette.highlight
: (objectTable.alternatingRows && row % 2 !== 0
? palette.base // palette.base
: palette.alternateBase) //palette.alternateBase)
Text Text
{ {
Layout.fillWidth: true text: model.display === null? "": model.display
text: model.display? model.display: "" elide: Text.ElideRight
width: parent.width
height: parent.height
verticalAlignment: Text.AlignVCenter
leftPadding: 9 //@d isable-check M16
color: palette.text
} }
@@ -116,16 +132,24 @@ Item
anchors.fill: parent anchors.fill: parent
hoverEnabled: true hoverEnabled: true
onDoubleClicked: onDoubleClicked:
{ {
employeesStack.push("EmployeeDetails.qml", {selectedEmployee: row}); employeesStack.push("EmployeeDetails.qml", {selectedEmployee: row});
} }
onEntered:
{
appliEmpTable.selectionModel.select(appliEmpTable.model.index(row, 0), ItemSelectionModel.SelectCurrent | ItemSelectionModel.Rows)
}
} }
} }
} }
Item
{
Layout.fillWidth: true
}
} }
Component.onCompleted: employeesStack.pop() Component.onCompleted: employeesStack.pop()

View File

@@ -8,6 +8,7 @@ class BusinessDAO(QObject):
newBusinessAdded = Signal() newBusinessAdded = Signal()
__cur = None __cur = None
__all_cols = None
def __init__(self): def __init__(self):
#print(f"*** File: {__file__}, init()") #print(f"*** File: {__file__}, init()")

View File

@@ -63,6 +63,7 @@ from ..ConfigLoader import ConfigLoader
class BusinessModel(QAbstractTableModel): class BusinessModel(QAbstractTableModel):
__visible_index = {} __visible_index = {}
__visible_columns = None
__col_name = "" __col_name = ""
__business_dao = None __business_dao = None
__business = None __business = None

View File

@@ -1,6 +1,56 @@
# This Python file uses the following encoding: utf-8 from .DbManager import DbManager
import json
import mariadb
from PySide6.QtCore import QObject, Signal
from ..PyqcrmFlags import PyqcrmAppliEmpyFlags
class EmployeeDAO: class EmployeeDAO(QObject):
newEmployeeAdded = Signal()
__cur = None
__all_cols = None
def __init__(self): def __init__(self):
pass super().__init__()
self.__con = DbManager().getConnection()
if self.__con:
self.__cur = self.__con.cursor()
def getEmployees(self, enc_key, criterion = "Alle", appli_emp = 0, processed = False):
'''
appli_emp:
0 = applicants and employees
1 = applicants only
2 = employees only
'''
try:
if self.__cur:
self.__cur.callproc("getEmployeesView", (appli_emp, processed, criterion, enc_key, ))
self.__all_cols = [desc[0] for desc in self.__cur.description]
return self.__cur.fetchall(), self.__all_cols
else:
return None, None
except mariadb.Error as e:
print(str(e))
def getEmployee(self, employee_id, enc_key = None):
try:
if self.__cur:
self.__cur.callproc("getEmployee", (employee_id, enc_key,))
#self.__all_cols = [desc[0] for desc in self.__cur.description]
return self.__cur.fetchall() #, self.__all_cols
else:
return None #, None
except mariadb.Error as e:
print(str(e))
def addEmployee(self, data, enc_key, employee = False):
try:
if self.__cur:
self.__cur.callproc("addApplicant", (json.dumps(data), employee, enc_key,))
self.__con.commit()
self.newEmployeeAdded.emit()
except mariadb.Error as e:
print(str(e))

View File

@@ -1,6 +1,58 @@
# This Python file uses the following encoding: utf-8 from PySide6.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, Signal
from .EmployeeDAO import EmployeeDAO
from ..PyqcrmFlags import PyqcrmFlags, PyqcrmAppliEmpyFlags
from ..ConfigLoader import ConfigLoader
class EmployeeModel: class EmployeeModel(QAbstractTableModel):
__data = None
__employee_dao = None
__visible_index = None
__visible_columns = None
__col_name = ""
__employee_dao = None
def __init__(self): def __init__(self):
pass super().__init__()
self.__employee_dao = EmployeeDAO()
self.__employee_dao.newEmployeeAdded.connect(self.__refreshView)
self.__conf = ConfigLoader().getConfig()
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
self.__getData()
@Slot(dict, bool)
def addEmployee(self, new_employee, employee = False):
print(new_employee)
self.__employee_dao.addEmployee(new_employee, self.__key, employee)
@Slot(str)
def viewCriterion(self, criterion):
self.__getData(criterion)
@Slot()
def __refreshView(self):
self.__getData()
def __getData(self, criterion = "Alle", processed = False):
self.beginResetModel()
rows, self.__visible_columns = self.__employee_dao.getEmployees(self.__key, criterion, 0, processed)
self.__data = rows
self.endResetModel()
def rowCount(self, parent= QModelIndex()):
return len (self.__data)
def columnCount(self, parent= QModelIndex()):
return len(self.__visible_columns) - 2
def data(self, index, role= Qt.DisplayRole):
if role == Qt.DisplayRole:
row = self.__data[index.row()]
return row[index.column() + 2]
return None
def headerData(self, section, orientation, role= Qt.DisplayRole):
if orientation == Qt.Horizontal and role ==Qt.DisplayRole:
self.__col_name = self.__visible_columns[section + 2]
return self.__col_name
return super().headerData(section, orientation, role)

View File

@@ -5,4 +5,9 @@ class PyqcrmFlags(IntFlag):
ADMIN = 1 ADMIN = 1
USER = 2 USER = 2
class PyqcrmAppliEmpyFlags(IntFlag):
ALL = 0
APPLICANT = 1
EMPLOYEE = 2

View File

@@ -14,6 +14,7 @@ from lib.DB.UserManager import UserManager
from lib.DB.AddressModel import AddressModel from lib.DB.AddressModel import AddressModel
from lib.DB.BTypeModel import BTypeModel from lib.DB.BTypeModel import BTypeModel
from lib.DB.ContactModel import ContactModel from lib.DB.ContactModel import ContactModel
from lib.DB.EmployeeModel import EmployeeModel
from lib.Printers import Printers from lib.Printers import Printers
@@ -37,12 +38,13 @@ address_model = None
business_model = None business_model = None
business_type = None business_type = None
contact_model = None contact_model = None
employee_model = None
printers = None printers = None
user = None user = None
def initializeProgram(): def initializeProgram():
#print(f"In {__file__} file, initializeProgram()") #print(f"In {__file__} file, initializeProgram()")
global address_model, bad_config, business_model, user, business_type, contact_model, db_con, printers global address_model, bad_config, business_model, user, business_type, contact_model, employee_model, db_con, printers
if not bad_config: if not bad_config:
dbconf = config.getConfig()['database'] dbconf = config.getConfig()['database']
DbManager(dbconf) DbManager(dbconf)
@@ -54,17 +56,19 @@ def initializeProgram():
address_model = AddressModel() address_model = AddressModel()
business_type = BTypeModel() business_type = BTypeModel()
contact_model = ContactModel() contact_model = ContactModel()
employee_model = EmployeeModel()
publishContext() publishContext()
bad_config = False bad_config = False
def publishContext(): def publishContext():
# print(f"In {__file__} file, publishContext()") # print(f"In {__file__} file, publishContext()")
global engine, address_model, bad_config, business_model, user, business_type, contact_model, printers global engine, address_model, bad_config, business_model, user, business_type, contact_model, employee_model, printers
engine.rootContext().setContextProperty("loggedin_user", user) engine.rootContext().setContextProperty("loggedin_user", user)
engine.rootContext().setContextProperty("business_model", business_model) engine.rootContext().setContextProperty("business_model", business_model)
engine.rootContext().setContextProperty("address_model", address_model) engine.rootContext().setContextProperty("address_model", address_model)
engine.rootContext().setContextProperty("business_type", business_type) engine.rootContext().setContextProperty("business_type", business_type)
engine.rootContext().setContextProperty("contact_model", contact_model) engine.rootContext().setContextProperty("contact_model", contact_model)
engine.rootContext().setContextProperty("employee_model", employee_model)
if __name__ == "__main__": if __name__ == "__main__":