Added total by column
gitea/salix/1984-travel_summary_total There was a failure building this commit
Details
gitea/salix/1984-travel_summary_total There was a failure building this commit
Details
This commit is contained in:
parent
d1408b812a
commit
f362963dbb
|
@ -43,7 +43,7 @@
|
|||
</vn-one>
|
||||
<vn-auto>
|
||||
<h4 translate>Entries</h4>
|
||||
<vn-table model="model">
|
||||
<vn-table>
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th shrink>Confirmed</vn-th>
|
||||
|
@ -61,16 +61,18 @@
|
|||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="entry in $ctrl.entries">
|
||||
<vn-check
|
||||
value="{{entry.isConfirmed}}"
|
||||
disabled="true">
|
||||
</vn-check>
|
||||
<vn-td shrink>
|
||||
<vn-check
|
||||
value="{{entry.isConfirmed}}"
|
||||
disabled="true">
|
||||
</vn-check>
|
||||
</vn-td>
|
||||
<vn-td shrink>{{entry.id}} </vn-td>
|
||||
<vn-td shrink>{{entry.supplierName}}</vn-td>
|
||||
<vn-td shrink>{{entry.ref}}</vn-td>
|
||||
<vn-td shrink>{{entry.hb}}</vn-td>
|
||||
<vn-td shrink>{{entry.freightValue}}</vn-td>
|
||||
<vn-td shrink>{{entry.packageValue}}</vn-td>
|
||||
<vn-td shrink>{{entry.freightValue | currency: 'EUR': 2}}</vn-td>
|
||||
<vn-td shrink>{{entry.packageValue | currency: 'EUR': 2}}</vn-td>
|
||||
<vn-td shrink>{{entry.cc}}</vn-td>
|
||||
<vn-td shrink>{{entry.pallet}}</vn-td>
|
||||
<vn-td shrink>{{entry.m3}}</vn-td>
|
||||
|
@ -81,13 +83,28 @@
|
|||
icon="insert_drive_file">
|
||||
</vn-icon>
|
||||
<vn-icon
|
||||
ng-if="entry.notes.length"
|
||||
ng-if="entry.observation.length"
|
||||
vn-tooltip="{{entry.observation}}"
|
||||
icon="insert_drive_file">
|
||||
</vn-icon>
|
||||
</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
<vn-tfoot>
|
||||
<vn-tr>
|
||||
<vn-td></vn-td>
|
||||
<vn-td></vn-td>
|
||||
<vn-td></vn-td>
|
||||
<vn-td></vn-td>
|
||||
<vn-td shrink><strong>{{$ctrl.total('hb')}}</strong></vn-td>
|
||||
<vn-td shrink><strong>{{$ctrl.total('freightValue') | currency: 'EUR': 2}}</strong></vn-td>
|
||||
<vn-td shrink><strong>{{$ctrl.total('packageValue') | currency: 'EUR': 2}}</strong></vn-td>
|
||||
<vn-td shrink><strong>{{$ctrl.total('cc')}}</strong></vn-td>
|
||||
<vn-td shrink><strong>{{$ctrl.total('pallet')}}</strong></vn-td>
|
||||
<vn-td shrink><strong>{{$ctrl.total('m3')}}</strong></vn-td>
|
||||
<vn-td></vn-td>
|
||||
</vn-tr>
|
||||
</vn-tfoot>
|
||||
</vn-table>
|
||||
</vn-auto>
|
||||
</vn-horizontal>
|
||||
|
|
|
@ -5,6 +5,7 @@ class Controller {
|
|||
constructor($scope, $http) {
|
||||
this.$ = $scope;
|
||||
this.$http = $http;
|
||||
this.entries = [];
|
||||
}
|
||||
|
||||
get travel() {
|
||||
|
@ -31,6 +32,15 @@ class Controller {
|
|||
this.entries = response.data;
|
||||
});
|
||||
}
|
||||
|
||||
total(field) {
|
||||
let total = 0;
|
||||
|
||||
for (let entry of this.entries)
|
||||
total += entry[field];
|
||||
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$scope', '$http'];
|
||||
|
|
|
@ -58,4 +58,18 @@ describe('component vnTravelSummary', () => {
|
|||
expect(controller.entries).toEqual('I am the entries');
|
||||
});
|
||||
});
|
||||
|
||||
describe('total()', () => {
|
||||
it('should calculate the total amount of a given property for every row', () => {
|
||||
controller.entries = [
|
||||
{id: 1, freightValue: 1, packageValue: 2, cc: 0.01},
|
||||
{id: 2, freightValue: 1, packageValue: 2, cc: 0.01},
|
||||
{id: 3, freightValue: 1, packageValue: 2, cc: 0.01}
|
||||
];
|
||||
|
||||
expect(controller.total('freightValue')).toEqual(3);
|
||||
expect(controller.total('packageValue')).toEqual(6);
|
||||
expect(controller.total('cc')).toEqual(0.03);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue