113 lines
2.8 KiB
JavaScript
113 lines
2.8 KiB
JavaScript
import ngModule from '../module';
|
|
import './style.scss';
|
|
|
|
class Controller {
|
|
constructor($scope, $state, $http, vnApp, $translate) {
|
|
this.$scope = $scope;
|
|
this.vnApp = vnApp;
|
|
this.$translate = $translate;
|
|
this.$state = $state;
|
|
this.$http = $http;
|
|
this.idsToRemove = [];
|
|
}
|
|
|
|
$onInit() {
|
|
this.getRows();
|
|
}
|
|
|
|
set order(value) {
|
|
this._order = value;
|
|
this.getVAT();
|
|
}
|
|
|
|
get order() {
|
|
return this._order;
|
|
}
|
|
|
|
getRows() {
|
|
let filter = {
|
|
where: {orderFk: this.$state.params.id},
|
|
include: [{
|
|
relation: 'item'
|
|
},
|
|
{relation: 'warehouse'}]
|
|
};
|
|
filter = encodeURIComponent(JSON.stringify(filter));
|
|
let query = `/order/api/OrderRows?filter=${filter}`;
|
|
|
|
this.$http.get(query).then(res => {
|
|
this.rows = res.data;
|
|
});
|
|
}
|
|
|
|
getVAT() {
|
|
let query = `/order/api/Orders/${this.$state.params.id}/getVAT`;
|
|
|
|
this.$http.get(query).then(res => {
|
|
this.VAT = res.data;
|
|
});
|
|
}
|
|
|
|
get subtotal() {
|
|
return this.order.total - this.VAT || 0;
|
|
}
|
|
|
|
showDeleteRow(index) {
|
|
this.lineIdToRemove = index;
|
|
this.$scope.deleteRow.show();
|
|
}
|
|
|
|
deleteRow(response) {
|
|
if (response == 'ACCEPT') {
|
|
let [lineRemoved] = this.rows.splice(this.lineIdToRemove, 1);
|
|
this.idsToRemove.push(lineRemoved.id);
|
|
let params = {
|
|
rows: this.idsToRemove,
|
|
actualOrderId: this.$state.params.id
|
|
};
|
|
let query = `/order/api/OrderRows/removes`;
|
|
|
|
this.$http.post(query, params).then(() => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
|
});
|
|
this.$scope.watcher.updateOriginalData();
|
|
this.getVAT();
|
|
this.card.reload();
|
|
}
|
|
this.lineIdToRemove = undefined;
|
|
}
|
|
|
|
// Item Descriptor
|
|
showDescriptor(event, itemFk) {
|
|
this.$scope.descriptor.itemFk = itemFk;
|
|
this.$scope.descriptor.parent = event.target;
|
|
this.$scope.descriptor.show();
|
|
}
|
|
|
|
onDescriptorLoad() {
|
|
this.$scope.popover.relocate();
|
|
}
|
|
|
|
save() {
|
|
let query = `/api/Orders/${this.order.id}/confirm`;
|
|
|
|
this.$http.post(query).then(() => {
|
|
this.vnApp.showSuccess(this.$translate.instant('Order confirmed'));
|
|
this.$state.go(`ticket.index`, {q: JSON.stringify({clientFk: this.order.clientFk})});
|
|
});
|
|
}
|
|
}
|
|
|
|
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];
|
|
|
|
ngModule.component('vnOrderLine', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
order: '<'
|
|
},
|
|
require: {
|
|
card: '^vnOrderCard'
|
|
}
|
|
});
|