Tarea #606 claim.summary

This commit is contained in:
gerard 2018-09-05 13:47:15 +02:00
parent b12fa80aa2
commit c424e845d1
9 changed files with 358 additions and 4 deletions

View File

@ -8,4 +8,4 @@ import './descriptor';
import './development'; import './development';
import './index/'; import './index/';
import './search-panel'; import './search-panel';
// import './summary'; import './summary';

View File

@ -30,7 +30,7 @@
</vn-tr> </vn-tr>
</vn-thead> </vn-thead>
<vn-tbody> <vn-tbody>
<vn-tr ng-repeat="claim in claims" ui-sref="claim.card.detail({id: claim.id})" class=clickable> <vn-tr ng-repeat="claim in claims" ui-sref="claim.card.summary({id: claim.id})" class=clickable>
<vn-td number>{{::claim.id}}</vn-td> <vn-td number>{{::claim.id}}</vn-td>
<vn-td number><span class="link" ng-click="$ctrl.showDescriptor($event, claim.client.id)">{{::claim.client.id}}</span></vn-td> <vn-td number><span class="link" ng-click="$ctrl.showDescriptor($event, claim.client.id)">{{::claim.client.id}}</span></vn-td>
<vn-td>{{::claim.client.name}}</vn-td> <vn-td>{{::claim.client.name}}</vn-td>
@ -39,7 +39,7 @@
<vn-td>{{::claim.claimState.description}}</vn-td> <vn-td>{{::claim.claimState.description}}</vn-td>
<vn-td> <vn-td>
<vn-icon-button <vn-icon-button
ng-click="$ctrl.preview($event, ticket)" ng-click="$ctrl.preview($event, claim)"
vn-tooltip="Preview" vn-tooltip="Preview"
icon="desktop_windows"> icon="desktop_windows">
</vn-icon-button> </vn-icon-button>
@ -54,3 +54,9 @@
</vn-pagination> </vn-pagination>
</div> </div>
<vn-client-descriptor-popover vn-id="descriptor"></vn-client-descriptor-popover> <vn-client-descriptor-popover vn-id="descriptor"></vn-client-descriptor-popover>
<vn-dialog class="dialog-summary"
vn-id="dialog-summary-claim">
<tpl-body>
<vn-claim-summary claim="$ctrl.claimSelected"></vn-claim-summary>
</tpl-body>
</vn-dialog>

View File

@ -56,6 +56,13 @@ export default class Controller {
event.stopImmediatePropagation(); event.stopImmediatePropagation();
} }
preview(event, claim) {
this.claimSelected = claim;
this.$.dialogSummaryClaim.show();
event.preventDefault();
event.stopImmediatePropagation();
}
onDescriptorLoad() { onDescriptorLoad() {
this.$.popover.relocate(); this.$.popover.relocate();
} }

View File

