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

62 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-06-09 08:20:18 +00:00
import ngModule from '../module';
import Section from 'salix/components/section';
import UserError from 'core/lib/user-error';
2021-06-09 08:20:18 +00:00
class Controller extends Section {
2021-08-09 12:06:23 +00:00
taxRate(invoiceInTax, taxRateSelection) {
const taxTypeSage = taxRateSelection && taxRateSelection.rate;
const taxableBase = invoiceInTax && invoiceInTax.taxableBase;
2021-06-29 06:59:55 +00:00
2021-06-25 05:47:53 +00:00
if (taxTypeSage && taxableBase)
2021-08-09 12:06:23 +00:00
return (taxTypeSage / 100) * taxableBase;
return 0;
2021-06-25 05:47:53 +00:00
}
2021-06-09 08:20:18 +00:00
add() {
this.$.model.insert({
2021-06-29 06:59:55 +00:00
invoiceIn: this.$params.id
2021-06-09 08:20:18 +00:00
});
}
2021-06-29 06:59:55 +00:00
2021-06-09 08:20:18 +00:00
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!'));
});
}
2021-06-09 08:20:18 +00:00
}
ngModule.vnComponent('vnInvoiceInTax', {
template: require('./index.html'),
controller: Controller,
require: {
card: '^vnInvoiceInCard'
},
bindings: {
invoiceIn: '<'
}
});