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

61 lines
1.4 KiB
JavaScript
Raw Permalink 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;
2022-04-11 06:23:54 +00:00
if (!this.invoceInIntrastat) return;
2022-02-16 09:30:56 +00:00
2022-04-11 06:23:54 +00:00
this.invoceInIntrastat.forEach(intrastat => {
2022-02-16 09:30:56 +00:00
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: '<'
}
});