salix/modules/supplier/front/account/index.js

80 lines
2.2 KiB
JavaScript

import ngModule from '../module';
import Section from 'salix/components/section';
class Controller extends Section {
constructor($element, $) {
super($element, $);
this.include = {
relation: 'bankEntity',
scope: {
fields: ['countryFk', 'id', 'name', 'bic']
}
};
const filter = {
where: {code: 'wireTransfer'}
};
this.$http.get(`payMethods/findOne`, {filter})
.then(res => {
this.wireTransferFk = res.data.id;
});
}
add() {
this.$.model.insert({
supplierFk: this.$params.id
});
}
onResponse(response) {
const data = this.$.model.data;
const supplierAccount = data[this.currentRowIndex];
supplierAccount.bankEntityFk = response.id;
}
showBankEntity(event, $index) {
if (event.defaultPrevented) return;
event.preventDefault();
this.currentRowIndex = $index;
this.$.bankEntity.open();
}
onBankEntityAccept() {
const query = `SupplierAccounts/${this.$params.id}/createBankEntity`;
return this.$http.patch(query, this.newBankEntity)
.then(res => this.supplierAccount.bankEntityFk = res.data.id);
}
onAddSave() {
const values = {
id: this.$params.id,
payMethodFk: this.wireTransferFk
};
const query = `Suppliers/${this.$params.id}`;
return this.$http.patch(query, values)
.then(() => this.$.watcher.notifySaved());
}
onSubmit() {
this.$.watcher.check();
this.$.model.save()
.then(() => {
this.$.watcher.notifySaved();
this.$.watcher.updateOriginalData();
return this.card.reload();
})
.then(() => {
if (this.supplier.payMethodFk != this.wireTransferFk)
this.$.payMethodToTransfer.show();
});
}
}
ngModule.vnComponent('vnSupplierAccount', {
template: require('./index.html'),
controller: Controller,
require: {
card: '^vnSupplierCard'
}
});