2022-11-14 14:19:16 +00:00
|
|
|
import ngModule from '../module';
|
|
|
|
import Section from 'salix/components/section';
|
|
|
|
|
|
|
|
export default class Controller extends Section {
|
|
|
|
constructor($element, $) {
|
|
|
|
super($element, $);
|
2023-01-04 08:23:18 +00:00
|
|
|
this.$http.get('NewWorkerConfigs/findOne').then(res => {
|
|
|
|
return this.worker = Object.assign({}, res.data);
|
|
|
|
});
|
2022-11-14 14:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit() {
|
|
|
|
return this.$.watcher.submit().then(json => {
|
2022-12-12 14:05:49 +00:00
|
|
|
this.$state.go('worker.card.basicData', {id: json.data.id});
|
2022-11-14 14:19:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
autofillBic() {
|
|
|
|
if (!this.worker || !this.worker.iban) return;
|
|
|
|
|
|
|
|
let bankEntityId = parseInt(this.worker.iban.substr(4, 4));
|
|
|
|
let filter = {where: {id: bankEntityId}};
|
|
|
|
|
|
|
|
if (this.ibanCountry != 'ES') return;
|
|
|
|
|
|
|
|
this.$http.get(`BankEntities`, {filter}).then(response => {
|
|
|
|
const hasData = response.data && response.data[0];
|
|
|
|
|
|
|
|
if (hasData)
|
|
|
|
this.worker.bankEntityFk = response.data[0].id;
|
|
|
|
else if (!hasData)
|
|
|
|
this.worker.bankEntityFk = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-14 14:03:55 +00:00
|
|
|
generateCodeUser() {
|
|
|
|
if (!this.worker.firstName || !this.worker.lastNames) return;
|
|
|
|
|
|
|
|
const totalName = this.worker.firstName.concat(' ' + this.worker.lastNames).toLowerCase();
|
|
|
|
const totalNameArray = totalName.split(' ');
|
|
|
|
let newCode = '';
|
|
|
|
|
|
|
|
for (let part of totalNameArray)
|
|
|
|
newCode += part.charAt(0);
|
|
|
|
|
|
|
|
this.worker.code = newCode.toUpperCase().slice(0, 3);
|
|
|
|
this.worker.name = totalNameArray[0] + newCode.slice(1);
|
|
|
|
}
|
|
|
|
|
2022-11-14 14:19:16 +00:00
|
|
|
get province() {
|
|
|
|
return this._province;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Province auto complete
|
|
|
|
set province(selection) {
|
|
|
|
this._province = selection;
|
2023-01-03 13:50:29 +00:00
|
|
|
|
|
|
|
if (!selection) return;
|
|
|
|
|
|
|
|
const country = selection.country;
|
|
|
|
|
|
|
|
if (!this.worker.countryFk)
|
|
|
|
this.worker.countryFk = country.id;
|
2022-11-14 14:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get town() {
|
|
|
|
return this._town;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Town auto complete
|
|
|
|
set town(selection) {
|
|
|
|
this._town = selection;
|
|
|
|
|
|
|
|
if (!selection) return;
|
|
|
|
|
|
|
|
const province = selection.province;
|
2023-01-03 13:50:29 +00:00
|
|
|
const country = province.country;
|
2022-11-14 14:19:16 +00:00
|
|
|
const postcodes = selection.postcodes;
|
|
|
|
|
2023-01-03 13:50:29 +00:00
|
|
|
if (!this.worker.provinceFk)
|
|
|
|
this.worker.provinceFk = province.id;
|
|
|
|
|
|
|
|
if (!this.worker.countryFk)
|
|
|
|
this.worker.countryFk = country.id;
|
2022-11-14 14:19:16 +00:00
|
|
|
|
|
|
|
if (postcodes.length === 1)
|
2023-01-03 13:50:29 +00:00
|
|
|
this.worker.postcode = postcodes[0].code;
|
2022-11-14 14:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get postcode() {
|
|
|
|
return this._postcode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Postcode auto complete
|
|
|
|
set postcode(selection) {
|
|
|
|
this._postcode = selection;
|
|
|
|
|
|
|
|
if (!selection) return;
|
|
|
|
|
|
|
|
const town = selection.town;
|
|
|
|
const province = town.province;
|
2023-01-03 13:50:29 +00:00
|
|
|
const country = province.country;
|
|
|
|
|
|
|
|
if (!this.worker.city)
|
|
|
|
this.worker.city = town.name;
|
2022-11-14 14:19:16 +00:00
|
|
|
|
2023-01-03 13:50:29 +00:00
|
|
|
if (!this.worker.provinceFk)
|
|
|
|
this.worker.provinceFk = province.id;
|
2022-11-14 14:19:16 +00:00
|
|
|
|
2023-01-03 13:50:29 +00:00
|
|
|
if (!this.worker.countryFk)
|
|
|
|
this.worker.countryFk = country.id;
|
2022-11-14 14:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onResponse(response) {
|
2023-01-03 13:50:29 +00:00
|
|
|
this.worker.postcode = response.code;
|
|
|
|
this.worker.city = response.city;
|
|
|
|
this.worker.provinceFk = response.provinceFk;
|
2022-11-14 14:19:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$element', '$scope'];
|
|
|
|
|
|
|
|
ngModule.vnComponent('vnWorkerCreate', {
|
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller
|
|
|
|
});
|