You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
monitor-doc/app/Http/Controllers/GeneralController.php

46 lines
1.3 KiB
PHTML

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Company;
2 years ago
use App\Models\Category;
use App\Models\Document;
class GeneralController extends Controller
{
public function index(Request $request)
{
$companies = [];
if($request->user()->region_id != null) {
$companies = Company::where('region_id', $request->user()->region_id)->pluck('id')->toArray();
}
2 years ago
$count = 0;
$categories = Category::all();
foreach($categories as $category) {
if(count($companies) > 0) {
$documents = $category->documents()->whereIn('company_id', $companies)->get();
} else {
$documents = $category->documents;
}
foreach($documents as $docs) {
2 years ago
if ($docs->is_close_due != 0) {
$count += 1;
}
}
}
if(count($companies) > 0) {
$update = Document::whereDate('due_date', '<=', now()->toDateString())->whereIn('company_id', $companies)->count();
} else {
$update = Document::whereDate('due_date', '<=', now()->toDateString())->count();
}
return inertia('Dashboard', [
2 years ago
'count_active' => $count,
'count_update' => $update
]);
}
}