FEAT_NONEB_GDRIVE_APPROACH

This commit is contained in:
velz 2026-03-06 11:17:17 +05:30
parent 804d98aa8c
commit 171be333e8
8 changed files with 3533 additions and 1547 deletions

View File

@ -130,3 +130,6 @@ HEALTH_INDIA_USERNAME =
HEALTH_INDIA_PASSWORD = HEALTH_INDIA_PASSWORD =
HEALTH_INDIA_PRIMARY_KEY_CONSTANT = HEALTH_INDIA_PRIMARY_KEY_CONSTANT =
LEAD_INSURER_FROM_MAIL_ID =
LEAD_CLIENT_FROM_MAIL_ID =

51
app/Config/RfqConfig.php Normal file
View File

@ -0,0 +1,51 @@
<?php
namespace Config;
use CodeIgniter\Config\BaseConfig;
class RfqConfig extends BaseConfig
{
/**
* Google Drive parent folder IDs for RFQ and QCR sheets.
*/
public string $rfqParentFolderId = '1MnYh5PTPDlc9mYMGsjmTv02y8EZ-BQf1';
public string $qcrParentFolderId = '1MnYh5PTPDlc9mYMGsjmTv02y8EZ-BQf1';
/**
* Default permissions for created sheets.
* Copied from GoogleSheetController::$config.
*/
public array $permissions = [
'editors' => [
'vitvelz@gmail.com',
'velz1990@gmail.com',
'venkateshraman786@gmail.com',
],
'viewers' => [],
];
/**
* Default protections for RFQ sheets.
* Copied from GoogleSheetController::$config.
*/
public array $protections = [
[
'range' => 'RFQ Page!B12:C12',
'users' => [
'velz1990@gmail.com',
'vitvelz@gmail.com',
'firebase-adminsdk-mcdfe@nhance-ee8d1.iam.gserviceaccount.com',
],
'groups' => [],
],
[
'range' => 'Claims Page!A1',
'users' => [
'velz1990@gmail.com',
'venkateshraman786@gmail.com',
'firebase-adminsdk-mcdfe@nhance-ee8d1.iam.gserviceaccount.com',
],
'groups' => [],
],
];
}

View File

