diff --git a/modules/claim/back/methods/claim/updateClaimDestination.js b/modules/claim/back/methods/claim/updateClaimDestination.js new file mode 100644 index 000000000..104fbaf0b --- /dev/null +++ b/modules/claim/back/methods/claim/updateClaimDestination.js @@ -0,0 +1,53 @@ + +module.exports = Self => { + Self.remoteMethod('updateClaimDestination', { + description: 'Update a claim with privileges', + accessType: 'WRITE', + accepts: [{ + arg: 'rows', + type: ['object'], + required: true, + description: `the sales which will be modified the claimDestinationFk` + }, { + arg: 'claimDestinationFk', + type: 'number', + required: true + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/updateClaimDestination`, + verb: 'post' + } + }); + + Self.updateClaimDestination = async(rows, claimDestinationFk, options) => { + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const models = Self.app.models; + for (let row of rows) { + const claimEnd = await models.ClaimEnd.findById(row.id, null, myOptions); + await claimEnd.updateAttribute('claimDestinationFk', claimDestinationFk, myOptions); + } + + if (tx) await tx.commit(); + + return {}; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/claim/back/models/claim.js b/modules/claim/back/models/claim.js index fba11cfb6..36187b78b 100644 --- a/modules/claim/back/models/claim.js +++ b/modules/claim/back/models/claim.js @@ -7,4 +7,5 @@ module.exports = Self => { require('../methods/claim/uploadFile')(Self); require('../methods/claim/updateClaimAction')(Self); require('../methods/claim/isEditable')(Self); + require('../methods/claim/updateClaimDestination')(Self); }; diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index 6c0e2402d..425c0cbe9 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -19,65 +19,88 @@ -
- - - - - - - - -
- - - - - Id - Ticket - Destination - Landed - Quantity - Description - Price - Disc. - Total - - - - + +
+ + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + +
+ + + IdTicketDestinationLandedQuantityDescriptionPriceDisc.Total
+ {{::saleClaimed.sale.itemFk | zeroFill:6}} - - - - + + {{::saleClaimed.sale.ticketFk}} - - - + + - - {{::saleClaimed.sale.ticket.landed | date: 'dd/MM/yyyy'}} - {{::saleClaimed.sale.quantity}} - {{::saleClaimed.sale.concept}} - {{::saleClaimed.sale.price | currency: 'EUR':2}} - {{::saleClaimed.sale.discount}} % - + {{::saleClaimed.sale.ticket.landed | date: 'dd/MM/yyyy'}}{{::saleClaimed.sale.quantity}}{{::saleClaimed.sale.concept}}{{::saleClaimed.sale.price | currency: 'EUR':2}}{{::saleClaimed.sale.discount}} % {{saleClaimed.sale.quantity * saleClaimed.sale.price * ((100 - saleClaimed.sale.discount) / 100) | currency: 'EUR':2}} - - + - - - - - - - +
+ +
- \ No newline at end of file + + + + + +
+
{{$ctrl.$t('Change destination to all selected rows', {total: $ctrl.checked.length})}}
+ + + + +
+
+ + + + +
\ No newline at end of file diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index 4b3214211..c65e45a77 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -5,6 +5,7 @@ import './style.scss'; export default class Controller extends Section { constructor($element, $) { super($element, $); + this.newDestination; this.filter = { include: [ {relation: 'sale', @@ -21,6 +22,55 @@ export default class Controller extends Section { }; this.getResolvedState(); this.maxResponsibility = 5; + this.smartTableOptions = { + activeButtons: { + search: true + }, + columns: [ + { + field: 'claimDestinationFk', + autocomplete: { + url: 'ClaimDestinations', + showField: 'description', + valueField: 'id' + } + } + ] + }; + } + + exprBuilder(param, value) { + console.log(param, value); + switch (param) { + case 'search': + return {saleFk: value}; + case 'itemFk': + return {'sale.itemFk': value}; + case 'ticketFk': + return {'sale.ticketFk': value}; + case 'claimDestinationFk': + case 'landed': + case 'quantity': + case 'description': + case 'price': + case 'discount': + case 'total': + case 'id': + return {[param]: value}; + } + } + + get checked() { + const salesClaimed = this.$.model.data || []; + console.log(salesClaimed); + + const checkedSalesClaimed = []; + for (let saleClaimed of salesClaimed) { + if (saleClaimed.$checked) + checkedSalesClaimed.push(saleClaimed); + } + + return checkedSalesClaimed; } getResolvedState() { @@ -125,6 +175,24 @@ export default class Controller extends Section { onSave() { this.vnApp.showSuccess(this.$t('Data saved!')); } + + onResponse() { + const rowsToEdit = []; + for (let row of this.checked) + rowsToEdit.push({id: row.id}); + + const data = { + rows: rowsToEdit, + claimDestinationFk: this.newDestination + }; + + const query = `Claims/updateClaimDestination`; + this.$http.post(query, data) + .then(() => { + this.$.model.refresh(); + this.vnApp.showSuccess(this.$t('Data saved!')); + }); + } } ngModule.vnComponent('vnClaimAction', { diff --git a/modules/claim/front/action/locale/es.yml b/modules/claim/front/action/locale/es.yml index 22b2740b3..97640d9dc 100644 --- a/modules/claim/front/action/locale/es.yml +++ b/modules/claim/front/action/locale/es.yml @@ -7,4 +7,7 @@ Regularize: Regularizar Do you want to insert greuges?: Desea insertar greuges? Insert greuges on client card: Insertar greuges en la ficha del cliente Greuge added: Greuge añadido -ClaimGreugeDescription: Reclamación id {{claimId}} \ No newline at end of file +ClaimGreugeDescription: Reclamación id {{claimId}} +Change destination: Cambiar destino +Change destination to all selected rows: Cambiar destino a {{total}} fila(s) seleccionada(s) +Add observation to all selected clients: Añadir observación a {{total}} cliente(s) seleccionado(s) diff --git a/modules/claim/front/action/style.scss b/modules/claim/front/action/style.scss index bac316287..f93d41f9f 100644 --- a/modules/claim/front/action/style.scss +++ b/modules/claim/front/action/style.scss @@ -39,4 +39,8 @@ vn-claim-action { max-height: 350px; } } + + .right { + float: right; + } } \ No newline at end of file