salix/modules/order/front/line/index.js

71 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-08-07 14:04:42 +00:00
import ngModule from '../module';
2019-11-12 13:18:46 +00:00
import Section from 'salix/components/section';
2018-08-07 14:04:42 +00:00
import './style.scss';
2019-11-12 13:18:46 +00:00
class Controller extends Section {
2018-08-07 14:04:42 +00:00
$onInit() {
this.getRows();
2019-01-14 10:35:48 +00:00
}
set order(value) {
this._order = value;
2018-08-07 14:04:42 +00:00
this.getVAT();
}
2019-01-14 10:35:48 +00:00
get order() {
return this._order;
}
2019-11-12 13:18:46 +00:00
get subtotal() {
return this.order ? this.order.total - this.VAT : 0;
}
2018-08-07 14:04:42 +00:00
getRows() {
let filter = {
2019-11-12 13:18:46 +00:00
where: {orderFk: this.$params.id},
include: [
{relation: 'item'},
{relation: 'warehouse'}
]
2018-08-07 14:04:42 +00:00
};
2019-11-12 13:18:46 +00:00
this.$http.get(`OrderRows`, {filter})
.then(res => this.rows = res.data);
2018-08-07 14:04:42 +00:00
}
getVAT() {
2019-11-12 13:18:46 +00:00
this.$http.get(`Orders/${this.$params.id}/getVAT`)
.then(res => this.VAT = res.data);
2019-01-14 10:35:48 +00:00
}
2019-11-12 13:18:46 +00:00
deleteRow(index) {
let [row] = this.rows.splice(index, 1);
let params = {
rows: [row.id],
actualOrderId: this.$params.id
};
2020-03-24 16:01:11 +00:00
return this.$http.post(`OrderRows/removes`, params)
.then(() => this.card.reload())
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
2018-08-07 14:04:42 +00:00
}
save() {
2019-11-12 13:18:46 +00:00
this.$http.post(`Orders/${this.$params.id}/confirm`).then(() => {
this.vnApp.showSuccess(this.$t('Order confirmed'));
this.$state.go(`ticket.index`, {
q: JSON.stringify({clientFk: this.order.clientFk})
});
2018-08-07 14:04:42 +00:00
});
}
}
ngModule.vnComponent('vnOrderLine', {
2018-08-07 14:04:42 +00:00
template: require('./index.html'),
controller: Controller,
bindings: {
order: '<'
2019-01-14 10:35:48 +00:00
},
require: {
card: '^vnOrderCard'
2018-08-07 14:04:42 +00:00
}
});