2018-08-07 14:04:42 +00:00
|
|
|
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();
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-07 14:04:42 +00:00
|
|
|
getRows() {
|
|
|
|
let filter = {
|
|
|
|
where: {orderFk: this.$state.params.id},
|
|
|
|
include: [{
|
2018-11-06 09:49:38 +00:00
|
|
|
relation: 'item'
|
2018-08-07 14:04:42 +00:00
|
|
|
},
|
|
|
|
{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() {
|
2018-10-08 13:21:06 +00:00
|
|
|
let query = `/order/api/Orders/${this.$state.params.id}/getVAT`;
|
2018-08-07 14:04:42 +00:00
|
|
|
|
|
|
|
this.$http.get(query).then(res => {
|
2018-10-08 13:21:06 +00:00
|
|
|
this.VAT = res.data;
|
2018-08-07 14:04:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-14 10:35:48 +00:00
|
|
|
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.getVAT();
|
|
|
|
this.card.reload();
|
|
|
|
}
|
|
|
|
this.lineIdToRemove = undefined;
|
2018-08-07 14:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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() {
|
2019-01-14 10:35:48 +00:00
|
|
|
let query = `/api/Orders/${this.order.id}/confirm`;
|
2018-08-07 14:04:42 +00:00
|
|
|
|
2019-01-14 10:35:48 +00:00
|
|
|
this.$http.post(query).then(() => {
|
|
|
|
this.vnApp.showSuccess(this.$translate.instant('Order confirmed'));
|
2019-02-05 08:27:01 +00:00
|
|
|
this.$state.go(`ticket.index`, {clientFk: this.order.clientFk});
|
2018-08-07 14:04:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Controller.$inject = ['$scope', '$state', '$http', 'vnApp', '$translate'];
|
|
|
|
|
|
|
|
ngModule.component('vnOrderLine', {
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|