2018-04-18 07:47:05 +00:00
|
|
|
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';
|
2018-04-18 07:47:05 +00:00
|
|
|
|
2020-03-18 07:35:59 +00:00
|
|
|
class Controller extends Component {
|
2018-05-16 06:13:39 +00:00
|
|
|
$onInit() {
|
|
|
|
this.data.registerChild(this);
|
2019-11-14 13:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2021-12-15 13:45:45 +00:00
|
|
|
this.ticketHaveNegatives();
|
2018-05-16 06:13:39 +00:00
|
|
|
}
|
2018-04-18 07:47:05 +00:00
|
|
|
|
2020-02-07 12:38:32 +00:00
|
|
|
loadDefaultTicketAction() {
|
2021-11-18 13:27:05 +00:00
|
|
|
const isSalesAssistant = this.aclService.hasAny(['salesAssistant']);
|
|
|
|
const defaultOption = isSalesAssistant ? 'turnInMana' : 'changePrice';
|
|
|
|
const filter = {where: {code: defaultOption}};
|
2020-02-07 12:38:32 +00:00
|
|
|
|
|
|
|
this.$http.get(`TicketUpdateActions`, {filter}).then(response => {
|
|
|
|
return this.ticket.option = response.data[0].id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onStepChange() {
|
2018-05-16 06:13:39 +00:00
|
|
|
return true;
|
2018-04-18 07:47:05 +00:00
|
|
|
}
|
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 => {
|
2019-09-02 12:36:54 +00:00
|
|
|
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 => {
|
2019-09-02 12:36:54 +00:00
|
|
|
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
|
|
|
|
2021-12-15 13:45:45 +00:00
|
|
|
ticketHaveNegatives() {
|
|
|
|
let haveNegatives = false;
|
2021-12-20 12:50:31 +00:00
|
|
|
let haveNotNegatives = false;
|
2022-01-28 08:15:41 +00:00
|
|
|
const haveDifferences = this.ticket.sale.haveDifferences;
|
2021-12-20 12:50:31 +00:00
|
|
|
|
2021-12-15 13:45:45 +00:00
|
|
|
this.ticket.sale.items.forEach(item => {
|
2022-01-26 07:54:48 +00:00
|
|
|
if (item.quantity > item.movable)
|
2021-12-15 13:45:45 +00:00
|
|
|
haveNegatives = true;
|
2021-12-20 12:50:31 +00:00
|
|
|
else
|
|
|
|
haveNotNegatives = true;
|
2021-12-15 13:45:45 +00:00
|
|
|
});
|
2021-12-20 12:50:31 +00:00
|
|
|
|
2021-12-21 19:58:58 +00:00
|
|
|
this.ticket.withoutNegatives = false;
|
2022-01-28 08:15:41 +00:00
|
|
|
this.haveNegatives = (haveNegatives && haveNotNegatives && haveDifferences);
|
2021-12-15 13:45:45 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 12:38:32 +00:00
|
|
|
onSubmit() {
|
|
|
|
if (!this.ticket.option) {
|
|
|
|
return this.vnApp.showError(
|
2020-07-23 14:07:08 +00:00
|
|
|
this.$t('Choose an option')
|
2020-02-07 12:38:32 +00:00
|
|
|
);
|
|
|
|
}
|
2021-12-17 11:38:56 +00:00
|
|
|
|
2021-12-15 13:45:45 +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,
|
2021-12-20 12:50:31 +00:00
|
|
|
option: parseInt(this.ticket.option),
|
|
|
|
isWithoutNegatives: this.ticket.withoutNegatives
|
2020-02-07 12:38:32 +00:00
|
|
|
};
|
|
|
|
|
2022-01-28 08:15:41 +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
|
|
|
}
|
2018-04-18 07:47:05 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 12:22:30 +00:00
|
|
|
ngModule.vnComponent('vnTicketBasicDataStepTwo', {
|
2018-05-25 08:03:45 +00:00
|
|
|
template: require('./index.html'),
|
2018-04-18 07:47:05 +00:00
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
|
|
|
ticket: '<'
|
2018-05-16 06:13:39 +00:00
|
|
|
},
|
|
|
|
require: {
|
2020-02-07 12:38:32 +00:00
|
|
|
card: '^vnTicketCard',
|
2019-04-16 13:00:21 +00:00
|
|
|
data: '^vnTicketBasicData'
|
2018-04-18 07:47:05 +00:00
|
|
|
}
|
|
|
|
});
|