Skip to content

Commit

Permalink
Merge pull request #227 from dbarzin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dbarzin authored Nov 12, 2024
2 parents e514e3b + 3dd2e88 commit 081d64c
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,33 +471,30 @@ private function generateActionPlanTable(
string|null $framework
) {
$actions =
DB::table('controls as c1')
DB::table('actions')
->select([
'c1.id',
'c1.action_plan',
'c1.score',
'c1.name',
'c1.plan_date',
'c1.realisation_date',
'c2.id as next_id',
'c2.plan_date as next_date',
'c1.action_plan',
'actions.id',
'actions.reference',
'actions.type',
'actions.scope',
'actions.name',
'actions.cause',
'actions.remediation',
'actions.due_date',
])
->leftjoin('controls as c2', 'c1.next_id', '=', 'c2.id')
->whereIn('c1.score', [1,2])
->whereIn('c2.status', [0,1])
->whereNull('c2.next_id');
->where('status',0);
// filter on framework
if ($framework !== null) {
$actions = $actions
->join('control_measure', 'c1.id', '=', 'control_measure.control_id')
->join('measures', 'measures.id', '=', 'control_measure.measure_id')
->join('action_measure', 'actions.id', '=', 'action_measure.action_id')
->join('measures', 'measures.id', '=', 'action_measure.measure_id')
->join('domains', 'domains.id', '=', 'measures.domain_id')
->where('domains.framework', '=', $framework);
}
// get it
$actions = $actions->get();

/*
// Fetch measures for all controls in one query
$controlMeasures = DB::table('control_measure')
->select([
Expand All @@ -514,6 +511,7 @@ private function generateActionPlanTable(
// Group measures by control_id
$measuresByControlId = $controlMeasures->groupBy('control_id');
// map clauses
foreach ($actions as $control) {
$control->measures = $measuresByControlId->get($control->id, collect())->map(function ($controlMeasure) {
Expand All @@ -524,6 +522,7 @@ private function generateActionPlanTable(
];
});
}
*/

$table = new Table(
[
Expand All @@ -541,33 +540,41 @@ private function generateActionPlanTable(
$table->addCell(13000, ['bgColor' => '#FFD5CA'])
->addText(trans('cruds.report.action_plan.title'), ['bold' => true]);
$table->addCell(3000, ['bgColor' => '#FFD5CA'])
->addText(trans('cruds.report.action_plan.next'), ['bold' => true]);
->addText(trans('cruds.action.fields.due_date'), ['bold' => true]);

// table content
foreach ($actions as $action) {
$table->addRow();
$table->addCell(2000)->addText(
$action->measures->implode('clause', ', '),
$action->reference,
null,
['align' => 'center']
);
$table->addCell(13000)->addText(
$action->name,
null,
['bold' => true],
['align' => 'left']
);
$table->addCell(3000)->addText(
$action->next_date,
$action->due_date,
null,
['align' => 'left']
);

$table->addRow();
$section = $table->addCell(18000, ['gridSpan' => 3]);
$textlines = explode("\n", $action->action_plan);
$textlines = explode("\n", $action->cause);
foreach ($textlines as $textline) {
$section->addText($textline);
}

$table->addRow();
$section = $table->addCell(18000, ['gridSpan' => 3]);
$textlines = explode("\n", $action->remediation);
foreach ($textlines as $textline) {
$section->addText($textline);
}

}

$templateProcessor->setComplexBlock('action_plans_table', $table);
Expand Down

0 comments on commit 081d64c

Please sign in to comment.