MERGE_LIVE_BUG_FIXES

This commit is contained in:
Ubuntu 2026-07-03 11:35:45 +05:30
commit c5fcb67949
6 changed files with 306 additions and 5 deletions

View File

@ -0,0 +1,117 @@
<?php
/**
* Manual integration script for employeesUplodWithEvents.
*
* Usage:
* php spark test:employee-upload-dates
*
* Inserts a real files row using sample enrollment excel and prints stored enrollment dates.
*/
namespace App\Commands;
use App\Controllers\EmployeeController;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Config\Database;
use Tests\Support\TestUploadedFile;
class TestEmployeeUploadDates extends BaseCommand
{
protected $group = 'Testing';
protected $name = 'test:employee-upload-dates';
protected $description = 'Test employeesUplodWithEvents with d-m-Y and d/m/Y enrollment dates and DB insert';
protected $usage = 'test:employee-upload-dates [--open=01-07-2026] [--close=31/07/2026]';
protected $options = [
'--open' => 'Enrollment open date (d-m-Y or d/m/Y)',
'--close' => 'Enrollment close date (d-m-Y or d/m/Y)',
];
public function run(array $params)
{
helper('utility');
$openDate = CLI::getOption('open') ?? '01-07-2026';
$closeDate = CLI::getOption('close') ?? '31/07/2026';
$sample = ROOTPATH . 'public/sample_excel/enrollment.xlsx';
if (!is_file($sample)) {
CLI::error('Sample file not found: ' . $sample);
return;
}
require_once ROOTPATH . 'tests/_support/TestUploadedFile.php';
$db = Database::connect('default');
$row = $db->query(
'SELECT client_id, policy_id, client_branch_id, created_by
FROM files
WHERE client_id IS NOT NULL
AND policy_id IS NOT NULL
AND client_branch_id IS NOT NULL
AND created_by IS NOT NULL
ORDER BY id DESC
LIMIT 1'
)->getRowArray();
if (empty($row)) {
CLI::error('No fixture row found in files table.');
return;
}
CLI::write('Input dates:', 'yellow');
CLI::write(" open : {$openDate}");
CLI::write(" close : {$closeDate}");
CLI::write('Converted:', 'yellow');
CLI::write(' open : ' . change_date_format($openDate, null, 'Y-m-d'));
CLI::write(' close : ' . change_date_format($closeDate, null, 'Y-m-d'));
$tmpPath = tempnam(sys_get_temp_dir(), 'enroll_manual_');
copy($sample, $tmpPath);
$uploadedFile = new TestUploadedFile(
$tmpPath,
basename($sample),
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
filesize($tmpPath),
UPLOAD_ERR_OK
);
$postData = [
'client_id' => (int) $row['client_id'],
'policy_id' => (int) $row['policy_id'],
'client_branch_id' => (int) $row['client_branch_id'],
'created_by' => (int) $row['created_by'],
'enrollment_open_date' => $openDate,
'enrollment_close_date' => $closeDate,
'emplist' => $uploadedFile,
];
$controller = new EmployeeController();
$result = $controller->employeesUplodWithEvents($postData);
CLI::newLine();
CLI::write('Upload result:', 'green');
CLI::write(json_encode($result, JSON_PRETTY_PRINT));
if (empty($result['file_id'])) {
return;
}
$file = $db->table('files')->where('id', $result['file_id'])->get()->getRowArray();
CLI::newLine();
CLI::write('DB record:', 'green');
CLI::write(json_encode([
'id' => $file['id'] ?? null,
'file_name' => $file['file_name'] ?? null,
'action' => $file['action'] ?? null,
'status' => $file['status'] ?? null,
'enrollment_open_date' => $file['enrollment_open_date'] ?? null,
'enrollment_close_date' => $file['enrollment_close_date'] ?? null,
], JSON_PRETTY_PRINT));
}
}

View File

