<?php
function Accounts_crearContacto($entity) {
	global $adb, $current_user;
	$data = $entity->data;
	$id = explode("x", $data['id'])[1];
	$assigned_user_id = explode("x", $data['assigned_user_id'])[1];
	$source = $data['source'];
	if ( $source == "CRM" ) {
		$source = "AUTOCREADO";
	}
	
	//var_dump($id);die();
	//$idEquipo = explode("x",$data['asset_no'])[1];
	$query = $adb-> pquery("SELECT cf_908, cf_910 FROM vtiger_accountscf WHERE accountid = ? ",array($id));

	$NombreContacto = $adb->query_result($query,0,'cf_908');
	$ApellidoContacto  = $adb->query_result($query,0,'cf_910');
	$Movil  = 'POR COMPLETAR';
	$Correo  = 'POR COMPLETAR';
	
	$model = Vtiger_Record_Model::getCleanInstance('Contacts');
	$model->set('mode', '');
	$model->set('firstname', $NombreContacto);
	$model->set('lastname', $ApellidoContacto);
	$model->set('mobile', $Movil );
	$model->set('email', $Correo );
	$model->set('assigned_user_id', $assigned_user_id);
	$model->set('account_id', $id);
	$model->set('source', $source);
	
	try {
		$model->save();
	} catch (Exception $e) {}
		
}