Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function create(array $input)
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'address' => ['required', 'string'],
'phone' => ['required', 'numbers', 'max:11'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this->passwordRules(),
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
Expand All @@ -33,9 +35,11 @@ public function create(array $input)
return tap(User::create([
'name' => $input['name'],
'email' => $input['email'],
'phone' => $input['phone'],
'address' => $input['address'],
'password' => Hash::make($input['password']),
'google_id' => null,
])->assignRole('user'), function (User $user) {
])->assignRole('User'), function (User $user) {
$this->createTeam($user);
});
});
Expand Down
1 change: 1 addition & 0 deletions app/Actions/Fortify/PasswordValidationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trait PasswordValidationRules
*/
protected function passwordRules()
{
(new Password)->length(10);
return ['required', 'string', new Password, 'confirmed'];
}
}
3 changes: 3 additions & 0 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function update($user, array $input)
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'address' => ['required', 'string'],
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
'phone' => ['numeric','min:11', 'nullable'],
])->validateWithBag('updateProfileInformation');
Expand All @@ -36,6 +37,7 @@ public function update($user, array $input)
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'address' => $input['address'],
'phone' => $input['phone'],
])->save();
}
Expand All @@ -53,6 +55,7 @@ protected function updateVerifiedUser($user, array $input)
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'address' => $input['address'],
'email_verified_at' => null,
'phone' => $input['phone'],
])->save();
Expand Down
98 changes: 65 additions & 33 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,42 @@

namespace App\Http\Controllers;

use App\Http\Livewire\AssignDepartments;
use App\Models\AssignDepartment;
use App\Models\AssignedDepartment;
use App\Models\cellNumber;
use App\Models\Departments;
use App\Models\Reports;
use App\Models\ReportType;
use App\Models\User;
use Illuminate\Support\Facades\DB as FacadesDB;
use PhpParser\Node\Expr\Assign;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;

use Barryvdh\DomPDF\Facade\Pdf as FacadePdf;
use Carbon\Carbon;
use Illuminate\Pagination\PaginationServiceProvider;

class AdminController extends Controller
{
public function index()
{
$reports = Reports::with('reports', 'locations')->latest()->get();

$reports = Reports::with('reports', 'locations')->paginate(15);

if($reports->isEmpty()) {
$location = [];
$incidents = [];
return view ('admin.adminDashboard')->with(['reports' => $reports, 'location' => $location, 'incidents' => $incidents]);
}
$incident = [];
$count = [];
$sum = [];
$departments = [];

foreach($reports as $report){
$location[] = FacadesDB::table('locations')->where('id', $report->location_id)->latest()->get();
}

foreach($reports as $report){
$incidents[] = FacadesDB::table('report_types')->where('id', $report->id)->latest()->get();
return view ('admin.adminDashboard')->with(['reports' => $reports, 'location' => $location, 'incidents' => $incidents, 'incident' => $incident, 'count' => $count, 'sum' => $sum, 'departments' => $departments]);
}

return view ('admin.adminDashboard')->with(['reports' => $reports, 'location' => $location, 'incidents' => $incidents]);

$location = [];
$incidents = [];
$incident = [];
$count = [];
$sum = [];
$departments = [];

return view ('admin.adminDashboard')->with(['reports' => $reports, 'location' => $location, 'incidents' => $incidents, 'incident' => $incident, 'count' => $count, 'sum' => $sum, 'departments' => $departments]);
}

public function admin()
Expand Down Expand Up @@ -69,7 +71,7 @@ public function report()
public function destroy($id)
{
cellNumber::destroy($id);
return redirect('admin/admin')->with('flash_message', 'Post deleted successfully!');
return view('admin.admin')->with('flash_message', 'Post deleted successfully!');
}

public function edit($id)
Expand Down Expand Up @@ -106,7 +108,7 @@ public function view($id)
public function destroyReport($id)
{
Reports::destroy($id);
return redirect('admin/dashboard')->with('flash_message', 'Post Deleted successfully!');
return view('admin.adminDashboard')->with('flash_message', 'Post Deleted successfully!');
}

public function viewReport($id)
Expand All @@ -128,7 +130,7 @@ public function viewReport($id)
}

