@extends('layouts.main_frontend') @section('title','RCSA - Aggregated Questionaire') @section('main-content') @php if(count($risks)<1){ $risks = [json_decode(json_encode(['id'=>1,'reference_no'=>'12345']))]; } $clr = $matrix['matrix_layout']['colours']; if(empty($clr)){ $clr = @$colors[$organization->matrix_length]; if(empty($clr)){ $clr = $colors[3]; } } //dd($matrix); $matrix_controls = $matrix['matrix_layout']['controls']; $matrix_risk = $matrix['matrix_layout']['risk']; $matrix_calc = json_decode($matrix['matrix_layout']['calc'], true); //echo "
"; print_r((array)$matrix_calc); exit; //dd($matrix_calc[4][3]); $thresold = $matrix['matrix_layout']['thresold']; //dd($thresold); @endphp Questionaire @php $i=0; @endphp @if(!empty($risks)) @foreach($risks as $key=>$risk) @php $i++; @endphp {{$risk->reference_no}} @if($i%3==0)@endif @endforeach @endif @if(!empty($risks)) @foreach($risks as $key=>$risk) 0) style="display:none" @endif data-index="{{$key}}"> @csrf Organization Department Name / Business Entity / Process RCSA Ref. No Risk Ref. No. Risk Event Name Risk Description {{$risk->description ?? ''}} @if(!empty($questionnaires[$risk->id])) @php $totalControl = count($riskControls[$risk->id]) @endphp Responses Respondent Name Risk Likelihood Risk Impact @foreach($riskControls[$risk->id] as $rc) {{$rc->control_reference_no}} @endforeach Calculated Residual Risk Perceived Residual Risk @php $agg_resp = [0,0,0,0]; $agg_controls=[]; $divisor = 0; $resp_best_control = array(); //$temp_design = $temp_performance = 0; @endphp @foreach($questionnaires[$risk->id] as $r_key => $qr) @php $controlAnswerCount = 0; @endphp {{$users[$qr->respondent_id]}} {{ucwords($matrix['likelihood'][$qr->inherent_risk_likelyhood])}} {{ucwords($matrix['impact'][$qr->inherent_risk_impact])}} @php $agg_resp[0] += intval($qr->inherent_risk_likelyhood); $agg_resp[1] += intval($qr->inherent_risk_impact); $designs = explode(',',$qr->control_designs); $performance = explode(',',$qr->control_performance); $internal_best_control = 0; $best_control = 5; @endphp @foreach($designs as $key=>$d) @php $controlAnswerCount++; //$internal_best_control = $matrix_controls[$d][$performance[$key]]; $internal_best_control = $matrix_controls[$performance[$key]][$d]; //echo $d.'__'.$performance[$key].'==>'.$internal_best_control.' = '.$best_control; if($internal_best_control <= $best_control) { //echo 'Yes'; $best_control = $internal_best_control; $resp_best_control[$r_key]['design'] = $matrix['control_design'][$d]; $resp_best_control[$r_key]['performance'] = $matrix['control_performance'][$performance[$key]]; $resp_best_control[$r_key]['intersect'] = $best_control; $resp_best_control[$r_key]['design_value'] = $d; $resp_best_control[$r_key]['peformace_value'] = $performance[$key]; } //echo ""; @endphp {{ucwords($matrix['control_design'][$d])}} {{ucwords($matrix['control_performance'][$performance[$key]])}} @php if(!isset($agg_controls[$key][0])) $agg_controls[$key][0] = 0; if(!isset($agg_controls[$key][1])) $agg_controls[$key][1] = 0; $agg_controls[$key][0] += intval($d); $agg_controls[$key][1] += intval($performance[$key]); @endphp @endforeach @php $remainControl = $totalControl-$controlAnswerCount; if($remainControl > 0) { for($c=0;$c<$remainControl; $c++) { echo ' '; } } @endphp {{ucwords($matrix['residual_risk'][$qr->calculated_residual_risk_impact])}} {{ucwords($matrix['residual_risk'][$qr->perceived_residual_risk_impact])}} @php $agg_resp[2] += intval($qr->calculated_residual_risk_impact); $agg_resp[3] += intval($qr->perceived_residual_risk_impact); $divisor++; @endphp @endforeach Aggregated Response @php //$final_likelihood = round($agg_resp[0]/$divisor); //$final_impact = round($agg_resp[1]/$divisor); $final_likelihood = number_format($agg_resp[0]/$divisor, 2, '.', ''); $final_impact = number_format($agg_resp[1]/$divisor, 2, '.', ''); if($final_likelihood <= $thresold[1]) { $final_likelihood = 1; } else if($final_likelihood > $thresold[1] && $final_likelihood <= $thresold[2]) { $final_likelihood = 2; } else if($final_likelihood > $thresold[2] && $final_likelihood <= $thresold[3]) { $final_likelihood = 3; } else if($final_likelihood > $thresold[3] && $final_likelihood <= $thresold[4]) { $final_likelihood = 4; } else if($final_likelihood > $thresold[4]) { $final_likelihood = 5; } if($final_impact <= $thresold[1]) { $final_impact = 1; } else if($final_impact > $thresold[1] && $final_impact <= $thresold[2]) { $final_impact = 2; } else if($final_impact > $thresold[2] && $final_impact <= $thresold[3]) { $final_impact = 3; } else if($final_impact > $thresold[3] && $final_impact <= $thresold[4]) { $final_impact = 4; } else if($final_impact > $thresold[4]) { $final_impact = 5; } //$intersect_residual = $matrix_risk[$final_likelihood][$final_impact]; $intersect_residual = $matrix_risk[$final_impact][$final_likelihood]; @endphp {{@ucwords($matrix['likelihood'][$final_likelihood])}} {{@ucwords($matrix['impact'][$final_impact])}} @php $average_design = array_sum(array_column($resp_best_control, 'design_value')); $average_performance = array_sum(array_column($resp_best_control, 'peformace_value')); //echo ""; print_r($resp_best_control); //$final_design = round($average_design/$divisor); //$final_performance = round($average_performance/$divisor); $final_design = number_format($average_design/$divisor, 2, '.', ''); $final_performance = number_format($average_performance/$divisor, 2, '.', ''); if($final_design <= $thresold[1]) { $final_design = 1; } else if($final_design > $thresold[1] && $final_design <= $thresold[2]) { $final_design = 2; } else if($final_design > $thresold[2] && $final_design <= $thresold[3]) { $final_design = 3; } else if($final_design > $thresold[3] && $final_design <= $thresold[4]) { $final_design = 4; } else if($final_design > $thresold[4]) { $final_design = 5; } if($final_performance <= $thresold[1]) { $final_performance = 1; } else if($final_performance > $thresold[1] && $final_performance <= $thresold[2]) { $final_performance = 2; } else if($final_performance > $thresold[2] && $final_performance <= $thresold[3]) { $final_performance = 3; } else if($final_performance > $thresold[3] && $final_performance <= $thresold[4]) { $final_performance = 4; } else if($final_performance > $thresold[4]) { $final_performance = 5; } //$intersect_control = $matrix_controls[$final_design][$final_performance]; $intersect_control = $matrix_controls[$final_performance][$final_design]; @endphp {{@ucwords($matrix['control_design'][$final_design])}} {{@ucwords($matrix['control_performance'][$final_performance])}} {{-- @foreach($agg_controls as $row) {{@ucwords($matrix['control_design'][round($row[0]/$divisor)])}} {{@ucwords($matrix['control_performance'][round($row[1]/$divisor)])}} @endforeach --}} @php $intersect_calculated_risk = $matrix_calc[$intersect_residual][$intersect_control]; //echo $intersect_residual; //$intersect_calculated_risk = round($agg_resp[2]/$divisor); @endphp {{@ucwords($matrix['residual_risk'][$intersect_calculated_risk])}} {{@ucwords($matrix['residual_risk'][round($agg_resp[3]/$divisor)])}} @endif @endforeach Comments {{ isset($model->comment) ? $model->comment : old('comment') }} @can('approve_questionnaire.edit') @if(isset($model->is_approved) && $model->is_approved == 'yes') @else Back Submit @endif @endcan @else Please select risk for this RCSA planner @endif @endsection @section('additionaljs') @endsection
{{ucwords($matrix['control_design'][$d])}}
{{ucwords($matrix['control_performance'][$performance[$key]])}}
{{ucwords($matrix['residual_risk'][$qr->calculated_residual_risk_impact])}}
{{@ucwords($matrix['likelihood'][$final_likelihood])}}
{{@ucwords($matrix['impact'][$final_impact])}}
"; print_r($resp_best_control); //$final_design = round($average_design/$divisor); //$final_performance = round($average_performance/$divisor); $final_design = number_format($average_design/$divisor, 2, '.', ''); $final_performance = number_format($average_performance/$divisor, 2, '.', ''); if($final_design <= $thresold[1]) { $final_design = 1; } else if($final_design > $thresold[1] && $final_design <= $thresold[2]) { $final_design = 2; } else if($final_design > $thresold[2] && $final_design <= $thresold[3]) { $final_design = 3; } else if($final_design > $thresold[3] && $final_design <= $thresold[4]) { $final_design = 4; } else if($final_design > $thresold[4]) { $final_design = 5; } if($final_performance <= $thresold[1]) { $final_performance = 1; } else if($final_performance > $thresold[1] && $final_performance <= $thresold[2]) { $final_performance = 2; } else if($final_performance > $thresold[2] && $final_performance <= $thresold[3]) { $final_performance = 3; } else if($final_performance > $thresold[3] && $final_performance <= $thresold[4]) { $final_performance = 4; } else if($final_performance > $thresold[4]) { $final_performance = 5; } //$intersect_control = $matrix_controls[$final_design][$final_performance]; $intersect_control = $matrix_controls[$final_performance][$final_design]; @endphp {{@ucwords($matrix['control_design'][$final_design])}} {{@ucwords($matrix['control_performance'][$final_performance])}} {{-- @foreach($agg_controls as $row) {{@ucwords($matrix['control_design'][round($row[0]/$divisor)])}} {{@ucwords($matrix['control_performance'][round($row[1]/$divisor)])}} @endforeach --}}
{{@ucwords($matrix['control_design'][$final_design])}}
{{@ucwords($matrix['control_performance'][$final_performance])}}
{{@ucwords($matrix['control_design'][round($row[0]/$divisor)])}}
{{@ucwords($matrix['control_performance'][round($row[1]/$divisor)])}} @endforeach --}}
{{@ucwords($matrix['residual_risk'][$intersect_calculated_risk])}}