add peratus votes on final report

This commit is contained in:
nurafrinaalimi16
2024-04-18 13:35:15 +08:00
parent 19570442f6
commit 0e28e4f8cd
@@ -10,23 +10,22 @@
<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>
<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)['student_id'] }}</td>
<td>{{ getNominee(result.nominee_id)['no_anggota'] }}</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>{{ 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.student_id }}</td>
<td>{{ no_vote.no_anggota }}</td>
<td>{{ no_vote.name }}</td>
<td>{{ getPartylist(no_vote.partylist_id) }}</td>
<td>{{ no_vote.unit }}</td>
<td>0</td>
</tr>
@@ -66,6 +65,14 @@ 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);
}
},