public function users() {
$users = User::all();
$users = User::latest()->paginate(1);

return view('admin.UsersRoles')->with('users', $users);
}
Expand All @@ -153,22 +155,20 @@ public function viewUser($id)
$incidents[] = FacadesDB::table('report_types')->where('id', $report->id)->latest()->get();
}

return view('admin.viewUser')->with(['user' => $user, 'count' => $count, 'reports' => $reports, 'location' => $location, 'incidents' => $incidents]);

return view('admin.viewUser')->with(['user' => $user, 'count' => $count, 'reports' => $reports, 'location' => $location, 'incidents' => $incidents]);
}

// Delete User - Route::middleware(rele:super-admin)->...
public function deleteUser($id)
{
if(Auth()->user()->id == $id) {
return redirect('admin\UsersRoles')->with('flash_message', 'This action is invalid');
return redirect('admin/all/users')->with('flash_message', 'This action is invalid');
}
else {
$user = User::where('id', $id)->get();
$user->destroy();
User::where('id', $id)->delete();
}

return redirect('admin\UsersRoles')->with('flash_message', 'User Deleted successfully!');
return redirect('admin/all/users')->with('flash_message', 'User Deleted successfully!');
}


Expand All @@ -188,10 +188,9 @@ public function assignRoleSuperAdmin($id) {
}

foreach($users as $user){
$user->syncRoles('super-admin');
$user->syncRoles('Admin');
}
return redirect('admin/all/users')->with('flash_message', 'User Role Updated successfully!');

}

// Change User Role To "admin"
Expand All @@ -201,7 +200,7 @@ public function assignRoleAdmin($id) {
return redirect('admin/all/users')->with('flash_message', 'This action is invalid');
}
foreach($users as $user){
$user->syncRoles('admin');
$user->syncRoles('Department');
}
return redirect('admin/all/users')->with('flash_message', 'User Role Updated successfully!');
}
Expand All @@ -214,13 +213,11 @@ public function assingRoleUser($id) {
}

foreach($users as $user){
$user->syncRoles('user');
$user->syncRoles('User');
}
return redirect('admin/all/users')->with('flash_message', 'User Role Updated successfully!');
}



