import ngModule from '../module'; import Section from 'salix/components/section'; import UserError from 'core/lib/user-error'; class Controller extends Section { taxRate(invoiceInTax, taxRateSelection) { const taxTypeSage = taxRateSelection && taxRateSelection.rate; const taxableBase = invoiceInTax && invoiceInTax.taxableBase; if (taxTypeSage && taxableBase) return (taxTypeSage / 100) * taxableBase; return 0; } add() { this.$.model.insert({ invoiceIn: this.$params.id }); } onSubmit() { this.$.watcher.check(); this.$.model.save().then(() => { this.$.watcher.notifySaved(); this.$.watcher.updateOriginalData(); this.card.reload(); }); } onResponse() { if (!this.expence) throw new UserError(`The fields can't be empty`); else if (!this.expence.code) throw new UserError(`The code can't be empty`); else if (!this.expence.description) throw new UserError(`The description can't be empty`); const params = []; params.push({ id: this.expence.code, isWithheld: this.expence.isWithheld, name: this.expence.description }); this.$http.post(`Expenses`, params) .then(() => { this.vnApp.showSuccess(this.$t('Expence saved!')); }); } } ngModule.vnComponent('vnInvoiceInTax', { template: require('./index.html'), controller: Controller, require: { card: '^vnInvoiceInCard' }, bindings: { invoiceIn: '<' } });