@ -0,0 +1,152 @@
<vn-vertical vn-one>
<vn-card class="summary" pad-medium>
<vn-vertical margin-medium>
<vn-auto>
<h5 text-center pad-small-v class="title">{{$ctrl.summary.claim.id}} - {{$ctrl.summary.claim.client.name}}</h5>
</vn-auto>
<vn-horizontal>
<vn-one>
<vn-label-value label="Created"
value="{{$ctrl.summary.claim.created | dateTime: 'dd/MM/yyyy'}}">
</vn-label-value>
<vn-label-value label="State"
value="{{::$ctrl.summary.claim.claimState.description}}">
</vn-label-value>
<vn-label-value label="Salesperson"
value="{{$ctrl.summary.claim.client.salesPerson.firstName}} {{$ctrl.summary.claim.client.salesPerson.name}}">
</vn-label-value>
<vn-label-value label="Attended by"
value="{{$ctrl.summary.claim.worker.firstName}} {{$ctrl.summary.claim.worker.name}}">
</vn-label-value>
</vn-one>
<vn-one>
<vn-textarea
vn-three
disabled="true"
label="Observation"
model="$ctrl.summary.claim.observation">
</vn-textarea>
</vn-one>
<vn-one>
<vn-input-range
vn-one
disabled="true"
label="Responsability"
value="$ctrl.summary.claim.responsibility"
max="4"
min="0"
step="1">
</vn-input-range>
</vn-one>
</vn-horizontal>
<vn-horizontal>
<vn-one margin-medium>
<h5 translate>Detail</h5>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th number>Id</vn-th>
<vn-th number>Landed</vn-th>
<vn-th number>Quantity</vn-th>
<vn-th number>Claimed</vn-th>
<vn-th number>Description</vn-th>
<vn-th number>Price</vn-th>
<vn-th number>Disc.</vn-th>
<vn-th number>Total</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="saleClaimed in $ctrl.summary.salesClaimed">
<vn-td number>{{saleClaimed.sale.id}}</vn-td>
<vn-td number>{{saleClaimed.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}}</vn-td>
<vn-td number>{{saleClaimed.sale.quantity}}</vn-td>
<vn-td number>{{saleClaimed.quantity}}</vn-td>
<vn-td number>{{saleClaimed.sale.concept}}</vn-td>
<vn-td number>{{saleClaimed.sale.price | currency:'€':2}}</vn-td>
<vn-td number>{{saleClaimed.sale.discount}} %</vn-td>
<vn-td number>
{{(saleClaimed.sale.quantity * saleClaimed.sale.price) -
((saleClaimed.sale.discount *
(saleClaimed.sale.quantity * saleClaimed.sale.price))/100) | currency:'€':2
}}
</vn-td>
</vn-tr>
</vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
</vn-table>
</vn-one>
</vn-horizontal>
<vn-horizontal>
<vn-one margin-medium>
<h5 translate>Development</h5>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th number>Reason</vn-th>
<vn-th number>Result</vn-th>
<vn-th number>Responsible</vn-th>
<vn-th number>Worker</vn-th>
<vn-th number>Redelivery</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="development in $ctrl.summary.developments">
<vn-td number>{{development.claimReason.description}}</vn-td>
<vn-td number>{{development.claimResult.description}}</vn-td>
<vn-td number>{{development.claimResponsible.description}}</vn-td>
<vn-td number>{{development.worker.firstName}}</vn-td>
<vn-td number>{{development.claimRedelivery.description}}</vn-td>
</vn-tr>
</vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
</vn-table>
</vn-one>
</vn-horizontal>
<vn-horizontal>
<vn-one margin-medium>
<h5 translate>Action</h5>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th number>Id</vn-th>
<vn-th number>Destination</vn-th>
<vn-th number>Landed</vn-th>
<vn-th number>Quantity</vn-th>
<vn-th number>Description</vn-th>
<vn-th number>Price</vn-th>
<vn-th number>Disc.</vn-th>
<vn-th number>Total</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="action in $ctrl.summary.actions">
<vn-td number>{{action.sale.id}}</vn-td>
<vn-td number>{{action.claimBeggining.description}}</vn-td>
<vn-td number>{{action.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}}</vn-td>
<vn-td number>{{action.sale.quantity}}</vn-td>
<vn-td number>{{action.sale.concept}}</vn-td>
<vn-td number>{{action.sale.price}}</vn-td>
<vn-td number>{{action.sale.discount}} %</vn-td>
<vn-td number>
{{(action.sale.quantity * action.sale.price) -
((action.sale.discount *
(action.sale.quantity * action.sale.price))/100) | currency:'€':2
}}
</vn-td>
</vn-tr>
</vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
</vn-table>
</vn-one>
</vn-horizontal>
</vn-vertical>
</vn-card>
</vn-vertical>

View File