/*
--------------------------------------------------
Update Report Status Controller
Expand Down Expand Up @@ -276,4 +273,39 @@ public function updateStatusRejected($id){
session()->flash('flash_message','An error occurred while processing your request');
return $controller->viewReport($id);
}

public function exportAsPDF()
{
$departments = Departments::all();

foreach ($departments as $department) {
$name[] = $department->department;
}

foreach($departments as $department){
$assigns[] = FacadesDB::table('assigns')->where('department_id', $department->id)->get();
}
$now = Carbon::now();
$startOfWeek = $now->startOfWeek()->format('Y-m-d H:i');
$endOfWeek = $now->endOfWeek()->format('Y-m-d H:i');

$reports = Reports::whereBetween('created_at', [$startOfWeek, $endOfWeek])->get();

foreach($reports as $report){
$i[] = $report->report_id;
}

$i = 0;
foreach($assigns as $assign){

$incidents[] = $reports->where('report_id', $assign[$i]->incidents_id)->count();
$i+1;

}

$count = $incidents;

$pdf = FacadePdf::loadView('pdf.reports', ['departments' => $name, 'count' => $count]);
return $pdf->download('reports.pdf');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/FacebookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function handleFacebookCallback() // this function get user login of goo
// 'password' => encrypt('123456dummy')
//'password' => Hash::make($user['password']),

])->assignRole('user');
])->assignRole('User');

Auth::login($newUser);

Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Auth/GoogleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ public function handleGoogleCallback() // this function get user login of googl
Auth::login($finduser);

return redirect('portal/portal');

}else{
$newUser = User::create([
'name' => $user->name,
'email' => $user->email,
'google_id'=> $user->id,
'profile_photo_url' => $user->getAvatar(),
])->assignRole('user');
])->assignRole('User');

Auth::login($newUser);

Expand Down
7 changes: 6 additions & 1 deletion app/Http/Controllers/Auth/PhoneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ class PhoneController extends Controller
{
public function viewVerifyPhone() {
$user = Auth()->user();

if($user->phone == null){
return view('profile.show')->with('message', 'Please save your Phone number before clicking get verifed');
}

if ($user->verification_code == null){
$verify = new PhoneController;
$verify;
$verify->sendVerification();
return view ('auth.verify-phone');
}

if ($user->phone_verified_at !== null){
Expand Down
10 changes: 6 additions & 4 deletions app/Http/Controllers/portalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function reports() {
if($reports->isEmpty()){
$reports = [];
$incidents = [];
$count = [];
}

foreach($reports as $report){
Expand All @@ -71,7 +72,7 @@ public function reports() {
$uniques = array_unique($incidents); // $votes = Vote::where('vote_type',1)->where('something',$something)->count();

// dd($uniques, $reports);
// $count = [];

$i = 0;
foreach($uniques as $unique){
$count[] = $reports->where('report_id', $unique[$i]->id)->count();
Expand Down Expand Up @@ -106,17 +107,18 @@ public function contact($report_id)
public function message($words)
{
$incidentId = (int)$words[0];
$locationId = (int)$words[2];
$locationId = (int)$words[3];

$incident = FacadesDB::table('report_types')->where('id', $incidentId)->get();
$location = FacadesDB::table('locations')->where('id', $locationId)->get();
$time = Carbon::now()->toDateTimeString()/* ->format('d/m/y/') */;

$words = [
"Incident Type: ", $incident[0]->report_name,
"\nDescription: ", $words[1],
"\nNumber of Victims: ", $words[1],
"\nNumber of Suspects: ", $words[2],
"\nLocation: ", $location[0]->location_name,
"\n\nSpecific Location: ", $words[3],
"\n\nSpecific Location: ", $words[4],
"\nDate: ", $time
];

Expand Down
30 changes: 27 additions & 3 deletions app/Http/Livewire/AdminLatestReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,38 @@

namespace App\Http\Livewire;

use App\Models\Reports;
use Carbon\Carbon;
use Livewire\Component;

class AdminLatestReports extends Component
{
public $reports;

public function mount($reports)
{

public function mount($reports){

/*
$monday = [];
$tuesday = [];
$wednesday = [];
$thursday = [];
$friday = [];
$saturday = [];
$sunday = [];
*/

$monday = Reports::whereDate('created_at', Carbon::now()->startOfWeek()->next(Carbon::MONDAY))->count(); // Monday
$tuesday = Reports::whereDate('created_at', Carbon::now()->startOfWeek()->next(Carbon::TUESDAY))->count(); // Tuesday
$wednesday = Reports::whereDate('created_at', Carbon::now()->startOfWeek()->next(Carbon::WEDNESDAY))->count(); // Wednesday
$thursday = Reports::whereDate('created_at', Carbon::now()->startOfWeek()->next(Carbon::THURSDAY))->count(); // Thursday
$friday = Reports::whereDate('created_at', Carbon::now()->startOfWeek()->next(Carbon::FRIDAY))->count(); // Friday
$saturday = Reports::whereDate('created_at', Carbon::now()->startOfWeek()->next(Carbon::SATURDAY))->count(); // Saturday
$sunday = Reports::whereDate('created_at', Carbon::now()->startOfWeek()->next(Carbon::SUNDAY))->count(); // Sunday

$reports = ['monday' => $monday, 'tuesday' => $tuesday, 'wednesday' => $wednesday, 'thursday' => $thursday, 'friday' => $friday, 'saturday' => $saturday, 'sunday' => $sunday];

// dd($reports);

$this->reports = $reports;
}

Expand Down
Loading