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

140 lines
3.9 KiB
JavaScript
Raw Normal View History

import ngModule from '../../module';
2020-03-18 07:35:59 +00:00
import Component from 'core/lib/component';
2020-09-09 13:49:59 +00:00
import './style.scss';
2020-03-18 07:35:59 +00:00
class Controller extends Component {
$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();
this.ticketHaveNegatives();
}
2020-02-07 12:38:32 +00:00
loadDefaultTicketAction() {
const isSalesAssistant = this.aclService.hasAny(['salesAssistant']);
2024-01-24 08:59:27 +00:00
this.ticket.option = isSalesAssistant ? 'mana' : 'renewPrices';
2020-02-07 12:38:32 +00:00
}
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
ticketHaveNegatives() {
let haveNegatives = false;
let haveNotNegatives = false;
this.ticket.withoutNegatives = false;
const haveDifferences = this.ticket.sale.haveDifferences;
this.ticket.sale.items.forEach(item => {
2022-01-26 07:54:48 +00:00
if (item.quantity > item.movable)
haveNegatives = true;
else
haveNotNegatives = true;
});
this.haveNegatives = (haveNegatives && haveNotNegatives && haveDifferences);
if (this.haveNegatives)
this.ticket.withoutNegatives = true;
}
2020-02-07 12:38:32 +00:00
onSubmit() {
2023-02-08 09:54:21 +00:00
if (this.haveNegatives && !this.ticket.withoutNegatives)
this.$.negativesConfirm.show();
else this.applyChanges();
}
onConfirmAccept() {
this.ticket.withWarningAccept = true;
this.applyChanges();
}
applyChanges() {
2020-02-07 12:38:32 +00:00
if (!this.ticket.option) {
return this.vnApp.showError(
this.$t('Choose an option')
2020-02-07 12:38:32 +00:00
);
}
2021-12-17 11:38:56 +00:00
const query = `tickets/${this.ticket.id}/componentUpdate`;
const params = {
2020-03-13 11:26:15 +00:00
clientFk: this.ticket.clientFk,
2021-06-17 09:52:12 +00:00
nickname: this.ticket.nickname,
2020-03-13 11:26:15 +00:00
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: this.ticket.option,
2023-02-08 09:54:21 +00:00
isWithoutNegatives: this.ticket.withoutNegatives,
withWarningAccept: this.ticket.withWarningAccept,
keepPrice: false
2020-02-07 12:38:32 +00:00
};
this.$http.post(query, params)
.then(res => {
this.ticketToMove = res.data.id;
this.vnApp.showMessage(
this.$t(`The ticket has been unrouted`)
);
})
.finally(() => {
this.$state.go('ticket.card.summary', {id: this.ticketToMove});
});
2020-02-07 12:38:32 +00:00
}
}
ngModule.vnComponent('vnTicketBasicDataStepTwo', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
},
require: {
2020-02-07 12:38:32 +00:00
card: '^vnTicketCard',
data: '^vnTicketBasicData'
}
});