An example of a query in the backend controller
public function show($id)
{
$structural = DB::table('attendance')->where('payroll_daily_id',$id)
->where('assignment','STRUCTURAL')
->select('payroll_daily_attendance.*')
->get();
$fetch = [];
foreach($structural as $key){
if(!isset($fetch[$key->wrk_id]['total_ot']) && !isset($fetch[$key->wrk_id]['total_days']) ){
$fetch[$key->wrk_id]['total_ot'] = 0;
$fetch[$key->wrk_id]['total_days'] = 0;
}
$fetch[$key->wrk_id]['wrk_id'] = $key->wrk_id;
$fetch[$key->wrk_id]['daily_rate'] = $key->rate;
$fetch[$key->wrk_id]['date'][$key->date]['work_hours'] = $key->reg_hour;
$fetch[$key->wrk_id]['date'][$key->date]['adj_hour'] = $key->adj_hour;
$fetch[$key->wrk_id]['total_ot'] += $key->ot_adj;
$fetch[$key->wrk_id]['total_days'] += $key->reg_hour;
}
return $fetch;
}
The displayed results from the executed query
1: {total_ot: 1, total_days: 24, wrk_id: 1, daily_rate: 575,...}
daily_rate: 575
date: {2020-09-24: {work_hours: 8, adj_hour: 0}, 2020-09-25: {work_hours: 8, adj_hour: 0},...}
total_days: 24
total_ot: 1
wrk_id: 1
2: {total_ot: 0, total_days: 48, wrk_id: 2, daily_rate: 450,...}
daily_rate: 450
date: {2020-09-24: {work_hours: 8, adj_hour: 0}, 2020-09-25: {work_hours: 8, adj_hour: 0},...}
total_days: 48
total_ot: 0
wrk_id: 2
3: {total_ot: 0, total_days: 8, wrk_id: 3, daily_rate: 560,...}
daily_rate: 560
date: {2020-09-24: {work_hours: 8, adj_hour: 0}}
total_days: 8
total_ot: 0
wrk_id: 3
Calculation process implemented in my Vue application
<table class="table table-sm borderless">
<thead>
<th></th>
<th></th>
</thead>
<tbody>
<tr v-for="fetch in assignmentTotal">
<td style="height:10px;">Structural</td>
<td style="height:10px;">{{(fetch.total_days / 8) * fetch.daily_rate}}</td>
</tr>
</tbody>
</table>