diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index 4732724d..abec6e2d 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -131,6 +131,13 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) {
$routes->post("edit", "ClientController::editClientPolicyPremium");
$routes->post("other_terms", "ClientController::otherPolicyTermsFormSubmit");
});
+
+ $routes->group("vehicle", ["filter" => "authMVC"], function ($routes) {
+ $routes->post("create", "ClientController::uploadVehicleFile");
+ $routes->post("edit", "ClientController::editUploadVehicleFile");
+ $routes->get("list/(:any)", "ClientController::listVehicleFiles/$1");
+ $routes->get("delete/(:any)", "ClientController::deleteVehicleFiles/$1");
+ });
});
@@ -294,6 +301,10 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) {
$routes->get("getPTCOShareCount/(:any)", "PolicyTransactionController::getPTCOShareCount/$1");
$routes->get("test_mail", "MasterController::testGmailAPI");
$routes->post("test_mail", "MasterController::testGmailAPI");
+ $routes->get("check_policy_no/(:any)", "ClientController::check_policy_no/$1");
+ $routes->get("get_client_policy_data_using_policy_no/(:any)", "ClientController::get_client_policy_data_using_policy_no/$1");
+ $routes->get("get_client_policy_data_using_policy_no_and_endo_no/(:any)", "ClientController::get_client_policy_data_using_policy_no_and_endo_no/$1");
+ $routes->get("checkInvoiceStatus/(:any)", "PolicyTransactionController::checkInvoiceStatus/$1");
});
@@ -322,16 +333,26 @@ $routes->group("policy_tranction", ["filter" => "authMVC"], function ($routes) {
$routes->post("upload", "PolicyTransactionController::uploadInsurerStatement");
$routes->get("getPaymentDetails/(:any)", "PolicyTransactionController::getInvoicePaymentDetails/$1");
$routes->post("saveInvoicePaymentDetails", "PolicyTransactionController::saveInvoicePaymentDetails");
+ $routes->get("deletePaymentEntry/(:any)", "PolicyTransactionController::deletePaymentEntry/$1");
+ $routes->get("downloadSampleInsurerStatement", "PolicyTransactionController::downloadSampleInsurerStatement");
+ $routes->get("getFileErr/(:any)", "PolicyTransactionController::getFileErr/$1");
});
});
+$routes->get("driveListFiles", "GoogleDriveController::listFiles");
+$routes->post('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
+$routes->get('dmsSearch', 'PolicyTransactionController::dmsSearch', ['filter' => 'authMVC']);
+$routes->get('downloadGdriveFile', 'GoogleDriveController::downloadGdriveFile', ['filter' => 'authMVC']);
+
$routes->cli('cli/processjob', 'JobWorker::processJob');
$routes->cli('cli/processjobs', 'JobWorker::processJobs');
-$routes->cli('cli/enrollment_status', 'JobWorker::enrollment_status');
+
$routes->get("processjob", "JobWorker::processJob");
$routes->cli('cli/new_gmail_token', 'MasterController::generateNewGmailAPIToken');
-$routes->cli('cli/send_mail_cli', 'MasterController::testGmailAPIViaCLI');
+$routes->cli('cli/send_mail_cli(/:any)?', 'MasterController::testGmailAPIViaCLI$1');
+$routes->cli('cli/app_check_list', 'MasterController::appCheckList');
+$routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken');
diff --git a/app/Config/Services.php b/app/Config/Services.php
index 23159f8b..fab85a50 100755
--- a/app/Config/Services.php
+++ b/app/Config/Services.php
@@ -6,6 +6,7 @@ use CodeIgniter\Config\BaseService;
use App\Libraries\Slug;
use App\Libraries\MyLogger;
use App\Libraries\GmailAPI;
+use App\Libraries\MyGoogleDrive;
use App\Libraries\DataServiceSqlite;
use App\Controllers\Home;
@@ -70,5 +71,14 @@ class Services extends BaseService
return new GmailAPI();
}
+
+ public static function myGoogleDrive($getShared = true)
+ {
+ if ($getShared) {
+ return static::getSharedInstance('myGoogleDrive');
+ }
+
+ return new MyGoogleDrive();
+ }
}
diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php
index 25c8170e..17e6f11d 100755
--- a/app/Controllers/ClientController.php
+++ b/app/Controllers/ClientController.php
@@ -38,6 +38,8 @@ use App\Models\PolicyTransactionModel;
use App\Models\PolicyTransactionStatusModel;
use App\Models\VehicleModel;
+use App\Controllers\EmpDataServiceController;
+
class ClientController extends AdminController
{
@@ -117,12 +119,8 @@ class ClientController extends AdminController
public function Testing() //this function for only tsesting some logics not use for business logic
{
- $params['mail'] = 'venkateshraman786@gmail.com';
- $params['subject'] = 'testing';
- $params['message'] = 'testing';
-
- $result = MailHelper::send_email($params);
- dd($result);
+ // $empDataServiceController = new EmpDataServiceController();
+ // $empDataServiceController->storeEndorsementNumber(23, '00000000000000000560');
}
public function index()
@@ -487,6 +485,7 @@ class ClientController extends AdminController
{
$this->myLogger->logme('error','create Client kyc function called');
$data = $this->request->getPost();
+ // print_r($data); die;
unset($data['file_name']);
$uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents';
$File = file_Upload($this->request->getFile('file_name'), $uploadFilePath);
@@ -646,11 +645,21 @@ class ClientController extends AdminController
$this->myLogger->logme('error','Client branch CREATE function called');
$data = $this->request->getPost();
+ // var_dump($data); die;
if (!isset($data['sez'])) {
$data['sez'] = 0;
} elseif ($data['sez']) {
$data['sez'] = 1;
}
+
+ $units = json_decode($data['units'], true) ?? [];
+
+ if (!is_array($units) || empty($units)) {
+ $client_data = $this->clientModel->where('id', $data['client_id'])->first();
+ $default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-');
+ $data['units'] = json_encode([$default_unit]);
+ }
+
$data['created_by'] = get_session_userid();
$insert = $this->clientBranchModel->insert($data);
@@ -704,6 +713,12 @@ class ClientController extends AdminController
$list_of_branch_units = $this->clientBranchModel->find($id);
$units = json_decode($list_of_branch_units['units']);
+
+ if (!is_array($units) || empty($units)) {
+ $client_data = $this->clientModel->where('id', $data['client_id'])->first();
+ $default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($data['branch_code'] ?? ''), '-');
+ $data['units'] = json_encode([$default_unit]);
+ }
if (!empty($units)) {
foreach ($units as $unit) {
@@ -714,6 +729,7 @@ class ClientController extends AdminController
$total_count = $emp_unit_count + $rr_unit_count + $rr_unit_count2;
}
+
$uncommonValues = [];
if ($total_count > 0) {
@@ -739,7 +755,6 @@ class ClientController extends AdminController
}
}
-
if (!isset($data['sez'])) {
$data['sez'] = 0;
} elseif ($data['sez']) {
@@ -1519,6 +1534,78 @@ class ClientController extends AdminController
+ public function uploadVehicleFile()
+ {
+ $this->myLogger->logme('error','uploadVehicleFile function called');
+ $data = $this->request->getPost();
+ $files = $this->request->getFiles();
+ // $data['client_id'] = 12;
+ // $data['vehicle_id'] = 1;
+
+ // upload path
+ $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents';
+
+ $insertedDocs = [];
+
+ // Check document names and files
+ if (isset($data['other_docs_name']) && isset($files['file_name'])) {
+ foreach ($data['other_docs_name'] as $key => $docName) {
+ // Get the corresponding file for this document name
+ $file = $files['file_name'][$key];
+
+ if (!empty($docName) && $file->isValid() && !$file->hasMoved()) {
+ // Upload the file
+ $uploadedFileName = file_Upload($file, $uploadFilePath);
+
+ if ($uploadedFileName) {
+ // Prepare data for each document upload
+ $docData = [
+ 'client_id' => $data['client_id'],
+ 'vehicle_id' => $data['vehicle_id'],
+ 'other_docs_name' => $docName,
+ 'file_name' => $uploadedFileName,
+ 'created_by' => get_session_userid(),
+ ];
+
+ // Insert into database
+ $insert = $this->clientKYCDocsModel->insert($docData);
+
+ if ($insert) {
+ $insertedDocs[] = $docData; // Collect successfully inserted docs
+ }
+ }
+ }
+ }
+
+ if (!empty($insertedDocs)) {
+ // Fetch all documents for the client
+ $vehicleDocs = $this->clientKYCDocsModel
+ ->where('client_id', $data['client_id'])
+ ->where('vehicle_id',$data['vehicle_id'])
+ ->findAll();
+ return $this->respond(['status' => true, 'code' => 200, 'vehicle_docs' => $vehicleDocs, 'inserted_docs' => $insertedDocs], 200);
+ } else {
+ return $this->respond(['status' => false, 'code' => 400, 'message' => 'No documents uploaded or inserted'], 200);
+ }
+ } else {
+ return $this->respond(['status' => false, 'code' => 400, 'message' => 'Invalid data submission'], 200);
+ }
+ }
+
+
+ public function editUploadVehicleFile()
+ {
+
+ }
+
+ public function listVehicleFiles()
+ {
+
+ }
+
+ public function deleteVehicleFiles(){
+
+ }
@@ -3255,6 +3342,55 @@ class ClientController extends AdminController
}
}
+ public function check_policy_no($policy_no)
+ {
+ $uniqueAC = $this->clientPolicyModel
+ ->where('policy_no', $policy_no)
+ ->where('is_active', 1)
+ ->findAll();
+
+ if($uniqueAC != null){
+ return $this->respond(['status' => true, 'message' => 'The Policy Number is Already Exist', 'code' => 200], 200);
+ }else{
+ return $this->respond(['status' => false, 'code' => 404], 200);
+ }
+ }
+
+ public function get_client_policy_data_using_policy_no($policy_no)
+ {
+ $data = $this->clientPolicyModel
+ ->select('client_policy.*, clients.client_type')
+ ->join('clients', 'client_policy.client_id = clients.id')
+ ->where('client_policy.policy_no', $policy_no)
+ ->where('client_policy.is_active', 1)
+ ->first();
+
+ if($data){
+ return $this->respond(['status' => true, 'data'=> $data, 'code' => 200], 200);
+ }else{
+ return $this->respond(['status' => false, 'message' => 'No Data Found', 'code' => 404], 200);
+ }
+ }
+
+ public function get_client_policy_data_using_policy_no_and_endo_no($policy_no, $endorsement_no)
+ {
+ $data = $this->clientPolicyModel
+ ->select('client_policy.*, endorsement.endorsement_type')
+ ->join('endorsement', 'client_policy.id = endorsement.client_policy_id')
+ ->where('client_policy.policy_no', $policy_no)
+ ->where('endorsement.endorsement_no', $endorsement_no)
+ ->where('client_policy.is_active', 1)
+ ->first();
+
+ if($data){
+ return $this->respond(['status' => true, 'data'=> $data, 'code' => 200], 200);
+ }else{
+ return $this->respond(['status' => false, 'message' => 'No Data Found', 'code' => 404], 200);
+ }
+ }
+
+
+
}
\ No newline at end of file
diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php
index fbf60d4e..3fef51e0 100755
--- a/app/Controllers/EmpDataServiceController.php
+++ b/app/Controllers/EmpDataServiceController.php
@@ -27,6 +27,7 @@ use App\Models\UserMessageModel;
use App\Models\CDMasterModel;
use App\Models\InsurerExcelExportTemplateModel;
use App\Models\ClientBranchModel;
+use App\Models\EndorsementModel;
use App\Controllers\Jobs;
use App\Controllers\JobWorker;
@@ -58,6 +59,7 @@ class EmpDataServiceController extends BaseController
protected $CDMasterModel;
protected $excelExportTemplateModel;
protected $clientBranchModel;
+ protected $endorsementModel;
public function __construct()
@@ -80,6 +82,7 @@ class EmpDataServiceController extends BaseController
$this->CDMasterModel = new CDMasterModel();
$this->excelExportTemplateModel = new InsurerExcelExportTemplateModel();
$this->clientBranchModel = new ClientBranchModel();
+ $this->endorsementModel = new EndorsementModel();
}
@@ -2145,6 +2148,7 @@ class EmpDataServiceController extends BaseController
$status = $file['status'];
$batch_code = $file['batch_code'];
$user_id = $file['created_by'];
+ $event_type = $file['event_type'];
$status_val = 'success';
@@ -2206,6 +2210,8 @@ class EmpDataServiceController extends BaseController
$this->empEndorsementModel->updateBatch($endorsement_details, 'group_key');
$this->employeePolicyModel->bulkUpdateForCorrection($emp_details);
+ $this->storeEndorsementNumber($file_id, $endorsement_id[0]);
+
// Update batch file status and amount
$this->batchFileModel->update($file_id, [
@@ -2801,6 +2807,8 @@ class EmpDataServiceController extends BaseController
// }
$this->employeePolicyModel->bulkUpdateForEndorsement($endorsement_details);
+ $this->storeEndorsementNumber($file_id, $endorsement_id);
+
// Update batch file status and amount
$this->batchFileModel->update($file_id, [
@@ -3320,6 +3328,7 @@ class EmpDataServiceController extends BaseController
$this->employeeModel->updateBatch($employees_table_data, 'id');
$this->employeePolicyModel->updateBatch($employee_policy_table_data, 'id');
$this->employeePolicyModel->bulkUpdateForEndorsement($emp_endorsement_table_data);
+ $this->storeEndorsementNumber($file_id, $endorsement_id);
// Update batch file status and amount
$this->batchFileModel->update($file_id, [
@@ -4367,34 +4376,58 @@ class EmpDataServiceController extends BaseController
$this->messageModel->insert($msg_data);
}
- public function updatajson()
- {
-
- // $columns = [
- // ["column_index" => 0, "column_name" => "SR NO", "db_column_name" => 'index'],
- // ["column_index" => 1, "column_name" => "EmployeeId", "db_column_name" => "emp_code"],
- // ["column_index" => 2, "column_name" => "UHID", "db_column_name" => "uhid"],
- // ["column_index" => 3, "column_name" => "DOJ", "db_column_name" => "emp_doj"],
- // ["column_index" => 4, "column_name" => "Name OF Insured", "db_column_name" => "emp_name"],
- // ["column_index" => 5, "column_name" => "Age", "db_column_name" => "emp_age"],
- // ["column_index" => 6, "column_name" => "Gender", "db_column_name" => "emp_gender"],
- // ["column_index" => 7, "column_name" => "DOC", "db_column_name" => null],
- // ["column_index" => 8, "column_name" => "TOTALSI", "db_column_name" => "basic_cover_si"],
- // ["column_index" => 9, "column_name" => "DOS", "db_column_name" => "dateofexit"],
- // ["column_index" => 10, "column_name" => "Mobile", "db_column_name" => 'emp_mobile'],
- // ["column_index" => 11, "column_name" => "EmailID", "db_column_name" => 'emp_email_c'],
- // ["column_index" => 12, "column_name" => "REMARKS", "db_column_name" => "remarks"],
- // ["column_index" => 13, "column_name" => "FLAG STATUS", "db_column_name" => null],
- // ["column_index" => 14, "column_name" => "EXCEPTIONS", "db_column_name" => null],
- // ["column_index" => 15, "column_name" => "ABHA", "db_column_name" => null]
- // ];
-
-
-
-
- // $json = json_encode($columns);
- // $this->excelExportTemplateModel->where('id', 37)->set('jsoncolumns', $json)->update();
+ public function storeEndorsementNumber($file_id, $endorsement_no)
+ {
+ // Log the function entry with input parameters
+ $this->myLogger->logme('error', "storeEndorsementNumber --- Starting function with file_id: $file_id and endorsement_no: $endorsement_no");
+
+ // Log before querying the database
+ $this->myLogger->logme('error', "storeEndorsementNumber --- Fetching file data for file_id: $file_id");
+
+ $filedata = $this->batchFileModel
+ ->select('
+ batch_files.client_id,
+ batch_files.client_policy_id,
+ batch_files.event_type, .
+ batch_files.created_by,
+ client_policy.insurer_id,
+ client_policy.tpa_id
+ ')
+ ->join('client_policy', 'batch_files.client_policy_id = client_policy.id')
+ ->where('batch_files.id', $file_id)
+ ->first();
+ // dd($filedata);
+
+ // Log after fetching data
+ if ($filedata) {
+ $this->myLogger->logme('error', 'File data fetched successfully: ' . json_encode($filedata));
+
+ // Log before inserting data
+ $this->myLogger->logme('error', 'storeEndorsementNumber --- Inserting endorsement data into endorsementModel');
+
+ $this->endorsementModel->insert([
+ 'client_id' => $filedata['client_id'],
+ 'client_policy_id' => $filedata['client_policy_id'],
+ 'insurer_id' => $filedata['insurer_id'],
+ 'tpa_id' => $filedata['tpa_id'],
+ 'endorsement_no' => $endorsement_no,
+ 'endorsement_type' => $filedata['event_type'],
+ 'created_by' => $filedata['created_by'],
+ ]);
+
+ // Log after data insertion
+ $this->myLogger->logme('error', 'storeEndorsementNumber --- Endorsement data inserted successfully for file_id: ' . $file_id);
+ } else {
+ // Log if no file data is found
+ $this->myLogger->logme('error', "storeEndorsementNumber --- No file data found for file_id: $file_id");
+ }
+
+ // Log function exit
+ $this->myLogger->logme('error',"storeEndorsementNumber --- Function execution completed for file_id: $file_id");
}
+
+
+
}
diff --git a/app/Controllers/GoogleDriveController.php b/app/Controllers/GoogleDriveController.php
new file mode 100644
index 00000000..5af27b9f
--- /dev/null
+++ b/app/Controllers/GoogleDriveController.php
@@ -0,0 +1,355 @@
+clientModel = new ClientModel();
+ $this->clientPolicyModel = new ClientPolicyModel();
+ $this->googleDrive = \Config\Services::myGoogleDrive();
+ $this->driveService = $this->googleDrive->getDriveService();
+ $this->cache = \Config\Services::cache(); // Load the cache service
+ }
+ public function listFiles()
+ {
+ // dd($this->getClientFolderIds(client_id : 18));
+ $file_path = WRITEPATH.'uploads/client_kyc_documents/nhance_bpf.pdf';
+ // dd($file_path);
+ // dd($this->uploadFiletoGdrive(client_id : 18,doc_type:'KYC',file_path:$file_path,file_name:"dummy.pdf"));
+ dd( $this->uploadFiletoGdrive(client_id: 12, doc_type: 'KYC', file_path: $file_path, file_name: "dummy.pdf"));
+
+ $session = \Config\Services::session();
+ $fileName = $request->getVar('filename');
+ $fileType = $request->getVar('filetype');
+ $userAccess = $session->get('userEmail');
+ $parentFolderID = '1M0GH3GbNUOYZLNeHXA5U7C_P2NSx7F7O';
+ $searchQuery = '';//"'your-folder-id' in parents"
+
+
+ try {
+
+ // $driveService = $this->googleDrive->getDriveService();
+ $searchQuery = "name contains 'test' and 'vitvelz@gmail.com' in readers";
+ // Query to list files
+ $response = $this->driveService->files->listFiles([
+ 'q' => $searchQuery,
+ 'supportsAllDrives' => true,
+ 'includeItemsFromAllDrives' => true,
+ 'fields' => 'nextPageToken, files(id, name, mimeType, size, createdTime, modifiedTime, owners, shared, permissions, webViewLink, thumbnailLink)',
+ 'pageSize' => 20,
+ ]);
+
+ $files = $response->getFiles();
+ if (empty($files)) {
+ echo "No files found.";
+ } else {
+ foreach ($files as $file) {
+ echo "File Name: " . $file->getName() . " | File ID: " . $file->getId() . "
";
+ }
+ }
+ } catch (\Exception $e) {
+ return $this->response->setStatusCode(500)->setBody($e->getMessage());
+ }
+ }
+
+ //by file id
+ public function downloadFile(string $fileId = '',string $fileName = '',string $mimeType = '',string $fileSize = '')
+ {
+ // dd($fileName);
+ try {
+ if($fileName == '' && $mimeType == '')
+ {
+ // Get file metadata
+ $file = $this->driveService->files->get($fileId, ['fields' => 'name, mimeType,size']);
+ $fileName = $file->getName();
+ $mimeType = $file->getMimeType();
+ $fileSize = $file->getSize();
+ }
+
+ // Download the file content from Google Drive
+ $response = $this->driveService->files->get($fileId, ['alt' => 'media']);
+
+ $fileContent = $response->getBody()->getContents();
+ // dd($fileContent);
+ $temp_file_name = WRITEPATH.'/tmp/'.date('YmdHis');
+ $this->cache->save('temp_gdrive_file', $temp_file_name, 300);
+ file_put_contents( $temp_file_name, $fileContent );
+ // Use CodeIgniter helper for downloading the file
+ return $this->response->download($temp_file_name, null)->setFileName($fileName);
+
+ } catch (\Exception $e) {
+ return $this->response->setStatusCode(500)->setBody($e->getMessage());
+ }
+ }
+
+ public function generateNewGoogleDriveAccessToken()
+ {
+ $this->driveService->generateNewToken();
+ }
+
+ public function getClientFolderIds(int $client_id = 0,int $client_policy_id = 0)
+ {
+ // Fetch client short name from the database
+ if($client_id)
+ {
+
+ //check folder ids in cahce,
+ $cacheKey = "client_gdrive_folderids_{$client_id}";
+ $folderIds = $this->cache->get($cacheKey);
+ // dd($folderIds);
+ if($folderIds !== NULL)//if available retrun from cache
+ {
+ return $folderIds;
+ }
+
+ //if not in cache then get it from grdrive
+ $client = $this->clientModel->find($client_id);
+ $clientShortName = $client['short_name']; // Assuming short_name is the column for client's short name
+ }
+ else if($client_policy_id)
+ {
+
+ $cacheKey = "client_policy_gdrive_folderids_{$client_policy_id}";
+ $folderIds = $this->cache->get($cacheKey);
+ // dd($folderIds);
+ if($folderIds !== NULL)//if available retrun from cache
+ {
+ return $folderIds;
+ }
+
+ $client = $this->clientPolicyModel->select('c.short_name,pt.policy_type,client_policy.policy_no')
+ ->join('clients c','client_policy.client_id = c.id')
+ ->join('policy_type pt','client_policy.policy_type_id = pt.id')
+ ->where('client_policy.id',$client_policy_id)
+ ->get()->getResultarray();
+ // dd($client);
+ $clientShortName = $client[0]['short_name'];
+ $policyFolderName = $client[0]['policy_type'].'-'.$client[0]['policy_no'];
+ }
+ else
+ {
+ return [];
+ }
+ // dd($policyFolderName);
+ // Define parent folder ID where client folders are stored
+ $parentFolderId = getenv('GDRIVE_ROOT_FOLDER_ID');; // Replace with your specific folder ID
+
+ // Check if the client folder exists in GDrive, if not create one
+ $clientFolderId = $this->checkOrCreateFolder($clientShortName, $parentFolderId);
+
+ // Check or create KYC_DOCS folder inside the client folder
+ $kycFolderId = $this->checkOrCreateFolder('KYC_DOCS', $clientFolderId);
+
+ // Check or create POLICY_DOCS folder inside the client folder
+ $policyFolderId = $this->checkOrCreateFolder('POLICY_DOCS', $clientFolderId);
+
+ if($client_policy_id && (isset($policyFolderName)))
+ {
+ $clientPolicyFolderId = $this->checkOrCreateFolder($policyFolderName, $policyFolderId);
+ $clientPolicyUploadFolderId = $this->checkOrCreateFolder('UPLOADS', $clientPolicyFolderId);
+ }
+
+
+ // Return folder IDs in the specified format
+ $folderIds = [
+ 'client_folder_id' => $clientFolderId, // example HCL,TCS
+ 'kyc_doc_folder_id' => $kycFolderId, // KYC_DOCS inside HCL,TCS
+ 'policy_doc_folder_id' => $policyFolderId, //POLICY_DOCS inside HCL,TCS
+ 'client_policy_doc_folder_id' => isset($clientPolicyFolderId) ? $clientPolicyFolderId : null, //GMC-POLICY_NO inside POLICY_DOCS folder
+ 'client_policy_uoload_doc_folder_id' => isset($clientPolicyUploadFolderId) ? $clientPolicyUploadFolderId : null, //UPLOADS folder in side GMC-POLICY_NO folder
+ ];
+
+ // Save the folder IDs in cache for future requests
+ $this->cache->save($cacheKey, $folderIds, 604800); // Cache for 7 Days (3600 seconds * 24 * 7 )
+ return $folderIds;
+ }
+
+
+ // Method to check if a folder exists or create one if it doesn't
+ public function checkOrCreateFolder($folderName, $parentFolderId)
+ {
+ // Step 1: Check if the folder exists
+ $folderId = $this->getFolderId($folderName, $parentFolderId);
+
+ if ($folderId === null) {
+ // Step 2: If folder does not exist, create it
+ $folderId = $this->createFolder($folderName, $parentFolderId);
+ }
+
+ // Step 3: Return the folder ID
+ return $folderId;
+ }
+
+ // Method to get the folder ID by searching in Google Drive
+ private function getFolderId($folderName, $parentFolderId)
+ {
+ $query = "name = '$folderName' and mimeType = 'application/vnd.google-apps.folder' and '$parentFolderId' in parents and trashed = false";
+
+ $response = $this->driveService->files->listFiles([
+ 'q' => $query,
+ 'spaces' => 'drive',
+ 'fields' => 'files(id, name)',
+ 'pageSize' => 1,
+ ]);
+
+ if (count($response->files) > 0) {
+ return $response->files[0]->id; // Return folder ID if found
+ }
+
+ return null; // Return null if folder doesn't exist
+ }
+
+ // Method to create a folder in Google Drive
+ private function createFolder($folderName, $parentFolderId)
+ {
+ $fileMetadata = new \Google_Service_Drive_DriveFile([
+ 'name' => $folderName,
+ 'mimeType' => 'application/vnd.google-apps.folder',
+ 'parents' => [$parentFolderId]
+ ]);
+
+ $folder = $this->driveService->files->create($fileMetadata, [
+ 'fields' => 'id',
+ ]);
+
+ return $folder->id; // Return the newly created folder's ID
+ }
+
+ // public function uploadFiletoGdrive(int $client_id = 0,int $client_policy_id = 0,string $doc_type,string
+ // $file_path,string $file_name)
+ public function uploadFiletoGdrive(int $client_id = 0, int $client_policy_id = 0, string $doc_type = '', string $file_path = '', string $file_name = '')
+ {
+ $gdriveFolderIds = $this->getClientFolderIds(client_id: $client_id,client_policy_id: $client_policy_id);
+ // Kint::dump($gdriveFolderIds);//die();
+ $parentFolderId = '';
+ if($client_id && $doc_type == 'KYC')
+ {
+ $parentFolderId = $gdriveFolderIds['kyc_doc_folder_id'];
+ }
+ else if($client_policy_id && $doc_type == 'POLICY')
+ {
+ $parentFolderId = $gdriveFolderIds['client_policy_doc_folder_id'];
+ }
+ else if($client_policy_id && $doc_type == 'UPLOADS')
+ {
+ $parentFolderId = $gdriveFolderIds['client_policy_uoload_doc_folder_id'];
+ }
+ if($parentFolderId == '')
+ {
+ return null;
+ }
+ // dd($parentFolderId);
+ $file = new \Google_Service_Drive_DriveFile([
+ 'name' => $file_name,
+ 'parents' => [$parentFolderId] // Specify the folder ID here
+ ]);
+
+ $file_blob_data = file_get_contents($file_path);
+
+ $createdFile = $this->driveService->files->create($file, [
+ 'data' => $file_blob_data,
+ 'mimeType' => 'application/octet-stream',
+ 'uploadType' => 'multipart',
+ 'fields' => 'id' // Specify fields to return
+ ]);
+
+ if($createdFile->id)
+ {
+ unlink($file_path);
+ }
+
+ return $createdFile->id;
+ }
+
+ public function downloadGdriveFile()
+ {
+ $client_id = $this->request->getGet('client_id');
+ $client_policy_id = $this->request->getGet('client_policy_id');
+ $file_type = $this->request->getGet('file_type');
+ $file_name = $this->request->getGet('file_name');
+ if(!is_numeric($client_policy_id))
+ $client_policy_id = 0;
+ else
+ $client_id = 0;
+
+ $gdriveFolderIds = $this->getClientFolderIds(client_id: $client_id,client_policy_id: $client_policy_id);
+ // dd($gdriveFolderIds);
+ $parentFolderId = '';
+ if($file_type == 'kyc')
+ {
+ $parentFolderId = $gdriveFolderIds['kyc_doc_folder_id'];
+ }
+ else if($file_type == 'policy')
+ {
+ $parentFolderId = $gdriveFolderIds['client_policy_doc_folder_id'];
+ }
+ else if($file_type == 'uploads')
+ {
+ $parentFolderId = $gdriveFolderIds['client_policy_uoload_doc_folder_id'];
+ }
+ if($parentFolderId == '')
+ {
+ return $this->response->setStatusCode(500)
+ ->setHeader('Content-Type', 'text/html')
+ ->setBody('');
+ }
+
+ return $this->searchGdriveFileByName(parentFolderID: $parentFolderId, fileName: $file_name);
+
+ }
+
+ //search files in gdrive by parent folder id and name of the file
+ public function searchGdriveFileByName(string $parentFolderID,string $fileName)
+ {
+ //check exisitng temp file from cache and delete it
+ if($this->cache->get('temp_gdrive_file') && is_file($this->cache->get('temp_gdrive_file')))
+ {
+ unlink($this->cache->get('temp_gdrive_file'));
+ }
+
+
+ try {
+
+ $searchQuery = "'$parentFolderID' in parents and (name contains '$fileName')";
+ // Query to list files
+ $response = $this->driveService->files->listFiles([
+ 'q' => $searchQuery,
+ 'supportsAllDrives' => true,
+ 'includeItemsFromAllDrives' => true,
+ 'fields' => 'nextPageToken, files(id, name, mimeType, size)',
+ 'pageSize' => 1,
+ ]);
+
+ $files = $response->getFiles();
+
+ if (empty($files)) {
+ return $this->response->setStatusCode(500)
+ ->setHeader('Content-Type', 'text/html')
+ ->setBody('');
+ }
+ else
+ {
+ //echo "File Name: " . $files[0]->getName() . " | File ID: " . $file[0]->getId() . "
";
+ // echo($files[0]->getId());
+ // echo 'working';
+ return $this->downloadFile(fileId:$files[0]->getId(),fileName:$files[0]->getName(),mimeType:$files[0]->getMimeType(),fileSize:$files[0]->getSize());
+ }
+ } catch (\Exception $e) {
+ return $this->response->setStatusCode(500)->setBody($e->getMessage());
+ }
+ }
+
+}
diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php
index 2e7ee6a4..51dee015 100755
--- a/app/Controllers/MasterController.php
+++ b/app/Controllers/MasterController.php
@@ -31,6 +31,7 @@ use App\Models\PolicyTypeModel;
use App\Models\CDMasterModel;
use App\Models\ClientDepositModel;
use App\Models\InsurerExcelExportTemplateModel;
+use App\Models\SettingsModel;
class MasterController extends AdminController
{
@@ -1527,11 +1528,106 @@ class MasterController extends AdminController
//testing a sample mail from cli
- public function testGmailAPIViaCLI()
+ public function testGmailAPIViaCLI(string $email_id = 'velmurugan.s@venbainfotech.com')
{
+ // print_r($email_id);die();
$gmailapi = \Config\Services::gmailapi();
- $res = MailHelper::send_email(['mail' => 'velmurugan.s@venbainfotech.com', 'subject' => 'Mail Via CLI', 'message' => 'This is sample mail sent via CLI mode']);
+ $res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => 'This is sample mail sent via CLI mode']);
print_r($res);
}
+
+
+ public function appCheckList()
+ {
+ //check temprory folders in writeable and public/uploads folder
+ $this->checkAndCreateDirectories();
+ $this->checkGoogleOAuthCredentialsinDB();
+ $this->getCronJobsList();
+
+ }
+
+ public function checkAndCreateDirectories()
+ {
+ echo "#################### CHECKING TEMP DIRECTORIES ############################\n";
+ // Array of folder names and their respective paths
+ $folders = [
+ 'e_card_template' => WRITEPATH . 'e_card_template/',
+ 'uploads' => WRITEPATH . 'uploads/',
+ 'excel' => WRITEPATH . 'uploads/excel/',
+ 'statements' => WRITEPATH . 'uploads/statements/',
+ 'import_excel' => WRITEPATH . 'uploads/import_excel/',
+ 'logs' => WRITEPATH . 'uploads/logs/',
+ 'client_kyc_documents' => WRITEPATH . 'uploads/client_kyc_documents/',
+ 'tmp' => WRITEPATH . 'tmp/',
+ 'e_card_imgs' => ROOTPATH . 'public/e_card_imgs',
+ 'uploads' => ROOTPATH . 'public/uploads',
+ 'add_image_upload' => ROOTPATH . 'public/uploads/add_image_upload/',//adverdisement images for enrollment app
+ 'logo' => ROOTPATH . 'public/uploads/logo/',
+ 'template_bg' => ROOTPATH . 'public/uploads/template_bg/'
+ ];
+
+ foreach ($folders as $folderName => $folderPath) {
+ // Check if the folder exists
+ if (!is_dir($folderPath)) {
+ // Try to create the folder
+ if (mkdir($folderPath, 0777, true)) {
+ // Set permissions to 0777
+ chmod($folderPath, 0777);
+ echo "\nDirectory '$folderPath' created successfully with 0777 permissions.\n";
+ } else {
+ // Handle error in directory creation
+ echo "Failed to create directory '$folderPath'.\n";
+ }
+ } else {
+ echo "Directory '$folderPath' already exists.\n";
+ }
+ }
+ echo "################################################################\n\n";
+ }
+
+ public function checkGoogleOAuthCredentialsinDB()
+ {
+ $settingsModel = new SettingsModel();
+ $token = $settingsModel->where('id', 1)->first();
+
+ echo "################ CHECKING GMAIL OAUTH FOR EMAIL ###################\n";
+ if (is_array($token) && !is_null($token['gmail_api_oauth_credentials'])) {
+
+ echo "Email OAuth credentials not found in database.\n";
+ echo "Check the following..!\n";
+ echo "1. Update Gmail Oauth credentials in 'gmail_api_oauth_credentials' field in 'settings' table in JSON format.\n";
+ echo "2. Call this cli route to generate new access token: 'php public/index.php cli/new_gmail_token' from root of the project.\n";
+ echo "3. Call this cli route : 'php public/index.php cli/send_mail_cli someone@gmail.com' to send test mail to testGmailAPIViaCLI ( replace someone@gmail.com with real time mail).\n";
+ }
+ else
+ {
+ echo "Gmail OAuth for sending email is set in DB\n";
+ }
+ echo "################################################################\n\n";
+ }
+
+
+ function getCronJobsList()
+ {
+ // Execute the shell command to get cron jobs
+ $output = null;
+ $resultCode = null;
+ echo "#################### CHECKING CRONJOBS ############################\n";
+ // Use shell_exec to get cron jobs from the current user's crontab
+ $output = shell_exec('crontab -l 2>&1');
+
+ // Check if the command was successful
+ if (strpos($output, 'no crontab') !== false) {
+ echo "No cron jobs are set for this user.\n";
+ } elseif ($output) {
+ // Return the cron job list
+ echo nl2br($output);
+ echo "\n" ;// Convert newlines to
for easier HTML rendering
+ } else {
+ echo "Error retrieving cron jobs or no cron jobs set.\n";
+ }
+ echo "################################################################\n\n";
+ }
+
}
\ No newline at end of file
diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php
index 3ac79b39..ce165798 100644
--- a/app/Controllers/PolicyTransactionController.php
+++ b/app/Controllers/PolicyTransactionController.php
@@ -157,7 +157,7 @@ class PolicyTransactionController extends BaseController
->join('client_branch', 'policy_transaction.client_branch_id = client_branch.id', 'left')
->join('insurers', 'pt_co_share_details.insurer_id = insurers.id', 'left')
->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left')
- ->join('policy_type', 'client_policy.policy_type_id = policy_type.id', 'left')
+ ->join('policy_type', 'policy_transaction.policy_type_id = policy_type.id', 'left')
->where('policy_transaction.is_active', 1)
->where('policy_transaction.action_type', 'inception')
->orderBy('policy_transaction.id', 'desc')
@@ -264,18 +264,26 @@ class PolicyTransactionController extends BaseController
$pt_co_share_details = $this->insertOrUpdateCoShareDetails($data, $insert);
- $client_policy_insert_data = $this->prepareClientPolicyInsertData($data);
- $client_policy_id = $this->clientPolicyModel->insert($client_policy_insert_data);
- $this->policyTransactionModel->update($insert, ['client_policy_id' => $client_policy_id]);
- $emp_policy_insert = $this->InsertIndividualEmpPolicyTable($emp_data, $client_policy_id);
+ if ($data['ct_type'] == 2) {
- if ($data['status'] == 'completed') {
- $this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']);
+ $client_policy_insert_data = $this->prepareClientPolicyInsertData($data);
+ $client_policy_id = $this->clientPolicyModel->insert($client_policy_insert_data);
+ $this->policyTransactionModel->update($insert, ['client_policy_id' => $client_policy_id]);
+ $emp_policy_insert = $this->InsertIndividualEmpPolicyTable($emp_data, $client_policy_id);
+
+ if ($data['status'] == 'completed') {
+ $this->processCompletedStatus($data, $client_policy_id, $data['insurer_id']);
+ }
}
+
$data['pt_co_share_details'] = $this->PTCOShareDetailsModel->where('pt_id', $insert)->where('is_active', 1)->findAll();
}
-
+
+ $client_data = $this->clientModel->where('id', $data['client_id'])->first();
+ $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll();
+ $data['entity_type_id'] = $client_data['entity_type_id'];
+
return $this->respondSuccess($insert, "Policy transaction created successfully", $data);
}
return $this->respondError("Failed to create policy transaction");
@@ -294,13 +302,12 @@ class PolicyTransactionController extends BaseController
if (empty($data['client_policy_id']) || $data['client_policy_id'] == 0) {
- $client_policy_insert_data = $this->prepareClientPolicyInsertData($data);
- // print_r($client_policy_insert_data); die;
- $client_policy_id = $this->clientPolicyModel->insert($client_policy_insert_data);
-
- $this->policyTransactionModel->update($id, ['client_policy_id' => $client_policy_id]);
-
- $this->InsertIndividualEmpPolicyTable($emp_data, $client_policy_id);
+ if ($data['ct_type'] == 2) {
+ $client_policy_insert_data = $this->prepareClientPolicyInsertData($data);
+ $client_policy_id = $this->clientPolicyModel->insert($client_policy_insert_data);
+ $this->policyTransactionModel->update($id, ['client_policy_id' => $client_policy_id]);
+ $this->InsertIndividualEmpPolicyTable($emp_data, $client_policy_id);
+ }
} else {
if (isset($data['emp_policy_id']) && !empty($data['emp_policy_id'][0])) {
@@ -308,7 +315,7 @@ class PolicyTransactionController extends BaseController
}
}
- if ($data['status'] == 'completed') {
+ if ($data['status'] == 'completed' && $data['ct_type'] == 2) {
$this->processCompletedStatus($data, $data['client_policy_id'], $data['insurer_id']);
}
@@ -345,27 +352,30 @@ class PolicyTransactionController extends BaseController
'bp_igst' => $data['igst'][$index] ?? 0,
'bp_sgst' => $data['sgst'][$index] ?? 0,
'bp_cgst' => $data['cgst'][$index] ?? 0,
- 'tp_amt' => $data['tp_ter_premium'][$index] ?? 0,
- 'tep_amt' => $data['tp_ter_premium'][$index] ?? 0,
+ 'tp_amt' => $data['tp_premium'][$index] ?? 0,
+ 'tep_amt' => $data['ter_premium'][$index] ?? 0,
'agreed_amt' => $data['agreed_amount'][$index] ?? 0,
'agreed_bp_per' => $data['agreed_bp'][$index] ?? 0,
- 'agreed_tp_per' => $data['agreed_tp_ter'][$index] ?? 0,
- 'agreed_tep_per' => $data['agreed_tp_ter'][$index] ?? 0,
+ 'agreed_tp_per' => $data['agreed_tp'][$index] ?? 0,
+ 'agreed_tep_per' => $data['agreed_ter'][$index] ?? 0,
'standerd_bp_per' => $data['standard_bp'][$index] ?? 0,
'standerd_tp_per' => $data['standard_tp'][$index] ?? 0,
- 'standerd_tep_per' => $data['standard_tep'][$index] ?? 0,
+ 'standerd_tep_per' => $data['standard_ter'][$index] ?? 0,
'actual_bp_amt' => $data['actual_bp_amt'][$index] ?? 0,
'actual_tp_amt' => $data['actual_tp_amt'][$index] ?? 0,
'actual_tep_amt' => $data['actual_tep_amt'][$index] ?? 0,
'actual_bp_per' => $data['actual_bp_per'][$index] ?? 0,
'actual_tp_per' => $data['actual_tp_per'][$index] ?? 0,
'actual_tep_per' => $data['actual_tep_per'][$index] ?? 0,
+ 'actual_bp_brokerage_amt' => $data['actual_bp_brokerage_amt'][$index] ?? 0,
+ 'actual_tp_brokerage_amt' => $data['actual_tp_brokerage_amt'][$index] ?? 0,
+ 'actual_tep_brokerage_amt' => $data['actual_tep_brokerage_amt'][$index] ?? 0,
'exp_amt' => $data['exp_amt'][$index] ?? 0,
'amount' => $data['total'][$index] ?? 0,
'stamp_duty' => $data['stamp_duty'][$index] ?? 0,
'cop_amt' => $data['co_premium'][$index] ?? 0,
'variance' => $data['variance'][$index] ?? 0,
- 'remark' => $data['remark'][$index] ?? null,
+ 'reward' => $data['reward'][$index] ?? null,
'created_by' => get_session_userid() ?? null,
'updated_by' => get_session_userid() ?? null,
'id' => $data['co_share_id'][$index] ?? null, // Assuming this is the ID to identify existing records
@@ -564,6 +574,7 @@ class PolicyTransactionController extends BaseController
policy_transaction.*,
clients.short_name as client_short_name,
clients.client_type,
+ clients.entity_type_id,
policy_type.policy_type,
client_policy.tpa_id as master_tpa_id,
client_policy.tpa_branch_id as master_tpa_branch_id,
@@ -586,7 +597,6 @@ class PolicyTransactionController extends BaseController
$data['updated_at'] = !empty($data['updated_at']) ? date('d-m-Y h:i:s A', strtotime($data['updated_at'])) : null;
// print_r($data); die;
-
$data['renewal_policy'] = $this->clientPolicyModel
->select('client_policy.*, policy_type.policy_type')
->join('policy_type', 'policy_type.id = client_policy.policy_type_id')
@@ -611,6 +621,11 @@ class PolicyTransactionController extends BaseController
->join('employee_polices', 'employees.id = employee_polices.employee_id', 'left')
->where('employees.client_id', $data['client_id'])
->where('employees.is_active', 1)->findAll();
+ $data['client_kyc'] = $this->clientKYCDocsModel->where('client_id', $data['client_id'])->findAll();
+ $data['vehicle_docs'] = $this->clientKYCDocsModel
+ ->where('client_id', $data['client_id'])
+ ->where('vehicle_id', $data['vehicle_id'])
+ ->findAll();
// print_r( $data['pt_co_share_details']); die;
@@ -819,7 +834,7 @@ class PolicyTransactionController extends BaseController
private function handleCompletedStatus($data, $policy_tran_id)
{
- if ($data['status'] == 'completed') {
+ if ($data['status'] == 'completed' && $data['ct_type'] == 2) {
$tolamt = $data['total'][0];
@@ -964,6 +979,23 @@ class PolicyTransactionController extends BaseController
}
+ public function checkInvoiceStatus($pt_id)
+ {
+ $data = $this->policyTransactionModel
+ ->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id')
+ ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id')
+ ->where('policy_transaction.id', $pt_id)
+ ->where('pt_co_share_details.statement_id IS NOT NULL')
+ ->where('insurer_statements.invoice_no IS NOT NULL')
+ ->countAllResults();
+
+ if($data){
+ return $this->respond(['status' => true, 'count'=> $data, 'code' => 200], 200);
+ }else{
+ return $this->respond(['status' => false, 'count'=> 0, 'message' => 'No Data Found', 'code' => 404], 200);
+ }
+ }
+
//---------------------------------------------------------------------------------------------------
//get BDS Reports data
@@ -1036,14 +1068,29 @@ class PolicyTransactionController extends BaseController
// dd( $data['insurers']);
$data['insurer_statement_list'] = $this->insurerStatements
- ->select('insurer_statements.*,
- insurers.name AS insurer_name,insurers.short_name,user_profiles.first_name,insurer_branch.branch_code
- ')
- ->join('insurers', 'insurer_statements.insurer_id = insurers.id')
- ->join('insurer_branch', 'insurer_statements.branch_id = insurer_branch.id')
- ->join('user_profiles', 'insurer_statements.created_by = user_profiles.id')
- ->orderBy('insurer_statements.id', 'desc')
- ->findAll();
+ ->select('insurer_statements.*,
+ insurers.name AS insurer_name,
+ insurers.short_name,
+ user_profiles.first_name,
+ insurer_branch.branch_code,
+ (SELECT SUM(pt_co_share_details.exp_amt)
+ FROM pt_co_share_details
+ WHERE pt_co_share_details.is_active = 1
+ AND pt_co_share_details.statement_id = insurer_statements.id
+ ) AS exp_inv_amt,
+ (SELECT SUM(inv_payment_details.inv_amt)
+ FROM inv_payment_details
+ WHERE inv_payment_details.is_active = 1
+ AND inv_payment_details.statement_id = insurer_statements.id
+ ) AS received_inv_amt'
+ )
+ ->join('insurers', 'insurer_statements.insurer_id = insurers.id')
+ ->join('insurer_branch', 'insurer_statements.branch_id = insurer_branch.id')
+ ->join('user_profiles', 'insurer_statements.created_by = user_profiles.id')
+ ->where('insurer_statements.is_active', 1)
+ ->orderBy('insurer_statements.id', 'DESC')
+ ->findAll();
+
// dd( $data['insurer_statement_list']);
$this->loadLayout('insurer_statement_list', $data);
}
@@ -1190,7 +1237,7 @@ class PolicyTransactionController extends BaseController
$line_items = count($excel_data);
// get uploaded month transactions data
$source_data = $this->PTCOShareDetailsModel->getNonReconcileredPolicyTransactions(month:$month,year:$year,insurer_id:$file['insurer_id'],insurer_branch_id:$file['branch_id']);
- // Kint::dump($source_data);
+ // var_dump($source_data);die();
// Kint::dump($excel_data);
// check policy no,insurer and etc in DB for this month
@@ -1378,7 +1425,7 @@ class PolicyTransactionController extends BaseController
// $ret_status = false;
// }
//update in DB
- //$this->insurerStatements->where('id', $file_id)->set(['file_status' => $status,'reason' => json_encode($error_data)])->update();
+ $this->insurerStatements->where('id', $file_id)->set(['file_status' => $status,'reason' => json_encode($error_data),'invoice_status' =>'pending'])->update();
return array('status' => $ret_status, 'error_code' => $error_data['error_code'],'error_data' => $error_data['error_data']);
}
@@ -1424,7 +1471,7 @@ class PolicyTransactionController extends BaseController
- // $this->insurerStatements->update($hiddenStatementId, $parentData);
+ $this->insurerStatements->update($hiddenStatementId, $parentData);
// Process child data
$invoiceAmounts = $jsonData['invoice_amount'];
@@ -1442,21 +1489,99 @@ class PolicyTransactionController extends BaseController
'inv_amt' => $invoiceAmount,
'utr_no' => $utrNo,
'received_date' => $paymentDate,
- 'statement_id' => $hiddenStatementId,
- 'id' => is_numeric($pk) ? (int)$pk : '',
+ 'statement_id' => $hiddenStatementId
];
- if($pk){ $childData['updated_by'] = get_session_userid(); }
+ if($pk){
+ $childData['updated_by'] = get_session_userid();
+ $childData['id'] = (int)$pk;
+ }
else { $childData['created_by'] = get_session_userid(); }
// print_r($childData);
// Insert or update
$this->invPaymentDetailsModel->save($childData);
- print_r($this->invPaymentDetailsModel->errors());
+ // print_r($this->invPaymentDetailsModel->errors());
}
return $this->respond(['dataStatus' => true, 'code' => 200], 200);
//return $this->response->setJSON(['dataStatus' => 'true']);
}
+
+ public function deletePaymentEntry()
+ {
+ $payment_id = $this->request->getUri()->getSegment(4);
+ //echo $payment_id;
+ $this->invPaymentDetailsModel->update($payment_id, ['is_active' => 0]);
+ return $this->respond(['dataStatus' => true, 'code' => 200], 200);
+ }
+
+ public function downloadSampleInsurerStatement()
+ {
+
+ $filePath = ROOTPATH . 'public/sample_excel/insurer_stament_sample.xlsx';
+ // Check if the file exists
+ if (file_exists($filePath)) {
+
+ // Set the appropriate MIME type
+ $mimeType = mime_content_type($filePath);
+
+ // Send the file to the client for download
+ return $this->response->download($filePath, null, $mimeType);
+ } else {
+ // File not found, show an error message or redirect
+ echo view('errors/html/production');
+ }
+ }
+
+ public function getFileErr()
+ {
+ $file_id = $this->request->getUri()->getSegment(4);
+ $file = $this->insurerStatements->find($file_id);
+ return $this->respond(['dataStatus' => true, 'code' => 200,'data' => $file['reason']], 200);
+ }
+
+
+ public function dmsSearch()
+ {
+ // echo 'scbsc';die();
+ if ($this->request->getMethod() == 'post')
+ {
+ // $jsonData = (array)$this->request->getJSON();
+ $customer_id = $this->request->getPost('customer_id');
+ $policy_id = $this->request->getPost('policy_id');
+ $cus_doc_name = $this->request->getPost('cus_doc_name');
+ $policy_doc_name = $this->request->getPost('policy_doc_name');
+ $pt_files = [];
+ $kyc_files = [];
+ // print_r($jsonData);die();
+ if($policy_id != "")
+ {
+ //get policy docs from policy transation related tables
+ $pt_files = $this->PTFileModel->getPolicyDriveFilesIndex($policy_id,$policy_doc_name);
+ // ~dd($this->PTFileModel->getLastQuery());
+ // ~dd($d);
+ }
+ if($customer_id != "")
+ {
+ $kyc_files = $this->clientKYCDocsModel->getClientKYCDriveFilesIndex($customer_id,$cus_doc_name);
+ // dd($this->clientKYCDocsModel->getLastQuery());
+ // !dd($kyc_files);
+ }
+
+ $data['files'] = array_merge($pt_files,$kyc_files);
+ // dd($data['files']);
+ }
+
+
+ $data['customers'] = $this->clientModel->select('id,client_name,short_name as display_value')->where('is_active',1)->get()->getResultarray();
+ $data['policies'] = $this->clientPolicyModel->select("client_policy.id,client_policy.policy_no,policy_type.policy_type,concat(policy_type.policy_type,' - ',client_policy.policy_no) as display_value")
+ ->join('policy_type','client_policy.policy_type_id = policy_type.id')
+ ->where('client_policy.is_active',1)->get()->getResultarray();
+ // dd($data);
+ $this->loadLayout('dms_search', $data);
+
+
+ }
}
\ No newline at end of file
diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php
index a764697b..ab40178e 100755
--- a/app/Helpers/utility_helper.php
+++ b/app/Helpers/utility_helper.php
@@ -1,5 +1,6 @@
select('team_id')->where('user_id', $user_id)->findAll();
+
+ // Debugging: Log or print the query result to check its structure
+ // var_dump($user_teams); // You can use this temporarily for testing
+ // log_message('info', 'User Teams: ' . json_encode($user_teams)); // Optionally log it
+
+ // Check if the result is not empty
+ if (!empty($user_teams)) {
+ // Extract only the 'team_id' values
+ $team_ids = array_column($user_teams, 'team_id');
+ return $team_ids; // Return array of team IDs
+ } else {
+ return []; // Return empty array if no teams found
+ }
+ }
+}
+
+
+
if (!function_exists('generate_client_code')) {
function generate_client_code($string = 'GC') {
diff --git a/app/Libraries/GmailAPI.php b/app/Libraries/GmailAPI.php
index ffa180c7..f08a832e 100755
--- a/app/Libraries/GmailAPI.php
+++ b/app/Libraries/GmailAPI.php
@@ -175,6 +175,6 @@ class GmailAPI
$this->storeTokenToDB($accessToken);
$this->myLogger->logme('error', 'New token generated and stored in the database.');
- print 'New token generated and stored in the database.';
+ print 'New token generated and stored in the database.';
}
}
diff --git a/app/Libraries/MyGoogleDrive.php b/app/Libraries/MyGoogleDrive.php
new file mode 100644
index 00000000..566098eb
--- /dev/null
+++ b/app/Libraries/MyGoogleDrive.php
@@ -0,0 +1,131 @@
+myLogger = \Config\Services::mylogger();
+ $this->client = new Google_Client();
+ $this->client->setAuthConfig(ROOTPATH . 'nhance-app-google-drive.json'); // App credentials
+ // putenv('GOOGLE_APPLICATION_CREDENTIALS=' . ROOTPATH . 'nhance-app-google-drive.json');
+ $this->client->useApplicationDefaultCredentials();
+
+ $this->client->addScope(Google_Service_Drive::DRIVE); // Full access to Google Drive
+ }
+
+ public function getDriveService()
+ {
+ return new Google_Service_Drive($this->client);
+ }
+
+ // this function serve no purpose on anywhere, just for test purpose
+ public function listFiles(string $searchQuery = '')
+ {
+ $service = $this->getDriveService();
+ // $searchQuery = "name contains 'test' and 'vitvelz@gmail.com' in readers";
+ $searchQuery = "name contains 'test' or name contains 'new'";
+ // $searchQuery = "name contains 'test' and mimeType = 'application/vnd.google-apps.folder' or name contains 'new' and mimeType = 'application/vnd.ms-excel'";
+ // List the files
+ $files = $service->files->listFiles([
+ 'q' => $searchQuery,
+ // 'supportsAllDrives' => true,
+ // 'includeItemsFromAllDrives' => true,
+ 'fields' => 'nextPageToken, files(id, name, mimeType, size, createdTime, modifiedTime, owners, shared, permissions, webViewLink, thumbnailLink)',
+ 'pageSize' => 20,
+ ]);
+ // print_r($files);
+ echo "\n**************\n";
+ foreach ($files->getFiles() as $file) {
+ echo 'File ID: ' . $file->getID() . "\n";
+ echo 'File Name: ' . $file->getName() . "\n";
+ // echo 'MIME Type: ' . $file->getMimeType() . "\n";
+ // echo 'Size: ' . $file->getSize() . " bytes\n";
+ // echo 'Created Time: ' . $file->getCreatedTime() . "\n";
+ // echo 'Modified Time: ' . $file->getModifiedTime() . "\n";
+ // echo 'Owner: ' . $file->getOwners()[0]->getEmailAddress() . "\n";
+ // echo 'Shared: ' . ($file->getShared() ? 'Yes' : 'No') . "\n";
+ // echo 'Permissions: ' . json_encode($file->getPermissions()) . "\n";
+ // echo 'Web View Link: ' . $file->getWebViewLink() . "\n";
+ // echo 'Thumbnail Link: ' . $file->getThumbnailLink() . "\n";
+ echo 'parents: ' .$file->getParents()."\n";
+ echo "-----\n";
+ }
+ }
+
+ // this fucntion is not generating any new token, just for testing purpose
+ public function generateNewToken()
+ {
+ // $this->uploadFile();die();
+ $this->listFiles();die();
+ // dd('called');
+ if (!is_cli()) {
+ throw new \RuntimeException('This method can only be accessed via the command line.');
+ }
+
+ if (php_sapi_name() != 'cli') {
+ throw new Exception('This application must be run on the command line.');
+ }
+
+ $authUrl = $this->client->createAuthUrl();
+ CLI::write('Open the following link in your browser');
+ CLI::write("\n");
+ CLI::write($authUrl);
+ // printf ("Open the following link in your browser:\n%s\n", $authUrl);
+ CLI::write('Enter verification code: ');
+ // print 'Enter verification code: ';
+ $authCode = trim(fgets(STDIN));
+
+ $accessToken = $this->client->fetchAccessTokenWithAuthCode($authCode);
+ if (array_key_exists('error', $accessToken)) {
+ $this->myLogger->logme('error', 'Error in getting access token from authCode' . join(', ', $accessToken));
+ throw new \Exception(join(', ', $accessToken));
+ }
+
+ $this->storeToken($accessToken);
+ $this->myLogger->logme('error', 'New token generated and stored in the writepath for google drive.');
+ print 'New token generated and stored in the writepath for google drive.';
+ }
+
+ /**
+ * Upload a file to Google Drive
+ * this function not used in anywhere
+ */
+ public function uploadFile($filePath = '', $fileName= '')
+ {
+ $service = $this->getDriveService();
+
+ // $file = new \Google_Service_Drive_DriveFile();
+ // $file->setName('tata.xlsx');
+ // $file->setParents('TEST');
+
+ // Create a new file metadata object
+ $file = new \Google_Service_Drive_DriveFile([
+ 'name' => 'mypdf.pdf',
+ 'parents' => ['1M0GH3GbNUOYZLNeHXA5U7C_P2NSx7F7O'] // Specify the folder ID here
+ ]);
+
+ $data = file_get_contents('C:\Users\Venba\Desktop\nhance_bpf.pdf');
+
+ $createdFile = $service->files->create($file, [
+ 'data' => $data,
+ 'mimeType' => 'application/octet-stream',
+ 'uploadType' => 'multipart',
+ 'fields' => 'id' // Specify fields to return
+ ]);
+
+ echo $createdFile->id;
+ }
+
+
+
+}
diff --git a/app/Models/ClientKYCDocsModel.php b/app/Models/ClientKYCDocsModel.php
index 6c9f3c8a..913fb375 100755
--- a/app/Models/ClientKYCDocsModel.php
+++ b/app/Models/ClientKYCDocsModel.php
@@ -17,6 +17,7 @@ class ClientKYCDocsModel extends Model
'is_active',
"created_by",
"updated_by",
+ "vehicle_id",
];
public function getKycDocsName($client_id){
@@ -27,4 +28,17 @@ class ClientKYCDocsModel extends Model
return $query;
}
+ public function getClientKYCDriveFilesIndex($client_id,$client_doc_name = '')
+ {
+ $query = $this->select('client_kyc_documents.client_id,client_kyc_documents.file_name, kyc_docs.file_name as doc_name,"url","client_policy_id","kyc" as file_type')
+ ->join('kyc_docs', 'kyc_docs.id = client_kyc_documents.kyc_doc_type_id')
+ ->where(['client_kyc_documents.client_id' => $client_id, 'client_kyc_documents.is_active' => 1])
+ ->when($client_doc_name, function($query) use ($client_doc_name){
+ return $query->where("kyc_docs.file_name like '%$client_doc_name%'");
+ })
+ ->get()
+ ->getResultArray();
+ return $query;
+ }
+
}
diff --git a/app/Models/EndorsementModel.php b/app/Models/EndorsementModel.php
new file mode 100644
index 00000000..22bcec72
--- /dev/null
+++ b/app/Models/EndorsementModel.php
@@ -0,0 +1,30 @@
+where('YEAR(pt.created_at)', $year)
->where('pt_co.insurer_id', $insurer_id)
->where('pt_co.insurer_branch_id', $insurer_branch_id)
+ ->where('pt_co.statement_id is null')
// ->where('pt_co.exp_amt', 0.00)
// ->orWhere('pt_co.exp_amt is null')
->get()
diff --git a/app/Models/PTFileModel.php b/app/Models/PTFileModel.php
index b2e99b50..702cb30d 100644
--- a/app/Models/PTFileModel.php
+++ b/app/Models/PTFileModel.php
@@ -25,5 +25,18 @@ class PTFileModel extends Model
];
+ public function getPolicyDriveFilesIndex($policy_id,$policy_doc_name)
+ {
+ $clients = $this->select('pt_files.doc_name,pt_files.file_name,pt_files.url,pt.client_id,pt.client_policy_id,"policy" as file_type')
+ ->join('policy_transaction pt', 'pt_files.pt_id = pt.id')
+ ->where('pt.client_policy_id', $policy_id)
+ ->where('pt.is_active',1)
+ ->when($policy_doc_name, function($query) use ($policy_doc_name){
+ return $query->where("pt_files.doc_name like '%$policy_doc_name%'");
+ })
+ ->get()
+ ->getResultArray();
+ return $clients;
+ }
}
diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php
index f849d41d..3649e768 100644
--- a/app/Models/PolicyTransactionModel.php
+++ b/app/Models/PolicyTransactionModel.php
@@ -72,6 +72,9 @@ class PolicyTransactionModel extends Model
'endorse_eff_date',
'sales_generated_by',
'serviced_by',
+ 'ct_type',
+ 'ct_tran_id',
+ 'remarks',
];
diff --git a/app/Views/client_kyc.php b/app/Views/client_kyc.php
index 6893b31c..99d0149e 100755
--- a/app/Views/client_kyc.php
+++ b/app/Views/client_kyc.php
@@ -30,43 +30,42 @@
-
| S.No | +Doc name | +File name | +Action | +
|---|---|---|---|
| = $index + 1 ?> | ++ | + | + "> + + | + +