added logic for updating user profile plus other bug fixes

This commit is contained in:
Kwesi Banson Jnr
2026-03-16 16:41:32 +00:00
parent 9cd017fb9a
commit 72180de8e4
30 changed files with 1346 additions and 49 deletions

View File

@@ -39,36 +39,61 @@ class ClientsController extends Controller
// dd('foo bar');
return view('client.index-inactive', $data);
}
public function indexBak(){
$client_arr = new Models\Client;
$client_arr = $client_arr->with('auth_user_info','country_info', 'created_by_info')->orderBy('name', 'ASC')->paginate(10);
$data = [
'page_title' => 'Clients',
'current_user' => session('current_user')
];
return view('client.index-rawjs', $data);
}
public function getClientJson(Request $request){
// $this->log_query();
$client_arr = \DB::table('clients')
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->join('flags AS flags', 'flags.country', '=', 'clients.country')
->select('clients.id', 'clients.name', 'clients.status','clients.progress_indicator_score', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy', 'flags.url AS theflag')
->whereRaw("status NOT IN ('inactive', 'Cancelled')")
->orderBy('name', 'ASC')
->get();
// ->paginate(15);
if($request->has('keyword')){
$keyword = $request->keyword;
$client_arr = \DB::table('clients')
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->join('flags AS flags', 'flags.country', '=', 'clients.country')
->select('clients.id','clients.name', 'clients.status', 'clients.progress_indicator_score','clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy', 'flags.url AS theflag')
->whereRaw("clients.name like '%$keyword%' or clients.status like '%$keyword%' OR clients.country like '%$keyword%' OR aumngr.name like '%$keyword%' OR aumodify.name like '%$keyword%' OR clients.progress_indicator_score like '%$keyword%'")
->orderBy('name', 'ASC')
->get();
if (strpos('inactive', $keyword) !== false ) {
// dump('foo bars');
$client_arr = \DB::table('clients')
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->join('flags AS flags', 'flags.country', '=', 'clients.country')
->select('clients.id','clients.name', 'clients.status', 'clients.progress_indicator_score','clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy', 'flags.url AS theflag')
// ->whereRaw("status IN ('Live', 'Prospective')")
->whereRaw("status NOT IN ('inactive', 'Cancelled')")
->whereRaw("clients.name LIKE '%$keyword%' OR clients.country LIKE '%$keyword%' OR aumngr.name like '%$keyword%' OR aumodify.name LIKE '%$keyword%'")
->orderBy('name', 'ASC')
->get();
// foreach ($client_arr as $value) {
// // code...
// dd($value);
// }
dump($client_arr->contains('status', 'inactive'));
}
elseif (strpos('Cancelled', $keyword) !== false ) {
$client_arr = \DB::table('clients')
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->join('flags AS flags', 'flags.country', '=', 'clients.country')
->select('clients.id','clients.name', 'clients.status', 'clients.progress_indicator_score','clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy', 'flags.url AS theflag')
// ->whereRaw("status IN ('Live', 'Prospective')")
->whereRaw("status NOT IN ('inactive', 'Cancelled')")
->whereRaw("clients.name LIKE '%$keyword%' OR clients.country LIKE '%$keyword%' OR aumngr.name LIKE '%$keyword%' OR aumodify.name LIKE '%$keyword%'")
->orderBy('name', 'ASC')
->get();
}else{
$client_arr = \DB::table('clients')
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->join('flags AS flags', 'flags.country', '=', 'clients.country')
->select('clients.id','clients.name', 'clients.status', 'clients.progress_indicator_score','clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy', 'flags.url AS theflag')
->whereRaw("status IN ('Live', 'Prospective')")
->whereRaw("clients.name LIKE '%$keyword%' OR clients.status LIKE '%$keyword%' OR clients.country LIKE '%$keyword%' OR aumngr.name LIKE '%$keyword%' OR aumodify.name LIKE '%$keyword%'")
->orderBy('name', 'ASC')
->get();
}
// ->paginate(15);
}
@@ -82,7 +107,7 @@ class ClientsController extends Controller
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->select('clients.id', 'clients.name', 'clients.status', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy')
->whereRaw("status <> 'Inactive'")
->paginate(10);
if($request->has('keyword')){
@@ -91,7 +116,8 @@ class ClientsController extends Controller
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->select('clients.id','clients.name', 'clients.status', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy')
->whereRaw("clients.name like '%$keyword%' or clients.status like '%$keyword%' OR clients.country like '%$keyword%' OR aumngr.name like '%$keyword%' OR aumodify.name like '%$keyword%'")
->whereRaw("status <> 'Inactive'")
->whereRaw("clients.name like '%$keyword%' OR clients.status like '%$keyword%' OR clients.country like '%$keyword%' OR aumngr.name like '%$keyword%' OR aumodify.name like '%$keyword%'")
->paginate(10);
}
return response()->json($client_arr);
@@ -104,7 +130,7 @@ class ClientsController extends Controller
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->join('flags AS flags', 'flags.country', '=', 'clients.country')
->select('clients.id', 'clients.name', 'clients.status','clients.progress_indicator_score', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy', 'flags.url AS theflag')
->whereRaw("status = 'inactive'")
->whereRaw("status IN ('inactive', 'Cancelled')")
->orderBy('name', 'ASC')
->get();
// ->paginate(15);
@@ -116,8 +142,8 @@ class ClientsController extends Controller
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->join('flags AS flags', 'flags.country', '=', 'clients.country')
->select('clients.id','clients.name', 'clients.status', 'clients.progress_indicator_score','clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy', 'flags.url AS theflag')
->whereRaw("status = 'inactive'")
->whereRaw("clients.name like '%$keyword%' or clients.status like '%$keyword%' OR clients.country like '%$keyword%' OR aumngr.name like '%$keyword%' OR aumodify.name like '%$keyword%' OR clients.progress_indicator_score like '%$keyword%'")
->whereRaw("status IN ('inactive', 'Cancelled')")
->whereRaw("clients.name LIKE '%$keyword%' OR clients.status LIKE '%$keyword%' OR clients.country LIKE '%$keyword%' OR aumngr.name LIKE '%$keyword%' OR aumodify.name LIKE '%$keyword%' OR clients.progress_indicator_score LIKE '%$keyword%'")
->orderBy('name', 'ASC')
->get();
// ->paginate(15);
@@ -130,7 +156,7 @@ class ClientsController extends Controller
->join('auth_users AS aumngr', 'aumngr.id', '=', 'clients.auth_user_id')
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->select('clients.id', 'clients.name', 'clients.status', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy')
->whereRaw("status = 'inactive'")
->whereRaw("status = 'Inactive'")
->paginate(10);
if($request->has('keyword')){
@@ -140,7 +166,7 @@ class ClientsController extends Controller
->join('auth_users AS aumodify', 'aumodify.id', '=', 'clients.last_modified_by')
->select('clients.id','clients.name', 'clients.status', 'clients.country', 'aumngr.name As accountMgr', 'aumodify.name AS modifiedBy')
// ->where('status', 'inactive')
->whereRaw("status = 'inactive'")
->whereRaw("status = 'Inactive'")
->whereRaw("clients.name like '%$keyword%' or clients.status like '%$keyword%' OR clients.country like '%$keyword%' OR aumngr.name like '%$keyword%' OR aumodify.name like '%$keyword%'")
->paginate(10);
}
@@ -159,7 +185,7 @@ class ClientsController extends Controller
$service_type = Models\Service::pluck('name', 'name');
$payment_type = ['Prepaid' => 'Prepaid', 'Postpaid' => 'Postpaid']; //Models\PaymentType::pluck('name', 'id');
$auth_users = Models\SystemUser::pluck('name', 'id');
$status = ['Live' => 'Live', 'inactive' => 'Inactive', 'Prospective' => 'Prospective', 'Cancelled' => 'Cancelled'];
$status = ['Live' => 'Live', 'Inactive' => 'Inactive', 'Prospective' => 'Prospective', 'Cancelled' => 'Cancelled'];
$currency = Models\Currency::pluck('name','name');
$company_types = ['Aggregator/Supplier' => 'Aggregator/Supplier', 'Enterprise' => 'Enterprise', 'Hybrid' => 'Hybrid'];
$industries = Models\Industry::orderBy('name', 'ASC')->pluck('name', 'name');

View File

@@ -24,7 +24,7 @@ class DashboardController extends Controller
$recent_clients = Models\Client::with('auth_user_info')->orderBy('id', 'DESC')->take(5)->get();
// $upcoming_birthdays = Models\StaffMember::whereDate('dob', '>=', $currentdate)->orderBy('dob', 'ASC')->take(5)->get();
$upcoming_birthdays = Models\StaffMember::whereRaw("(month(dob) >= month(curdate())) AND day(dob) >= day(curdate())")->orderBy('dob', 'ASC')->take(5)->get();
$upcoming_hodidays = Models\NationalHoliday::whereRaw("(month(event_date) >= month(curdate()))")->orderBy('event_date', 'ASC')->take(5)->get();
$upcoming_hodidays = Models\NationalHoliday::whereRaw("(month(event_date) >= month(curdate()))")->whereRaw("(year(event_date) >= year(curdate()))")->orderBy('event_date', 'ASC')->take(15)->get();
// dd($upcoming_hodidays);
// $recent_clients = Models\Client::orderBy('id', 'DESC')->take(5)->get();

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Http\Controllers;
use Webklex\PHPIMAP\ClientManager;
use Webklex\PHPIMAP\Exceptions\ConnectionFailedException;
use App\Libs\ImapService;
use Illuminate\Http\JsonResponse;
class EmailController extends Controller
{
public function indexInbox(ImapService $imap): JsonResponse{
try {
$emails = $imap->getLatestEmails(10);
return response()->json($emails);
// Or for view: return view('emails.index', compact('emails'));
} catch (\Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function index()
{
try {
// Initialize IMAP client
$client = app(ClientManager::class)->account('default');
$client->connect();
// Get INBOX folder
$folder = $client->getFolder('INBOX');
// Fetch last 10 emails (newest first)
$messages = $folder->messages()->unseen()->limit(10)->get();
// Prepare data for view
$emails = $messages->map(function ($message) {
return [
'subject' => $message->getSubject() ?? '(No Subject)',
'sender' => $message->getFrom()[0]->mail ?? 'Unknown',
'email_date' => $message->getDate()->toDateTimeString(),
'email_body' => substr(strip_tags($message->getTextBody()), 0, 200) . '...',
];
});
// Disconnect
$client->disconnect();
dd($emails);
// Return view or JSON
// return view('emails.index', compact('emails'));
// Or for API: return response()->json($emails);
} catch (ConnectionFailedException $e) {
return response()->json(['error' => 'Failed to connect: ' . $e->getMessage()], 500);
} catch (\Exception $e) {
return response()->json(['error' => 'Error: ' . $e->getMessage()], 500);
}
}
}

View File

@@ -21,8 +21,6 @@ class StaffMembersController extends Controller
}
public function profile($staff_member_id){
$staff_member = Models\StaffMember::find($staff_member_id);
// dd($staff_member);
$data = [
'page_title' => 'Staff Profile',
'staff_member' => $staff_member,
@@ -30,6 +28,12 @@ class StaffMembersController extends Controller
];
return view('staff_members.profile', $data);
}
public function profile_json(){
$staff_member_id = session('current_user.id');
$staff_member = Models\StaffMember::findOrFail($staff_member_id);
return response()->json(['code' => 1, 'staff_member' => $staff_member]);
}
public function indexOld(){
$staff_members_arr = new Models\StaffMember;
$data = [
@@ -38,6 +42,26 @@ class StaffMembersController extends Controller
];
return view('staff_members.index', $data);
}
public function profileupdate(Request $request)
{
$account_arr = Models\StaffMember::find($request->user_id);
$account_arr->name = $request->name;
$account_arr->email = $request->email;
$account_arr->phone = $request->phone;
$msg_text = 'Staff detials successfully Updated';
if ($request->password == true) {
$account_arr->password = md5($request->password);
$msg_text = "Staff details and password successfully updated";
}
$result = $account_arr->save();
if ($result == true) {
$data = ['code' => 1, 'msg' => $msg_text];
}
else{
$data = ['code' => 1, 'msg' => 'Staff details could not be updated at this time. Try again!'];
}
return response()->json($data);
}
public function getstaffMemberssJson(Request $request)
{
#$this->log_query();

View File

@@ -53,6 +53,12 @@ class SystemUsersController extends Controller
return view('systemusers.index', $data);
}
public function profile_json(){
$staff_member_id = session('current_user.id');
$staff_member = Models\SystemUser::findOrFail($staff_member_id);
return response()->json(['code' => 1, 'staff_member' => $staff_member]);
}
/**
* Show the form for creating a new resource.
@@ -156,6 +162,25 @@ class SystemUsersController extends Controller
Session::flash('success_message', 'Account successfully Updated');
return redirect(url('systemusers'));
}
public function profileupdate(Request $request){
$account_arr = Models\SystemUser::find($request->user_id);
$account_arr->name = $request->name;
$account_arr->email = $request->email;
$account_arr->phone = $request->phone;
$msg_text = 'Account successfully Updated';
if ($request->password == true) {
$account_arr->password = md5($request->password);
$msg_text = "Account details and password successfully updated";
}
$result = $account_arr->save();
if ($result == true) {
$data = ['code' => 1, 'msg' => $msg_text];
}
else{
$data = ['code' => 1, 'msg' => 'Account could not be updated at this time. Try again!'];
}
return response()->json($data);
}
/**
* Remove the specified resource from storage.

57
app/Libs/ImapService.php Normal file
View File

@@ -0,0 +1,57 @@
<?php
namespace App\Libs;
class ImapService
{
protected $connection;
public function __construct()
{
/*
$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$username = "kwesibanson@gmail.com"; // env('IMAP_USERNAME', 'your.email@gmail.com');
$password = "yutbgxtlqwwepalr"; //env('IMAP_PASSWORD', 'your-app-password');
*/
$hostname = '{imap-mail.outlook.com:993/imap/ssl/novalidate-cert}INBOX';
$username = "kwesi_banson@hotmail.com"; // env('IMAP_USERNAME', 'your.email@gmail.com');
$password = "uyligiqtreyubvvp"; //"okxixwlqppkpfepy"; //env('IMAP_PASSWORD', 'your-app-password');
$this->connection = @imap_open($hostname, $username, $password);
if (!$this->connection) {
throw new \Exception('Cannot connect: ' . imap_last_error());
}
}
public function getLatestEmails($limit = 10): array
{
$emails = imap_search($this->connection, 'ALL', SE_UID);
if (!$emails) {
return [];
}
rsort($emails); // Newest first
$result = [];
foreach (array_slice($emails, 0, $limit) as $uid) {
$header = imap_headerinfo($this->connection, imap_msgno($this->connection, $uid), FT_UID);
$body = imap_fetchbody($this->connection, imap_msgno($this->connection, $uid), 1, FT_UID);
$body = quoted_printable_decode($body);
$result[] = [
'subject' => isset($header->subject) ? imap_utf8($header->subject) : '(No Subject)',
'from' => $header->from[0]->mailbox . '@' . $header->from[0]->host,
'date' => $header->date ?? 'Unknown',
'body' => substr(strip_tags($body), 0, 200) . '...',
];
}
return $result;
}
public function __destruct()
{
if ($this->connection) {
imap_close($this->connection);
}
}
}

View File

@@ -1,12 +0,0 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class DailyQoute extends Model
{
// public $timestamps = false;
protected $guarded = array('id');
public $table = "daily_qoutes";
}

10
app/Models/DailyQuote.php Normal file
View File

@@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class DailyQuote extends Model
{
//
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\models;
use Illuminate\Database\Eloquent\Model;
class IncomingEmail extends Model
{
protected $guarded = array('id');
public $table = "incoming_emails";
}