#1236 route.summary
gitea/salix/dev This commit looks good Details

This commit is contained in:
Gerard 2019-03-22 11:10:23 +01:00
parent 7ae011b3b6
commit f4476ca690
10 changed files with 303 additions and 3 deletions

View File

@ -0,0 +1,97 @@
module.exports = Self => {
Self.remoteMethod('summary', {
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/summary`,
verb: 'GET'
}
});
Self.summary = async id => {
let summary = {};
// Item basic data and taxes
let filter = {
where: {id: id},
include: [
{relation: 'ticket',
scope: {
fields: ['id', 'packages', 'warehouseFk', 'nickname', 'clientFk', 'priority'],
include: [
{
relation: 'client',
scope: {
fields: ['id', 'street'],
}
},
{
relation: 'state',
scope: {
fields: ['id', 'stateFk'],
include: [{relation: 'state'}]
}
},
{
relation: 'warehouse',
scope: {
fields: ['id', 'name']
}
}
]
}
}, {
relation: 'agencyMode',
scope: {
fields: ['id', 'name']
}
}, {
relation: 'worker',
scope: {
fields: ['id', 'userFk'],
include: [
{
relation: 'user',
scope: {
fields: ['id', 'nickname']
}
}
]
}
}, {
relation: 'vehicle',
scope: {
fields: ['id', 'm3']
}
}
],
};
summary.route = await Self.app.models.Route.findOne(filter);
for (let i = 0; i < summary.route.ticket().length; i++) {
let ticket = summary.route.ticket()[i];
let query = `
SELECT vn.ticketTotalVolume(?) AS m3`;
let options = [ticket.id];
let [volume] = await Self.rawSql(query, options);
ticket.volume = volume.m3;
}
return summary;
};
};

View File

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

View File

@ -61,6 +61,11 @@
"type": "belongsTo", "type": "belongsTo",
"model": "AgencyMode", "model": "AgencyMode",
"foreignKey": "agencyModeFk" "foreignKey": "agencyModeFk"
},
"ticket": {
"type": "hasMany",
"model": "Ticket",
"foreignKey": "routeFk"
} }
} }
} }

View File

@ -26,7 +26,7 @@
<vn-th th-id="worker">Worker</vn-th> <vn-th th-id="worker">Worker</vn-th>
<vn-th th-id="agency">Agency</vn-th> <vn-th th-id="agency">Agency</vn-th>
<vn-th th-id="vehicle">Vehicle</vn-th> <vn-th th-id="vehicle">Vehicle</vn-th>
<vn-th th-id="created">Created</vn-th> <vn-th th-id="created">Date</vn-th>
<vn-th th-id="m3" number></vn-th> <vn-th th-id="m3" number></vn-th>
<vn-th th-id="description">Description</vn-th> <vn-th th-id="description">Description</vn-th>
<vn-th></vn-th> <vn-th></vn-th>

View File

@ -66,7 +66,7 @@ export default class Controller {
preview(event, route) { preview(event, route) {
this.routeSelected = route; this.routeSelected = route;
this.$.dialogSummaryClaim.show(); this.$.summary.show();
event.preventDefault(); event.preventDefault();
event.stopImmediatePropagation(); event.stopImmediatePropagation();
} }

View File

@ -0,0 +1,98 @@
<vn-card class="summary">
<h5>{{$ctrl.summary.route.id}} - {{$ctrl.summary.route.description}}</h5>
<vn-horizontal>
<vn-one>
<vn-label-value label="Id"
value="{{$ctrl.summary.route.id}}">
</vn-label-value>
<vn-label-value label="Date"
value="{{$ctrl.summary.route.created | dateTime: 'dd/MM/yyyy'}}">
</vn-label-value>
<vn-label-value label="Agency"
value="{{$ctrl.summary.route.agencyMode.name}}">
</vn-label-value>
<vn-label-value label="Vehicle"
value="{{$ctrl.summary.route.vehicleFk}}">
</vn-label-value>
<vn-label-value label="Driver"
value="{{$ctrl.summary.route.worker.user.nickname}}">
</vn-label-value>
<vn-label-value label="Cost"
value="{{$ctrl.summary.route.cost | currency: 'EUR':2}}">
</vn-label-value>
</vn-one>
<vn-one>
<vn-label-value label="Time"
value="{{$ctrl.summary.route.time | dateTime: 'HH:MM'}}">
</vn-label-value>
<vn-label-value label="Finished"
value="{{$ctrl.summary.route.finished}}">
</vn-label-value>
<vn-label-value label="Km Start"
value="{{$ctrl.summary.route.kmStart}}">
</vn-label-value>
<vn-label-value label="Km End"
value="{{$ctrl.summary.route.kmEnd}}">
</vn-label-value>
<vn-label-value label="Volume"
value="{{$ctrl.summary.route.m3 | dashIfEmpty}} / {{$ctrl.summary.route.vehicle.m3 | dashIfEmpty}} m³">
</vn-label-value>
<vn-label-value label="Packages"
value="{{$ctrl.packagesTotal}}">
</vn-label-value>
</vn-one>
<vn-one>
<vn-textarea
vn-three
disabled="true"
label="Description"
model="$ctrl.summary.route.description">
</vn-textarea>
</vn-one>
<vn-auto>
<h4 translate>Ticket</h4>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th number>Ticket id</vn-th>
<vn-th>Alias</vn-th>
<vn-th number>Packages</vn-th>
<vn-th number>Volume</vn-th>
<vn-th>Warehouse</vn-th>
<vn-th >Street</vn-th>
<vn-th>State</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="ticket in $ctrl.summary.route.ticket">
<vn-td number>
<span
ng-click="$ctrl.showTicketDescriptor($event, ticket.id)"
class="link">
{{ticket.id | zeroFill:6}}
</span>
</vn-td>
<vn-td>
<span
ng-click="$ctrl.showClientDescriptor($event, ticket.clientFk)"
class="link">
{{ticket.nickname}}
</span>
</vn-td>
<vn-td number>{{ticket.packages}}</vn-td>
<vn-td number>{{ticket.volume}}</vn-td>
<vn-td>{{ticket.warehouse.name}}</vn-td>
<vn-td expand title="{{ticket.client.street}}">{{ticket.client.street}}</vn-td>
<vn-td>{{ticket.state.state.name}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-auto>
</vn-horizontal>
</vn-card>
<vn-ticket-descriptor-popover
vn-id="ticketDescriptor">
</vn-ticket-descriptor-popover>
<vn-client-descriptor-popover
vn-id="clientDescriptor">
</vn-client-descriptor-popover>

View File

@ -0,0 +1,58 @@
import ngModule from '../module';
import './style.scss';
class Controller {
constructor($scope, $http) {
this.$http = $http;
this.$ = $scope;
}
set route(value) {
this._route = value;
if (value && value.id)
this.getSummary();
}
sumPackages() {
this.packagesTotal = 0;
this.summary.route.ticket.forEach(ticket => {
this.packagesTotal += ticket.packages;
});
}
showTicketDescriptor(event, ticketFk) {
this.$.ticketDescriptor.ticketFk = ticketFk;
this.$.ticketDescriptor.parent = event.target;
this.$.ticketDescriptor.show();
event.preventDefault();
}
showClientDescriptor(event, clientFk) {
this.$.clientDescriptor.clientFk = clientFk;
this.$.clientDescriptor.parent = event.target;
this.$.clientDescriptor.show();
event.preventDefault();
}
get route() {
return this._route;
}
getSummary() {
this.$http.get(`/api/Routes/${this.route.id}/summary`).then(response => {
this.summary = response.data;
if (response.data && response.data.route && response.data.route.ticket)
this.sumPackages();
});
}
}
Controller.$inject = ['$scope', '$http'];
ngModule.component('vnRouteSummary', {
template: require('./index.html'),
controller: Controller,
bindings: {
route: '<'
}
});

View File

@ -0,0 +1,27 @@
import './index.js';
describe('Route', () => {
describe('Component summary', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('route'));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnRouteSummary');
controller.route = {id: 1};
}));
describe('getSummary()', () => {
it('should perform a query to set summary', () => {
$httpBackend.when('GET', `/api/Routes/1/summary`).respond(200, 24);
$httpBackend.expect('GET', `/api/Routes/1/summary`);
controller.getSummary();
$httpBackend.flush();
expect(controller.summary).toEqual(24);
});
});
});
});

View File

@ -0,0 +1,7 @@
Driver: Conductor
Vehicle: Vehículo
Packages: Bultos
Time: F. Inicio
Finished: F. Fin
Km Start: Km de inicio
Km End: Km de fin

View File

@ -0,0 +1,5 @@
@import "./variables";
vn-route-summary .summary {
max-width: $width-large;
}