function isAssignToChanged($moduleName, $recordId, $user)
 {
     $wsModuleName = $this->getWsModuleName($moduleName);
     $handler = vtws_getModuleHandlerFromName($wsModuleName, $user);
     $meta = $handler->getMeta();
     $moduleOwnerFields = $meta->getOwnerFields();
     $assignToChanged = false;
     $vtEntityDelta = new VTEntityDelta();
     foreach ($moduleOwnerFields as $ownerField) {
         $assignToChanged = $vtEntityDelta->hasChanged($moduleName, $recordId, $ownerField);
         if ($assignToChanged) {
             break;
         }
     }
     return $assignToChanged;
 }
function HelpDesk_notifyOwnerOnTicketChange($entityData)
{
    global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID;
    $moduleName = $entityData->getModuleName();
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $isNew = $entityData->isNew();
    if (!$isNew) {
        $reply = 'Re : ';
    } else {
        $reply = '';
    }
    // SalesPlatform.ru begin
    $subject = ' [ ' . getTranslatedString('Ticket No', $moduleName) . ' ' . $entityData->get('ticket_no') . ' ] ' . $reply . $entityData->get('ticket_title');
    //$subject = $entityData->get('ticket_no') . ' [ '.getTranslatedString('LBL_TICKET_ID', $moduleName)
    //					.' : '.$entityId.' ] '.$reply.$entityData->get('ticket_title');
    // SalesPlatform.ru end
    $email_body = HelpDesk::getTicketEmailContents($entityData, true);
    if (PerformancePrefs::getBoolean('NOTIFY_OWNER_EMAILS', true) === true) {
        //send mail to the assigned to user and the parent to whom this ticket is assigned
        require_once 'modules/Emails/mail.php';
        $wsAssignedUserId = $entityData->get('assigned_user_id');
        $userIdParts = explode('x', $wsAssignedUserId);
        $ownerId = $userIdParts[1];
        $ownerType = vtws_getOwnerType($ownerId);
        if ($ownerType == 'Users') {
            $to_email = getUserEmailId('id', $ownerId);
        }
        if ($ownerType == 'Groups') {
            $to_email = implode(',', getDefaultAssigneeEmailIds($ownerId));
        }
        if ($to_email != '') {
            if ($isNew) {
                $mail_status = send_mail('HelpDesk', $to_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
            } else {
                $entityDelta = new VTEntityDelta();
                $statusHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'ticketstatus');
                $solutionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'solution');
                $ownerHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'assigned_user_id');
                $descriptionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'description');
                if ($statusHasChanged && $entityData->get('ticketstatus') == "Closed" || $solutionHasChanged || $ownerHasChanged || $descriptionHasChanged) {
                    $mail_status = send_mail('HelpDesk', $to_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
                }
            }
            $mail_status_str = $to_email . "=" . $mail_status . "&&&";
        } else {
            $mail_status_str = "'" . $to_email . "'=0&&&";
        }
        if ($mail_status != '') {
            $mail_error_status = getMailErrorString($mail_status_str);
        }
    }
}
function updateInventoryProductRel($entity)
{
    global $log, $adb, $updateInventoryProductRel_update_product_array, $updateInventoryProductRel_deduct_stock;
    $entity_id = vtws_getIdComponents($entity->getId());
    $entity_id = $entity_id[1];
    $update_product_array = $updateInventoryProductRel_update_product_array;
    $log->debug("Entering into function updateInventoryProductRel(" . $entity_id . ").");
    if (!empty($update_product_array)) {
        foreach ($update_product_array as $id => $seq) {
            foreach ($seq as $seq => $product_info) {
                foreach ($product_info as $key => $index) {
                    $updqtyinstk = getPrdQtyInStck($key);
                    $upd_qty = $updqtyinstk + $index;
                    updateProductQty($key, $upd_qty);
                }
            }
        }
    }
    $moduleName = $entity->getModuleName();
    if ($moduleName === 'Invoice') {
        $statusFieldName = 'invoicestatus';
        $statusFieldValue = 'Cancel';
    } elseif ($moduleName === 'PurchaseOrder') {
        $statusFieldName = 'postatus';
        $statusFieldValue = 'Received Shipment';
    }
    $statusChanged = false;
    $vtEntityDelta = new VTEntityDelta();
    $oldEntity = $vtEntityDelta->getOldValue($moduleName, $entity_id, $statusFieldName);
    $recordDetails = $entity->getData();
    $statusChanged = $vtEntityDelta->hasChanged($moduleName, $entity_id, $statusFieldName);
    if ($statusChanged) {
        if ($recordDetails[$statusFieldName] == $statusFieldValue) {
            $adb->pquery("UPDATE vtiger_inventoryproductrel SET incrementondel=0 WHERE id=?", array($entity_id));
            $updateInventoryProductRel_deduct_stock = false;
            if (empty($update_product_array)) {
                addProductsToStock($entity_id);
            }
        } elseif ($oldEntity == $statusFieldValue) {
            $updateInventoryProductRel_deduct_stock = false;
            deductProductsFromStock($entity_id);
        }
    } elseif ($recordDetails[$statusFieldName] == $statusFieldValue) {
        $updateInventoryProductRel_deduct_stock = false;
    }
    if ($updateInventoryProductRel_deduct_stock) {
        $adb->pquery("UPDATE vtiger_inventoryproductrel SET incrementondel=1 WHERE id=?", array($entity_id));
        $product_info = $adb->pquery("SELECT productid,sequence_no, quantity from vtiger_inventoryproductrel WHERE id=?", array($entity_id));
        $numrows = $adb->num_rows($product_info);
        for ($index = 0; $index < $numrows; $index++) {
            $productid = $adb->query_result($product_info, $index, 'productid');
            $qty = $adb->query_result($product_info, $index, 'quantity');
            $sequence_no = $adb->query_result($product_info, $index, 'sequence_no');
            $qtyinstk = getPrdQtyInStck($productid);
            $upd_qty = $qtyinstk - $qty;
            updateProductQty($productid, $upd_qty);
            $sub_prod_query = $adb->pquery("SELECT productid from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($entity_id, $sequence_no));
            if ($adb->num_rows($sub_prod_query) > 0) {
                for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                    $sub_prod_id = $adb->query_result($sub_prod_query, $j, "productid");
                    $sqtyinstk = getPrdQtyInStck($sub_prod_id);
                    $supd_qty = $sqtyinstk - $qty;
                    updateProductQty($sub_prod_id, $supd_qty);
                }
            }
        }
    }
    $log->debug("Exit from function updateInventoryProductRel(" . $entity_id . ")");
}
Example #4
0
function Contacts_sendCustomerPortalLoginDetails($entityData)
{
    $adb = PearDatabase::getInstance();
    $moduleName = $entityData->getModuleName();
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $entityDelta = new VTEntityDelta();
    $portalChanged = $entityDelta->hasChanged($moduleName, $entityId, 'portal');
    $email = $entityData->get('email');
    if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
        $sql = "SELECT id, user_name, user_password, isactive FROM vtiger_portalinfo WHERE id=?";
        $result = $adb->pquery($sql, array($entityId));
        $insert = false;
        if ($adb->num_rows($result) == 0) {
            $insert = true;
        } else {
            $dbusername = $adb->query_result($result, 0, 'user_name');
            $isactive = $adb->query_result($result, 0, 'isactive');
            if ($email == $dbusername && $isactive == 1 && !$entityData->isNew()) {
                $update = false;
            } else {
                if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
                    $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?";
                    $adb->pquery($sql, array($email, 1, $entityId));
                    $update = true;
                } else {
                    $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?";
                    $adb->pquery($sql, array($email, 0, $entityId));
                    $update = false;
                }
            }
        }
        $password = makeRandomPassword();
        $md5_password = md5($password);
        if ($insert == true) {
            $sql = "INSERT INTO vtiger_portalinfo(id,user_name,user_password,type,isactive) VALUES(?,?,?,?,?)";
            $params = array($entityId, $email, $md5_password, 'C', 1);
            $adb->pquery($sql, $params);
        }
        if ($update == true && $portalChanged == true) {
            $sql = "UPDATE vtiger_portalinfo SET user_password=? WHERE id=?";
            $params = array($md5_password, $entityId);
            $adb->pquery($sql, $params);
        }
        if (($insert == true || ($update = true && $portalChanged == true)) && $entityData->get('emailoptout') == 0) {
            global $current_user, $HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME;
            require_once "modules/Emails/mail.php";
            $emailData = Contacts::getPortalEmailContents($entityData, $password, 'LoginDetails');
            $subject = $emailData['subject'];
            if (empty($subject)) {
                $subject = 'Customer Portal Login Details';
            }
            $contents = $emailData['body'];
            $contents = decode_html(getMergedDescription($contents, $entityId, 'Contacts'));
            if (empty($contents)) {
                require_once 'config.inc.php';
                global $PORTAL_URL;
                $contents = 'LoginDetails';
                $contents .= "<br><br> User ID : " . $entityData->get('email');
                $contents .= "<br> Password: "******"' . $PORTAL_URL . '" style="font-family:Arial, Helvetica, sans-serif;font-size:13px;">' . vtranslate('click here', $moduleName) . '</a>';
                $contents .= "<br>" . $portalURL;
            }
            $subject = decode_html(getMergedDescription($subject, $entityId, 'Contacts'));
            send_mail('Contacts', $entityData->get('email'), $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $contents, '', '', '', '', '', true);
        }
    } else {
        $sql = "UPDATE vtiger_portalinfo SET user_name=?,isactive=0 WHERE id=?";
        $adb->pquery($sql, array($email, $entityId));
    }
}