add peratus votes on final report

This commit is contained in:
nurafrinaalimi16
2024-04-18 13:35:15 +08:00
parent 19570442f6
commit 0e28e4f8cd
@@ -1,48 +1,47 @@
<template>
<div class="container">
<div class="row">
<div class="col-md-12">
<div v-for="position in positions">
<h5>{{ position.name }}</h5>
<div class="table-responsive">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th width="10%">No. Anggota</th>
<th width="30%">Nama</th>
<th width="20%">Partylist</th>
<th width="20%">Unit</th>
<th width="20%">Undian</th>
</tr>
</thead>
<tbody>
<tr v-for="result in results" v-if="result.position_id==position.id">
<td>{{ getNominee(result.nominee_id)['student_id'] }}</td>
<td>{{ getNominee(result.nominee_id)['name'] }}</td>
<td>{{ getPartylist(getNominee(result.nominee_id)['partylist_id']) }}</td>
<td>{{ getNominee(result.nominee_id)['Unit'] }}</td>
<td>{{ result.votes}}</td>
</tr>
<tr v-for="no_vote in no_votes" v-if="no_vote.position_id==position.id">
<td>{{ no_vote.student_id }}</td>
<td>{{ no_vote.name }}</td>
<td>{{ getPartylist(no_vote.partylist_id) }}</td>
<td>{{ no_vote.unit }}</td>
<td>0</td>
</tr>
</tbody>
</table>
<div class="container">
<div class="row">
<div class="col-md-12">
<div v-for="position in positions">
<h5>{{ position.name }}</h5>
<div class="table-responsive">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th width="10%">No. Anggota</th>
<th width="30%">Nama</th>
<th width="20%">Unit</th>
<th width="20%">Undian</th>
<th width="20%">Peratus (%)</th>
</tr>
</thead>
<tbody>
<tr v-for="result in results" v-if="result.position_id == position.id">
<td>{{ getNominee(result.nominee_id)['no_anggota'] }}</td>
<td>{{ getNominee(result.nominee_id)['name'] }}</td>
<td>{{ getNominee(result.nominee_id)['unit'] }}</td>
<td>{{ result.votes }}</td>
<td>{{ calculatePercentage(result.votes, position.id) }}</td>
</tr>
<tr v-for="no_vote in no_votes" v-if="no_vote.position_id == position.id">
<td>{{ no_vote.no_anggota }}</td>
<td>{{ no_vote.name }}</td>
<td>{{ no_vote.unit }}</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
<hr />
</div>
<hr/>
</div>
</div>
</div>
</div>
</template>
<script>
export default{
data: function() {
export default {
data: function () {
return {
nominees: [],
results: [],
@@ -66,21 +65,29 @@ export default{
if (id == partylists[i]['id'])
return partylists[i]['name'];
return 'No Partylist';
},
calculatePercentage(votes, positionId) {
const totalVotes = this.results
.filter(result => result.position_id === positionId)
.reduce((total, result) => total + result.votes, 0);
return ((votes / totalVotes) * 100).toFixed(2);
}
},
created: function () {
this.util.notify('Loading please wait...', 'loading');
var vm = this;
axios.get(config.API+'election/result/'+this.election_id)
.then(response=>{
axios.get(config.API + 'election/result/' + this.election_id)
.then(response => {
$.notifyClose();
vm.nominees = response.data.nominee;
vm.results = response.data.result;
vm.partylists = response.data.partylist;
vm.positions = response.data.position;
})
.catch(error=>{
.catch(error => {
$.notifyClose();
vm.util.showResult(error, 'error');
})