Files
crm.clientright.ru/modules/Leads/views/SaveConvertLead.php
Fedor ac7467f0b4 Major CRM updates: AI Assistant, Court Status API, S3 integration improvements, and extensive file storage system
- Added comprehensive AI Assistant system (aiassist/ directory):
  * Vector search and embedding capabilities
  * Typebot proxy integration
  * Elastic search functionality
  * Message classification and chat history
  * MCP proxy for external integrations

- Implemented Court Status API (GetCourtStatus.php):
  * Real-time court document status checking
  * Integration with external court systems
  * Comprehensive error handling and logging

- Enhanced S3 integration:
  * Improved file backup system with metadata
  * Batch processing capabilities
  * Enhanced error logging and recovery
  * Copy operations with URL fixing

- Added Telegram contact creation API
- Improved error logging across all modules
- Enhanced callback system for AI responses
- Extensive backup file storage with timestamps
- Updated documentation and README files

- File storage improvements:
  * Thousands of backup files with proper metadata
  * Fix operations for broken file references
  * Project-specific backup and recovery systems
  * Comprehensive file integrity checking

Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
2025-10-16 11:17:21 +03:00

124 lines
5.0 KiB
PHP

<?php
/*+***********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*************************************************************************************/
vimport('~~/include/Webservices/ConvertLead.php');
class Leads_SaveConvertLead_View extends Vtiger_View_Controller {
public function requiresPermission(\Vtiger_Request $request) {
$permissions = parent::requiresPermission($request);
$permissions[] = array('module_parameter' => 'module', 'action' => 'DetailView', 'record_parameter' => 'record');
$permissions[] = array('module_parameter' => 'module', 'action' => 'ConvertLead', 'record_parameter' => 'record');
return $permissions;
}
public function process(Vtiger_Request $request) {
$recordId = $request->get('record');
$modules = $request->get('modules');
$assignId = $request->get('assigned_user_id');
$currentUser = Users_Record_Model::getCurrentUserModel();
$entityValues = array();
$entityValues['transferRelatedRecordsTo'] = $request->get('transferModule');
$entityValues['assignedTo'] = vtws_getWebserviceEntityId(vtws_getOwnerType($assignId), $assignId);
$entityValues['leadId'] = vtws_getWebserviceEntityId($request->getModule(), $recordId);
$entityValues['imageAttachmentId'] = $request->get('imageAttachmentId');
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $request->getModule());
$convertLeadFields = $recordModel->getConvertLeadFields();
$availableModules = array('Accounts', 'Contacts', 'Potentials');
foreach ($availableModules as $module) {
if(vtlib_isModuleActive($module)&& in_array($module, $modules)) {
$entityValues['entities'][$module]['create'] = true;
$entityValues['entities'][$module]['name'] = $module;
// Converting lead should save records source as CRM instead of WEBSERVICE
$entityValues['entities'][$module]['source'] = 'CRM';
foreach ($convertLeadFields[$module] as $fieldModel) {
$fieldName = $fieldModel->getName();
$fieldValue = $request->get($fieldName);
//Potential Amount Field value converting into DB format
if ($fieldModel->getFieldDataType() === 'currency') {
if($fieldModel->get('uitype') == 72){
// Some of the currency fields like Unit Price, Totoal , Sub-total - doesn't need currency conversion during save
$fieldValue = Vtiger_Currency_UIType::convertToDBFormat($fieldValue, null, true);
} else {
$fieldValue = Vtiger_Currency_UIType::convertToDBFormat($fieldValue);
}
} elseif ($fieldModel->getFieldDataType() === 'date') {
$fieldValue = DateTimeField::convertToDBFormat($fieldValue);
} elseif ($fieldModel->getFieldDataType() === 'reference' && $fieldValue) {
if($fieldModel->get('uitype') == 77){
$fieldValue = vtws_getWebserviceEntityId(vtws_getOwnerType($fieldValue), $fieldValue);
} else {
$ids = vtws_getIdComponents($fieldValue);
if (count($ids) === 1) {
$fieldValue = vtws_getWebserviceEntityId(getSalesEntityType($fieldValue), $fieldValue);
}
}
}
$entityValues['entities'][$module][$fieldName] = $fieldValue;
}
}
}
try {
$result = vtws_convertlead($entityValues, $currentUser);
} catch(Exception $e) {
$this->showError($request, $e);
exit;
}
if(!empty($result['Accounts'])) {
$accountIdComponents = vtws_getIdComponents($result['Accounts']);
$accountId = $accountIdComponents[1];
}
if(!empty($result['Contacts'])) {
$contactIdComponents = vtws_getIdComponents($result['Contacts']);
$contactId = $contactIdComponents[1];
}
if(!empty($accountId)) {
header("Location: index.php?view=Detail&module=Accounts&record=$accountId");
} elseif (!empty($contactId)) {
header("Location: index.php?view=Detail&module=Contacts&record=$contactId");
} else {
$this->showError($request);
exit;
}
}
function showError($request, $exception=false) {
$viewer = $this->getViewer($request);
$moduleName = $request->getModule();
$isDupicatesFailure = false;
if ($exception != false) {
$viewer->assign('EXCEPTION', $exception->getMessage());
if ($exception instanceof DuplicateException) {
$isDupicatesFailure = true;
$viewer->assign('EXCEPTION', $exception->getDuplicationMessage());
}
}
$currentUser = Users_Record_Model::getCurrentUserModel();
$viewer->assign('IS_DUPICATES_FAILURE', $isDupicatesFailure);
$viewer->assign('CURRENT_USER', $currentUser);
$viewer->assign('MODULE', $moduleName);
$viewer->view('ConvertLeadError.tpl', $moduleName);
}
public function validateRequest(Vtiger_Request $request) {
$request->validateWriteAccess();
}
}