03-07-2025 - vadivel - ts tat dashboard api released

This commit is contained in:
vadivelJ96 2025-07-03 17:17:15 +05:30
parent 4a757775d9
commit 1b7fba8286
3 changed files with 474 additions and 13 deletions

View File

@ -97,6 +97,10 @@ $routes->post('forgotPassword/changePassword', 'UserController::forgotChangePass
$routes->get('plans/cancle_plan', 'PlanController::canclePlan');
$routes->get('plans/get_plan_approval_status', 'PlanController::get_plan_approval_status');
$routes->get('plans/selectedServiceDashboardWeekly','PlanController::selectedServiceDashboardWeekly');
$routes->get('plans/selectedServiceDashboardDaily','PlanController::selectedServiceDashboardDaily');
$routes->get('plans/plan_pdf', 'PlanController::plan_pdf');
//Master

View File

@ -24,6 +24,7 @@ use App\Models\OrganizationModel;
use App\Models\PlanRemarkModel;
use App\Models\UserVisaDetailsModel;
use App\Models\MailTemplateModel;
use App\Models\ReportsModel;
use Mpdf\Mpdf;
class PlanController extends ResourceController
@ -48,6 +49,7 @@ class PlanController extends ResourceController
protected $planRemarkModel;
protected $userVisaDetailsModel;
protected $mailTemplateModel;
protected $reportsModel;
public function __construct()
{
@ -71,6 +73,7 @@ class PlanController extends ResourceController
$this->planRemarkModel = new PlanRemarkModel();
$this->userVisaDetailsModel = new UserVisaDetailsModel();
$this->mailTemplateModel = new MailTemplateModel();
$this->reportsModel = new ReportsModel();
}
@ -1010,18 +1013,10 @@ class PlanController extends ResourceController
}
}
$data['statusBasedCount'] = $statusResult;
$data['typeBasedCount'] = $typeResult;
$data['todayTripCounts'] = [
'date_range' => $today,
'Domestic' => $todayCounts['Domestic'],
'International' => $todayCounts['International']
];
$data['weekTripCounts'] = [
'date_range' => $startOfWeek . ' to ' . $endOfWeek,
'Domestic' => $weekCounts['Domestic'],
'International' => $weekCounts['International']
];
$data['statusBasedCount'] = $statusResult;
$data['typeBasedCount'] = $typeResult;
$data['todayTripCounts'] = $this->selectedServiceDashboardDaily();
$data['weekTripCounts'] = $this->selectedServiceDashboardWeekly();
return $this->respond(['status' => 200, 'message' => 'success', 'data' => $data ]);
@ -1388,16 +1383,82 @@ class PlanController extends ResourceController
}
// faf stands for flight accomodation and forex
public function selectedServiceDashboardWeekly(){
$flightResult = $this->reportsModel->flightServiceDashboardWeekly();
$accomodationResult = $this->reportsModel->accomodationServiceDashboardWeekly();
$forexResult = $this->reportsModel->forexServiceDashboardWeekly();
$result = [
"flightService" => $flightResult ,
"acomodationService" => $accomodationResult ,
"forexService" => $forexResult
];
return $result = $this->splitResultbasedOnTripType($result);
}
public function selectedServiceDashboardDaily(){
$flightResult = $this->reportsModel->flightServiceDashboardDaily();
$accomodationResult = $this->reportsModel->accomodationServiceDashboardDaily();
$forexResult = $this->reportsModel->forexServiceDashboardDaily();
$result = [
"flightService" => $flightResult ,
"acomodationService" => $accomodationResult ,
"forexService" => $forexResult
];
return $result = $this->splitResultbasedOnTripType($result);
}
function splitResultBasedOnTripType(array $result): array
{
$finalResult = [];
$trip_types = ['International', 'Domestic'];
$statuses = ['Pending Approval', 'Partially Approved', 'Approved', 'Rejected', 'Cancelled'];
foreach ($result as $service => $entries) {
$resultSet = [] ;
foreach ($trip_types as $trip_type) {
foreach ($statuses as $status) {
$resultSet[$service][$trip_type][$status] = 0;
}
}
foreach ($entries as $entry) {
$tripType = $entry['trip_type'];
$status = $entry['Status'];
$count = (int) $entry['count'];
$resultSet[$service][$tripType][$status] += $count;
}
foreach ($statuses as $status) {
$resultSet[$service]['Both'][$status] =
$resultSet[$service]['International'][$status] +
$resultSet[$service]['Domestic'][$status];
}
$finalResult [] = $resultSet;
}
return $finalResult;
}

View File

