salix/modules/ticket/front/basic-data/step-two/index.js

113 lines
3.0 KiB
JavaScript
Raw Normal View History

import ngModule from '../../module';
class Controller {
2020-02-07 12:38:32 +00:00
constructor($http, $state, $translate, vnApp) {
this.$http = $http;
2020-02-07 12:38:32 +00:00
this.$state = $state;
this.$translate = $translate;
this.vnApp = vnApp;
}
$onInit() {
this.data.registerChild(this);
}
get ticket() {
return this._ticket;
}
set ticket(value) {
this._ticket = value;
if (!value) return;
2019-01-25 11:52:12 +00:00
this.getTotalPrice();
this.getTotalNewPrice();
this.getTotalDifferenceOfPrice();
2020-02-07 12:38:32 +00:00
this.loadDefaultTicketAction();
}
2020-02-07 12:38:32 +00:00
loadDefaultTicketAction() {
let filter = {where: {code: 'changePrice'}};
this.$http.get(`TicketUpdateActions`, {filter}).then(response => {
return this.ticket.option = response.data[0].id;
});
}
onStepChange() {
return true;
}
2019-01-25 11:52:12 +00:00
getTotalPrice() {
let totalPrice = 0;
this.ticket.sale.items.forEach(item => {
let itemTotalPrice = item.quantity * item.price;
totalPrice += itemTotalPrice;
});
this.totalPrice = totalPrice;
}
getTotalNewPrice() {
let totalNewPrice = 0;
this.ticket.sale.items.forEach(item => {
if (item.component)
totalNewPrice += item.quantity * item.component.newPrice;
2019-01-25 11:52:12 +00:00
});
this.totalNewPrice = totalNewPrice;
}
getTotalDifferenceOfPrice() {
let totalPriceDifference = 0;
this.ticket.sale.items.forEach(item => {
if (item.component)
totalPriceDifference += item.component.difference;
2019-01-25 11:52:12 +00:00
});
this.totalPriceDifference = totalPriceDifference;
}
2020-02-07 12:38:32 +00:00
onSubmit() {
if (!this.ticket.option) {
return this.vnApp.showError(
this.$translate.instant('Choose an option')
);
}
let query = `tickets/${this.ticket.id}/componentUpdate`;
let params = {
2020-03-13 11:26:15 +00:00
clientFk: this.ticket.clientFk,
agencyModeFk: this.ticket.agencyModeFk,
addressFk: this.ticket.addressFk,
zoneFk: this.ticket.zoneFk,
warehouseFk: this.ticket.warehouseFk,
companyFk: this.ticket.companyFk,
2020-02-07 12:38:32 +00:00
shipped: this.ticket.shipped,
landed: this.ticket.landed,
isDeleted: this.ticket.isDeleted,
option: parseInt(this.ticket.option)
};
this.$http.post(query, params).then(res => {
this.vnApp.showMessage(
this.$translate.instant(`The ticket has been unrouted`)
);
this.card.reload();
this.$state.go('ticket.card.summary', {id: this.$state.params.id});
});
}
}
2020-02-07 12:38:32 +00:00
Controller.$inject = ['$http', '$state', '$translate', 'vnApp'];
ngModule.component('vnTicketBasicDataStepTwo', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
},
require: {
2020-02-07 12:38:32 +00:00
card: '^vnTicketCard',
data: '^vnTicketBasicData'
}
});