diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index e81526d0..c92798d5 100755
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -322,16 +322,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/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 60daeb55..f3cdc177 100644
--- a/app/Controllers/PolicyTransactionController.php
+++ b/app/Controllers/PolicyTransactionController.php
@@ -990,14 +990,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);
}
@@ -1144,7 +1159,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
@@ -1332,7 +1347,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']);
}
@@ -1378,7 +1393,7 @@ class PolicyTransactionController extends BaseController
- // $this->insurerStatements->update($hiddenStatementId, $parentData);
+ $this->insurerStatements->update($hiddenStatementId, $parentData);
// Process child data
$invoiceAmounts = $jsonData['invoice_amount'];
@@ -1396,21 +1411,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/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..6e70bc33 100755
--- a/app/Models/ClientKYCDocsModel.php
+++ b/app/Models/ClientKYCDocsModel.php
@@ -27,4 +27,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/PTCOShareDetailsModel.php b/app/Models/PTCOShareDetailsModel.php
index f5f56f85..274b572b 100644
--- a/app/Models/PTCOShareDetailsModel.php
+++ b/app/Models/PTCOShareDetailsModel.php
@@ -96,6 +96,7 @@ class PTCOShareDetailsModel extends Model
->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/Views/dms_search.php b/app/Views/dms_search.php
new file mode 100644
index 00000000..77518613
--- /dev/null
+++ b/app/Views/dms_search.php
@@ -0,0 +1,225 @@
+
+
+
| S.No | +Doc name | +File name | +Action | +
|---|---|---|---|
| = $index + 1 ?> | ++ | + | + "> + + | + +