feat(claim_action): add smart-table and 'change destinantion' to all rows
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-04-08 07:37:17 +02:00
parent 43fcd0c473
commit df26a40e63
6 changed files with 249 additions and 72 deletions

View File

@ -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;
}
};
};

View File

@ -7,4 +7,5 @@ module.exports = Self => {
require('../methods/claim/uploadFile')(Self); require('../methods/claim/uploadFile')(Self);
require('../methods/claim/updateClaimAction')(Self); require('../methods/claim/updateClaimAction')(Self);
require('../methods/claim/isEditable')(Self); require('../methods/claim/isEditable')(Self);
require('../methods/claim/updateClaimDestination')(Self);
}; };

View File

@ -19,6 +19,11 @@
</vn-label-value> </vn-label-value>
</vn-card> </vn-card>
<vn-card class="vn-pa-lg vn-w-lg"> <vn-card class="vn-pa-lg vn-w-lg">
<smart-table
model="model"
options="$ctrl.smartTableOptions"
expr-builder="$ctrl.exprBuilder(param, value)">
<slot-actions>
<section class="header"> <section class="header">
<vn-tool-bar class="vn-mb-md"> <vn-tool-bar class="vn-mb-md">
<vn-button <vn-button
@ -26,6 +31,11 @@
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId" disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId"
vn-http-click="$ctrl.importToNewRefundTicket()" vn-http-click="$ctrl.importToNewRefundTicket()"
translate-attr="{title: 'Imports claim details'}"> translate-attr="{title: 'Imports claim details'}">
</vn-button>
<vn-button
label="Change destination"
ng-show="$ctrl.checked.length > 0"
ng-click="changeDestination.show()">
</vn-button> </vn-button>
<vn-range <vn-range
label="Responsability" label="Responsability"
@ -44,40 +54,53 @@
on-change="$ctrl.save({isChargedToMana: value})"> on-change="$ctrl.save({isChargedToMana: value})">
</vn-check> </vn-check>
</section> </section>
<vn-data-viewer model="model"> </slot-actions>
<vn-table model="model"> <slot-table>
<vn-thead> <table model="model">
<vn-tr> <thead>
<vn-th number>Id</vn-th> <tr>
<vn-th number>Ticket</vn-th> <th shrink>
<vn-th>Destination</vn-th> <vn-multi-check
<vn-th expand>Landed</vn-th> model="model"
<vn-th number>Quantity</vn-th> check-field="$checked">
<vn-th>Description</vn-th> </vn-multi-check>
<vn-th number>Price</vn-th> </th>
<vn-th number>Disc.</vn-th> <th number field="itemFk">Id</th>
<vn-th number>Total</vn-th> <th number field="ticketFk">Ticket</th>
</vn-tr> <th field="claimDestinationFk">Destination</th>
</vn-thead> <th expand field="landed">Landed</th>
<vn-tbody> <th number field="quantity">Quantity</th>
<vn-tr <th field="description">Description</th>
<th number field="price">Price</th>
<th number field="discount">Disc.</th>
<th number field="total">Total</th>
</tr>
</thead>
<tbody>
<tr
ng-repeat="saleClaimed in $ctrl.salesClaimed" ng-repeat="saleClaimed in $ctrl.salesClaimed"
vn-repeat-last on-last="$ctrl.focusLastInput()"> vn-repeat-last on-last="$ctrl.focusLastInput()">
<vn-td number> <td>
<span <vn-check
ng-model="saleClaimed.$checked"
vn-click-stop>
</vn-check>
</td>
<td number>
<vn-span
ng-click="itemDescriptor.show($event, saleClaimed.sale.itemFk)" ng-click="itemDescriptor.show($event, saleClaimed.sale.itemFk)"
class="link"> class="link">
{{::saleClaimed.sale.itemFk | zeroFill:6}} {{::saleClaimed.sale.itemFk | zeroFill:6}}
</span> </vn-span>
</vn-td> </td>
<vn-td number> <td number>
<span <vn-span
class="link" class="link"
ng-click="ticketDescriptor.show($event, saleClaimed.sale.ticketFk)"> ng-click="ticketDescriptor.show($event, saleClaimed.sale.ticketFk)">
{{::saleClaimed.sale.ticketFk}} {{::saleClaimed.sale.ticketFk}}
</span> </vn-span>
</vn-td> </td>
<vn-td expand> <td expand>
<vn-autocomplete vn-one id="claimDestinationFk" <vn-autocomplete vn-one id="claimDestinationFk"
ng-model="saleClaimed.claimDestinationFk" ng-model="saleClaimed.claimDestinationFk"
data="claimDestinations" data="claimDestinations"
@ -85,35 +108,35 @@
value-field="id" value-field="id"
show-field="description"> show-field="description">
</vn-autocomplete> </vn-autocomplete>
</vn-td> </td>
<vn-td expand>{{::saleClaimed.sale.ticket.landed | date: 'dd/MM/yyyy'}}</vn-td> <td expand>{{::saleClaimed.sale.ticket.landed | date: 'dd/MM/yyyy'}}</td>
<vn-td number>{{::saleClaimed.sale.quantity}}</vn-td> <td number>{{::saleClaimed.sale.quantity}}</td>
<vn-td expand>{{::saleClaimed.sale.concept}}</vn-td> <td expand>{{::saleClaimed.sale.concept}}</td>
<vn-td number>{{::saleClaimed.sale.price | currency: 'EUR':2}}</vn-td> <td number>{{::saleClaimed.sale.price | currency: 'EUR':2}}</td>
<vn-td number>{{::saleClaimed.sale.discount}} %</vn-td> <td number>{{::saleClaimed.sale.discount}} %</td>
<vn-td number> <td number>
{{saleClaimed.sale.quantity * saleClaimed.sale.price * {{saleClaimed.sale.quantity * saleClaimed.sale.price *
((100 - saleClaimed.sale.discount) / 100) | currency: 'EUR':2}} ((100 - saleClaimed.sale.discount) / 100) | currency: 'EUR':2}}
</vn-td> </td>
<vn-td shrink> <td shrink>
<vn-icon-button <vn-icon-button
vn-tooltip="Remove line" vn-tooltip="Remove line"
icon="delete" icon="delete"
ng-click="model.remove($index)" ng-click="model.remove($index)"
tabindex="-1"> tabindex="-1">
</vn-icon-button> </vn-icon-button>
</vn-td> </td>
</vn-tr> </tr>
</vn-tbody> </tbody>
</vn-table> </table>
</vn-data-viewer> <!-- <button-bar>
<vn-button-bar> <button
<vn-button
label="Regularize" label="Regularize"
disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId" disabled="$ctrl.claim.claimStateFk == $ctrl.resolvedStateId"
vn-http-click="$ctrl.regularize()"> vn-http-click="$ctrl.regularize()">
</vn-button> </button>
</vn-button-bar> </button-bar> -->
</smart-table>
</vn-card> </vn-card>
<vn-item-descriptor-popover <vn-item-descriptor-popover
vn-id="item-descriptor" vn-id="item-descriptor"
@ -128,3 +151,28 @@
message="Do you want to insert greuges?" message="Do you want to insert greuges?"
on-accept="$ctrl.onUpdateGreugeAccept()"> on-accept="$ctrl.onUpdateGreugeAccept()">
</vn-confirm> </vn-confirm>
<!-- Dialog of change destionation -->
<vn-dialog
vn-id="changeDestination"
on-accept="$ctrl.onResponse()">
<tpl-body>
<section class="SMSDialog">
<h5 class="vn-py-sm">{{$ctrl.$t('Change destination to all selected rows', {total: $ctrl.checked.length})}}</h5>
<vn-horizontal>
<vn-autocomplete vn-one id="claimDestinationFk"
ng-model="$ctrl.newDestination"
data="claimDestinations"
fields="['id','description']"
value-field="id"
show-field="description"
vn-focus>
</vn-autocomplete>
</vn-horizontal>
</section>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
<button response="accept" translate>Save</button>
</tpl-buttons>
</vn-dialog>

View File

@ -5,6 +5,7 @@ import './style.scss';
export default class Controller extends Section { export default class Controller extends Section {
constructor($element, $) { constructor($element, $) {
super($element, $); super($element, $);
this.newDestination;
this.filter = { this.filter = {
include: [ include: [
{relation: 'sale', {relation: 'sale',
@ -21,6 +22,55 @@ export default class Controller extends Section {
}; };
this.getResolvedState(); this.getResolvedState();
this.maxResponsibility = 5; 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() { getResolvedState() {
@ -125,6 +175,24 @@ export default class Controller extends Section {
onSave() { onSave() {
this.vnApp.showSuccess(this.$t('Data saved!')); 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', { ngModule.vnComponent('vnClaimAction', {

View File

@ -8,3 +8,6 @@ Do you want to insert greuges?: Desea insertar greuges?
Insert greuges on client card: Insertar greuges en la ficha del cliente Insert greuges on client card: Insertar greuges en la ficha del cliente
Greuge added: Greuge añadido Greuge added: Greuge añadido
ClaimGreugeDescription: Reclamación id {{claimId}} 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)

View File

@ -39,4 +39,8 @@ vn-claim-action {
max-height: 350px; max-height: 350px;
} }
} }
.right {
float: right;
}
} }