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

67 lines
1.7 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 {
2022-05-12 06:27:04 +00:00
constructor($element, $, vnWeekDays) {
super($element, $);
this.expense = {};
}
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() {
2022-05-12 06:27:04 +00:00
try {
if (!this.expense.code)
throw new Error(`The code can't be empty`);
if (!this.expense.description)
throw new UserError(`The description can't be empty`);
2022-05-12 06:27:04 +00:00
const data = [{
id: this.expense.code,
isWithheld: this.expense.isWithheld,
name: this.expense.description
}];
this.$http.post(`Expenses`, data) .then(() => {
this.vnApp.showSuccess(this.$t('Expense saved!'));
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
}
}
2021-06-09 08:20:18 +00:00
}
ngModule.vnComponent('vnInvoiceInTax', {
template: require('./index.html'),
controller: Controller,
require: {
card: '^vnInvoiceInCard'
},
bindings: {
invoiceIn: '<'
}
});