Somewhat fix errors when adding an applicant

This commit is contained in:
Yuri Becker
2025-04-16 11:00:06 +02:00
parent f0382a960e
commit cf5822c950
5 changed files with 38 additions and 62 deletions

View File

@@ -13,11 +13,12 @@ ColumnLayout {
saveBtn.enabled = true; saveBtn.enabled = true;
} }
function onAddNewEmployee(added) { function onAddNewEmployee(added) {
if (added) if (added) {
console.log('addedsuccesfully'); console.log('addedsuccesfully');
else
console.log('failedtoadd');
contentStack.pop(); contentStack.pop();
} else {
console.log('failedtoadd');
}
} }
Layout.fillHeight: true Layout.fillHeight: true
@@ -36,33 +37,25 @@ ColumnLayout {
font.pixelSize: 35 font.pixelSize: 35
text: qsTr("Mitarbeiter / Bewerber hinzufügen") text: qsTr("Mitarbeiter / Bewerber hinzufügen")
} }
ButtonGroup {
buttons: radio.children
onClicked: {
checkFields();
personalData.requiredField();
}
}
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
spacing: 50 spacing: Dimensions.l
Frame { Frame {
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
Layout.fillWidth: true Layout.fillWidth: true
Layout.horizontalStretchFactor: 1
//implicitWidth: parent.width
ApplicantPersonalData { ApplicantPersonalData {
id: personalData id: personalData
width: parent.width implicitWidth: parent.width
} }
} }
Frame { Frame {
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
Layout.fillWidth: true Layout.fillWidth: true
visible: radio.children[1].checked Layout.horizontalStretchFactor: 1
ColumnLayout { ColumnLayout {
Layout.alignment: Qt.AlignTop Layout.alignment: Qt.AlignTop
@@ -74,7 +67,6 @@ ColumnLayout {
} }
ApplicantNationalInsurance { ApplicantNationalInsurance {
id: nationalInsurance id: nationalInsurance
} }
ApplicantVarious { ApplicantVarious {
id: applicantVarious id: applicantVarious
@@ -103,7 +95,7 @@ ColumnLayout {
onClicked: { onClicked: {
const new_applicant = JsLib.parseForm(personalData, bankAccount, nationalInsurance, applicantVarious); const new_applicant = JsLib.parseForm(personalData, bankAccount, nationalInsurance, applicantVarious);
employee_model.addEmployee(new_applicant, false); employee_model.addEmployee(new_applicant);
} }
} }
} }

View File

@@ -95,24 +95,33 @@ ColumnLayout {
id: street id: street
label: qsTr("Straße") label: qsTr("Straße")
mandatory: true
TextField { TextField {
implicitWidth: fieldM implicitWidth: fieldM
placeholderText: qsTr("Musterstraße") placeholderText: qsTr("Musterstraße")
validator: NotEmptyValidator {
}
} }
} }
Field { Field {
id: houseno id: houseno
mandatory: true
label: qsTr("Hausnummer") label: qsTr("Hausnummer")
TextField { TextField {
implicitWidth: fieldS implicitWidth: fieldS
placeholderText: qsTr("1a") placeholderText: qsTr("1a")
validator: NotEmptyValidator {
}
} }
} }
Field { Field {
label: qsTr("PLZ") label: qsTr("PLZ")
mandatory: true
ComboBox { ComboBox {
id: postcode id: postcode
@@ -125,6 +134,8 @@ ColumnLayout {
onActivated: currentValue onActivated: currentValue
onCurrentIndexChanged: city.currentIndex = postcode.currentIndex onCurrentIndexChanged: city.currentIndex = postcode.currentIndex
validator: NotEmptyValidator {}
} }
} }
Field { Field {

View File

@@ -7,14 +7,10 @@ GridLayout {
id: personalData id: personalData
function checkPersonalField() { function checkPersonalField() {
if (radio.children[0].checked) {
return (firstname.text.trim() && lastname.text.trim());
} else {
return (firstname.text.trim() && lastname.text.trim() && street.text.trim() && houseno.text.trim() && (postcode.editText.trim() || postcode.currentText.trim()) && (city.editText.trim() || city.currentText.trim()) && birthday.text.trim() && phonenumber.text.trim() && cellphone.text.trim() && email.text.trim() && jobdescription.text.trim() && contractstart.text.trim() && contractend.text.trim() && briefAnrede.text.trim()); return (firstname.text.trim() && lastname.text.trim() && street.text.trim() && houseno.text.trim() && (postcode.editText.trim() || postcode.currentText.trim()) && (city.editText.trim() || city.currentText.trim()) && birthday.text.trim() && phonenumber.text.trim() && cellphone.text.trim() && email.text.trim() && jobdescription.text.trim() && contractstart.text.trim() && contractend.text.trim() && briefAnrede.text.trim());
} }
}
function requiredField() { function requiredField() {
var pf = (radio.children[1].checked) ? "Pflichtfeld" : ""; const pf = "Pflichtfeld";
street.placeholderText = pf; street.placeholderText = pf;
phonenumber.placeholderText = pf; phonenumber.placeholderText = pf;
cellphone.placeholderText = pf; cellphone.placeholderText = pf;
@@ -131,7 +127,8 @@ GridLayout {
popup.height: 300 popup.height: 300
textRole: "display" textRole: "display"
validator: PostcodeValidator {} validator: PostcodeValidator {
}
onActivated: currentValue onActivated: currentValue
onCurrentIndexChanged: city.currentIndex = postcode.currentIndex onCurrentIndexChanged: city.currentIndex = postcode.currentIndex
@@ -160,7 +157,6 @@ GridLayout {
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Geburtsname") text: qsTr("Geburtsname")
visible: radio.children[1].checked
} }
TextField { TextField {
id: birthname id: birthname
@@ -169,14 +165,12 @@ GridLayout {
Layout.columnSpan: 3 Layout.columnSpan: 3
Layout.fillWidth: true Layout.fillWidth: true
visible: radio.children[1].checked
onTextChanged: checkFields() onTextChanged: checkFields()
} }
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Geburtsdatum*") text: qsTr("Geburtsdatum*")
visible: radio.children[1].checked
} }
TextField { TextField {
id: birthday id: birthday
@@ -185,7 +179,6 @@ GridLayout {
Layout.columnSpan: 3 Layout.columnSpan: 3
Layout.fillWidth: true Layout.fillWidth: true
visible: radio.children[1].checked
validator: RegularExpressionValidator { validator: RegularExpressionValidator {
regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/
@@ -204,7 +197,6 @@ GridLayout {
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Geburtsort*") text: qsTr("Geburtsort*")
visible: radio.children[1].checked
} }
TextField { TextField {
id: placeofbirth id: placeofbirth
@@ -213,7 +205,6 @@ GridLayout {
Layout.columnSpan: 3 Layout.columnSpan: 3
Layout.fillWidth: true Layout.fillWidth: true
visible: radio.children[1].checked
onTextChanged: checkFields() onTextChanged: checkFields()
} }
@@ -269,14 +260,14 @@ GridLayout {
placeholderText: qsTr("beispiel@domain.de") placeholderText: qsTr("beispiel@domain.de")
placeholderTextColor: "red" placeholderTextColor: "red"
validator: EmailAddressValidator {} validator: EmailAddressValidator {
}
onTextChanged: checkFields() onTextChanged: checkFields()
} }
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Familienstand") text: qsTr("Familienstand")
visible: radio.children[1].checked
} }
ComboBox { ComboBox {
id: maritalstatus id: maritalstatus
@@ -287,12 +278,10 @@ GridLayout {
Layout.fillWidth: true Layout.fillWidth: true
editable: false editable: false
model: [qsTr("ledig"), qsTr("verheiratet"), qsTr("verwitwet"), qsTr("geschieden")] model: [qsTr("ledig"), qsTr("verheiratet"), qsTr("verwitwet"), qsTr("geschieden")]
visible: radio.children[1].checked
} }
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Stundenlohn") text: qsTr("Stundenlohn")
visible: radio.children[1].checked
} }
TextField { TextField {
id: salary id: salary
@@ -302,14 +291,12 @@ GridLayout {
Layout.columnSpan: 3 Layout.columnSpan: 3
Layout.fillWidth: true Layout.fillWidth: true
placeholderTextColor: "red" placeholderTextColor: "red"
visible: radio.children[1].checked
onTextChanged: checkFields() onTextChanged: checkFields()
} }
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Jobbeschreibung") text: qsTr("Jobbeschreibung")
visible: radio.children[1].checked
} }
TextField { TextField {
id: jobdescription id: jobdescription
@@ -319,14 +306,12 @@ GridLayout {
Layout.columnSpan: 3 Layout.columnSpan: 3
Layout.fillWidth: true Layout.fillWidth: true
placeholderTextColor: "red" placeholderTextColor: "red"
visible: radio.children[1].checked
onTextChanged: checkFields() onTextChanged: checkFields()
} }
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Vertragsbeginn") text: qsTr("Vertragsbeginn")
visible: radio.children[1].checked
} }
TextField { TextField {
id: contractstart id: contractstart
@@ -336,7 +321,6 @@ GridLayout {
Layout.columnSpan: 3 Layout.columnSpan: 3
Layout.fillWidth: true Layout.fillWidth: true
placeholderTextColor: "red" placeholderTextColor: "red"
visible: radio.children[1].checked
validator: RegularExpressionValidator { validator: RegularExpressionValidator {
regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/
@@ -355,7 +339,6 @@ GridLayout {
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Vertragsende") text: qsTr("Vertragsende")
visible: radio.children[1].checked
} }
TextField { TextField {
id: contractend id: contractend
@@ -365,7 +348,6 @@ GridLayout {
Layout.columnSpan: 3 Layout.columnSpan: 3
Layout.fillWidth: true Layout.fillWidth: true
placeholderTextColor: "red" placeholderTextColor: "red"
visible: radio.children[1].checked
validator: RegularExpressionValidator { validator: RegularExpressionValidator {
regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/ regularExpression: /((^|)(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]))\.((^|)(0[1-9]{1}|1[0-2]{1}))\.((^|)(196[0-9]{1}|19[7-9]{1}[0-9]{1}|20[0-9]{2}))/
@@ -384,7 +366,6 @@ GridLayout {
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Arbeitszeiten Tage") text: qsTr("Arbeitszeiten Tage")
visible: radio.children[1].checked
} }
ComboBox { ComboBox {
id: workdays id: workdays
@@ -393,12 +374,10 @@ GridLayout {
Layout.fillWidth: true Layout.fillWidth: true
model: ["1", "2", "3", "4", "5", "6", "7"] model: ["1", "2", "3", "4", "5", "6", "7"]
visible: radio.children[1].checked
} }
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
text: qsTr("Stunden") text: qsTr("Stunden")
visible: radio.children[1].checked
} }
ComboBox { ComboBox {
id: workhours id: workhours
@@ -407,7 +386,6 @@ GridLayout {
Layout.fillWidth: true Layout.fillWidth: true
model: ["1", "2", "3", "4", "5", "6", "7", "8"] model: ["1", "2", "3", "4", "5", "6", "7", "8"]
visible: radio.children[1].checked
} }
Label { Label {
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight

View File

@@ -16,10 +16,10 @@ class EmployeeDAO(QObject):
if self.__con: if self.__con:
self.__cur = self.__con.cursor() self.__cur = self.__con.cursor()
def getEmployees(self, enc_key, criterion = "Alle", processed = False, fired = False, every_state = True): def getEmployees(self, enc_key, criterion="Alle", processed=False, fired=False, every_state=True):
try: try:
if self.__cur: if self.__cur:
self.__cur.callproc("getEmployeeTable", (criterion, processed, fired, every_state, enc_key, )) self.__cur.callproc("getEmployeeTable", (criterion, processed, fired, every_state, enc_key,))
self.__all_cols = [desc[0] for desc in self.__cur.description] self.__all_cols = [desc[0] for desc in self.__cur.description]
return self.__cur.fetchall(), self.__all_cols return self.__cur.fetchall(), self.__all_cols
else: else:
@@ -27,24 +27,19 @@ class EmployeeDAO(QObject):
except mariadb.Error as e: except mariadb.Error as e:
print(str(e)) print(str(e))
def getEmployee(self, employee_id, enc_key = None): def getEmployee(self, employee_id, enc_key=None):
try: try:
if self.__cur: if self.__cur:
self.__cur.callproc("getEmployee", (employee_id, enc_key,)) self.__cur.callproc("getEmployee", (employee_id, enc_key,))
#self.__all_cols = [desc[0] for desc in self.__cur.description] # self.__all_cols = [desc[0] for desc in self.__cur.description]
return self.__cur.fetchall() #, self.__all_cols return self.__cur.fetchall() # , self.__all_cols
else: else:
return None return None
except mariadb.Error as e: except mariadb.Error as e:
print(str(e)) print(str(e))
def addEmployee(self, data, enc_key, applicant = True): def addEmployee(self, data, enc_key, applicant=True):
try:
if self.__cur: if self.__cur:
self.__cur.callproc("addApplicant", (json.dumps(data), applicant, enc_key,)) self.__cur.callproc("addApplicant", (json.dumps(data), applicant, enc_key,))
self.__con.commit() self.__con.commit()
self.newEmployeeAdded.emit(True) self.newEmployeeAdded.emit(True)
except mariadb.Error as e:
print(str(e))
self.newEmployeeAdded.emit(False)

View File

@@ -27,7 +27,7 @@ class EmployeeModel(QAbstractTableModel):
self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY'] self.__key = self.__conf['pyqcrm']['ENCRYPTION_KEY']
self.__getData() self.__getData()
@Slot(dict, bool) @Slot(dict)
def addEmployee(self, new_employee): def addEmployee(self, new_employee):
if 'worklicense' in new_employee: if 'worklicense' in new_employee:
new_employee['worklicense'] = int(new_employee['worklicense']) new_employee['worklicense'] = int(new_employee['worklicense'])