salix/modules/invoiceIn/front/intrastat/index.js

61 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-02-16 09:30:56 +00:00
import ngModule from '../module';
import Section from 'salix/components/section';
class Controller extends Section {
set invoceInIntrastat(value) {
this._invoceInIntrastat = value;
if (value) this.calculateTotals();
}
get invoceInIntrastat() {
return this._invoceInIntrastat;
}
calculateTotals() {
this.amountTotal = 0.0;
this.netTotal = 0.0;
this.stemsTotal = 0.0;
if (!this._invoceInIntrastat) return;
this._invoceInIntrastat.forEach(intrastat => {
this.amountTotal += intrastat.amount;
this.netTotal += intrastat.net;
this.stemsTotal += intrastat.stems;
});
}
add() {
this.$.model.insert({});
}
deleteIntrastat($index) {
this.$.model.remove($index);
this.$.model.save().then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.calculateTotals();
});
}
onSubmit() {
this.$.watcher.check();
this.$.model.save().then(() => {
this.$.watcher.notifySaved();
this.$.watcher.updateOriginalData();
this.calculateTotals();
this.card.reload();
});
}
}
ngModule.vnComponent('vnInvoiceInIntrastat', {
template: require('./index.html'),
controller: Controller,
require: {
card: '^vnInvoiceInCard'
},
bindings: {
invoiceIn: '<'
}
});