160 lines
5.1 KiB
PHP
160 lines
5.1 KiB
PHP
<?php
|
|
|
|
if (!function_exists('check_columns_count')) {
|
|
function check_columns_count($definedColumns,$excelColumns)
|
|
{
|
|
$mismatchedColumns = [];
|
|
|
|
foreach ($definedColumns as $colName => $definedCol) {
|
|
$definedColIdx = $definedCol['col_idx'];
|
|
$definedColName = $definedCol['col_name'];
|
|
|
|
if ($excelColumns[$definedColIdx] !== $definedColName) {
|
|
$mismatchedColumns[] = "Column order conflict. Column order no ".($definedColIdx + 1)." expected : ".$definedColName." and received : ".$excelColumns[$definedColIdx];
|
|
}
|
|
}
|
|
|
|
return $mismatchedColumns;
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('check_row_is_empty_or_null')) {
|
|
|
|
function check_row_is_empty_or_null($arr) {
|
|
unset($arr[0]);// unset SNO in the array, becoz we need to check only datapoints are empty not SNo, it may added by accidentally
|
|
foreach ($arr as $item) {
|
|
if ($item !== null && !empty($item)) {
|
|
return false; // If any item is not empty or not null, return false
|
|
}
|
|
}
|
|
return true; // If all items are empty or null, return true
|
|
}
|
|
}
|
|
|
|
if (!function_exists('check_excel_date_format')) {
|
|
|
|
function check_excel_date_format($dateString,$format)
|
|
{
|
|
|
|
if($dateString == ""){ return array('status' => true); }
|
|
$date = DateTime::createFromFormat('d-M-Y', $dateString);
|
|
|
|
if ($date !== false && !is_array($date::getLastErrors())) {
|
|
return array('status' => true);
|
|
} else {
|
|
return array('status' => false,'error' => "wrong date format: Expected 'd-M-Y' and received $dateString");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if(!function_exists('check_relationship'))
|
|
{
|
|
function check_relationship($row,$relationship)
|
|
{
|
|
// print_r($col);print_r($relationship);
|
|
// echo '<br>';
|
|
if($row[5] != null && $row[4] != null)
|
|
{
|
|
$slug = \Config\Services::slug();
|
|
$col = $slug->slugify($row[5]);
|
|
// echo $col;die();
|
|
if($col != 'self' && $col != 'spouse')
|
|
{
|
|
if($relationship[ $col ]['sex'] != $row[4])
|
|
{
|
|
$error = "Gender relationship conflict: Expected ".$relationship[ $col ]['sex'].", received $row[4]";
|
|
return array('status' => false,'error' => $error);
|
|
}
|
|
|
|
}
|
|
return array('status' => true);
|
|
}
|
|
else
|
|
{
|
|
return array('status' => false,'error' => 'Rule Conflict: Both Relationship or Gender required');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if(!function_exists('check_doj'))
|
|
{
|
|
function check_doj($row)
|
|
{
|
|
$slug = \Config\Services::slug();
|
|
$relationship = $slug->slugify($row[5]);
|
|
// echo $relationship;echo $row[7];
|
|
if($relationship == 'self' && $row[7] == "") { return array('status' => false,'error' => "DOJ mandantory for self"); }
|
|
return array('status' => true);
|
|
}
|
|
}
|
|
|
|
|
|
if(!function_exists('check_employee_band'))
|
|
{
|
|
function check_employee_band($row)
|
|
{
|
|
$slug = \Config\Services::slug();
|
|
$relationship = $slug->slugify($row[5]);
|
|
// echo $relationship;echo $row[7];
|
|
if($relationship == 'self' && $row[9] == "") { return array('status' => false,'error' => "Band mandantory for self"); }
|
|
return array('status' => true);
|
|
}
|
|
}
|
|
|
|
if(!function_exists('check_basic_pay'))
|
|
{
|
|
function check_basic_pay($row)
|
|
{
|
|
$slug = \Config\Services::slug();
|
|
$relationship = $slug->slugify($row[5]);
|
|
// echo $relationship;echo $row[7];
|
|
if($relationship == 'self' && $row[8] == "") { return array('status' => false,'error' => "Basic pay mandantory for self"); }
|
|
return array('status' => true);
|
|
}
|
|
}
|
|
|
|
|
|
if (!function_exists('check_dob_diff'))
|
|
{
|
|
function check_dob_diff($row,$relationships) {
|
|
// echo 'called';
|
|
if($row[3] != null && $row[5] != null)
|
|
{
|
|
$dob = change_date_format($row[3],'d-M-Y','Y-m-d');
|
|
// echo $row[3].' - '.$dob;echo '<br>';
|
|
$currentDateTime = new DateTime();//die();
|
|
$passedDateTime = new DateTime($dob);
|
|
$interval = $currentDateTime->diff($passedDateTime);
|
|
|
|
$slug = \Config\Services::slug();
|
|
$relationship = $slug->slugify($row[5]);
|
|
$age_min = $relationships[$relationship]['age_min'];
|
|
$age_max = $relationships[$relationship]['age_max'];
|
|
// echo $relationship.','.$age_min.'-'.$age_max;
|
|
if($age_min !== null && $age_min > $interval->y)
|
|
{
|
|
return array('status' => false,'error' => "Age conflict : minimum $age_min yrs allowed, received $interval->y");
|
|
}
|
|
if($age_max !== null && $age_max < $interval->y)
|
|
{
|
|
return array('status' => false,'error' => "Age conflict : maximum $age_max yrs allowed, received $interval->y");
|
|
}
|
|
return array('status' => true);
|
|
}
|
|
else
|
|
{
|
|
return array('status' => false,'error' => 'Rule Conflict: Both DOB or Relationship required');
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|