From 4ac28e7eb25b1bf92cbf54df3705a82209c628ef Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Mon, 14 Jul 2025 13:06:15 +0530 Subject: [PATCH] issues fixes --- app/Controllers/PlanController.php | 85 ++++++++++++++++++++++++++---- app/Models/UserModel.php | 2 +- 2 files changed, 75 insertions(+), 12 deletions(-) diff --git a/app/Controllers/PlanController.php b/app/Controllers/PlanController.php index 0e05a08..026ad19 100644 --- a/app/Controllers/PlanController.php +++ b/app/Controllers/PlanController.php @@ -969,13 +969,7 @@ class PlanController extends ResourceController 6 => 'Completed', 7 => 'Cancelled' ]; - for ($i = 1; $i <= 7; $i++) { // Fixed loop condition - if($i == 5 || $i == 6){ continue; } - $statusResult[] = [ - 'value' => $statusLabels[$i], - 'count' => $statusCounts[$i] ?? 0 // Handle missing values - ]; - } + // Count occurrences of each type ID $typeCounts = array_count_values(array_column($plans, 'trip_type')); @@ -984,13 +978,77 @@ class PlanController extends ResourceController 1 => 'Domestic', 2 => 'International' ]; + + $todayStart = date('Y-m-d 00:00:00'); + $todayEnd = date('Y-m-d 23:59:59'); + $startOfWeek = date('Y-m-d 00:00:00', strtotime('monday this week')); + $endOfWeek = date('Y-m-d 23:59:59', strtotime('sunday this week')); + + $typeResultToday = []; + $typeResultWeekly = []; + + $todayType = array_filter($plans, function ($plan) use ($todayStart, $todayEnd) { + return $plan['created_on'] >= $todayStart && $plan['created_on'] <= $todayEnd; + }); + + $todayTypeCounts = array_count_values(array_column($todayType, 'trip_type')); + + $weeklyType = array_filter($plans, function ($plan) use ($startOfWeek, $endOfWeek) { + return $plan['created_on'] >= $startOfWeek && $plan['created_on'] <= $endOfWeek; + }); + + $weeklyTypeCounts = array_count_values(array_column($weeklyType, 'trip_type')); + for ($i = 1; $i <= 2; $i++) { // Fixed loop condition $typeResult[] = [ - 'value' => $typeLabels[$i], + 'value' => $typeLabels[$i], 'count' => $typeCounts[$i] ?? 0 // Handle missing values ]; + $typeResultToday[] = [ + 'value' => $typeLabels[$i], + 'count' => $todayTypeCounts[$i] ?? 0 // Handle missing values + ]; + $typeResultWeekly[] = [ + 'value' => $typeLabels[$i], + 'count' => $weeklyTypeCounts[$i] ?? 0 // Handle missing values + ]; } + $statusResultToday = []; + $statusResultWeekly = []; + + $todayStatus = array_filter($plans, function ($plan) use ($todayStart, $todayEnd) { + return $plan['created_on'] >= $todayStart && $plan['created_on'] <= $todayEnd; + }); + $todayStatusCounts = array_count_values(array_column($todayStatus, 'status')); + + $weeklyStatus = array_filter($plans, function ($plan) use ($startOfWeek, $endOfWeek) { + return $plan['created_on'] >= $startOfWeek && $plan['created_on'] <= $endOfWeek; + }); + $weeklyStatusCounts = array_count_values(array_column($weeklyStatus, 'status')); + + for ($i = 1; $i <= 7; $i++) { // Fixed loop condition + if($i == 5 || $i == 6){ continue; } + $statusResult[] = [ + 'value' => $statusLabels[$i], + 'count' => $statusCounts[$i] ?? 0 // Handle missing values + ]; + $statusResultToday[] = [ + 'value' => $statusLabels[$i], + 'count' => $todayStatusCounts[$i] ?? 0 // Handle missing values + ]; + $statusResultWeekly[] = [ + 'value' => $statusLabels[$i], + 'count' => $weeklyStatusCounts[$i] ?? 0 // Handle missing values + ]; + } + + $data['statusBasedCount'] = $statusResult; + $data['statusBasedTodayCount'] = $statusResultToday; + $data['statusBasedWeeklyCount'] = $statusResultWeekly; + $data['typeBasedCount'] = $typeResult; + $data['typeBasedTodayCount'] = $typeResultToday; + $data['typeBasedWeeklyCount'] = $typeResultWeekly; // === Today's Date & Week Range === $today = date('Y-m-d'); @@ -1068,7 +1126,7 @@ class PlanController extends ResourceController // Fetch the plan - $plan = $this->planModel->select( 'm_plan.*, + $plan = $this->planModel->select( 'm_plan.*, CONCAT_WS(U.first_name," ",U.last_name) as user_name, U.employee_code,U.passport_number,U.date_of_expiry,U.place_of_issue,U.forex_pre_paid_card_number, CONCAT_WS(C.first_name," ",C.last_name) as plan_created_by, @@ -1078,7 +1136,8 @@ class PlanController extends ResourceController IB.dropdown_value as is_billable_value, POT.dropdown_value as purpose_of_travel_value, FD.dropdown_value as functional_department_value, - Dep.name as cost_center_value' + CC.name as cost_center_value,ORG.logo', + // Dep.name as cost_center_value' // old. don't why dep name used. ) ->join('m_users U', 'U.user_id = m_plan.user_id ', 'left') ->join('m_users C', 'C.user_id = m_plan.created_by ', 'left') @@ -1089,10 +1148,14 @@ class PlanController extends ResourceController ->join('m_dropdown POT', 'POT.dropdown_key = m_plan.purpose_of_travel AND POT.dropdown = "plan_purpose_of_travel"', 'left') ->join('m_dropdown FD', 'FD.dropdown_key = m_plan.functional_department AND FD.dropdown = "plan_functional_department"', 'left') ->join('m_department Dep', 'Dep.department_id = m_plan.cost_center_id ', 'left') + ->join('m_cost_center CC', 'CC.cost_center_id = m_plan.cost_center_id ', 'left') + ->join('m_organization ORG', 'ORG.org_id = m_plan.org_id ', 'left') ->where('m_plan.is_active', 1) ->find($planId); - $userId = isset($plan['traveller_id']) && !empty($plan['traveller_id']) ? $plan['created_by'] : $plan['user_id']; + $userId = isset($plan['traveller_id']) && !empty($plan['traveller_id']) ? $plan['created_by'] : $plan['user_id']; + // $orgId = !empty($plan) ? $plan['org_id'] : ""; + $orgLogo = !empty($plan) ? $plan['logo'] : ""; $tripType = $plan['trip_type']; $plan['allowed_class'] = getAllowedClassForUser($tripType,$userId); diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index c3cba7d..3c7ed00 100644 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -10,7 +10,7 @@ class UserModel extends Model protected $primaryKey = 'user_id'; // Primary key // Fields that can be mass assigned - protected $allowedFields = ['first_name','last_name','password','email','mobile_no','alternate_mobile_no','date_of_birth','address','gender','postal_code','country_code','employee_code','role_id','department_id','group_id','first_approver','first_approver_email','second_approver','second_approver_email','third_approver','third_approver_email','exceptional_approver','exceptional_approver_email','user_type','passport_number','place_of_issue','passport_document','passport_firstname','passport_middlename','passport_lastname','nationality','date_of_issue','date_of_expiry','created_on','created_by','updated_on','updated_by','is_active','org_id', 'temp_password', 'forex_pre_paid_card_number', 'emergency_contact_number', 'd_seat_preference', 'd_meal_preference', 'i_seat_preference', 'i_meal_preference', 'agent_supported_service_ids', 'd_additonalInfo', 'i_additonalInfo', 'forex_expiry_date', 'delegated_to_user_id', 'delegation_start_date', 'delegation_end_date','last_login_at']; + protected $allowedFields = ['first_name','last_name','password','email','mobile_no','alternate_mobile_no','date_of_birth','address','gender','postal_code','country_code','employee_code','role_id','department_id','group_id','first_approver','first_approver_email','second_approver','second_approver_email','third_approver','third_approver_email','exceptional_approver','exceptional_approver_email','user_type','passport_number','place_of_issue','passport_document','passport_firstname','passport_middlename','passport_lastname','nationality','date_of_issue','date_of_expiry','created_on','created_by','updated_on','updated_by','is_active','org_id', 'temp_password', 'forex_pre_paid_card_number', 'emergency_contact_number', 'd_seat_preference', 'd_meal_preference', 'i_seat_preference', 'i_meal_preference', 'agent_supported_service_ids', 'd_additonalInfo', 'i_additonalInfo', 'forex_expiry_date', 'delegated_to_user_id', 'delegation_start_date', 'delegation_end_date','last_login_at','company_name']; // Specify the return type of the results protected $returnType = 'array';