salix/modules/worker/front/create/index.js

142 lines
3.7 KiB
JavaScript
Raw Normal View History

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, $);
this.worker = {companyFk: this.vnConfig.user.companyFk};
this.$http.get(`WorkerConfigs/findOne`, {field: ['payMethodFk']}).then(res => {
if (res.data) this.worker.payMethodFk = res.data.payMethodFk;
});
2022-11-14 14:19:16 +00:00
}
onSubmit() {
if (!this.worker.iban && !this.worker.bankEntityFk) {
delete this.worker.iban;
delete this.worker.bankEntityFk;
}
2022-11-14 14:19:16 +00:00
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
});
}
2023-03-03 12:46:18 +00:00
get ibanCountry() {
if (!this.worker || !this.worker.iban) return false;
let countryCode = this.worker.iban.substr(0, 2);
return countryCode;
}
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}};
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;
});
}
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);
if (!this.worker.companyFk)
this.worker.companyFk = this.vnConfig.user.companyFk;
}
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
});