From df00a75fd3636ebae1e4c7b430b73b2856920048 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Thu, 2 Jul 2026 16:38:09 +0530 Subject: [PATCH 1/2] GWM : email template nhance logo issue --- app/Helpers/sendMailNotification.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index 8ce547d..21f2097 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -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']; From 7da591dd4cc916bde18f974b33e84b1b3fcd0a83 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Fri, 3 Jul 2026 11:30:34 +0530 Subject: [PATCH 2/2] FIX_COUNT_AND_ENROLLMENT_DATE_ISSUE --- app/Commands/TestEmployeeUploadDates.php | 117 ++++++++++++++++ app/Controllers/EmployeeController.php | 4 +- app/Controllers/EmployeeRestController.php | 7 +- tests/_support/TestUploadedFile.php | 40 ++++++ tests/unit/EmployeesUploadWithEventsTest.php | 139 +++++++++++++++++++ 5 files changed, 304 insertions(+), 3 deletions(-) create mode 100644 app/Commands/TestEmployeeUploadDates.php create mode 100644 tests/_support/TestUploadedFile.php create mode 100644 tests/unit/EmployeesUploadWithEventsTest.php diff --git a/app/Commands/TestEmployeeUploadDates.php b/app/Commands/TestEmployeeUploadDates.php new file mode 100644 index 0000000..ef563f9 --- /dev/null +++ b/app/Commands/TestEmployeeUploadDates.php @@ -0,0 +1,117 @@ + '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)); + } +} diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 1616f34..0a6838b 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -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]); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index fae441e..502a6d5 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -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; diff --git a/tests/_support/TestUploadedFile.php b/tests/_support/TestUploadedFile.php new file mode 100644 index 0000000..8579bc5 --- /dev/null +++ b/tests/_support/TestUploadedFile.php @@ -0,0 +1,40 @@ +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; + } +} diff --git a/tests/unit/EmployeesUploadWithEventsTest.php b/tests/unit/EmployeesUploadWithEventsTest.php new file mode 100644 index 0000000..4e5c286 --- /dev/null +++ b/tests/unit/EmployeesUploadWithEventsTest.php @@ -0,0 +1,139 @@ +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 + */ + 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 + ); + } +}