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(); this.ticketHaveNegatives(); } 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; } ticketHaveNegatives() { let haveNegatives = false; this.ticket.sale.items.forEach(item => { if (item.quantity > item.visible) haveNegatives = true; }); this.haveNegatives = haveNegatives; } onSubmit() { if (!this.ticket.option) { return this.vnApp.showError( this.$t('Choose an option') ); } if (this.ticket.withoutNegatives) { let salesNewTicket = []; this.ticket.sale.items.forEach(item => { if (item.visible >= item.quantity) salesNewTicket.push(item); }); const params = { sales: salesNewTicket }; const query = `tickets/${this.ticket.id}/transferSales`; this.$http.post(query, params); } const query = `tickets/${this.ticket.id}/componentUpdate`; const 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' } });