@ -366,4 +366,400 @@ class ReportsModel extends Model
}
public function flightServiceDashboardWeekly(){
$sql = "SELECT
COALESCE(t.count, 0) AS count,
s.trip_type,
s.status_label AS Status
FROM (
SELECT trip_type, status_label
FROM (
SELECT 'International' AS trip_type
UNION
SELECT 'Domestic'
) trip_types
CROSS JOIN (
SELECT 'Pending Approval' AS status_label
UNION SELECT 'Partially Approved'
UNION SELECT 'Approved'
UNION SELECT 'Rejected'
UNION SELECT 'Cancelled'
) statuses
) s
-- Step 2: Left join real data
LEFT JOIN (
SELECT
COUNT(cf.flight_id) as count,
case
when mp.trip_type = 1 then 'Domestic'
when mp.trip_type = 2 then 'International'
END AS trip_type ,
case
when mp.status = 1 then 'Pending Approval'
when mp.status = 2 then 'Partially Approved'
when mp.status = 3 then 'Approved'
when mp.status = 4 then 'Rejected'
when mp.status = 7 then 'Cancelled'
END AS Status
FROM c_flight cf
JOIN m_plan mp ON cf.plan_id = mp.plan_id
WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
AND cf.created_on < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
-- previous week
-- WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)
-- AND cf.created_on < DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY);
AND mp.is_active = 1
GROUP BY mp.status,mp.trip_type
) t ON s.trip_type = t.trip_type AND s.status_label = t.Status
";
$binds = [];
$result = $this->db->query($sql,$binds)->getResultArray();
return $result ;
}
public function accomodationServiceDashboardWeekly(){
$sql = "SELECT
COALESCE(t.count, 0) AS count,
s.trip_type,
s.status_label AS Status
FROM (
SELECT trip_type, status_label
FROM (
SELECT 'International' AS trip_type
UNION ALL
SELECT 'Domestic'
) trip_types
CROSS JOIN (
SELECT 'Pending Approval' AS status_label
UNION ALL SELECT 'Partially Approved'
UNION ALL SELECT 'Approved'
UNION ALL SELECT 'Rejected'
UNION ALL SELECT 'Cancelled'
) statuses
) s
-- Step 2: Left join real data
LEFT JOIN (
SELECT
COUNT(ca.accomodation_id) as count,
case
when mp.trip_type = 1 then 'Domestic'
when mp.trip_type = 2 then 'International'
END AS trip_type ,
case
when mp.status = 1 then 'Pending Approval'
when mp.status = 2 then 'Partially Approved'
when mp.status = 3 then 'Approved'
when mp.status = 4 then 'Rejected'
when mp.status = 7 then 'Cancelled'
END AS Status
FROM c_accomodation ca
JOIN m_plan mp ON ca.plan_id = mp.plan_id
WHERE ca.created_on >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
AND ca.created_on < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
-- previous week
-- WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)
-- AND cf.created_on < DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY);
AND mp.is_active = 1
GROUP BY mp.status,mp.trip_type
) t ON s.trip_type = t.trip_type AND s.status_label = t.Status
";
$binds = [];
$result = $this->db->query($sql,$binds)->getResultArray();
return $result ;
}
public function forexServiceDashboardWeekly(){
$sql = "SELECT
COALESCE(t.count, 0) AS count,
s.trip_type,
s.status_label AS Status
FROM (
SELECT trip_type, status_label
FROM (
SELECT 'International' AS trip_type
UNION ALL
SELECT 'Domestic'
) trip_types
CROSS JOIN (
SELECT 'Pending Approval' AS status_label
UNION ALL SELECT 'Partially Approved'
UNION ALL SELECT 'Approved'
UNION ALL SELECT 'Rejected'
UNION ALL SELECT 'Cancelled'
) statuses
) s
-- Step 2: Left join real data
LEFT JOIN (
SELECT
COUNT(cf.forex_id) as count,
case
when mp.trip_type = 1 then 'Domestic'
when mp.trip_type = 2 then 'International'
END AS trip_type ,
case
when mp.status = 1 then 'Pending Approval'
when mp.status = 2 then 'Partially Approved'
when mp.status = 3 then 'Approved'
when mp.status = 4 then 'Rejected'
when mp.status = 7 then 'Cancelled'
END AS Status
FROM c_forex cf
JOIN m_plan mp ON cf.plan_id = mp.plan_id
WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)
AND cf.created_on < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)
-- previous week
-- WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)
-- AND cf.created_on < DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY);
AND mp.is_active = 1
GROUP BY mp.status,mp.trip_type
) t ON s.trip_type = t.trip_type AND s.status_label = t.Status
";
$binds = [];
$result = $this->db->query($sql,$binds)->getResultArray();
return $result ;
}
public function flightServiceDashboardDaily(){
$sql = "SELECT
COALESCE(t.count, 0) AS count,
s.trip_type,
s.status_label AS Status
FROM (
SELECT trip_type, status_label
FROM (
SELECT 'International' AS trip_type
UNION ALL
SELECT 'Domestic'
) trip_types
CROSS JOIN (
SELECT 'Pending Approval' AS status_label
UNION ALL SELECT 'Partially Approved'
UNION ALL SELECT 'Approved'
UNION ALL SELECT 'Rejected'
UNION ALL SELECT 'Cancelled'
) statuses
) s
-- Step 2: Left join real data
LEFT JOIN (
SELECT
COUNT(cf.flight_id) as count,
case
when mp.trip_type = 1 then 'Domestic'
when mp.trip_type = 2 then 'International'
END AS trip_type ,
case
when mp.status = 1 then 'Pending Approval'
when mp.status = 2 then 'Partially Approved'
when mp.status = 3 then 'Approved'
when mp.status = 4 then 'Rejected'
when mp.status = 7 then 'Cancelled'
END AS Status
FROM c_flight cf
JOIN m_plan mp ON cf.plan_id = mp.plan_id
WHERE DATE(cf.created_on) = CURDATE()
AND mp.is_active = 1
GROUP BY mp.status,mp.trip_type
) t ON s.trip_type = t.trip_type AND s.status_label = t.Status
";
$binds = [];
$result = $this->db->query($sql,$binds)->getResultArray();
return $result ;
}
public function accomodationServiceDashboardDaily(){
$sql = "SELECT
COALESCE(t.count, 0) AS count,
s.trip_type,
s.status_label AS Status
FROM (
SELECT trip_type, status_label
FROM (
SELECT 'International' AS trip_type
UNION ALL
SELECT 'Domestic'
) trip_types
CROSS JOIN (
SELECT 'Pending Approval' AS status_label
UNION ALL SELECT 'Partially Approved'
UNION ALL SELECT 'Approved'
UNION ALL SELECT 'Rejected'
UNION ALL SELECT 'Cancelled'
) statuses
) s
-- Step 2: Left join real data
LEFT JOIN (
SELECT
COUNT(ca.accomodation_id) as count,
case
when mp.trip_type = 1 then 'Domestic'
when mp.trip_type = 2 then 'International'
END AS trip_type ,
case
when mp.status = 1 then 'Pending Approval'
when mp.status = 2 then 'Partially Approved'
when mp.status = 3 then 'Approved'
when mp.status = 4 then 'Rejected'
when mp.status = 7 then 'Cancelled'
END AS Status
FROM c_accomodation ca
JOIN m_plan mp ON ca.plan_id = mp.plan_id
WHERE DATE(ca.created_on) = CURDATE()
AND mp.is_active = 1
GROUP BY mp.status,mp.trip_type
) t ON s.trip_type = t.trip_type AND s.status_label = t.Status
";
$binds = [];
$result = $this->db->query($sql,$binds)->getResultArray();
return $result ;
}
public function forexServiceDashboardDaily(){
$sql = "SELECT
COALESCE(t.count, 0) AS count,
s.trip_type,
s.status_label AS Status
FROM (
SELECT trip_type, status_label
FROM (
SELECT 'International' AS trip_type
UNION ALL
SELECT 'Domestic'
) trip_types
CROSS JOIN (
SELECT 'Pending Approval' AS status_label
UNION ALL SELECT 'Partially Approved'
UNION ALL SELECT 'Approved'
UNION ALL SELECT 'Rejected'
UNION ALL SELECT 'Cancelled'
) statuses
) s
-- Step 2: Left join real data
LEFT JOIN (
SELECT
COUNT(cf.forex_id) as count,
case
when mp.trip_type = 1 then 'Domestic'
when mp.trip_type = 2 then 'International'
END AS trip_type ,
case
when mp.status = 1 then 'Pending Approval'
when mp.status = 2 then 'Partially Approved'
when mp.status = 3 then 'Approved'
when mp.status = 4 then 'Rejected'
when mp.status = 7 then 'Cancelled'
END AS Status
FROM c_forex cf
JOIN m_plan mp ON cf.plan_id = mp.plan_id
WHERE DATE(cf.created_on) = CURDATE()
AND mp.is_active = 1
GROUP BY mp.status,mp.trip_type
) t ON s.trip_type = t.trip_type AND s.status_label = t.Status
";
$binds = [];
$result = $this->db->query($sql,$binds)->getResultArray();
return $result ;
}
}