109 lines
3.0 KiB
JavaScript
109 lines
3.0 KiB
JavaScript
import ngModule from '../../module';
|
|
import Component from 'core/lib/component';
|
|
import './style.scss';
|
|
|
|
class Controller extends Component {
|
|
$onInit() {
|
|
this.data.registerChild(this);
|
|
}
|
|
|
|
get ticket() {
|
|
return this._ticket;
|
|
}
|
|
|
|
set ticket(value) {
|
|
this._ticket = value;
|
|
|
|
if (!value) return;
|
|
|
|
this.getTotalPrice();
|
|
this.getTotalNewPrice();
|
|
this.getTotalDifferenceOfPrice();
|
|
this.loadDefaultTicketAction();
|
|
}
|
|
|
|
loadDefaultTicketAction() {
|
|
const isSalesAssistant = this.aclService.hasAny(['salesAssistant']);
|
|
const defaultOption = isSalesAssistant ? 'turnInMana' : 'changePrice';
|
|
const filter = {where: {code: defaultOption}};
|
|
|
|
this.$http.get(`TicketUpdateActions`, {filter}).then(response => {
|
|
return this.ticket.option = response.data[0].id;
|
|
});
|
|
}
|
|
|
|
onStepChange() {
|
|
return true;
|
|
}
|
|
|
|
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;
|
|
});
|
|
this.totalNewPrice = totalNewPrice;
|
|
}
|
|
|
|
getTotalDifferenceOfPrice() {
|
|
let totalPriceDifference = 0;
|
|
this.ticket.sale.items.forEach(item => {
|
|
if (item.component)
|
|
totalPriceDifference += item.component.difference;
|
|
});
|
|
this.totalPriceDifference = totalPriceDifference;
|
|
}
|
|
|
|
onSubmit() {
|
|
if (!this.ticket.option) {
|
|
return this.vnApp.showError(
|
|
this.$t('Choose an option')
|
|
);
|
|
}
|
|
|
|
let query = `tickets/${this.ticket.id}/componentUpdate`;
|
|
let params = {
|
|
clientFk: this.ticket.clientFk,
|
|
nickname: this.ticket.nickname,
|
|
agencyModeFk: this.ticket.agencyModeFk,
|
|
addressFk: this.ticket.addressFk,
|
|
zoneFk: this.ticket.zoneFk,
|
|
warehouseFk: this.ticket.warehouseFk,
|
|
companyFk: this.ticket.companyFk,
|
|
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.$t(`The ticket has been unrouted`)
|
|
);
|
|
this.card.reload();
|
|
this.$state.go('ticket.card.summary', {id: this.$params.id});
|
|
});
|
|
}
|
|
}
|
|
|
|
ngModule.vnComponent('vnTicketBasicDataStepTwo', {
|
|
template: require('./index.html'),
|
|
controller: Controller,
|
|
bindings: {
|
|
ticket: '<'
|
|
},
|
|
require: {
|
|
card: '^vnTicketCard',
|
|
data: '^vnTicketBasicData'
|
|
}
|
|
});
|