diff --git a/app/Config/Routes.php b/app/Config/Routes.php index e9d2aea9..c16dd299 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -737,6 +737,7 @@ $routes->group("employeeRest", ["filter" => ['GlobalPostFileUploadGuard', 'ratel $routes->get("getFEContent", "EmployeeRestController::getFEContent"); $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage"); $routes->get("getEcardURL", "EmployeeRestController::getEcardURL"); + $routes->post("sendMailForIndividualEmployeeEcard", "EmployeeRestController::sendMailForIndividualEmployeeEcard"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index b88825dd..ee3caadd 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -5169,14 +5169,12 @@ class EmployeeRestController extends AdminController try { //for inception upload - if($type == 'EB'){ + if ($type == 'EB') { - $data['actions'] = ['addition' => 'Addition (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; - } - else - { - $data['actions'] = ['addition' => 'Adding New Assets', 'deletion' => 'Removing Assets', 'correction' => 'Correction of assets details']; - } + $data['actions'] = ['all' => 'All', 'addition' => 'Addition (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; + } else { + $data['actions'] = ['addition' => 'Adding New Assets', 'deletion' => 'Removing Assets', 'correction' => 'Correction of assets details']; + } return $this->respond([ 'status' => true, @@ -5904,4 +5902,30 @@ class EmployeeRestController extends AdminController ], 200); } + public function sendMailForIndividualEmployeeEcard() + { + $received_data = $this->request->getJSON(true) ?? []; + + $id = $received_data['emp_policy_id'] ?? null; + $client_policy_id = $received_data['client_policy_id'] ?? null; + + if (empty($id)) { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'emp_policy_id is required'], 200); + } + + if (empty($client_policy_id)) { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'client_policy_id is required'], 200); + } + + $ids[] = $id; + $empDataServiceController = new EmpDataServiceController(); + $result = $empDataServiceController->sendMailForDownloadingECard(['ids' => $ids, 'client_policy_id' => $client_policy_id], 1); + + if (isset($result['status']) && $result['status'] == true) { + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Mail sent successfully', 'result' => $result], 200); + } + + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to sent mail.', 'result' => $result], 200); + } + } diff --git a/app/Filters/AuthJWT.php b/app/Filters/AuthJWT.php index 45f4517a..6bde4421 100755 --- a/app/Filters/AuthJWT.php +++ b/app/Filters/AuthJWT.php @@ -3,6 +3,7 @@ namespace App\Filters; use App\Helpers\JWTToken; +use App\Filters\Cors; use CodeIgniter\Filters\FilterInterface; use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; @@ -18,6 +19,13 @@ use App\Models\LevelContactModel; class AuthJWT implements FilterInterface { + protected Cors $corsFilter; + + public function __construct() + { + $this->corsFilter = new Cors(); + } + // public function before(RequestInterface $request, $arguments = null) // { // $jwt = $request->getHeader('Authorization'); @@ -84,20 +92,20 @@ class AuthJWT implements FilterInterface $authHeader = $request->getHeaderLine('Authorization'); if (!$authHeader) { - return $this->reject(403, 'Access Forbidden'); + return $this->reject($request, 403, 'Access Forbidden'); } $result = JWTToken::validateJWT($authHeader); if ($result['status'] !== true) { - return $this->reject(401, $result['message']); + return $this->reject($request, 401, $result['message']); } $decoded = $result['decoded']; $id = $decoded['id'] ?? null; if (!$id) { - return $this->reject(401, 'Invalid token payload'); + return $this->reject($request, 401, 'Invalid token payload'); } if (isset($decoded['emp_code'])) { @@ -111,7 +119,7 @@ class AuthJWT implements FilterInterface if (!$user || $user['token_time_out'] <= time()) { $model->update($id, ['token_time_out' => null]); - return $this->reject(401, 'Token expired'); + return $this->reject($request, 401, 'Token expired'); } // Refresh sliding expiration @@ -132,12 +140,20 @@ class AuthJWT implements FilterInterface return true; } - private function reject(int $code, string $message) + private function reject(RequestInterface $request, int $code, string $message): ResponseInterface { - return service('response') - ->setStatusCode($code) - ->setJSON(['status' => $code, 'message' => $message]) - ->send(); + $response = service('response'); + $response->setStatusCode($code); + $response->setContentType('application/json'); + $response->setBody(json_encode([ + 'status' => $code, + 'message' => $message, + ])); + + // Early before-filter returns skip global Cors after(), so attach CORS here. + $this->corsFilter->after($request, $response); + + return $response; } diff --git a/public/sample_excel/sample_addition.xls b/public/sample_excel/sample_addition.xls index ae5b59e2..9adc6a03 100755 Binary files a/public/sample_excel/sample_addition.xls and b/public/sample_excel/sample_addition.xls differ diff --git a/public/sample_excel/sample_correction.xls b/public/sample_excel/sample_correction.xls index 744769c1..17af876c 100755 Binary files a/public/sample_excel/sample_correction.xls and b/public/sample_excel/sample_correction.xls differ diff --git a/public/sample_excel/sample_deletion.xls b/public/sample_excel/sample_deletion.xls index 7bada1b5..2a331b4d 100755 Binary files a/public/sample_excel/sample_deletion.xls and b/public/sample_excel/sample_deletion.xls differ diff --git a/public/sample_excel/sample_inception.xls b/public/sample_excel/sample_inception.xls index 695c681a..85619a24 100755 Binary files a/public/sample_excel/sample_inception.xls and b/public/sample_excel/sample_inception.xls differ diff --git a/public/sample_excel/sample_multievent_file.xlsx b/public/sample_excel/sample_multievent_file.xlsx index 552e4888..1c5efbff 100755 Binary files a/public/sample_excel/sample_multievent_file.xlsx and b/public/sample_excel/sample_multievent_file.xlsx differ diff --git a/public/sample_excel/sample_si_enhancement.xls b/public/sample_excel/sample_si_enhancement.xls index 3149edc9..6930b191 100755 Binary files a/public/sample_excel/sample_si_enhancement.xls and b/public/sample_excel/sample_si_enhancement.xls differ diff --git a/send-mail-individual-employee-ecard-api.md b/send-mail-individual-employee-ecard-api.md new file mode 100644 index 00000000..1c961abe --- /dev/null +++ b/send-mail-individual-employee-ecard-api.md @@ -0,0 +1,180 @@ +# Send Individual Employee E-Card Mail API + +Sends the E-Card download mail to a single employee (Self relationship only). + +**Controller:** `EmployeeRestController::sendMailForIndividualEmployeeEcard` +**Method:** `POST` + +--- + +## Endpoint + +``` +POST /employeeRest/sendMailForIndividualEmployeeEcard +``` + +--- + +## Authentication + +**JWT token is required.** This endpoint is available only in the authenticated route group. + +| Filter | Description | +|--------|-------------| +| `GlobalPostFileUploadGuard` | POST upload guard | +| `ratelimit` | Rate limiting | +| `appSignature` | App signature validation | +| `authJWT` | JWT token validation | + +### Required Headers + +| Header | Required | Description | +|--------|----------|-------------| +| `Content-Type` | Yes | `application/json` | +| `App-Signature` | Yes | Must match server `APP_SIGNATURE` from `.env` | +| `Authorization` | Yes | JWT token in format `Bearer ` | + +### Example Headers + +``` +Content-Type: application/json +App-Signature: +Authorization: Bearer +``` + +--- + +## Request Body (JSON) + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| `emp_policy_id` | integer | Yes | Employee policy ID (`employee_polices.id`) | +| `client_policy_id` | integer | Yes | Client policy ID | + +### Example Request + +```json +{ + "emp_policy_id": 12345, + "client_policy_id": 678 +} +``` + +### cURL Example + +```bash +curl -X POST "https:///employeeRest/sendMailForIndividualEmployeeEcard" \ + -H "Content-Type: application/json" \ + -H "App-Signature: " \ + -H "Authorization: Bearer " \ + -d '{ + "emp_policy_id": 12345, + "client_policy_id": 678 + }' +``` + +--- + +## Success Response + +**HTTP Status:** `200` + +```json +{ + "status": true, + "code": 200, + "message": "Mail sent successfully", + "result": {} +} +``` + +--- + +## Error Responses + +### Missing `emp_policy_id` + +**HTTP Status:** `200` + +```json +{ + "status": false, + "code": 404, + "message": "emp_policy_id is required" +} +``` + +### Missing `client_policy_id` + +**HTTP Status:** `200` + +```json +{ + "status": false, + "code": 404, + "message": "client_policy_id is required" +} +``` + +### Mail Send Failed + +**HTTP Status:** `200` + +```json +{ + "status": false, + "code": 404, + "message": "Failed to sent mail.", + "result": {} +} +``` + +### Missing / Invalid Token + +**HTTP Status:** `401` or `403` + +```json +{ + "status": 401, + "message": "Token is Invalid" +} +``` + +### Invalid App Signature + +**HTTP Status:** `403` + +```json +{ + "status": false, + "message": "Forbidden: Invalid App Signature" +} +``` + +--- + +## Notes + +- `emp_policy_id` is the **employee policy record ID**, not the employee master ID. +- Mail is sent only when E-Card notification is enabled for the client. +- Employee must be active with a valid corporate email and TPA ID. +- This API uses the same logic as `EmployeeController::send_mail_for_individual_employee_ecard`. + +--- + +## Route Registration + +Defined in `app/Config/Routes.php`: + +```php +$routes->group("employeeRest", ["filter" => ['GlobalPostFileUploadGuard', 'ratelimit', 'appSignature', 'authJWT']], function ($routes) { + $routes->post("sendMailForIndividualEmployeeEcard", "EmployeeRestController::sendMailForIndividualEmployeeEcard"); +}); +``` + +--- + +## Source + +Implementation: `app/Controllers/EmployeeRestController.php` → `sendMailForIndividualEmployeeEcard()` +Service: `app/Controllers/EmpDataServiceController.php` → `sendMailForDownloadingECard()`