function HelpDesk_notifyOnPortalTicketComment($entityData)
{
    $adb = PearDatabase::getInstance();
    $moduleName = $entityData->getModuleName();
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $ownerIdInfo = getRecordOwnerId($entityId);
    if (!empty($ownerIdInfo['Users'])) {
        $ownerId = $ownerIdInfo['Users'];
        $ownerName = getOwnerName($ownerId);
        $to_email = getUserEmailId('id', $ownerId);
    }
    if (!empty($ownerIdInfo['Groups'])) {
        $ownerId = $ownerIdInfo['Groups'];
        $groupInfo = getGroupName($ownerId);
        $ownerName = $groupInfo[0];
        $to_email = implode(',', getDefaultAssigneeEmailIds($ownerId));
    }
    $wsParentId = $entityData->get('parent_id');
    $parentIdParts = explode('x', $wsParentId);
    $parentId = $parentIdParts[1];
    $entityDelta = new VTEntityDelta();
    $oldComments = $entityDelta->getOldValue($entityData->getModuleName(), $entityId, 'comments');
    $newComments = $entityDelta->getCurrentValue($entityData->getModuleName(), $entityId, 'comments');
    $commentDiff = str_replace($oldComments, '', $newComments);
    $latestComment = strip_tags($commentDiff);
    //send mail to the assigned to user when customer add comment
    $subject = getTranslatedString('LBL_RESPONDTO_TICKETID', $moduleName) . "##" . $entityId . "##" . getTranslatedString('LBL_CUSTOMER_PORTAL', $moduleName);
    $contents = getTranslatedString('Dear', $moduleName) . " " . $ownerName . "," . "<br><br>" . getTranslatedString('LBL_CUSTOMER_COMMENTS', $moduleName) . "<br><br>\n\t\t\t\t\t\t<b>" . $latestComment . "</b><br><br>" . getTranslatedString('LBL_RESPOND', $moduleName) . "<br><br>" . getTranslatedString('LBL_REGARDS', $moduleName) . "<br>" . getTranslatedString('LBL_SUPPORT_ADMIN', $moduleName);
    //get the contact email id who creates the ticket from portal and use this email as from email id in email
    $result = $adb->pquery("SELECT lastname, firstname, email FROM vtiger_contactdetails WHERE contactid=?", array($parentId));
    $customername = $adb->query_result($result, 0, 'firstname') . ' ' . $adb->query_result($result, 0, 'lastname');
    $customername = decode_html($customername);
    //Fix to display the original UTF-8 characters in sendername instead of ascii characters
    $from_email = $adb->query_result($result, 0, 'email');
    //send mail to assigned to user
    $adb->println("Send mail to the user who is the owner of the module about the portal ticket");
    $mail_status = send_mail('HelpDesk', $to_email, '', $from_email, $subject, $contents);
}
 function handleEvent($eventName, $entityData)
 {
     $moduleName = $entityData->getModuleName();
     // Validate the event target
     if ($moduleName != 'PurchaseOrder') {
         return;
     }
     //Get Current User Information
     global $current_user, $currentModule;
     /**
      * Adjust the balance amount against total & paid amount
      * NOTE: beforesave the total amount will not be populated in event data.
      */
     if ($eventName == 'vtiger.entity.aftersave') {
         if ($currentModule != 'PurchaseOrder') {
             return;
         }
         $entityDelta = new VTEntityDelta();
         $oldCurrency = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
         $oldConversionRate = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'conversion_rate');
         $newCurrency = $entityDelta->getCurrentValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
         $db = PearDatabase::getInstance();
         $wsid = vtws_getWebserviceEntityId('PurchaseOrder', $entityData->getId());
         $wsrecord = vtws_retrieve($wsid, $current_user);
         if ($oldCurrency != $newCurrency && $oldCurrency != '') {
             if ($oldConversionRate != '') {
                 $wsrecord['paid'] = floatval($wsrecord['paid'] / $oldConversionRate * $wsrecord['conversion_rate']);
             }
         }
         /*
                     $wsrecord['balance'] = floatval($wsrecord['hdnGrandTotal'] - $wsrecord['paid']);
                     if ($wsrecord['balance'] == 0)
                         $wsrecord['postatus'] = 'Received Shipment';
                     $query = "UPDATE vtiger_purchaseorder SET balance=?,paid=? WHERE purchaseorderid=?";
                     $db->pquery($query, array($wsrecord['balance'], $wsrecord['paid'], $entityData->getId()));
                     // TODO Make it available for other event handlers
         */
     }
 }
 function handleEvent($eventName, $entityData)
 {
     $moduleName = $entityData->getModuleName();
     // Validate the event target
     if ($moduleName != 'Invoice') {
         return;
     }
     //Get Current User Information
     global $current_user, $currentModule;
     /**
      * Adjust the balance amount against total & received amount
      * NOTE: beforesave the total amount will not be populated in event data.
      */
     if ($eventName == 'vtiger.entity.aftersave') {
         // Trigger from other module (due to indirect save) need to be ignored - to avoid inconsistency.
         if ($currentModule != 'Invoice') {
             return;
         }
         $entityDelta = new VTEntityDelta();
         $oldCurrency = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
         $newCurrency = $entityDelta->getCurrentValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
         $oldConversionRate = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'conversion_rate');
         $db = PearDatabase::getInstance();
         $wsid = vtws_getWebserviceEntityId('Invoice', $entityData->getId());
         $wsrecord = vtws_retrieve($wsid, $current_user);
         if ($oldCurrency != $newCurrency && $oldCurrency != '') {
             if ($oldConversionRate != '') {
                 $wsrecord['received'] = floatval($wsrecord['received'] / $oldConversionRate * $wsrecord['conversion_rate']);
             }
         }
         $wsrecord['balance'] = floatval($wsrecord['hdnGrandTotal'] - $wsrecord['received']);
         if ($wsrecord['balance'] == 0) {
             $wsrecord['invoicestatus'] = 'Paid';
         }
         $query = "UPDATE vtiger_invoice SET balance=?,received=? WHERE invoiceid=?";
         $db->pquery($query, array($wsrecord['balance'], $wsrecord['received'], $entityData->getId()));
     }
 }