X7ROOT File Manager
Current Path:
/home/hamdjcne/app.hamdalillahitravel.com/app/Controllers
home
/
hamdjcne
/
app.hamdalillahitravel.com
/
app
/
Controllers
/
ðŸ“
..
📄
.DS_Store
(6 KB)
📄
Accounts.php
(52.25 KB)
📄
Activity.php
(4.49 KB)
📄
Analytics.php
(12.22 KB)
📄
Api.php
(41.41 KB)
📄
Auth.php
(34.64 KB)
📄
BaseController.php
(1.77 KB)
📄
Dashboard.php
(42.95 KB)
📄
Notification.php
(6.22 KB)
📄
Order.php
(118.16 KB)
📄
Service.php
(61.77 KB)
📄
Settings.php
(40.13 KB)
📄
Staff.php
(67.17 KB)
📄
Tour.php
(32.09 KB)
📄
Wallets.php
(43.15 KB)
📄
Webhook.php
(5.14 KB)
Editing: Staff.php
<?php namespace App\Controllers; class Staff extends BaseController { //Fueling Station public function manager($param1='', $param2='', $param3='') { // check session login if($this->session->get('fls_id') == ''){ $request_uri = uri_string(); $this->session->set('fls_redirect', $request_uri); return redirect()->to(site_url('auth')); } $mod = 'staff/manager'; $log_id = $this->session->get('fls_id'); $role_id = $this->Crud->read_field('id', $log_id, 'user', 'role_id'); $role = strtolower($this->Crud->read_field('id', $role_id, 'access_role', 'name')); $role_c = $this->Crud->module($role_id, $mod, 'create'); $role_r = $this->Crud->module($role_id, $mod, 'read'); $role_u = $this->Crud->module($role_id, $mod, 'update'); $role_d = $this->Crud->module($role_id, $mod, 'delete'); if($role_r == 0){ return redirect()->to(site_url('dashboard')); } $data['log_id'] = $log_id; $data['role'] = $role; $data['role_c'] = $role_c; $table = 'user'; $form_link = site_url($mod); if($param1){$form_link .= '/'.$param1;} if($param2){$form_link .= '/'.$param2.'/';} if($param3){$form_link .= $param3;} // pass parameters to view $data['param1'] = $param1; $data['param2'] = $param2; $data['param3'] = $param3; $data['form_link'] = $form_link; // manage record if($param1 == 'manage') { // prepare for delete if($param2 == 'delete') { if($param3) { $edit = $this->Crud->read_single('id', $param3, $table); //echo var_dump($edit); if(!empty($edit)) { foreach($edit as $e) { $data['d_id'] = $e->id; } } if($this->request->getMethod() == 'post'){ $del_id = $this->request->getVar('d_partner_id'); $code = $this->Crud->read_field('id', $del_id, 'user', 'fullname'); $by = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $action = $by.' deleted Area Manager ('.$code.')'; if($this->Crud->deletes('id', $del_id, $table) > 0) { ///// store activities $this->Crud->activity('user', $del_id, $action); echo $this->Crud->msg('success', 'Area Manager Deleted'); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('danger', 'Please try later'); } die; } } } elseif($param2 == 'email') { if($param3) { $edit = $this->Crud->read_single('id', $param3, $table); //echo var_dump($edit); if(!empty($edit)) { foreach($edit as $e) { $data['d_id'] = $e->id; } } } } elseif ($param2 == 'activate'){ if($param3) { $edit = $this->Crud->read_single('id', $param3, $table); //echo var_dump($edit); if(!empty($edit)) { foreach($edit as $e) { $data['d_id'] = $e->id; } } if($this->request->getMethod() == 'post'){ $del_id = $this->request->getVar('d_partner_id'); $code = $this->Crud->read_field('id', $del_id, 'user', 'fullname'); $by = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $action = $by.' Activated Merchant ('.$code.')'; if($this->Crud->updates('id', $del_id, $table, array('merchant_status'=>1,'activate'=>1)) > 0) { ///// store activities $this->Crud->activity('user', $del_id, $action); echo $this->Crud->msg('success', 'Merchant Account Approved'); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('info', 'No Changes!'); } die; } } } else { // prepare for edit if($param2 == 'edit') { if($param3) { $edit = $this->Crud->read_single('id', $param3, $table); if(!empty($edit)) { foreach($edit as $e) { $data['e_id'] = $e->id; $data['e_fullname'] = $e->fullname; $data['e_company_name'] = $e->company_name; $data['e_email'] = $e->email; $data['e_phone'] = $e->phone; $data['e_country_id'] = $e->country_id; $data['e_state_id'] = $e->state_id; $data['e_lga_id'] = $e->lga_id; $data['e_address'] = $e->address; $data['e_ban'] = $e->activate; $data['e_img'] = $e->img_id; $data['e_logo'] = $e->logo; $data['e_territory'] = $e->territory; } } } } //profile view if($param2 == 'profile') { $vendor_id = $param3; $data['v_id'] = $vendor_id; $data['fullname'] = $this->Crud->read_field('id', $vendor_id, 'user', 'fullname'); $data['v_phone'] = $this->Crud->read_field('id', $vendor_id, 'user', 'phone'); $data['v_dob'] = $this->Crud->read_field('id', $vendor_id, 'user', 'dob'); $data['reg_date'] = $this->Crud->read_field('id', $vendor_id, 'user', 'reg_date'); $data['v_email'] = $this->Crud->read_field('id', $vendor_id, 'user', 'email'); $v_img_id = $this->Crud->read_field('id', $vendor_id, 'user', 'img_id'); $data['v_img'] = site_url($this->Crud->image($v_img_id, 'big')); $v_status = $this->Crud->read_field('id', $vendor_id, 'user', 'activate'); if(!empty($v_status)) { $v_status = '<span class="text-success">VERIFIED</span>'; } else { $v_status = '<span class="text-danger">UNVERIFIED</span>'; } $data['v_status'] = $v_status; $data['v_address'] = $this->Crud->read_field('id', $vendor_id, 'user', 'address'); $v_state_id = $this->Crud->read_field('id', $vendor_id, 'user', 'state_id'); $data['v_state'] = $this->Crud->read_field('id', $v_state_id, 'state', 'name'); $v_country_id = $this->Crud->read_field('id', $vendor_id, 'user', 'country_id'); $data['v_country'] = $this->Crud->read_field('id', $v_country_id, 'country', 'name'); } if($this->request->getMethod() == 'post'){ $user_i = $this->request->getVar('user_id'); $fullname = $this->request->getVar('fullname'); $company_name = $this->request->getVar('company_name'); $email = $this->request->getVar('email'); $phone = $this->request->getVar('phone'); $country_id = $this->request->getVar('country_id'); $lga_id = $this->request->getVar('lga'); $state = $this->request->getVar('state'); $img = $this->request->getVar('img'); $password = $this->request->getVar('password'); $logo_id = $this->request->getVar('logo'); $address = $this->request->getVar('address'); $territory = $this->request->getVar('territory'); $activate = $this->request->getVar('activate'); //// Image upload if(file_exists($this->request->getFile('pics'))) { $path = 'assets/images/users/'.$log_id.'/'; $file = $this->request->getFile('pics'); $getImg = $this->Crud->img_upload($path, $file); if(!empty($getImg->path)) $img_id = $this->Crud->save_image($log_id, $getImg->path); } elseif(empty($img) && $img == 0){ echo $this->Crud->msg('warning', 'Please Select Image'); $img_id = 0; // die; } else { $img_id = $img; } $role_id = $this->Crud->read_field('name', 'Area Manager', 'access_role', 'id'); if($password) { $upd_data['password'] = md5($password); } $upd_data = array( 'fullname' => $fullname, 'email' => $email, 'phone' => $phone, 'address' => $address, 'country_id' => 161, 'state_id' => $state, 'lga_id' => $lga_id, 'role_id' => $role_id, 'territory' => json_encode($territory), 'activate' => $activate, 'img_id' => $img_id ); // do create or update if($user_i) { $upd_rec = $this->Crud->updates('id', $user_i, $table, $upd_data); if($upd_rec > 0) { ///// store activities $by = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $code = $this->Crud->read_field('id', $user_i, 'user', 'fullname'); $action = $by.' updated Area Manager ('.$code.') Record'; $this->Crud->activity('user', $user_i, $action); if($territory){ foreach($territory as $terz){ $managers = json_decode($this->Crud->read_field('id', $terz, 'territory', 'manager'), true); // Ensure $managers is an array if (!is_array($managers)) { $managers = []; } // Check if the manager ID exists in the array if (!in_array($user_i, $managers)) { // Add the new manager ID to the array $managers[] = $user_i; // Convert back to JSON format $updated_managers = json_encode($managers); // Update the territory table with the new manager list $this->Crud->updates('id', $terz, 'territory', ['manager' => $updated_managers]); } } } echo $this->Crud->msg('success', 'Area Manager Account Updated'); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('info', 'No Changes'); } die; } else { if($this->Crud->check2('fullname', $fullname, 'email', $email, $table) > 0) { echo $this->Crud->msg('warning', 'Record Already Exist'); } else { $upd_data['activate'] = 1; $upd_data['reg_date'] = date(fdate); $ins_rec = $this->Crud->create($table, $upd_data); if($ins_rec > 0) { echo $this->Crud->msg('success', 'Record Created'); $name = ucwords($fullname); $login_url = site_url('auth/login'); // Adjust based on your login URL // Assuming username and password are retrieved or generated $user_email = $email; $user_password = $password; // Replace with actual user password $message = ' <h2>Welcome to ' . app_name . '!</h2> <p>Hello <strong>' . $name . '</strong>,</p> <p>Your account has been successfully created. Below are your login credentials:</p> <h3>Login Credentials:</h3> <ul> <li><strong>Email:</strong> ' . $user_email . '</li> <li><strong>Password:</strong> ' . $user_password . '</li> </ul> <p><a href="' . $login_url . '" class="button" style="background:#28a745;padding:10px 20px;color:white;text-decoration:none;border-radius:5px;">Login to Your Account</a></p> <p>If the button above doesn’t work, copy and paste the following URL into your browser:</p> <p><a href="' . $login_url . '">' . $login_url . '</a></p> <p class="note"><strong>Security Tip:</strong> We recommend changing your password after your first login.</p> <p>Best Regards,</p> <p>The ' . app_name . ' Team</p> '; $body = 'Dear ' . $name . ', <br><br>' . $message; $this->Crud->send_email($email, 'Your Login Credentials for ' . app_name, $body); if($territory){ foreach($territory as $terz){ $managers = json_decode($this->Crud->read_field('id', $terz, 'territory', 'manager'), true); // Ensure $managers is an array if (!is_array($managers)) { $managers = []; } // Check if the manager ID exists in the array if (!in_array($ins_rec, $managers)) { // Add the new manager ID to the array $managers[] = $ins_rec; // Convert back to JSON format $updated_managers = json_encode($managers); // Update the territory table with the new manager list $this->Crud->updates('id', $terz, 'territory', ['manager' => $updated_managers]); } } } $uzer = 'FY00'.$ins_rec; $this->Crud->updates('id', $ins_rec, 'user', array('user_no'=>$uzer)); ///// store activities $by = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $code = $this->Crud->read_field('id', $ins_rec, 'user', 'fullname'); $action = $by.' created Area Manager ('.$code.') Record'; $this->Crud->activity('user', $ins_rec, $action); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('danger', 'Please try later'); } } } die; } } } if ($param1 == 'export') { $start = $this->session->get('start_date'); $end = $this->session->get('end_date'); $state_id = $this->session->get('state_id'); $status = $this->session->get('status'); $states = ''; if (!empty($state)) { $st = $this->Crud->read_field('id', $state, 'state', 'name'); $states = $st . ' State '; } $comms = $this->Crud->filter_merchant('', '', $log_id, '', 'all', 'all', ''); $codes = ''; if (!empty($comms)) { $count = 1; foreach ($comms as $co) { $item = array(); $item[] = $count; $item[] = date('Y-m-d', strtotime($co->reg_date)); $i = 0; $state = $this->Crud->read_field('id', $co->state_id, 'state', 'name'); $m_status = 'Approved'; if($co->merchant_status == 0){ $m_status = 'Not Approved'; } $item[] = $co->fullname; $item[] = $co->email; $item[] = $co->phone; $item[] = $co->address; $item[] = $co->company_name; $item[] = $state; $item[] = $m_status; $item[] = 'Merchant'; $i++; $row[] = $item; $count += 1; } } $date = ''; if (!empty($start) && !empty($end)) { $date = date('dmY', strtotime($start)) . '-' . date('dmY', strtotime($end)); } // now export CSV $dfile_name = $states . 'Merchant Report-' . $date; $fname = $dfile_name . '.csv'; header("Content-Type: text/csv;charset=utf-8"); header("Content-Disposition: attachment;filename=$fname"); header("Pragma: no-cache"); header("Expires: 0"); $output = fopen('php://output', 'w'); // Column Title fputcsv($output, array('S/N', 'Reg Date', 'Fullname', 'Email', 'Phone', 'Address', 'Company Name', 'State', 'Approval Status', 'Role')); // Column Items if (!empty($row)) { foreach ($row as $fields) { fputcsv($output, $fields); } } fclose($output); die; } // record listing if($param1 == 'load') { $limit = $param2; $offset = $param3; $rec_limit = 75; $item = ''; if(empty($limit)) {$limit = $rec_limit;} if(empty($offset)) {$offset = 0;} if(!empty($this->request->getPost('state_id'))) { $state_id = $this->request->getPost('state_id'); } else { $state_id = ''; } if(!empty($this->request->getPost('territory'))) { $territory = $this->request->getPost('territory'); } else { $territory = ''; } if(!empty($this->request->getPost('status'))) { $status = $this->request->getPost('status'); } else { $status = ''; } $search = $this->request->getPost('search'); if(!empty($this->request->getPost('start_date'))) { $start_date = $this->request->getPost('start_date'); } else { $start_date = ''; } if(!empty($this->request->getPost('end_date'))) { $end_date = $this->request->getPost('end_date'); } else { $end_date = ''; } $items = ' '; //echo $status; $log_id = $this->session->get('fls_id'); if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $all_rec = $this->Crud->filter_manager('', '', $log_id, $state_id, $territory, $search); if(!empty($all_rec)) { $counts = count($all_rec); } else { $counts = 0; } $query = $this->Crud->filter_manager($limit, $offset, $log_id, $state_id, $territory, $search); $data['count'] = $counts; if(!empty($query)) { foreach($query as $q) { $id = $q->id; $fullname = $q->fullname; $company_name = $q->company_name; $email = $q->email; $phone = $q->phone; $address = $q->address; $state = $this->Crud->read_field('id', $q->state_id, 'state', 'name'); $country = $this->Crud->read_field('id', $q->country_id, 'country', 'name'); $city = $this->Crud->read_field('id', $q->lga_id, 'city', 'name'); $img = $q->logo; if(empty($img)){ $img = 'assets/media/svg/avatars/blank.svg'; } $territory = json_decode($q->territory,true); $activate = $q->activate; $u_role = $this->Crud->read_field('id', $q->role_id, 'access_role', 'name'); $reg_date = date('M d, Y h:iA', strtotime($q->reg_date)); $approved = ''; if($activate == 1) { $color = 'success'; $approve_text = 'Account Activated'; $approved = '<span class="text-primary"><i class="ri-check-circle-line"></i></span> '; } else { $color = 'danger'; $approve_text = 'Account Deactivated'; } $are = ''; if (!empty($territory)) { $lga_names = []; foreach ($territory as $lga => $lgas) { // echo $lgas; $lga_names[] = '<span class="badge bg-success">' . $this->Crud->read_field('id', $lgas, 'territory', 'name') . '</span>'; // Format as a badge } // Output names joined by space $are .= implode(' ', $lga_names); } else { $are .= '<span class="text-muted">No Areas Selected</span>'; } // add manage buttons $item .= ' <tr> <td> '.$reg_date.' </td> <td class="d-flex align-items-center"> <!--begin:: Avatar --> <div class="symbol symbol-circle symbol-50px overflow-hidden me-3"> <a href="javascript:;"> <div class="symbol-label"> <img src="'.site_url($img).'" alt="'.ucwords($fullname).'" class="w-100" /> </div> </a> </div> <!--end::Avatar--> <!--begin::User details--> <div class="d-flex flex-column"> <a href="javascript:;" class="text-gray-800 text-hover-success mb-1">'.ucwords($fullname).'</a> <span>'.$email.'</span> </div> <!--begin::User details--> </td> <td> <div class="d-flex flex-column"> <span>'.$are.'</span> </div> </td> <td> <div class="d-flex flex-column"> <span class="text-gray-800 mb-1">'.ucwords($address).'</span> <span>'.$city.' '.$state.'</span> </div> </td> <td> <div class="badge badge-light-'.$color.' fw-bold">'.$approve_text.'</div> </td> <td> <div class="d-flex justify-content-end flex-shrink-0"> <a href="javascript:;" class="pop btn btn-icon btn-success btn-active-color-light btn-sm me-2" pageTitle="Edit Merchant '.$fullname.'" pagesize="modal-lg" data-bs-toggle="tooltip" data-bs-placement="top" title="Edit Merchant" pageName="'.site_url($mod.'/manage/edit/'.$id).'"> <i class="ki-duotone ki-pencil fs-2"><span class="path1"></span><span class="path2"></span></i> </a> <a href="javascript:;" class="pop btn btn-icon btn-danger btn-active-color-light btn-sm me-2" data-bs-toggle="tooltip" data-bs-placement="top" title="Delete Merchant" pageTitle="Delete Merchant '.$fullname.'" pageName="'.site_url($mod.'/manage/delete/'.$id).'"> <i class="ki-duotone ki-trash fs-2"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span></i> </a> <a href="'.site_url('accounts/profile_view/'.$id).'" data-bs-toggle="tooltip" data-bs-placement="top" title="View Merchant" class="btn btn-icon btn-primary me-2 btn-active-color-light btn-sm" > <i class="ki-duotone ki-eye fs-2"><span class="path1"></span><span class="path2"></span><span class="path3"></span></i> </a> </div> </td> </tr> '; } } } if(empty($item)) { $resp['item'] = $items.' <tr><td colspan="8"><div class="text-center text-muted"> <br/><br/><br/><br/> <i class="ki-duotone ki-profile-user" style="font-size:150px;"> <span class="path1"></span> <span class="path2"></span> <span class="path3"></span> <span class="path4"></span> </i><br/><br/>No Area Manager Returned </div></td></tr> '; } else { $resp['item'] = $items . $item; } $resp['count'] = $counts; $more_record = $counts - ($offset + $rec_limit); $resp['left'] = $more_record; if($counts > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } echo json_encode($resp); die; } if($param1 == 'manage') { // view for form data posting return view($mod.'_form', $data); } else { // view for main page $data['title'] = 'Area Manager - '.app_name; $data['page_active'] = $mod; return view($mod, $data); } } public function executive($param1='', $param2='', $param3='') { // check session login if($this->session->get('fls_id') == ''){ $request_uri = uri_string(); $this->session->set('fls_redirect', $request_uri); return redirect()->to(site_url('auth')); } $mod = 'staff/executive'; $log_id = $this->session->get('fls_id'); $role_id = $this->Crud->read_field('id', $log_id, 'user', 'role_id'); $role = strtolower($this->Crud->read_field('id', $role_id, 'access_role', 'name')); $role_c = $this->Crud->module($role_id, $mod, 'create'); $role_r = $this->Crud->module($role_id, $mod, 'read'); $role_u = $this->Crud->module($role_id, $mod, 'update'); $role_d = $this->Crud->module($role_id, $mod, 'delete'); if($role_r == 0){ return redirect()->to(site_url('dashboard')); } $data['log_id'] = $log_id; $data['role'] = $role; $data['role_c'] = $role_c; $table = 'user'; $form_link = site_url($mod); if($param1){$form_link .= '/'.$param1;} if($param2){$form_link .= '/'.$param2.'/';} if($param3){$form_link .= $param3;} // pass parameters to view $data['param1'] = $param1; $data['param2'] = $param2; $data['param3'] = $param3; $data['form_link'] = $form_link; // manage record if($param1 == 'manage') { // prepare for delete if($param2 == 'delete') { if($param3) { $edit = $this->Crud->read_single('id', $param3, $table); //echo var_dump($edit); if(!empty($edit)) { foreach($edit as $e) { $data['d_id'] = $e->id; } } if($this->request->getMethod() == 'post'){ $del_id = $this->request->getVar('d_partner_id'); $code = $this->Crud->read_field('id', $del_id, 'user', 'fullname'); $by = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $action = $by.' deleted Sales Executive Manager ('.$code.')'; if($this->Crud->deletes('id', $del_id, $table) > 0) { ///// store activities $this->Crud->activity('user', $del_id, $action); echo $this->Crud->msg('success', 'Sales Executive Manager Deleted'); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('danger', 'Please try later'); } die; } } } elseif($param2 == 'email') { if($param3) { $edit = $this->Crud->read_single('id', $param3, $table); //echo var_dump($edit); if(!empty($edit)) { foreach($edit as $e) { $data['d_id'] = $e->id; } } } } elseif ($param2 == 'activate'){ if($param3) { $edit = $this->Crud->read_single('id', $param3, $table); //echo var_dump($edit); if(!empty($edit)) { foreach($edit as $e) { $data['d_id'] = $e->id; } } if($this->request->getMethod() == 'post'){ $del_id = $this->request->getVar('d_partner_id'); $code = $this->Crud->read_field('id', $del_id, 'user', 'fullname'); $by = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $action = $by.' Activated Merchant ('.$code.')'; if($this->Crud->updates('id', $del_id, $table, array('merchant_status'=>1,'activate'=>1)) > 0) { ///// store activities $this->Crud->activity('user', $del_id, $action); echo $this->Crud->msg('success', 'Merchant Account Approved'); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('info', 'No Changes!'); } die; } } } else { // prepare for edit if($param2 == 'edit') { if($param3) { $edit = $this->Crud->read_single('id', $param3, $table); if(!empty($edit)) { foreach($edit as $e) { $data['e_id'] = $e->id; $data['e_fullname'] = $e->fullname; $data['e_company_name'] = $e->company_name; $data['e_email'] = $e->email; $data['e_phone'] = $e->phone; $data['e_country_id'] = $e->country_id; $data['e_state_id'] = $e->state_id; $data['e_lga_id'] = $e->lga_id; $data['e_address'] = $e->address; $data['e_ban'] = $e->activate; $data['e_img'] = $e->img_id; $data['e_logo'] = $e->logo; $data['e_territory'] = $e->territory; $data['e_area'] = $e->area; $data['e_manager_id'] = $e->manager_id; } } } } //profile view if($param2 == 'profile') { $vendor_id = $param3; $data['v_id'] = $vendor_id; $data['fullname'] = $this->Crud->read_field('id', $vendor_id, 'user', 'fullname'); $data['v_phone'] = $this->Crud->read_field('id', $vendor_id, 'user', 'phone'); $data['v_dob'] = $this->Crud->read_field('id', $vendor_id, 'user', 'dob'); $data['reg_date'] = $this->Crud->read_field('id', $vendor_id, 'user', 'reg_date'); $data['v_email'] = $this->Crud->read_field('id', $vendor_id, 'user', 'email'); $v_img_id = $this->Crud->read_field('id', $vendor_id, 'user', 'img_id'); $data['v_img'] = site_url($this->Crud->image($v_img_id, 'big')); $v_status = $this->Crud->read_field('id', $vendor_id, 'user', 'activate'); if(!empty($v_status)) { $v_status = '<span class="text-success">VERIFIED</span>'; } else { $v_status = '<span class="text-danger">UNVERIFIED</span>'; } $data['v_status'] = $v_status; $data['v_address'] = $this->Crud->read_field('id', $vendor_id, 'user', 'address'); $v_state_id = $this->Crud->read_field('id', $vendor_id, 'user', 'state_id'); $data['v_state'] = $this->Crud->read_field('id', $v_state_id, 'state', 'name'); $v_country_id = $this->Crud->read_field('id', $vendor_id, 'user', 'country_id'); $data['v_country'] = $this->Crud->read_field('id', $v_country_id, 'country', 'name'); } if($this->request->getMethod() == 'post'){ $user_i = $this->request->getVar('user_id'); $fullname = $this->request->getVar('fullname'); $company_name = $this->request->getVar('company_name'); $email = $this->request->getVar('email'); $phone = $this->request->getVar('phone'); $country_id = $this->request->getVar('country_id'); $lga_id = $this->request->getVar('lga'); $state = $this->request->getVar('state'); $img = $this->request->getVar('img'); $password = $this->request->getVar('password'); $logo_id = $this->request->getVar('logo'); $address = $this->request->getVar('address'); $territory = $this->request->getVar('territory'); $area = $this->request->getVar('area'); $activate = $this->request->getVar('activate'); $manager_id = $this->request->getVar('manager_id'); //// Image upload if(file_exists($this->request->getFile('pics'))) { $path = 'assets/images/users/'.$log_id.'/'; $file = $this->request->getFile('pics'); $getImg = $this->Crud->img_upload($path, $file); if(!empty($getImg->path)) $img_id = $this->Crud->save_image($log_id, $getImg->path); } elseif(empty($img) && $img == 0){ echo $this->Crud->msg('warning', 'Please Select Image'); $img_id = 0; // die; } else { $img_id = $img; } $role_id = $this->Crud->read_field('name', 'Sales Executive', 'access_role', 'id'); $terz = array($territory); $areaz = array($area); if($password) { $upd_data['password'] = md5($password); } $upd_data = array( 'fullname' => $fullname, 'email' => $email, 'phone' => $phone, 'address' => $address, 'country_id' => 161, 'state_id' => $state, 'lga_id' => $lga_id, 'role_id' => $role_id, 'territory' => json_encode($terz), 'area' => json_encode($areaz), 'activate' => $activate, 'img_id' => $img_id, 'manager_id' => $manager_id ); // do create or update if($user_i) { $upd_rec = $this->Crud->updates('id', $user_i, $table, $upd_data); if($upd_rec > 0) { ///// store activities $by = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $code = $this->Crud->read_field('id', $user_i, 'user', 'fullname'); $action = $by.' updated Sales Executive ('.$code.') Record'; $this->Crud->activity('user', $user_i, $action); if ($area) { // Fetch the existing manager JSON from the `territory` table $managers_json = $this->Crud->read_field('id', $territory, 'territory', 'areas'); // Decode JSON into an associative array (ensure it's an array) $managers = json_decode($managers_json, true); if (!is_array($managers)) { $managers = []; } // Ensure the area ID exists in the structure if (!isset($managers[$area])) { $managers[$area] = []; } // Check if the sales ID already exists if (!in_array($user_i, $managers[$area])) { // Add the new sales ID to the area's array $managers[$area][] = $user_i; // Convert back to JSON format $updated_managers = json_encode($managers); // Update the `territory` table with the new manager structure $this->Crud->updates('id', $territory, 'territory', ['areas' => $updated_managers]); } } echo $this->Crud->msg('success', 'Sales Executive Account Updated'); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('info', 'No Changes'); } die; } else { if($this->Crud->check2('fullname', $fullname, 'email', $email, $table) > 0) { echo $this->Crud->msg('warning', 'Record Already Exist'); } else { $upd_data['activate'] = 1; $upd_data['reg_date'] = date(fdate); $ins_rec = $this->Crud->create($table, $upd_data); if($ins_rec > 0) { echo $this->Crud->msg('success', 'Record Created'); $name = ucwords($fullname); $login_url = site_url('auth/login'); // Adjust based on your login URL // Assuming username and password are retrieved or generated $user_email = $email; $user_password = $password; // Replace with actual user password $message = ' <h2>Welcome to ' . app_name . '!</h2> <p>Hello <strong>' . $name . '</strong>,</p> <p>Your account has been successfully created. Below are your login credentials:</p> <h3>Login Credentials:</h3> <ul> <li><strong>Email:</strong> ' . $user_email . '</li> <li><strong>Password:</strong> ' . $user_password . '</li> </ul> <p><a href="' . $login_url . '" class="button" style="background:#28a745;padding:10px 20px;color:white;text-decoration:none;border-radius:5px;">Login to Your Account</a></p> <p>If the button above doesn’t work, copy and paste the following URL into your browser:</p> <p><a href="' . $login_url . '">' . $login_url . '</a></p> <p class="note"><strong>Security Tip:</strong> We recommend changing your password after your first login.</p> <p>Best Regards,</p> <p>The ' . app_name . ' Team</p> '; $body = 'Dear ' . $name . ', <br><br>' . $message; $this->Crud->send_email($email, 'Your Login Credentials for ' . app_name, $body); if ($area) { // Fetch the existing manager JSON from the `territory` table $managers_json = $this->Crud->read_field('id', $territory, 'territory', 'areas'); // Decode JSON into an associative array (ensure it's an array) $managers = json_decode($managers_json, true); if (!is_array($managers)) { $managers = []; } // Ensure the area ID exists in the structure if (!isset($managers[$area])) { $managers[$area] = []; } // Check if the sales ID already exists if (!in_array($ins_rec, $managers[$area])) { // Add the new sales ID to the area's array $managers[$area][] = $ins_rec; // Convert back to JSON format $updated_managers = json_encode($managers); // Update the `territory` table with the new manager structure $this->Crud->updates('id', $territory, 'territory', ['areas' => $updated_managers]); } } $uzer = 'FY00'.$ins_rec; $this->Crud->updates('id', $ins_rec, 'user', array('user_no'=>$uzer)); ///// store activities $by = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $code = $this->Crud->read_field('id', $ins_rec, 'user', 'fullname'); $action = $by.' created Sales Executive ('.$code.') Record'; $this->Crud->activity('user', $ins_rec, $action); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('danger', 'Please try later'); } } } die; } } } if ($param1 == 'export') { $start = $this->session->get('start_date'); $end = $this->session->get('end_date'); $state_id = $this->session->get('state_id'); $status = $this->session->get('status'); $states = ''; if (!empty($state)) { $st = $this->Crud->read_field('id', $state, 'state', 'name'); $states = $st . ' State '; } $comms = $this->Crud->filter_merchant('', '', $log_id, '', 'all', 'all', ''); $codes = ''; if (!empty($comms)) { $count = 1; foreach ($comms as $co) { $item = array(); $item[] = $count; $item[] = date('Y-m-d', strtotime($co->reg_date)); $i = 0; $state = $this->Crud->read_field('id', $co->state_id, 'state', 'name'); $m_status = 'Approved'; if($co->merchant_status == 0){ $m_status = 'Not Approved'; } $item[] = $co->fullname; $item[] = $co->email; $item[] = $co->phone; $item[] = $co->address; $item[] = $co->company_name; $item[] = $state; $item[] = $m_status; $item[] = 'Merchant'; $i++; $row[] = $item; $count += 1; } } $date = ''; if (!empty($start) && !empty($end)) { $date = date('dmY', strtotime($start)) . '-' . date('dmY', strtotime($end)); } // now export CSV $dfile_name = $states . 'Merchant Report-' . $date; $fname = $dfile_name . '.csv'; header("Content-Type: text/csv;charset=utf-8"); header("Content-Disposition: attachment;filename=$fname"); header("Pragma: no-cache"); header("Expires: 0"); $output = fopen('php://output', 'w'); // Column Title fputcsv($output, array('S/N', 'Reg Date', 'Fullname', 'Email', 'Phone', 'Address', 'Company Name', 'State', 'Approval Status', 'Role')); // Column Items if (!empty($row)) { foreach ($row as $fields) { fputcsv($output, $fields); } } fclose($output); die; } // record listing if($param1 == 'load') { $limit = $param2; $offset = $param3; $rec_limit = 75; $item = ''; if(empty($limit)) {$limit = $rec_limit;} if(empty($offset)) {$offset = 0;} if(!empty($this->request->getPost('state_id'))) { $state_id = $this->request->getPost('state_id'); } else { $state_id = ''; } if(!empty($this->request->getPost('territory'))) { $territory = $this->request->getPost('territory'); } else { $territory = ''; } if(!empty($this->request->getPost('status'))) { $status = $this->request->getPost('status'); } else { $status = ''; } $search = $this->request->getPost('search'); if(!empty($this->request->getPost('start_date'))) { $start_date = $this->request->getPost('start_date'); } else { $start_date = ''; } if(!empty($this->request->getPost('end_date'))) { $end_date = $this->request->getPost('end_date'); } else { $end_date = ''; } $items = ' '; //echo $status; $log_id = $this->session->get('fls_id'); if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $all_rec = $this->Crud->filter_executive('', '', $log_id, $state_id, $territory, $search); if(!empty($all_rec)) { $counts = count($all_rec); } else { $counts = 0; } $query = $this->Crud->filter_executive($limit, $offset, $log_id, $state_id, $territory, $search); $data['count'] = $counts; if(!empty($query)) { foreach($query as $q) { $id = $q->id; $fullname = $q->fullname; $company_name = $q->company_name; $email = $q->email; $phone = $q->phone; $address = $q->address; $state = $this->Crud->read_field('id', $q->state_id, 'state', 'name'); $country = $this->Crud->read_field('id', $q->country_id, 'country', 'name'); $city = $this->Crud->read_field('id', $q->lga_id, 'city', 'name'); $manager = $this->Crud->read_field('id', $q->manager_id, 'user', 'fullname'); if(empty($manager)){ $manager = 'Not Assigned'; } $img = $q->logo; if(empty($img)){ $img = 'assets/media/svg/avatars/blank.svg'; } $territory = json_decode($q->territory,true); $area = json_decode($q->area,true); $activate = $q->activate; $u_role = $this->Crud->read_field('id', $q->role_id, 'access_role', 'name'); $reg_date = date('M d, Y h:iA', strtotime($q->reg_date)); $approved = ''; if($activate == 1) { $color = 'success'; $approve_text = 'Account Activated'; $approved = '<span class="text-primary"><i class="ri-check-circle-line"></i></span> '; } else { $color = 'danger'; $approve_text = 'Account Deactivated'; } $are = ''; if (!empty($territory)) { $lga_names = []; foreach ($territory as $lga_id) { // Use $lga_id as key, ignore value ([]) $city_name = $this->Crud->read_field('id', $lga_id, 'territory', 'name'); // Fetch city name if ($city_name) { $lga_names[] = '<span class="badge bg-success">' . $city_name . '</span>'; // Format as badge } } // Output names joined by space $are .= implode(' ', $lga_names); } else { $are .= '<span class="text-muted">No Territory Selected</span>'; } // add manage buttons $terz = ''; if (!empty($area)) { $lga_names = []; foreach ($area as $lga_id) { // Use $lga_id as key, ignore value ([]) $city_name = $this->Crud->read_field('id', $lga_id, 'city', 'name'); // Fetch city name if ($city_name) { $lga_names[] = '<span class="badge bg-success">' . $lga_id . '</span>'; // Format as badge } } // Output names joined by space $terz .= implode(' ', $lga_names); } else { $terz .= '<span class="text-muted">No Areas Selected</span>'; } // add manage buttons $item .= ' <tr> <td> '.$reg_date.' </td> <td class="d-flex align-items-center"> <!--begin:: Avatar --> <div class="symbol symbol-circle symbol-50px overflow-hidden me-3"> <a href="javascript:;"> <div class="symbol-label"> <img src="'.site_url($img).'" alt="'.ucwords($fullname).'" class="w-100" /> </div> </a> </div> <!--end::Avatar--> <!--begin::User details--> <div class="d-flex flex-column"> <a href="javascript:;" class="text-gray-800 text-hover-success mb-1">'.ucwords($fullname).'</a> <span>'.$email.'</span> </div> <!--begin::User details--> </td> <td> <div class="d-flex flex-column"> <span class="text-gray-800 mb-1">'.ucwords($address).'</span> <span>'.$city.' '.$state.'</span> </div> </td> <td> <div class="d-flex flex-column"> <span>'.$are.'</span> <br><span class="text-success">Manager: '.$manager.'</span> </div> </td> <td> <div class="d-flex flex-column"> <span>'.$terz.'</span> </div> </td> <td> <div class="badge badge-light-'.$color.' fw-bold">'.$approve_text.'</div> </td> <td> <div class="d-flex justify-content-end flex-shrink-0"> <a href="javascript:;" class="pop btn btn-icon btn-success btn-active-color-light btn-sm me-2" pageTitle="Edit Merchant '.$fullname.'" pagesize="modal-lg" data-bs-toggle="tooltip" data-bs-placement="top" title="Edit Merchant" pageName="'.site_url($mod.'/manage/edit/'.$id).'"> <i class="ki-duotone ki-pencil fs-2"><span class="path1"></span><span class="path2"></span></i> </a> <a href="javascript:;" class="pop btn btn-icon btn-danger btn-active-color-light btn-sm me-2" data-bs-toggle="tooltip" data-bs-placement="top" title="Delete Merchant" pageTitle="Delete Merchant '.$fullname.'" pageName="'.site_url($mod.'/manage/delete/'.$id).'"> <i class="ki-duotone ki-trash fs-2"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span><span class="path5"></span></i> </a> <a href="'.site_url('accounts/profile_view/'.$id).'" data-bs-toggle="tooltip" data-bs-placement="top" title="View Merchant" class="btn btn-icon btn-primary me-2 btn-active-color-light btn-sm" > <i class="ki-duotone ki-eye fs-2"><span class="path1"></span><span class="path2"></span><span class="path3"></span></i> </a> </div> </td> </tr> '; } } } if(empty($item)) { $resp['item'] = $items.' <tr><td colspan="8"><div class="text-center text-muted"> <br/><br/><br/><br/> <i class="ki-duotone ki-profile-user" style="font-size:150px;"> <span class="path1"></span> <span class="path2"></span> <span class="path3"></span> <span class="path4"></span> </i><br/><br/>No Sales Executive Returned </div></td></tr> '; } else { $resp['item'] = $items . $item; } $resp['count'] = $counts; $more_record = $counts - ($offset + $rec_limit); $resp['left'] = $more_record; if($counts > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } echo json_encode($resp); die; } if($param1 == 'manage') { // view for form data posting return view($mod.'_form', $data); } else { // view for main page $data['title'] = 'Sales Executive - '.app_name; $data['page_active'] = $mod; return view($mod, $data); } } public function send_email($param1='', $param2=''){ $uid = $this->request->getPost('user_id'); $email = $this->Crud->read_field('id', $uid, 'user', 'email'); $fullname = $this->Crud->read_field('id', $uid, 'user', 'fullname'); if(empty($email)){ echo $this->Crud->msg('danger', 'Invalid Account Email'); die; } if ($param1 == 'login') { $name = ucwords($fullname); $login_url = site_url('auth/login'); // Adjust based on your login URL $generated_password = '0000'; // Assuming username and password are retrieved or generated $user_email = $email; $user_password = $generated_password; // Replace with actual user password $message = ' <h2>Welcome to ' . app_name . '!</h2> <p>Hello <strong>' . $name . '</strong>,</p> <p>Your account has been successfully created. Below are your login credentials:</p> <h3>Login Credentials:</h3> <ul> <li><strong>Email:</strong> ' . $user_email . '</li> <li><strong>Password:</strong> ' . $user_password . '</li> </ul> <p><a href="' . $login_url . '" class="button" style="background:#28a745;padding:10px 20px;color:white;text-decoration:none;border-radius:5px;">Login to Your Account</a></p> <p>If the button above doesn’t work, copy and paste the following URL into your browser:</p> <p><a href="' . $login_url . '">' . $login_url . '</a></p> <p class="note"><strong>Security Tip:</strong> We recommend changing your password after your first login.</p> <p>Best Regards,</p> <p>The ' . app_name . ' Team</p> '; $body = 'Dear ' . $name . ', <br><br>' . $message; $inz = $this->Crud->send_email($email, 'Your Login Credentials for ' . app_name, $body); if ($inz > 0) { echo $this->Crud->msg('success', 'Login credentials sent successfully!'); } else { echo $this->Crud->msg('danger', 'Failed to send login credentials. <br>Please try again later.'); } die; } if($param1 == 'otp'){ $reset = substr(md5(time().rand()), 0, 6); if($this->Crud->updates('id', $uid, 'user', array('reset'=>$reset)) > 0) { $fullname = $this->Crud->read_field('id', $uid, 'user', 'fullname'); // send email if ($email) { $msg = 'Dear ' . ucwords($fullname) . ',<br><br> We have received a request to verify your identity for ' . app_name . '. Please use the following One-Time Password (OTP) to proceed with your request:<br><br> OTP: <strong>' . $reset . '</strong><br><br> This OTP is valid for a limited time. If you did not initiate this request or have concerns about the security of your account, please contact our support team immediately at ' . push_email . '.<br><br> Thank you for choosing ' . app_name . '.<br><br> Best regards,<br> ' . app_name . ' Team'; $inz = $this->Crud->send_email($email, 'Your One-Time Password (OTP)', $msg); if($inz > 0){ echo $this->Crud->msg('success', 'Your One-Time Password Email sent successfully!'); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('danger', 'Your One-Time Password Email Failed. <br>Try Again Later'); } die; } } } } public function profile_view($param1='', $param2='', $param3='', $param4='') { // check login $log_id = $this->session->get('fls_id'); if(empty($log_id)) return redirect()->to(site_url('auth')); $role_id = $this->Crud->read_field('id', $log_id, 'user', 'role_id'); $role = strtolower($this->Crud->read_field('id', $role_id, 'access_role', 'name')); $main_email = $this->Crud->read_field('id', $log_id, 'user', 'email'); $data['log_id'] = $log_id; $data['role'] = $role; if($param1 == 'records'){ if($param2 == 'activity_load'){ $limit = $param3; $offset = $param4; $count = 0; $rec_limit = 25; $item = ''; if($limit == '') {$limit = $rec_limit;} if($offset == '') {$offset = 0;} $id = $this->request->getVar('id'); if(!empty($this->request->getPost('start_date'))) { $start_date = $this->request->getPost('start_date'); } else { $start_date = ''; } if(!empty($this->request->getPost('end_date'))) { $end_date = $this->request->getPost('end_date'); } else { $end_date = ''; } if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $query = $this->Crud->filter_activity($limit, $offset, $id, '', $start_date, $end_date); $all_rec = $this->Crud->filter_activity('', '', $id, '', $start_date, $end_date); if(!empty($all_rec)) { $counts = count($all_rec); } else { $counts = 0; } if(!empty($query)) { foreach($query as $q) { $id = $q->id; $type = $q->item; $user_id = $q->user_id; $type_id = $q->item_id; $action = $q->action; $reg_date = date('M d, Y h:i A', strtotime($q->reg_date)); $user = $this->Crud->read_field('id', $user_id, 'user', 'fullname'); $timespan = $this->Crud->timespan(strtotime($q->reg_date)); $item .= ' <tr> <td>'.$reg_date.'</td> <td>'.ucwords($type).'</td> <td>'.ucwords($user).'</td> <td>'.$action.'</td> <td>'.$timespan.'</td> </tr> '; } } } if(empty($item)) { $resp['item'] = ' <tr><td colspan="8"><div class="text-center text-muted"> <br/><br/><br/><br/> <i class="ki-duotone ki-profile-user" style="font-size:150px;"> <span class="path1"></span> <span class="path2"></span> <span class="path3"></span> <span class="path4"></span> </i><br/><br/>No Activity Returned </div></td></tr> '; } else { $resp['item'] = $item; } $resp['count'] = $counts; $more_record = $counts - ($offset + $rec_limit); $resp['left'] = $more_record; if($counts > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } echo json_encode($resp); die; } if($param2 == 'voucher_load') { $limit = $param3; $offset = $param4; $count = 0; $rec_limit = 50; $item = ''; if($limit == '') {$limit = $rec_limit;} if($offset == '') {$offset = 0;} $id = $this->request->getVar('id'); if(!empty($this->request->getVar('start_date'))) { $start_date = $this->request->getVar('start_date'); } else { $start_date = ''; } if(!empty($this->request->getVar('end_date'))) { $end_date = $this->request->getVar('end_date'); } else { $end_date = ''; } $search = $this->request->getVar('search'); if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $query = $this->Crud->filter_voucher($limit, $offset, $id, 'all', $search, $start_date, $end_date); $all_rec = $this->Crud->filter_voucher('', '', $id, 'all', $search, $start_date, $end_date); if(!empty($all_rec)) { $count = count($all_rec); } else { $count = 0; } $curr = '₦'; if(!empty($query)) { foreach($query as $q) { $id = $q->id; $code = $q->code; $user_id = $q->user_id; $price = $q->price; $status = $q->status; $reg_date = date('M d, Y h:i A', strtotime($q->reg_date)); // user $user = $this->Crud->read_field('id', $user_id, 'user', 'fullname'); $user_role_id = $this->Crud->read_field('id', $user_id, 'user', 'role_id'); $user_role = strtoupper($this->Crud->read_field('id', $user_role_id, 'access_role', 'name')); $user_image_id = $this->Crud->read_field('id', $user_id, 'user', 'img_id'); $user_image = $this->Crud->image($user_image_id, 'big'); $stat = '<div class="badge badge-light-danger">Not Used</div>'; if($q->status == 1){ $stat = '<div class="badge badge-light-primary">Used</div>'; } if($q->status == 2){ $stat = '<div class="badge badge-light-success">Transfered</div>'; } $all_btn = ''; if($q->status == 0){ $all_btn = ' <div class="d-flex justify-content-end flex-shrink-0"> </div> '; } $item .= ' <tr> <td>'.$reg_date.'</td> <td> <a href="javascript:;" class="text-gray-800 text-hover-success mb-1">'.$code.'</a> </td> <td> <a href="javascript:;" class="text-gray-600 text-hover-success mb-1">'.curr.number_format($price,2).'</a> </td> <td>'.$stat.'</td> <td> '.$all_btn.' </td> </tr> '; } } } if(empty($item)) { $resp['item'] = '<tr><td colspan="8"> <div class="text-center text-muted"> <br/><br/> <i class="ki-duotone ki-wallet fs-5x"> <span class="path1"></span> <span class="path2"></span> <span class="path3"></span> <span class="path4"></span> </i><br/><br/>No Voucher Returned </div></td></tr> '; } else { $resp['item'] = $item; } $more_record = $count - ($offset + $rec_limit); $resp['left'] = $more_record; if($count > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } echo json_encode($resp); die; } if($param2 == 'transaction_load') { $limit = $param3; $offset = $param4; $count = 0; $rec_limit = 25; $item = ''; if($limit == '') {$limit = $rec_limit;} if($offset == '') {$offset = 0;} if(!empty($this->request->getVar('status'))) { $status = $this->request->getVar('status'); } else { $status = ''; } if(!empty($this->request->getVar('state'))) { $state = $this->request->getVar('state'); } else { $state = ''; } if(!empty($this->request->getVar('merchant_id'))) { $merchant_id = $this->request->getVar('merchant_id'); } else { $merchant_id = ''; } if(!empty($this->request->getVar('lga'))) { $lga = $this->request->getVar('lga'); } else { $lga = ''; } if(!empty($this->request->getVar('start_date'))) { $start_date = $this->request->getVar('start_date'); } else { $start_date = ''; } if(!empty($this->request->getVar('end_date'))) { $end_date = $this->request->getVar('end_date'); } else { $end_date = ''; } $search = $this->request->getVar('search'); $id = $this->request->getVar('id'); $log_role_id = $this->Crud->read_field('id', $id, 'user', 'role_id'); $log_role = $this->Crud->read_field('id', $log_role_id, 'access_role', 'name'); if($log_role == 'Merchant'){ $merchant_id = $id; $user_id = ''; } if($log_role == 'Customer'){ $merchant_id = ''; $user_id = $id; } if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $query = $this->Crud->filter_transaction($limit, $offset, $user_id, $status, $merchant_id, $state, $lga, $search, $start_date, $end_date); $all_rec = $this->Crud->filter_transaction('', '', $user_id, $status, $merchant_id, $state, $lga, $search, $start_date, $end_date); if(!empty($all_rec)) { $count = count($all_rec); } else { $count = 0; } $curr = '₦'; if(!empty($query)) { foreach($query as $q) { $id = $q->id; $code = $q->code; $state_id = $q->state_id; $city_id = $q->city_id; $user_id = $q->user_id; $merchant_id = $q->merchant_id; $quantity = $q->litre; $total = number_format((float)$q->amount, 2); $reg_date = date('M d, Y h:i A', strtotime($q->reg_date)); // category $merchant = $this->Crud->read_field('id', $merchant_id, 'user', 'company_name'); // state $state = $this->Crud->read_field('id', $state_id, 'state', 'name'); $city = $this->Crud->read_field('id', $city_id, 'city', 'name'); // user $user = $this->Crud->read_field('id', $user_id, 'user', 'fullname'); $item .= ' <tr> <td>'.$reg_date.'</td> <td>'.ucwords($user).'</td> <td>'.ucwords($merchant).'</td> <td><span class="text-gray-600 text-hover-success mb-1">'.$code.'</span><br><span>'.curr.$total.'</span></td> <td>'.number_format($quantity,4).' LTR</td> </tr> '; } } } if(empty($item)) { $resp['item'] = '<tr><td colspan="8"> <div class="text-center text-muted"> <br/><br/> <i class="ki-duotone ki-wallet fs-5x" style="font-size:150px;"> <span class="path1"></span> <span class="path2"></span> <span class="path3"></span> <span class="path4"></span> </i><br/><br/>No Transaction Returned </div></td></tr> '; } else { $resp['item'] = $item; } $more_record = $count - ($offset + $rec_limit); $resp['left'] = $more_record; if($count > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } echo json_encode($resp); die; } if($param2 == 'wallet_load') { $limit = $param3; $offset = $param4; $count = 0; $rec_limit = 25; $item = ''; if($limit == '') {$limit = $rec_limit;} if($offset == '') {$offset = 0;} if(!empty($this->request->getVar('start_date'))) { $start_date = $this->request->getVar('start_date'); } else { $start_date = ''; } if(!empty($this->request->getVar('end_date'))) { $end_date = $this->request->getVar('end_date'); } else { $end_date = ''; } $search = $this->request->getVar('search'); $type = $this->request->getVar('type'); $id = $this->request->getVar('id'); if(!$log_id) { $item = '<div class="text-center text-muted">Session Timeout! - Please login again</div>'; } else { $query = $this->Crud->filter_wallet($limit, $offset, $id, $type, $search, $start_date, $end_date); $all_rec = $this->Crud->filter_wallet('', '', $id, $type, $search, $start_date, $end_date); if(!empty($all_rec)) { $count = count($all_rec); } else { $count = 0; } $curr = '₦'; $credit = 0;$debit = 0; $wallet = $this->Crud->read_single('user_id', $id, 'wallet'); if(!empty($wallet)){ foreach($wallet as $po){ if($po->type == 'credit'){ $credit += (float)$po->amount; } if($po->type == 'debit'){ $debit += (float)$po->amount; } } } if(!empty($query)) { foreach($query as $q) { $id = $q->id; $user_id = $q->user_id; $type = $q->type; $mod = $q->item; $remark = $q->remark; $amount = number_format((float)$q->amount, 2); $reg_date = date('M d, Y h:i A', strtotime($q->reg_date)); if($q->type == 'credit'){ $typ = '<div class="badge badge-light-primary fs-7">CREDIT</div>'; } if($q->type == 'debit'){ $typ = '<div class="badge badge-light-danger fs-7">DEBIT</div>'; } $item .= ' <tr> <td>'.$reg_date.'</td> <td> '.$typ.' </td> <td> <a href="javascript:;" class="text-gray-600 text-hover-success mb-1">'.curr.($amount).'</a> </td> <td>'.ucwords($remark).'</td> </tr> '; } } } $balance = $credit - $debit; if(empty($item)) { $resp['item'] = '<tr><td colspan="8"> <div class="text-center text-muted"> <br/><br/><br/><br/> <i class="ki-duotone ki-wallet fs-4x"> <span class="path1"></span> <span class="path2"></span> <span class="path3"></span> <span class="path4"></span> </i><br/><br/>No Wallet Returned </div></td></tr> '; } else { $resp['item'] = $item; } $more_record = $count - ($offset + $rec_limit); $resp['left'] = $more_record; $resp['credit'] = $curr . number_format($credit, 2); $resp['debit'] = $curr . number_format($debit, 2); $resp['balance'] = $curr . number_format($balance, 2); if($count > ($offset + $rec_limit)) { // for load more records $resp['limit'] = $rec_limit; $resp['offset'] = $offset + $limit; } else { $resp['limit'] = 0; $resp['offset'] = 0; } echo json_encode($resp); die; } } if($param1 == 'activate'){ if($this->request->getMethod() == 'post') { $user_id = $this->request->getVar('user_id'); $st = $this->Crud->read_field('id', $user_id, 'user', 'activate'); if($st == 0){ $act = 1; } else { $act = 0; } $upd = $this->Crud->updates('id', $user_id, 'user', array('activate'=>$act)); if($upd > 0){ echo $this->Crud->msg('success', 'Account status Updated!!'); $code = $this->Crud->read_field('id', $user_id, 'user', 'fullname'); $action = $code.' Updated ('.$code.')Account status'; $this->Crud->activity('authentication', $user_id, $action); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('info', 'No Changes!!'); } die; } } if($param1 == 'update'){ if($this->request->getMethod() == 'post') { $user_id = $this->request->getVar('user_id'); $email = $this->request->getVar('email'); $fullname = $this->request->getVar('firstname').' '.$this->request->getVar('surname'); $phone = $this->request->getVar('phone'); $company_name = $this->request->getVar('company_name'); $lga_id = $this->request->getVar('lga_id'); $address = $this->request->getVar('address'); $state_id = $this->request->getVar('state_id'); $lat = $this->request->getVar('latitude'); $lng = $this->request->getVar('longitude'); $img_id = $this->request->getVar('img_id'); $main_email = $this->Crud->read_field('id', $user_id, 'user', 'email'); if(!$email || !$fullname) { echo $this->Crud->msg('danger', 'Full Name and Email field(s) missing'); die; } if($email != $main_email) { if($this->Crud->check('email', $email, 'user') > 0) { echo $this->Crud->msg('danger', 'Email already taken, try another'); die; } } //// Image upload if(file_exists($this->request->getFile('avatar'))) { $path = 'assets/images/users/'.$user_id.'/'; $file = $this->request->getFile('avatar'); $getImg = $this->Crud->img_upload($path, $file); if(!empty($getImg->path)) $img_id = $this->Crud->save_image($user_id, $getImg->path); if($role == 'merchant'){ $img_id = $getImg->path; } } $state = $this->Crud->read_field('name', $state_id, 'state', 'id'); $lga = $this->Crud->read_field('name', $lga_id, 'city', 'id'); // update profile $upd_data['email'] = $email; $upd_data['fullname'] = $fullname; $upd_data['phone'] = $phone; $upd_data['lga_id'] = $lga; $upd_data['lat'] = $lat; $upd_data['lng'] = $lng; $upd_data['company_name'] = $company_name; $upd_data['address'] = $address; $upd_data['state_id'] = $state; if($role == 'merchant'){ $upd_data['logo'] = $img_id; } else { $upd_data['img_id'] = $img_id; } if($this->Crud->updates('id', $user_id, 'user', $upd_data) > 0) { echo $this->Crud->msg('success', 'Record Updated'); $by = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $code = $this->Crud->read_field('id', $user_id, 'user', 'fullname'); $action = $by.' Updated ('.$code.') Account Profile Information '; $this->Crud->activity('authentication', $user_id, $action); echo '<script>location.reload(false);</script>'; } else { echo $this->Crud->msg('info', 'No Changes'); } die; } } $log_id = $param1; $data['email'] = $this->Crud->read_field('id', $log_id, 'user', 'email'); $role_id = $this->Crud->read_field('id', $log_id, 'user', 'role_id'); $role = strtolower($this->Crud->read_field('id', $role_id, 'access_role', 'name')); $data['user_role'] = $role; $data['user_id'] = $log_id; $data['company_name'] = $this->Crud->read_field('id', $log_id, 'user', 'company_name'); $data['fullname'] = $this->Crud->read_field('id', $log_id, 'user', 'fullname'); $lga_id = $this->Crud->read_field('id', $log_id, 'user', 'lga_id'); $data['city'] = $this->Crud->read_field('id', $lga_id, 'city', 'name'); $data['lat'] = $this->Crud->read_field('id', $log_id, 'user', 'lat'); $data['lng'] = $this->Crud->read_field('id', $log_id, 'user', 'lng'); $data['phone'] = $this->Crud->read_field('id', $log_id, 'user', 'phone'); $data['address'] = $this->Crud->read_field('id', $log_id, 'user', 'address'); $state_id = $this->Crud->read_field('id', $log_id, 'user', 'state_id'); $data['state'] = $this->Crud->read_field('id', $state_id, 'state', 'name'); $data['country_id'] = $this->Crud->read_field('id', $log_id, 'user', 'country_id'); $img_id = $this->Crud->read_field('id', $log_id, 'user', 'img_id'); $logo = $this->Crud->read_field('id', $log_id, 'user', 'logo'); $data['state_id'] = $state_id; $data['lga_id'] = $lga_id; $data['img_id'] = $img_id; if(!empty($logo)){ $data['img'] = $logo; } else { $data['img'] = $this->Crud->image($img_id, 'big'); } $data['title'] = 'Profile View - '.app_name; $data['page_active'] = 'profile'; return view('accounts/profile', $data); } public function get_state($country){ if(empty($country)){ echo '<label for="activate">State</label> <input type="text" class="form-control" name="state" id="state" readonly placeholder="Select Country First">'; } else { $state = $this->Crud->read_single_order('country_id', $country, 'state', 'name', 'asc'); echo '<label for="activate">State</label> <select class="form-select js-select2" data-search="on" id="state" name="state" onchange="lgaa();"> <option value="">Select</option> '; foreach($state as $qr) { $hid = ''; $sel = ''; echo '<option value="'.$qr->id.'" '.$sel.'>'.$qr->name.'</option>'; } echo '</select> <script> $(".js-select2").select2();</script>'; } } public function get_lga($state){ if(empty($state)){ echo '<label for="activate">City</label> <input type="text" class="form-control" name="lga" id="lga" readonly placeholder="Select State First">'; } else { $state = $this->Crud->read_single_order('state_id', $state, 'city', 'name', 'asc'); echo '<label for="activate" class="mb-2">City</label> <select class="form-select select2" data-search="on" id="lga" name="lga" onchange="branc();"> <option value="">Select</option> '; foreach($state as $qr) { $hid = ''; $sel = ''; echo '<option value="'.$qr->id.'" '.$sel.'>'.$qr->name.'</option>'; } echo '</select> <script> $(".js-select2").select2();</script>'; } } public function get_branch($state){ if(empty($state)){ echo '<label for="activate">Branch</label> <input type="text" class="form-control" name="branch" id="branch" readonly placeholder="Select LGA First">'; } else { $state = $this->Crud->read_single_order('city_id', $state, 'branch', 'name', 'asc'); echo '<label for="activate">Branch</label> <select class="form-select js-select2" data-search="on" id="branch" name="branch" onchange="load();"> <option value="">Select</option> '; foreach($state as $qr) { $hid = ''; $sel = ''; echo '<option value="'.$qr->id.'" '.$sel.'>'.$qr->name.'</option>'; } echo '</select> <script> $(".js-select2").select2();</script>'; } } }
Upload File
Create Folder