<?php

/*
  workflows invoke custom function example method function file (myexample.inc)

  put this file in the modules/workflow/ directory. if the directory does
   not exist, then just create it.
  
  see the myexample_register.php file for more information.
*/

function function_sendmail_cambiocotizacionportercero( $entity ) {
    require_once 'modules/Emails/mail.php';
    global $adb;
    global $site_URL;

    $data = $entity->data;

    $parent_id_ = explode("x", $data['parent_id'])[1];
    $id_ = explode("x", $data['id'])[1];
    $ticket_no = $data['ticket_no'];
    $ticket_title = $data['ticket_title'];
    $cotizacionporterceros = $data['cf_945'];
    if ( $cotizacionporterceros == "Precios de lista Enviados para Cotizacion" ){

    $query = $adb->pquery("SELECT vtiger_users.email1, accountname FROM	vtiger_account INNER JOIN vtiger_crmentity ON vtiger_account.accountid = vtiger_crmentity.crmid INNER JOIN vtiger_users ON vtiger_crmentity.smownerid = vtiger_users.id WHERE crmid = ".$parent_id_, array());
    $email1 = $adb->query_result($query, 0, 'email1');
    $accountname = $adb->query_result($query, 0, 'accountname');

    #Copiar a recepcion
    $query_cc = $adb->pquery("SELECT email1 FROM vtiger_user2role INNER JOIN vtiger_users ON vtiger_user2role.userid=vtiger_users.id where roleid = 'H16'");
    $email_cc = $adb->query_result($query_cc, 0, 'email1');


    $url = $site_URL . "index.php?module=HelpDesk&view=Detail&record=$id_";
$mensaje1 = <<<EOT
<!DOCTYPE html>
<html>
<head>
  <title>Notificacion VTIGER </title>
</head>
<body>
<p>
<h2>Se Enviaron Precios de Lista para Cotizacion desde una incidencia de la cuenta: $accountname</h2>
<h3>Ticket Nro $ticket_no : $ticket_title</h3> 
Ver: <a href='$url'> $ticket_no - $ticket_title</a>
</body>
</html>
EOT;

    //echo $email1.'</br>';
    //echo $email_cc.'</br>';
    //echo $mensaje1;
$bcc ='jjpena@creantis.com';
    send_mail('HelpDesk', $email1, 'CRM Fursys', 'vtiger-admin@fursys.com.pe',"CRM Fursys",$mensaje1, $email_cc, $bcc, $atc="",$eid="",$logo='',$ug='');
    }
}