diff --git a/modules/route/back/methods/route/getTickets.js b/modules/route/back/methods/route/getTickets.js index a0014a60d..211a2e7bb 100644 --- a/modules/route/back/methods/route/getTickets.js +++ b/modules/route/back/methods/route/getTickets.js @@ -29,7 +29,7 @@ module.exports = Self => { order: 'priority', include: [ { - relation: 'state', + relation: 'ticketState', scope: { fields: ['id', 'stateFk'], include: [{relation: 'state'}] diff --git a/modules/ticket/back/methods/ticket/getPossibleStowaways.js b/modules/ticket/back/methods/ticket/getPossibleStowaways.js index 3565d64ab..675270840 100644 --- a/modules/ticket/back/methods/ticket/getPossibleStowaways.js +++ b/modules/ticket/back/methods/ticket/getPossibleStowaways.js @@ -38,7 +38,6 @@ module.exports = Self => { let highestDate = new Date(ship.shipped.getTime()); highestDate.setHours(23, 59, 59); - let possibleStowaways = await models.Ticket.find({ where: { id: {neq: ticketFk}, @@ -53,7 +52,7 @@ module.exports = Self => { include: [ {relation: 'agencyMode'}, {relation: 'warehouse'}, - {relation: 'state', + {relation: 'ticketState', scope: { fields: ['stateFk'], include: { diff --git a/modules/ticket/back/methods/ticket/summary.js b/modules/ticket/back/methods/ticket/summary.js index 2035b4d31..79a7c24d9 100644 --- a/modules/ticket/back/methods/ticket/summary.js +++ b/modules/ticket/back/methods/ticket/summary.js @@ -90,7 +90,7 @@ module.exports = Self => { } } }, { - relation: 'state', + relation: 'ticketState', scope: { fields: ['stateFk'], include: { diff --git a/modules/ticket/back/models/ticket.json b/modules/ticket/back/models/ticket.json index 21c34232b..63b69b914 100644 --- a/modules/ticket/back/models/ticket.json +++ b/modules/ticket/back/models/ticket.json @@ -110,7 +110,7 @@ "model": "TicketObservation", "foreignKey": "ticketFk" }, - "state": { + "ticketState": { "type": "hasOne", "model": "TicketState", "foreignKey": "ticketFk" diff --git a/modules/ticket/front/card/index.js b/modules/ticket/front/card/index.js index 8dce23aa7..80174b5e2 100644 --- a/modules/ticket/front/card/index.js +++ b/modules/ticket/front/card/index.js @@ -45,7 +45,7 @@ class Controller extends ModuleCard { }, }, }, { - relation: 'state', + relation: 'ticketState', scope: { fields: ['stateFk'], include: { diff --git a/modules/ticket/front/descriptor/addStowaway.html b/modules/ticket/front/descriptor/addStowaway.html index f05a6584f..56bb321d9 100644 --- a/modules/ticket/front/descriptor/addStowaway.html +++ b/modules/ticket/front/descriptor/addStowaway.html @@ -26,7 +26,7 @@ {{ticket.landed | date: 'dd/MM/yyyy'}} {{ticket.agencyMode.name}} {{ticket.warehouse.name}} - {{ticket.state.state.name}} + {{ticket.ticketState.state.name}} diff --git a/modules/ticket/front/descriptor/index.html b/modules/ticket/front/descriptor/index.html index ede553b72..56bb1a724 100644 --- a/modules/ticket/front/descriptor/index.html +++ b/modules/ticket/front/descriptor/index.html @@ -86,7 +86,7 @@
+ value="{{$ctrl.ticket.ticketState.state.name}}"> { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + console.log(this.edit[0].sale); + this.edit[0].sale.price = 277; this.clearDiscount(); modified = false; }).catch(e => { diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index f5ec9cf0b..607a0396e 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -12,19 +12,19 @@ + on-change="$ctrl.changeState(value)"> - - + --> + + @@ -80,14 +85,13 @@ - @@ -117,7 +121,7 @@ show-field="name" value-field="id" search-function="$ctrl.itemSearchFunc($search)" - on-change="$ctrl.onChangeQuantity(sale)" + on-change="$ctrl.changeQuantity(sale)" order="id DESC" tabindex="1"> @@ -131,14 +135,14 @@ + on-change="$ctrl.changeQuantity(sale)"> @@ -152,23 +156,23 @@ - + on-change="$ctrl.changeConcept(sale)"> {{sale.price | currency: 'EUR':2}} {{(sale.discount / 100) | percentage}} @@ -206,60 +210,106 @@ ticket-fk="$ctrl.ticket.id"> - + + on-open="$ctrl.getMana()" + on-close="$ctrl.edit = null">
- -
+
-
MANÁ: {{$ctrl.mana | currency: 'EUR':0}}
+
MANÁ: {{$ctrl.edit.mana | currency: 'EUR': 0}}

New price

-

{{$ctrl.newPrice | currency: 'EUR':2}}

+

+ {{$ctrl.getNewPrice() | currency: 'EUR': 2}} +

- + + vn-id="editDiscount" + on-open="$ctrl.getMana()" + on-close="$ctrl.edit = null">
- - +
+
Mana: {{$ctrl.edit.mana | currency: 'EUR':0}}
+
+
+ + +
+

New price

+

+ {{$ctrl.getNewPrice() | currency: 'EUR': 2}} +

+
+
+
+
+ + + + + +
+
+ + +
+
+ Mana: {{$ctrl.edit.mana | currency: 'EUR': 0}} +
+
+
+
+
@@ -306,10 +356,10 @@ Id - Shipped - Agency - Warehouse - Address + Shipped + Agency + Warehouse + Address @@ -352,28 +402,6 @@
- - - - - - - - - - - \ No newline at end of file + + + + + Send shortage SMS + + + Recalculate price + + + Update discount + + + Add claim + + + Mark as reserved + + + Unmark as reserved + + \ No newline at end of file diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index 3d7e38f42..31b9f9a60 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -5,8 +5,8 @@ import './style.scss'; class Controller extends Section { constructor($element, $) { super($element, $); - this.edit = {}; - this.moreOptions = [ + // this.edit = {}; + /* this.moreOptions = [ { name: 'Send shortage SMS', callback: this.showSMSDialog @@ -30,7 +30,7 @@ class Controller extends Section { callback: this.calculateSalePrice, show: () => this.hasOneSaleSelected() }, - ]; + ]; */ this._sales = []; } @@ -53,13 +53,19 @@ class Controller extends Section { this.refreshTotal(); } - get editedPrice() { + /* get editedPrice() { return this._editedPrice; } set editedPrice(value) { this._editedPrice = value; this.updateNewPrice(); + } */ + + get ticketState() { + if (!this.ticket) return null; + + return this.ticket.ticketState.state.code; } refreshTotal() { @@ -93,7 +99,7 @@ class Controller extends Section { return this.subtotal + this.VAT; } - onMoreOpen() { + /* onMoreOpen() { let options = this.moreOptions.filter(option => { const hasShowProperty = Object.hasOwnProperty.call(option, 'show'); const shouldShow = !hasShowProperty || option.show === true || @@ -106,16 +112,16 @@ class Controller extends Section { onMoreChange(callback) { callback.call(this); - } + } */ - get isChecked() { + /* get isChecked() { if (this.sales) { for (let instance of this.sales) if (instance.checked) return true; } return false; - } + } */ /** * Returns checked instances @@ -130,6 +136,34 @@ class Controller extends Section { }); } + /** + * Returns the total of checked instances + * + * @return {Number} Total checked instances + */ + checkedLinesCount() { + const checkedLines = this.checkedLines(); + if (checkedLines) + return checkedLines.length; + + return 0; + } + + hasCheckedLines() { + const checkedLines = this.checkedLines(); + + if (checkedLines) + return checkedLines.length > 0; + + return false; + } + + hasOneSaleSelected() { + if (this.checkedLinesCount() === 1) + return true; + return false; + } + /** * Returns new instances * @@ -160,22 +194,11 @@ class Controller extends Section { return indexes; } - firstCheckedLine() { + /* firstCheckedLine() { const checkedLines = this.checkedLines(); if (checkedLines) return checkedLines[0]; - } - - /** - * Returns the total of checked instances - * - * @return {Number} Total checked instances - */ - totalCheckedLines() { - const checkedLines = this.checkedLines(); - if (checkedLines) - return checkedLines.length; - } + } */ removeCheckedLines() { const sales = this.checkedLines(); @@ -191,19 +214,19 @@ class Controller extends Section { this.refreshTotal(); } - onStateOkClick() { + /* onStateOkClick() { let filter = {where: {code: 'OK'}, fields: ['id']}; let json = encodeURIComponent(JSON.stringify(filter)); return this.$http.get(`States?filter=${json}`).then(res => { - this.onStateChange(res.data[0].id); + this.changeState(res.data[0].id); }); } - - onStateChange(value) { - let params = {ticketFk: this.$state.params.id, stateFk: value}; + */ + changeState(value) { + let params = {ticketFk: this.$params.id, code: value}; this.$http.post('TicketTrackings/changeState', params).then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); this.card.reload(); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }).finally(() => { if (this.newInstances().length === 0) this.$.watcher.updateOriginalData(); @@ -223,7 +246,7 @@ class Controller extends Section { let query = `Sales/removes`; this.$http.post(query, params).then(() => { this.removeCheckedLines(); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); }); } } @@ -258,58 +281,51 @@ class Controller extends Section { this.$.watcher.updateOriginalData(); const query = `tickets/${this.ticket.id}/transferSales`; - this.$http.post(query, params).then(res => { - this.goToTicket(res.data.id); - }); + this.$http.post(query, params) + .then(res => this.$state.go('ticket.card.sale', {id: res.data.id})); } createClaim() { - const claim = { - ticketFk: this.ticket.id, - clientFk: this.ticket.clientFk, - ticketCreated: this.ticket.shipped - }; const sales = this.checkedLines(); + const params = { + claim: { + ticketFk: this.ticket.id, + clientFk: this.ticket.clientFk, + ticketCreated: this.ticket.shipped + }, + sales: sales + }; if (this.newInstances().length === 0) this.$.watcher.updateOriginalData(); - this.$http.post(`Claims/createFromSales`, {claim: claim, sales: sales}).then(res => { - this.$state.go('claim.card.basicData', {id: res.data.id}); - }); + this.$http.post(`Claims/createFromSales`, params) + .then(res => this.$state.go('claim.card.basicData', {id: res.data.id})); } - goToTicket(ticketId) { - this.$state.go('ticket.card.sale', {id: ticketId}); - } - - // Slesperson Mana - getManaSalespersonMana() { - this.$http.get(`Tickets/${this.$state.params.id}/getSalesPersonMana`).then(res => { - this.mana = res.data; - }); + getMana() { + this.$http.get(`Tickets/${this.$params.id}/getSalesPersonMana`) + .then(res => this.edit.mana = res.data); } showEditPricePopover(event, sale) { if (!this.isEditable) return; - this.sale = sale; - this.newPrice = this.sale.price; + this.edit = { - ticketFk: this.ticket.id, - id: sale.id, - quantity: sale.quantity + price: sale.price, + sale: sale }; - this.$.editPricePopover.parent = event.target; - this.$.editPricePopover.show(); + this.$.editPricePopover.show(event); } updatePrice() { - if (this.newPrice && this.newPrice != this.sale.price) { - const query = `Sales/${this.edit.id}/updatePrice`; - this.$http.post(query, {newPrice: this.newPrice}).then(res => { - this.sale.price = res.data.price; + const sale = this.edit.sale; + if (this.edit.price != sale.price) { + const query = `Sales/${sale.id}/updatePrice`; + this.$http.post(query, {newPrice: this.edit.price}).then(res => { + sale.price = res.data.price; - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); }).finally(() => { if (this.newInstances().length === 0) this.$.watcher.updateOriginalData(); @@ -319,26 +335,93 @@ class Controller extends Section { this.$.editPricePopover.hide(); } - updateNewPrice() { + /* updateNewPrice() { this.newPrice = this.sale.quantity * this.newPrice - ((this.sale.discount * (this.sale.quantity * this.newPrice)) / 100); } - + */ showEditDiscountPopover(event, sale) { if (this.isLocked) return; - this.sale = sale; - this.edit = [{ - ticketFk: this.ticket.id, - id: sale.id, - quantity: sale.quantity, - price: sale.price, - discount: sale.discount - }]; - this.$.editPopover.parent = event.target; - this.$.editPopover.show(); + this.edit = { + discount: sale.discount, + sale: sale + }; + + this.$.editDiscount.show(event); } - showEditDialog() { + showEditDiscountDialog(event) { + if (this.isLocked) return; + + this.edit = { + discount: null, + sales: this.checkedLines() + }; + + this.$.editDiscountDialog.show(event); + } + + changeDiscount() { + const sale = this.edit.sale; + if (this.edit.discount != sale.discount) + this.updateDiscount([sale]); + + this.$.editDiscount.hide(); + } + + changeMultipleDiscount() { + const sales = this.edit.sales; + const hasChanges = sales.some(sale => { + return sale.discount != this.edit.discount; + }); + + console.log(hasChanges); + + if (hasChanges) + this.updateDiscount(sales); + + this.$.editDiscountDialog.hide(); + } + + updateDiscount(sales) { + const saleIds = sales.map(sale => { + return sale.id; + }); + + const params = {salesIds: saleIds, newDiscount: this.edit.discount}; + const query = `Tickets/${this.$params.id}/updateDiscount`; + this.$http.post(query, params).then(() => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + + for (let sale of sales) + sale.discount = this.edit.discount; + }).catch(e => { + this.vnApp.showError(e.message); + }); + } + + getNewPrice() { + if (this.edit) { + const sale = this.edit.sale; + let newDiscount = sale.discount; + let newPrice = this.edit.price || sale.price; + + if (this.edit.discount != null) + newDiscount = this.edit.discount; + + if (this.edit.price != null) + newPrice = this.edit.price; + + const price = sale.quantity * newPrice; + const discount = (newDiscount * price) / 100; + + return price - discount; + } + + return 0; + } + + /* showEditDialog() { this.edit = this.checkedLines(); this.$.editDialog.show(); } @@ -351,6 +434,12 @@ class Controller extends Section { hideEditPopover() { this.$.model.refresh(); this.$.editPopover.hide(); + } */ + + hasReserves() { + return this.sales.some(sale => { + return sale.reserved == true; + }); } /* @@ -395,7 +484,7 @@ class Controller extends Section { const path = this.$state.href('order.card.catalog', {id: res.data}); window.open(path, '_blank'); - this.vnApp.showSuccess(this.$translate.instant('Order created')); + this.vnApp.showSuccess(this.$t('Order created')); }); } @@ -417,7 +506,7 @@ class Controller extends Section { this.newSMS = { destinationFk: this.ticket.clientFk, destination: phone, - message: this.$translate.instant('Product not available', params) + message: this.$t('Product not available', params) }; this.$.sms.open(); } @@ -433,7 +522,7 @@ class Controller extends Section { * Creates a new sale if it's a new instance * Updates the sale quantity for existing instance */ - onChangeQuantity(sale) { + changeQuantity(sale) { if (!sale.quantity) return; if (!sale.id) @@ -443,13 +532,13 @@ class Controller extends Section { } /* - * Updates a sale quantity + * Changes a sale quantity */ updateQuantity(sale) { - const data = {quantity: parseInt(sale.quantity)}; + const data = {quantity: sale.quantity}; const query = `Sales/${sale.id}/updateQuantity`; this.$http.post(query, data).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); }).catch(e => { this.$.model.refresh(); throw e; @@ -460,13 +549,13 @@ class Controller extends Section { } /* - * Updates a sale concept + * Changes a sale concept */ - updateConcept(sale) { + changeConcept(sale) { const data = {newConcept: sale.concept}; const query = `Sales/${sale.id}/updateConcept`; this.$http.post(query, data).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); }).catch(e => { this.$.model.refresh(); throw e; @@ -499,7 +588,7 @@ class Controller extends Section { sale.price = newSale.price; sale.item = newSale.item; - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); }).finally(() => { if (this.newInstances().length === 0) this.$.watcher.updateOriginalData(); @@ -518,17 +607,11 @@ class Controller extends Section { }); } - hasOneSaleSelected() { - if (this.totalCheckedLines() === 1) - return true; - return false; - } - calculateSalePrice() { const sale = this.checkedLines()[0]; const query = `Sales/${sale.id}/recalculatePrice`; this.$http.post(query).then(res => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); this.$.model.refresh(); }); } diff --git a/modules/ticket/front/summary/index.html b/modules/ticket/front/summary/index.html index 901e089db..ae97f49b5 100644 --- a/modules/ticket/front/summary/index.html +++ b/modules/ticket/front/summary/index.html @@ -16,7 +16,7 @@ + value="{{$ctrl.summary.ticketState.state.name}}"> diff --git a/modules/ticket/front/summary/index.js b/modules/ticket/front/summary/index.js index 864f118d2..980ccd449 100644 --- a/modules/ticket/front/summary/index.js +++ b/modules/ticket/front/summary/index.js @@ -31,7 +31,7 @@ class Controller extends Section { get isEditable() { try { - return !this.ticket.state.state.alertLevel; + return !this.ticket.ticketState.state.alertLevel; } catch (e) {} return true; diff --git a/package-lock.json b/package-lock.json index e89c594c9..daa43abcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10740,7 +10740,8 @@ }, "yargs-parser": { "version": "13.1.1", - "resolved": "", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz", + "integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==", "dev": true, "requires": { "camelcase": "^5.0.0",