@ -0,0 +1,28 @@
import ngModule from '../module';
class Controller {
constructor($http) {
this.$http = $http;
}
getSummary() {
this.$http.get(`/claim/api/Claims/${this.claim.id}/getSummary`).then(response => {
this.summary = response.data;
});
}
$onChanges() {
if (this.claim && this.claim.id)
this.getSummary();
}
}
Controller.$inject = ['$http'];
ngModule.component('vnClaimSummary', {
template: require('./index.html'),
controller: Controller,
bindings: {
claim: '<'
}
});

View File

@ -0,0 +1,41 @@
import './index.js';
describe('Claim', () => {
describe('Component summary', () => {
let $componentController;
let controller;
let $httpBackend;
beforeEach(() => {
angular.mock.module('claim');
});
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnClaimSummary');
controller.claim = {id: 1};
}));
describe('getSummary()', () => {
it("should perform a query to set summary", () => {
$httpBackend.when('GET', `/claim/api/Claims/1/getSummary`).respond(200, 24);
$httpBackend.expect('GET', `/claim/api/Claims/1/getSummary`);
controller.getSummary();
$httpBackend.flush();
expect(controller.summary).toEqual(24);
});
});
describe('$onChanges()', () => {
it("should call getSummary when item.id is defined", () => {
spyOn(controller, 'getSummary');
controller.$onChanges();
expect(controller.getSummary).toHaveBeenCalledWith();
});
});
});
});

View File

@ -0,0 +1,104 @@
module.exports = Self => {
Self.remoteMethod('getSummary', {
description: 'Updates the item taxes',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The item id',
http: {source: 'path'}
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/getSummary`,
verb: 'GET'
}
});
Self.getSummary = async id => {
let promises = [];
let summary = {};
// Claim
let filter = {
where: {id: id},
include: [
{relation: 'worker', scope: {fields: ['name', 'firstName']}},
{relation: 'claimState', scope: {fields: ['id', 'description']}},
{
relation: 'client',
scope: {
fields: ['salesPersonFk', 'name'],
include: {
relation: 'salesPerson',
fields: ['firstName', 'name']
}
}
}
]
};
promises.push(Self.app.models.Claim.find(filter));
// Claim detail
filter = {
where: {claimFk: id},
include: [
{relation: 'sale',
scope: {
fields: ['concept', 'ticketFk', 'price', 'quantity', 'discount'],
include: {
relation: 'ticket'
}
}
}
]
};
promises.push(Self.app.models.ClaimBeginning.find(filter));
// Claim developments
filter = {
where: {claimFk: id},
include: [
{relation: 'claimResponsible'},
{relation: 'worker'},
{relation: 'claimDestination'},
{relation: 'claimReason'},
{relation: 'claimResult'},
{relation: 'claimRedelivery'}
]
};
promises.push(Self.app.models.ClaimDevelopment.find(filter));
// Claim action
filter = {
where: {claimFk: id},
include: [
{relation: 'sale',
scope: {
fields: ['concept', 'price', 'quantity', 'discount', 'ticketFk', 'itemFk'],
include: [
{relation: 'ticket'}
]
}
},
{relation: 'claimBeggining'}
]
};
promises.push(Self.app.models.ClaimEnd.find(filter));
let res = await Promise.all(promises);
[summary.claim] = res[0];
summary.salesClaimed = res[1];
summary.developments = res[2];
summary.actions = res[3];
return summary;
};
};

View File

@ -0,0 +1,13 @@
const app = require(`${servicesDir}/claim/server/server`);
describe('claim getSummary()', () => {
it('should return summary with claim, salesClaimed, developments and actions defined ', async() => {
let result = await app.models.Claim.getSummary(1);
let keys = Object.keys(result);
expect(keys).toContain('claim');
expect(keys).toContain('salesClaimed');
expect(keys).toContain('developments');
expect(keys).toContain('actions');
});
});

View File

@ -0,0 +1,3 @@
module.exports = Self => {
require('../methods/claim/getSummary')(Self);
};