@ -503,6 +503,8 @@ $routes->group("leads", ["filter" => "authMVC"], function ($routes) {
$routes->match(['get', 'post'],"list", "LeadsController::viewLeadsList"); $routes->match(['get', 'post'],"list", "LeadsController::viewLeadsList");
$routes->post("create", "LeadsController::createLead"); $routes->post("create", "LeadsController::createLead");
$routes->get("list/(:any)", "LeadsController::getLeadDataForEdit/$1"); $routes->get("list/(:any)", "LeadsController::getLeadDataForEdit/$1");
$routes->get("createRfqSheet", "LeadsController::createRfqSheet");
$routes->get("mailTemplate", "LeadsController::getLeadMailTemplate");
$routes->get("sendMail", "LeadsController::sendMailWithAttachement"); $routes->get("sendMail", "LeadsController::sendMailWithAttachement");
$routes->post("sendMail", "LeadsController::sendMailWithAttachement"); $routes->post("sendMail", "LeadsController::sendMailWithAttachement");
$routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1"); $routes->get("exportQCRandRFQ/(:any)", "LeadsController::exportQCRandRFQ/$1");
@ -516,6 +518,10 @@ $routes->group("rfq", ["filter" => "authMVC"], function ($routes) {
$routes->post("createQCR", "LeadsController::createQCR"); $routes->post("createQCR", "LeadsController::createQCR");
$routes->get("list/(:any)", "LeadsController::viewRFQ/$1"); $routes->get("list/(:any)", "LeadsController::viewRFQ/$1");
$routes->get("nonEB","LeadsController::rfqNonEB"); $routes->get("nonEB","LeadsController::rfqNonEB");
// Non-EB dedicated RFQ/QCR endpoints (do not alter existing ones)
$routes->get("nonEB/rfq/(:any)","LeadsController::viewNonEbRFQFromList/$1");
$routes->get("nonEB/qcr/(:any)","LeadsController::viewNonEbQCRFromList/$1");
$routes->get("placementData/(:num)", "LeadsController::getPlacementData/$1");
}); });

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,11 @@
<?php namespace App\Libraries; <?php
namespace App\Libraries;
use Google_Client; use Google_Client;
use Google_Service_Sheets;
use Google_Service_Drive; use Google_Service_Drive;
use Google_Service_Sheets_ValueRange; use Google_Service_Sheets;
use Google_Service_Sheets_BatchUpdateSpreadsheetRequest; use Google_Service_Sheets_BatchUpdateSpreadsheetRequest;
use Google_Service_Sheets_ValueRange;
class GoogleSheetLib class GoogleSheetLib
{ {
@ -12,7 +13,6 @@ class GoogleSheetLib
protected Google_Service_Sheets $sheets; protected Google_Service_Sheets $sheets;
protected Google_Service_Drive $drive; protected Google_Service_Drive $drive;
public function __construct() public function __construct()
{ {
$this->client = new Google_Client(); $this->client = new Google_Client();
@ -28,7 +28,7 @@ class GoogleSheetLib
// Required scopes // Required scopes
$this->client->addScope([ $this->client->addScope([
Google_Service_Drive::DRIVE, Google_Service_Drive::DRIVE,
Google_Service_Sheets::SPREADSHEETS Google_Service_Sheets::SPREADSHEETS,
]); ]);
// Init services // Init services
@ -53,7 +53,7 @@ class GoogleSheetLib
public function write(string $spreadsheetId, array $values, string $range = 'Sheet1') public function write(string $spreadsheetId, array $values, string $range = 'Sheet1')
{ {
$body = new Google_Service_Sheets_ValueRange([ $body = new Google_Service_Sheets_ValueRange([
'values' => $values 'values' => $values,
]); ]);
$this->sheets $this->sheets
@ -81,7 +81,6 @@ class GoogleSheetLib
return $response->getBody()->getContents(); return $response->getBody()->getContents();
} }
/* ================= COPY TEMPLATE ================= */ /* ================= COPY TEMPLATE ================= */
public function copyTemplate(string $templateId, string $name, string $folderId): string public function copyTemplate(string $templateId, string $name, string $folderId): string
@ -92,10 +91,10 @@ class GoogleSheetLib
'name' => $name, 'name' => $name,
'parents' => [$folderId], 'parents' => [$folderId],
]),[ ]), [
'supportsAllDrives' => true, 'supportsAllDrives' => true,
'fields' => 'id, name, parents' 'fields' => 'id, name, parents',
] ]
); );
return $file->id; return $file->id;
@ -116,7 +115,7 @@ class GoogleSheetLib
private function createPermission(string $fileId, string $email, string $role) private function createPermission(string $fileId, string $email, string $role)
{ {
$type = str_starts_with($email, 'group:') ? 'group' : 'user'; $type = str_starts_with($email, 'group:') ? 'group' : 'user';
$email = str_replace('group:', '', $email); $email = str_replace('group:', '', $email);
$this->drive->permissions->create( $this->drive->permissions->create(
@ -124,9 +123,9 @@ class GoogleSheetLib
new \Google_Service_Drive_Permission([ new \Google_Service_Drive_Permission([
'type' => $type, 'type' => $type,
'role' => $role, 'role' => $role,
'emailAddress' => $email 'emailAddress' => $email,
]), ]),
['sendNotificationEmail' => false,'supportsAllDrives' => true] ['sendNotificationEmail' => false, 'supportsAllDrives' => true]
); );
} }
@ -135,7 +134,7 @@ class GoogleSheetLib
public function applyProtectionsold(string $spreadsheetId, array $ranges) public function applyProtectionsold(string $spreadsheetId, array $ranges)
{ {
$spreadsheet = $this->sheets->spreadsheets->get($spreadsheetId); $spreadsheet = $this->sheets->spreadsheets->get($spreadsheetId);
$sheetId = $spreadsheet->getSheets()[0]->getProperties()->getSheetId(); $sheetId = $spreadsheet->getSheets()[0]->getProperties()->getSheetId();
$requests = []; $requests = [];
@ -145,96 +144,95 @@ class GoogleSheetLib
$requests[] = [ $requests[] = [
'addProtectedRange' => [ 'addProtectedRange' => [
'protectedRange' => [ 'protectedRange' => [
'range' => [ 'range' => [
'sheetId' => $sheetId 'sheetId' => $sheetId,
], ],
'warningOnly' => false 'warningOnly' => false,
] ],
] ],
]; ];
} }
$this->sheets->spreadsheets->batchUpdate( $this->sheets->spreadsheets->batchUpdate(
$spreadsheetId, $spreadsheetId,
new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([ new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
'requests' => $requests 'requests' => $requests,
]) ])
); );
} }
public function applyProtections(string $spreadsheetId, array $protections) public function applyProtections(string $spreadsheetId, array $protections)
{ {
// Fetch spreadsheet metadata // Fetch spreadsheet metadata
$spreadsheet = $this->sheets->spreadsheets->get( $spreadsheet = $this->sheets->spreadsheets->get(
$spreadsheetId, $spreadsheetId,
['fields' => 'sheets(properties(sheetId,title,gridProperties))'] ['fields' => 'sheets(properties(sheetId,title,gridProperties))']
);
// Map sheet names
$sheetMap = [];
foreach ($spreadsheet->getSheets() as $sheet) {
$props = $sheet->getProperties();
$sheetMap[$props->getTitle()] = [
'sheetId' => $props->getSheetId(),
'rowCount' => $props->getGridProperties()->getRowCount(),
'colCount' => $props->getGridProperties()->getColumnCount(),
];
}
$requests = [];
foreach ($protections as $protection) {
$rangeStr = $protection['range'];
if (!str_contains($rangeStr, '!')) {
throw new \Exception("Invalid range format: {$rangeStr}");
}
[$sheetName, $a1] = explode('!', $rangeStr, 2);
if (!isset($sheetMap[$sheetName])) {
throw new \Exception("Sheet not found: {$sheetName}");
}
$sheetMeta = $sheetMap[$sheetName];
$gridRange = $this->convertA1ToGridRange(
$a1,
$sheetMeta['sheetId'],
$sheetMeta['rowCount'],
$sheetMeta['colCount']
); );
$protectedRange = [ // Map sheet names
'range' => $gridRange, $sheetMap = [];
'description' => 'RFQ Protected Area', foreach ($spreadsheet->getSheets() as $sheet) {
'warningOnly' => false, $props = $sheet->getProperties();
'editors' => [ $sheetMap[$props->getTitle()] = [
'users' => $protection['users'] ?? [], 'sheetId' => $props->getSheetId(),
'groups' => $protection['groups'] ?? [] 'rowCount' => $props->getGridProperties()->getRowCount(),
] 'colCount' => $props->getGridProperties()->getColumnCount(),
]; ];
}
$requests[] = [ $requests = [];
'addProtectedRange' => [
'protectedRange' => $protectedRange foreach ($protections as $protection) {
]
]; $rangeStr = $protection['range'];
if (! str_contains($rangeStr, '!')) {
throw new \Exception("Invalid range format: {$rangeStr}");
}
[$sheetName, $a1] = explode('!', $rangeStr, 2);
if (! isset($sheetMap[$sheetName])) {
throw new \Exception("Sheet not found: {$sheetName}");
}
$sheetMeta = $sheetMap[$sheetName];
$gridRange = $this->convertA1ToGridRange(
$a1,
$sheetMeta['sheetId'],
$sheetMeta['rowCount'],
$sheetMeta['colCount']
);
$protectedRange = [
'range' => $gridRange,
'description' => 'RFQ Protected Area',
'warningOnly' => false,
'editors' => [
'users' => $protection['users'] ?? [],
'groups' => $protection['groups'] ?? [],
],
];
$requests[] = [
'addProtectedRange' => [
'protectedRange' => $protectedRange,
],
];
}
if (! empty($requests)) {
$batch = new \Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
'requests' => $requests,
]);
$this->sheets->spreadsheets->batchUpdate($spreadsheetId, $batch);
}
return true;
} }
if (!empty($requests)) {
$batch = new \Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
'requests' => $requests
]);
$this->sheets->spreadsheets->batchUpdate($spreadsheetId, $batch);
}
return true;
}
/* ================= URL ================= */ /* ================= URL ================= */
public function sheetUrl(string $sheetId): string public function sheetUrl(string $sheetId): string
@ -242,43 +240,41 @@ class GoogleSheetLib
return "https://docs.google.com/spreadsheets/d/{$sheetId}/edit"; return "https://docs.google.com/spreadsheets/d/{$sheetId}/edit";
} }
private function convertA1ToGridRange($a1, $sheetId, $maxRows, $maxCols)
{
if (preg_match('/^([A-Z]+)(\d+)(?::([A-Z]+)(\d+))?$/i', $a1, $m)) {
private function convertA1ToGridRange($a1, $sheetId, $maxRows, $maxCols) $startCol = $this->colToIndex($m[1]);
{ $startRow = intval($m[2]) - 1;
if (preg_match('/^([A-Z]+)(\d+)(?::([A-Z]+)(\d+))?$/i', $a1, $m)) {
$startCol = $this->colToIndex($m[1]); if (! empty($m[3])) {
$startRow = intval($m[2]) - 1; $endCol = $this->colToIndex($m[3]) + 1;
$endRow = intval($m[4]);
} else {
$endCol = $startCol + 1;
$endRow = $startRow + 1;
}
if (!empty($m[3])) { return [
$endCol = $this->colToIndex($m[3]) + 1; 'sheetId' => $sheetId,
$endRow = intval($m[4]); 'startRowIndex' => $startRow,
} else { 'endRowIndex' => $endRow,
$endCol = $startCol + 1; 'startColumnIndex' => $startCol,
$endRow = $startRow + 1; 'endColumnIndex' => $endCol,
];
} }
return [ throw new \Exception("Unsupported A1 format: {$a1}");
'sheetId' => $sheetId,
'startRowIndex' => $startRow,
'endRowIndex' => $endRow,
'startColumnIndex' => $startCol,
'endColumnIndex' => $endCol
];
} }
throw new \Exception("Unsupported A1 format: {$a1}"); private function colToIndex($letters)
} {
$letters = strtoupper($letters);
private function colToIndex($letters) $index = 0;
{ for ($i = 0; $i < strlen($letters); $i++) {
$letters = strtoupper($letters); $index = $index * 26 + (ord($letters[$i]) - 64);
$index = 0; }
for ($i = 0; $i < strlen($letters); $i++) { return $index - 1;
$index = $index * 26 + (ord($letters[$i]) - 64);
} }
return $index - 1;
}
} }