@ -397,8 +397,8 @@ class EmployeeController extends AdminController
$status = 'inprogress';
$hr_id = $post_data['created_by'] ?? null;
$enrollment_open_date = change_date_format($enrollment_open_date, 'd/m/Y', 'Y-m-d');
$enrollment_close_date = change_date_format($enrollment_close_date, 'd/m/Y', 'Y-m-d');
$enrollment_open_date = change_date_format($enrollment_open_date, null, 'Y-m-d');
$enrollment_close_date = change_date_format($enrollment_close_date, null, 'Y-m-d');
$file_id = $this->fileModel->insert(['file_name' => $filename, 'client_id' => $client_id, 'policy_id' => $policy_id, 'created_by' => $loggedInUserID, 'status' => $status, 'action' => $action, 'client_branch_id' => $branch_id, 'uploaded_by' => 1, 'enrollment_open_date' => $enrollment_open_date, 'enrollment_close_date' => $enrollment_close_date, 'hr_id' => $hr_id]); //here field policy_id have client_policy_id and not policy id from policy master
$this->myLogger->logme("error", '{file_id} uploaded success', ['file_id' => $file_id]);

View File

@ -3251,11 +3251,16 @@ class EmployeeRestController extends AdminController
$value['insurer_name'] = $insurerData->name ?? null;
$value['insurer_short_name'] = $insurerData->short_name ?? null;
$employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0,branch_id:$client_branch_id);
$totalCount = 0;
$enrolledCount = 0;
$draftCount = 0;
if(count($employeeDetails))
{
foreach ($employeeDetails as $item) {
if ($item['relationship'] !== 'Self') {
continue;
}
$totalCount++;
if ($item['emp_status'] === 'enrolled') {
$enrolledCount++;
} elseif ($item['emp_status'] === 'draft') {
@ -3264,7 +3269,7 @@ class EmployeeRestController extends AdminController
}
}
$value['totalMembersCount'] = count($employeeDetails);
$value['totalMembersCount'] = $totalCount;
$value['membersCountOfEnrolled'] = $enrolledCount;
$value['membersCountOfDraft'] = $draftCount;
$value['membersCountOfLoggedIn'] = $loggedInCounts[$value['client_policy_id']] ?? 0;

View File

@ -109,9 +109,9 @@ class sendMailNotification
$subject = $notification_data['subject'];
$app_link = getenv('App_Url');
$app_link = env('App_Url');
$mail_content = $notification_data['mail_content'];
$nhance_logo = getenv('NHANCE_LOGO');
$nhance_logo = env('NHANCE_LOGO');
$client_logo = base_url() . "public/uploads/logo/" . $client_data['client_logo'];

View File

@ -0,0 +1,40 @@
<?php
namespace Tests\Support;
use CodeIgniter\HTTP\Files\UploadedFile;
/**
* UploadedFile stub for CLI tests bypasses is_uploaded_file() / move_uploaded_file().
*/
class TestUploadedFile extends UploadedFile
{
public function isValid(): bool
{
return $this->getError() === UPLOAD_ERR_OK && is_file($this->getTempName());
}
public function move(string $targetPath, ?string $name = null, bool $overwrite = false)
{
$targetPath = rtrim($targetPath, '/') . '/';
if (!is_dir($targetPath)) {
mkdir($targetPath, 0777, true);
}
$name ??= $this->getName();
$destination = $targetPath . $name;
if (!$overwrite && is_file($destination)) {
$destination = $targetPath . uniqid('test_', true) . '_' . $name;
}
if (!copy($this->getTempName(), $destination)) {
return false;
}
@unlink($this->getTempName());
return true;
}
}

View File

@ -0,0 +1,139 @@
<?php
namespace Tests\Unit;
use App\Models\FileModel;
use CodeIgniter\Test\CIUnitTestCase;
use Tests\Support\TestUploadedFile;
/**
* Tests employeesUplodWithEvents enrollment date handling (d-m-Y / d/m/Y) and file upload validation.
*
* @internal
*/
class EmployeesUploadWithEventsTest extends CIUnitTestCase
{
private const SAMPLE_EXCEL = ROOTPATH . 'public/sample_excel/enrollment.xlsx';
protected function setUp(): void
{
parent::setUp();
helper('utility');
}
/**
* @dataProvider enrollmentDateFormatProvider
*/
public function testChangeDateFormatAcceptsDashAndSlashFormats(
string $openDate,
string $closeDate,
string $expectedOpen,
string $expectedClose
): void {
$this->assertSame($expectedOpen, change_date_format($openDate, null, 'Y-m-d'));
$this->assertSame($expectedClose, change_date_format($closeDate, null, 'Y-m-d'));
}
/**
* Mirrors employeesUplodWithEvents date + files insert payload (EmployeeController.php ~395-403).
*
* @dataProvider enrollmentDateFormatProvider
*/
public function testEnrollmentDatesAreConvertedBeforeFilesTableInsert(
string $openDate,
string $closeDate,
string $expectedOpen,
string $expectedClose
): void {
$postData = [
'client_id' => 12,
'policy_id' => 34,
'client_branch_id' => 56,
'created_by' => 78,
'enrollment_open_date' => $openDate,
'enrollment_close_date' => $closeDate,
];
$insertPayload = $this->buildFilesInsertPayload($postData, 'enrollment_test.xlsx', 78);
$this->assertSame($expectedOpen, $insertPayload['enrollment_open_date']);
$this->assertSame($expectedClose, $insertPayload['enrollment_close_date']);
$this->assertSame('enrollment', $insertPayload['action']);
$this->assertSame('inprogress', $insertPayload['status']);
$this->assertSame(12, $insertPayload['client_id']);
$this->assertSame(34, $insertPayload['policy_id']);
$this->assertSame(56, $insertPayload['client_branch_id']);
$this->assertSame(78, $insertPayload['created_by']);
$this->assertSame(78, $insertPayload['hr_id']);
}
public function testValidateExcelFileAcceptsSampleEnrollmentUpload(): void
{
if (!is_file(self::SAMPLE_EXCEL)) {
$this->markTestSkipped('Sample enrollment excel not found.');
}
$uploadedFile = $this->createTestUploadedFile(self::SAMPLE_EXCEL);
$this->assertTrue(validateExcelFile($uploadedFile));
$this->assertTrue($uploadedFile->move(WRITEPATH . 'uploads/excel/'));
$movedPath = WRITEPATH . 'uploads/excel/' . $uploadedFile->getName();
$this->assertFileExists($movedPath);
@unlink($movedPath);
}
public function testFileModelAllowedFieldsIncludeEnrollmentDates(): void
{
$reflection = new \ReflectionClass(FileModel::class);
$property = $reflection->getProperty('allowedFields');
$property->setAccessible(true);
$allowedFields = $property->getValue(new FileModel());
$this->assertContains('enrollment_open_date', $allowedFields);
$this->assertContains('enrollment_close_date', $allowedFields);
}
public static function enrollmentDateFormatProvider(): array
{
return [
'd-m-Y format' => ['01-07-2026', '31-07-2026', '2026-07-01', '2026-07-31'],
'd/m/Y format' => ['01/07/2026', '31/07/2026', '2026-07-01', '2026-07-31'],
'mixed formats' => ['15-08-2026', '30/08/2026', '2026-08-15', '2026-08-30'],
];
}
/**
* @return array<string, mixed>
*/
private function buildFilesInsertPayload(array $postData, string $filename, int $loggedInUserId): array
{
return [
'file_name' => $filename,
'client_id' => $postData['client_id'] ?? null,
'policy_id' => $postData['policy_id'] ?? null,
'created_by' => $loggedInUserId,
'status' => 'inprogress',
'action' => 'enrollment',
'client_branch_id' => $postData['client_branch_id'] ?? null,
'uploaded_by' => 1,
'enrollment_open_date' => change_date_format($postData['enrollment_open_date'] ?? null, null, 'Y-m-d'),
'enrollment_close_date' => change_date_format($postData['enrollment_close_date'] ?? null, null, 'Y-m-d'),
'hr_id' => $postData['created_by'] ?? null,
];
}
private function createTestUploadedFile(string $sourcePath): TestUploadedFile
{
$tmpPath = tempnam(sys_get_temp_dir(), 'enroll_test_') . '.xlsx';
copy($sourcePath, $tmpPath);
return new TestUploadedFile(
$tmpPath,
basename($sourcePath),
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
filesize($tmpPath),
UPLOAD_ERR_OK
);
}
}