Skip to content

Commit

Permalink
code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarzin committed Sep 14, 2023
1 parent 8262cbb commit 2fedff9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 33 deletions.
10 changes: 5 additions & 5 deletions app/Http/Controllers/ControlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ public function domains(Request $request)
$domains = DB::table('domains')
->select(DB::raw('distinct domains.id, domains.title'))
->join('controls', 'domains.id', '=', 'controls.domain_id')
->whereNull("realisation_date")
->orderBy("domains.title")
->whereNull('realisation_date')
->orderBy('domains.title')
->get();

// get all scopes
Expand Down Expand Up @@ -440,8 +440,8 @@ public function measures(Request $request)
$domains = DB::table('domains')
->select(DB::raw('distinct domains.id, domains.title, domains.description'))
->join('controls', 'domains.id', '=', 'controls.domain_id')
->whereNull("realisation_date")
->orderBy("domains.title")
->whereNull('realisation_date')
->orderBy('domains.title')
->get();

// get all scopes
Expand Down Expand Up @@ -645,7 +645,7 @@ public function doPlan(Request $request)
// Check duplicate control on same scope
if (Control::whereNull('realisation_date')
->where('id', '<>', $control->id)
->where("measure_id","=",$control->measure_id)
->where('measure_id', '=', $control->measure_id)
->where('scope', '=', $request->scope)
->count() > 0) {
return back()
Expand Down
57 changes: 29 additions & 28 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public function index(Request $request)
->count();

// count control never made
$controls_never_made = DB::select('
$controls_never_made = DB::select(
'
select domain_id
from controls c1
where realisation_date is null and
Expand All @@ -62,37 +63,37 @@ public function index(Request $request)
);

// Last controls made by measures
$active_controls =
$active_controls =
DB::table('controls as c1')
->select(['c1.id', 'c1.measure_id', 'domains.title', 'c1.realisation_date', 'c1.score'])
->join('controls as c2', 'c2.id', '=', 'c1.next_id')
->join('domains', 'domains.id', '=', 'c1.domain_id')
->whereNull("c2.realisation_date")
->whereNull('c2.realisation_date')
->orderBy('c1.id')
->get();
// dd($active_controls);

// Get controls todo
$controls_todo =
DB::table("controls as c1")
->select([
"c1.id",
"c1.measure_id",
"c1.name",
"c1.scope",
"c1.clause",
"c1.domain_id",
"c1.plan_date",
"c2.id as prev_id",
"c2.realisation_date as prev_date",
"c2.score as score",
"domains.title as domain"
])
$controls_todo =
DB::table('controls as c1')
->select([
'c1.id',
'c1.measure_id',
'c1.name',
'c1.scope',
'c1.clause',
'c1.domain_id',
'c1.plan_date',
'c2.id as prev_id',
'c2.realisation_date as prev_date',
'c2.score as score',
'domains.title as domain',
])
->join('controls as c2', 'c1.id', '=', 'c2.next_id')
->join('domains', 'domains.id', '=', 'c1.domain_id')
->whereNull("c1.realisation_date")
->where("c1.plan_date", "<", Carbon::today()->addDays(30)->format('Y-m-d'))
->orderBy("c1.plan_date")
->whereNull('c1.realisation_date')
->where('c1.plan_date', '<', Carbon::today()->addDays(30)->format('Y-m-d'))
->orderBy('c1.plan_date')
->get();
// dd($plannedMeasurements);

Expand Down Expand Up @@ -122,14 +123,14 @@ public function index(Request $request)
// Count number of action plans
$action_plans_count =
DB::table('controls as c1')
->leftjoin('controls as c2', 'c1.id', '=', 'c2.next_id')
->whereNull("c1.realisation_date")
->where(function ($query) {
return $query
->where("c2.score","=",1)
->orWhere("c2.score","=",2);
->leftjoin('controls as c2', 'c1.id', '=', 'c2.next_id')
->whereNull('c1.realisation_date')
->where(function ($query) {
return $query
->where('c2.score', '=', 1)
->orWhere('c2.score', '=', 2);
})
->count();
->count();

$request->session()->put('action_plans_count', $action_plans_count);

Expand Down

0 comments on commit 2fedff9

Please sign in to comment.