View File

@ -1,13 +1,12 @@
<?php <?php
namespace App\Models; namespace App\Models;
use CodeIgniter\Model; use CodeIgniter\Model;
class LeadsModel extends Model class LeadsModel extends Model
{ {
protected $table = 'leads'; protected $table = 'leads';
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $allowedFields = [ protected $allowedFields = [
'id', 'id',
'actual_lead_id', 'actual_lead_id',
@ -108,20 +107,19 @@ class LeadsModel extends Model
'quote_received_insurer', 'quote_received_insurer',
'acm_id', 'acm_id',
'policy_with_correction', 'policy_with_correction',
'agreed_percentage', 'agreed_percentage', 'misc',
]; ];
// Callbacks // Callbacks
protected $allowCallbacks = true; protected $allowCallbacks = true;
protected $beforeInsert = ["checkAndADDCreatedByValue"]; protected $beforeInsert = ["checkAndADDCreatedByValue"];
protected $afterInsert = []; protected $afterInsert = [];
protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"];
protected $afterUpdate = []; protected $afterUpdate = [];
protected $beforeFind = []; protected $beforeFind = [];
protected $afterFind = []; protected $afterFind = [];
protected $beforeDelete = []; protected $beforeDelete = [];
protected $afterDelete = []; protected $afterDelete = [];
protected function checkAndADDCreatedByValue(array $data) protected function checkAndADDCreatedByValue(array $data)
{ {
@ -176,7 +174,7 @@ class LeadsModel extends Model
->join('lead_files', 'leads.id = lead_files.lead_id AND lead_files.type = 2 AND lead_files.is_active = 1', 'left') ->join('lead_files', 'leads.id = lead_files.lead_id AND lead_files.type = 2 AND lead_files.is_active = 1', 'left')
->where('leads.is_active', 1); ->where('leads.is_active', 1);
if (!empty($where)) { if (! empty($where)) {
$data->where($where); $data->where($where);
} }
@ -185,7 +183,7 @@ class LeadsModel extends Model
public function getLeadForInsertClientList($type = null, $client_id = null) public function getLeadForInsertClientList($type = null, $client_id = null)
{ {
$query = $this->db->table('leads') $query = $this->db->table('leads')
->select('leads.*, user_profiles.first_name as user_name') ->select('leads.*, user_profiles.first_name as user_name')
->join('user_profiles', 'leads.created_by = user_profiles.id') ->join('user_profiles', 'leads.created_by = user_profiles.id')
->where('leads.is_active', 1) ->where('leads.is_active', 1)
@ -194,8 +192,6 @@ class LeadsModel extends Model
->where("(leads.is_client_created = '' OR leads.is_client_created IS NULL)") ->where("(leads.is_client_created = '' OR leads.is_client_created IS NULL)")
->where("(leads.is_policy_created = '' OR leads.is_policy_created IS NULL)"); ->where("(leads.is_policy_created = '' OR leads.is_policy_created IS NULL)");
if ($type) { if ($type) {
$query->where('leads.lead_type', $type); $query->where('leads.lead_type', $type);
} }
@ -291,12 +287,10 @@ class LeadsModel extends Model
// $lead_data[0]['total'] = $total; // $lead_data[0]['total'] = $total;
// $lead_data[0]['policy_with_correction'] = $policy_with_correction_count; // $lead_data[0]['policy_with_correction'] = $policy_with_correction_count;
// // dd($lead_data[0]); // // dd($lead_data[0]);
// return $lead_data[0]; // return $lead_data[0];
// } // }
public function getDashData() public function getDashData()
{ {
// Get all unique statuses // Get all unique statuses
@ -321,7 +315,7 @@ class LeadsModel extends Model
$selectParts = []; $selectParts = [];
foreach ($statuses as $row) { foreach ($statuses as $row) {
$status = $row['status']; $status = $row['status'];
$alias = strtolower(str_replace(' ', '_', $status)); $alias = strtolower(str_replace(' ', '_', $status));
$selectParts[] = "SUM(CASE WHEN status = '{$status}' THEN 1 ELSE 0 END) AS `{$alias}`"; $selectParts[] = "SUM(CASE WHEN status = '{$status}' THEN 1 ELSE 0 END) AS `{$alias}`";
$selectParts[] = "GROUP_CONCAT(CASE WHEN status = '{$status}' THEN id END) AS `{$alias}_ids`"; $selectParts[] = "GROUP_CONCAT(CASE WHEN status = '{$status}' THEN id END) AS `{$alias}_ids`";
@ -339,19 +333,17 @@ class LeadsModel extends Model
// Calculate total // Calculate total
$total = 0; $total = 0;
foreach ($lead_data as $key => $val) { foreach ($lead_data as $key => $val) {
if (!str_ends_with($key, '_ids')) { if (! str_ends_with($key, '_ids')) {
$total += (int) $val; $total += (int) $val;
} }
} }
$lead_data['total'] = $total; $lead_data['total'] = $total;
$lead_data['policy_with_correction'] = $policy_with_correction_data['count'] ?? 0; $lead_data['policy_with_correction'] = $policy_with_correction_data['count'] ?? 0;
$lead_data['policy_with_correction_ids'] = $policy_with_correction_data['ids'] ?? null; $lead_data['policy_with_correction_ids'] = $policy_with_correction_data['ids'] ?? null;
// dd($lead_data); // dd($lead_data);
return $lead_data; return $lead_data;
} }
} }

View File

@ -1,14 +1,13 @@
<?php <?php
namespace App\Models; namespace App\Models;
use CodeIgniter\Model; use CodeIgniter\Model;
class PolicyTypeModel extends Model class PolicyTypeModel extends Model
{ {
protected $table = 'policy_type'; protected $table = 'policy_type';
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $allowedFields = [ protected $allowedFields = [
"id", "id",
"policy_type", "policy_type",
"bap", "bap",
@ -22,6 +21,6 @@ class PolicyTypeModel extends Model
"etp", "etp",
"iep", "iep",
"itp", "itp",
"question_json",'itep','etep', 'policy_category', "question_json", 'itep', 'etep', 'policy_category', 'misc',
]; ];
} }

File diff suppressed because it is too large Load Diff