Tracket issue : GWM

This commit is contained in:
Gowtham M 2025-08-05 10:47:56 +05:30
parent a832ea284c
commit b47cd582e2
7 changed files with 121 additions and 20 deletions

3
.gitignore vendored
View File

@ -10,3 +10,6 @@
# Ignore env File here # Ignore env File here
.env .env
/writable/pdf/forex/*
/writable/pdf/trips/*

View File

@ -1018,8 +1018,11 @@ class PlanController extends ResourceController
$todayStart = date('Y-m-d 00:00:00'); $todayStart = date('Y-m-d 00:00:00');
$todayEnd = date('Y-m-d 23:59:59'); $todayEnd = date('Y-m-d 23:59:59');
$startOfWeek = date('Y-m-d 00:00:00', strtotime('monday this week')); // $startOfWeek = date('Y-m-d 00:00:00', strtotime('monday this week'));
$endOfWeek = date('Y-m-d 23:59:59', strtotime('sunday this week')); // $endOfWeek = date('Y-m-d 23:59:59', strtotime('sunday this week'));
$startOfWeek = date('Y-m-d 00:00:00', strtotime('-6 days'));
$endOfWeek = date('Y-m-d 23:59:59'); // today
$typeResultToday = []; $typeResultToday = [];
$typeResultWeekly = []; $typeResultWeekly = [];
@ -1215,8 +1218,9 @@ class PlanController extends ResourceController
$plan['flight'] = $flights; $plan['flight'] = $flights;
//get accomodation details //get accomodation details
$plan['accomodation'] = $this->accomodationModel->select('c_accomodation.* , C.dropdown_value as hotel_class') $plan['accomodation'] = $this->accomodationModel->select('c_accomodation.*, C.dropdown_value as hotel_class, H.hotel_name')
->join('m_dropdown C', 'C.dropdown_key = c_accomodation.class AND C.dropdown = "hotel_class"', 'left') ->join('m_dropdown C', 'C.dropdown_key = c_accomodation.class AND C.dropdown = "hotel_class"', 'left')
->join('m_hotels H', 'H.hotel_id = c_accomodation.hotel_id', 'left')
->where('c_accomodation.plan_id', $planId) ->where('c_accomodation.plan_id', $planId)
->where('c_accomodation.is_active', 1)->findAll(); ->where('c_accomodation.is_active', 1)->findAll();
@ -1476,7 +1480,9 @@ class PlanController extends ResourceController
public function url() public function url()
{ {
echo '<pre>'; echo '<pre>';
print_r(getPlanApproverAction(119)); die; $user = $this->userModel->where('email', 'pavithrakavi1100@gmail.com')->first();
echo getUserPlanCreationRestrictionStatus($user); die;
print_r(getPlanApproverAction(126)); die;
return $this->generatePlanPdf(57, true); return $this->generatePlanPdf(57, true);
die; die;

View File

@ -51,18 +51,54 @@ if (!function_exists('checkUserExist')) {
if (!function_exists('getUserPlanCreationRestrictionStatus')) { if (!function_exists('getUserPlanCreationRestrictionStatus')) {
function getUserPlanCreationRestrictionStatus($user) function getUserPlanCreationRestrictionStatus($user)
{ {
if($user['group_id'] != null && ( $user['first_approver'] != null || $user['second_approver'] != null || $user['third_approver'] != null ) ) if($user['group_id'] != null)
{ {
$groupModel = new GroupModel(); $groupModel = new GroupModel();
$groupData = $groupModel->find($user['group_id']); $groupData = $groupModel->find($user['group_id']);
if($groupData) if($groupData)
{ {
if($groupData['domestic_policy_id'] != null && $groupData['international_policy_id'] != null) $domesticPolicyId = $groupData['domestic_policy_id'];
return 'Both Type Plan Creation Allowed'; $internationalPolicyId = $groupData['international_policy_id'];
else if($groupData['domestic_policy_id'] != null) $policyDetailsModel = new PolicyDetailsModel();
return 'Only Domestic Plan Creation Allowed';
else if($groupData['international_policy_id'] != null) if($domesticPolicyId != null && $internationalPolicyId != null)
return 'Only International Plan Creation Allowed'; {
$domesticPolicy = $policyDetailsModel->where('policy_id',$domesticPolicyId)->where('service_id', 1)->find();
$domesticCheck = checkApproverSetOrNotBasedOnPolicy($domesticPolicy,$user);
$internationalPolicy = $policyDetailsModel->where('policy_id',$internationalPolicyId)->where('service_id', 1)->find();
$internationalCheck = checkApproverSetOrNotBasedOnPolicy($internationalPolicy,$user);
if($domesticCheck == true && $internationalCheck == true)
return 'Both Type Plan Creation Allowed';
else
return 'Plan Creation Not Allowed';
}
else if($domesticPolicyId != null)
{
$domesticPolicy = $policyDetailsModel->where('policy_id',$domesticPolicyId)->where('service_id', 1)->find();
$check = checkApproverSetOrNotBasedOnPolicy($domesticPolicy,$user);
$internationalPolicy = $policyDetailsModel->where('policy_id',$domesticPolicyId)->where('service_id', 1)->find();
$check = checkApproverSetOrNotBasedOnPolicy($internationalPolicy,$user);
if($check == true)
return 'Only Domestic Plan Creation Allowed';
else
return 'Plan Creation Not Allowed';
}
else if($internationalPolicyId != null)
{
$internationalPolicy = $policyDetailsModel->where('policy_id',$internationalPolicyId)->where('service_id', 1)->find();
$check = checkApproverSetOrNotBasedOnPolicy($internationalPolicy,$user);
if($check == true)
return 'Only International Plan Creation Allowed';
else
return 'Plan Creation Not Allowed';
}
}else{ }else{
@ -77,6 +113,51 @@ if (!function_exists('getUserPlanCreationRestrictionStatus')) {
} }
} }
function checkApproverSetOrNotBasedOnPolicy($Policy,$user)
{
// Step 1: Determine required approver levels (a1 to a4)
$requiredApprovers = [];
foreach (['', '_exceptional', '_amendment'] as $type) {
for ($i = 1; $i <= 4; $i++) {
$key = "a{$i}{$type}_action";
if (isset($Policy[0][$key]) && $Policy[0][$key] === 'Approval') {
$requiredApprovers[] = $i; // add level (1 to 4)
}
}
}
// Remove duplicates (in case multiple types require same level)
$requiredApprovers = array_unique($requiredApprovers);
// Step 2: Check user profile for each required approver level
$missingApprovers = [];
foreach ($requiredApprovers as $level) {
$profileKey = match ($level) {
1 => 'first_approver',
2 => 'second_approver',
3 => 'third_approver',
4 => 'fourth_approver',
};
if (empty($user[$profileKey]) || $user[$profileKey] == 0) {
$missingApprovers[] = $profileKey;
}
}
// Step 3: Final check
if (!empty($missingApprovers)) {
// One or more approvers missing
// echo "Missing approvers in user profile: " . implode(', ', $missingApprovers);
return false;
} else {
// echo "All required approvers are set in user profile.";
return true;
}
}
if (!function_exists('isDataChanged')) { if (!function_exists('isDataChanged')) {
function isDataChanged($model, $id, array $newData): bool function isDataChanged($model, $id, array $newData): bool
{ {

View File

@ -46,7 +46,7 @@ if (!function_exists('sendPlanCreationMail')) {
// Skip if action is None // Skip if action is None
if ($value['action'] === 'None') { continue; } if ($value['action'] === 'None') { continue; }
// mail success check // mail success check
if ($value['is_mail_send'] === 1) { continue; } if ($value['is_mail_send'] == 1) { continue; }
// skip with below condition // skip with below condition
if($mailOn == 'send_mail_to_only_approver' && $action['parallel_process_from'] == 1){ continue; } if($mailOn == 'send_mail_to_only_approver' && $action['parallel_process_from'] == 1){ continue; }

View File

@ -748,7 +748,6 @@ if (!function_exists('getPlanApproverAction')) {
->whereIn($actionField, ['Approval', 'Notification', 'None']) ->whereIn($actionField, ['Approval', 'Notification', 'None'])
->where('is_active', 1) ->where('is_active', 1)
->first(); ->first();
if ($record) { if ($record) {
$user = $userModel->where('user_id', $record[$idField])->first(); $user = $userModel->where('user_id', $record[$idField])->first();
if ($user) { if ($user) {

View File

@ -12,6 +12,7 @@ class AccomodationModel extends Model
protected $allowedFields = [ protected $allowedFields = [
'plan_id', 'plan_id',
'destination_city', 'destination_city',
'hotel_id',
'hotel_name', 'hotel_name',
'class', 'class',
'checkin_date', 'checkin_date',

View File

@ -74,6 +74,7 @@ class ReportsModel extends Model
GROUP BY plan_id GROUP BY plan_id
) AS al ON m_plan.plan_id = al.plan_id ) AS al ON m_plan.plan_id = al.plan_id
WHERE WHERE
mts.is_active = 1 mts.is_active = 1
AND mts.status_value = 'Approved' AND mts.status_value = 'Approved'
@ -415,8 +416,12 @@ class ReportsModel extends Model
JOIN m_plan mp ON cf.plan_id = mp.plan_id JOIN m_plan mp ON cf.plan_id = mp.plan_id
WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY) WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL 6 DAY)
AND cf.created_on < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY) AND cf.created_on < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
-- 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 -- previous week
-- WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY) -- WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)
@ -482,8 +487,11 @@ class ReportsModel extends Model
JOIN m_plan mp ON ca.plan_id = mp.plan_id JOIN m_plan mp ON ca.plan_id = mp.plan_id
WHERE ca.created_on >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY) WHERE ca.created_on >= DATE_SUB(CURDATE(), INTERVAL 6 DAY)
AND ca.created_on < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY) AND ca.created_on < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
-- 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 -- previous week
-- WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY) -- WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)
@ -547,8 +555,11 @@ class ReportsModel extends Model
JOIN m_plan mp ON cf.plan_id = mp.plan_id JOIN m_plan mp ON cf.plan_id = mp.plan_id
WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY) WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL 6 DAY)
AND cf.created_on < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY) AND cf.created_on < DATE_ADD(CURDATE(), INTERVAL 1 DAY)
-- 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 -- previous week
-- WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY) -- WHERE cf.created_on >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)