Example #1
0
File: Save.php Project: hardikk/HNH
    $focus->mode = $_REQUEST['mode'];
}
//$focus->retrieve($_REQUEST['record']);
foreach ($focus->column_fields as $fieldname => $val) {
    if (isset($_REQUEST[$fieldname])) {
        if (is_array($_REQUEST[$fieldname])) {
            $value = $_REQUEST[$fieldname];
        } else {
            $value = trim($_REQUEST[$fieldname]);
        }
        $log->info("the value is " . $value);
        $focus->column_fields[$fieldname] = $value;
    }
}
if (isset($_REQUEST['annualrevenue'])) {
    $value = convertToDollar($_REQUEST['annualrevenue'], $rate);
    $focus->column_fields['annualrevenue'] = $value;
}
if ($_REQUEST['assigntype'] == 'U') {
    $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id'];
} elseif ($_REQUEST['assigntype'] == 'T') {
    $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id'];
}
$focus->save("Leads");
$return_id = $focus->id;
$log->info("the return id is " . $return_id);
$parenttab = getParentTab();
if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") {
    $return_module = vtlib_purify($_REQUEST['return_module']);
} else {
    $return_module = "Leads";
Example #2
0
            if ($sublevel == LENDER_GROUP_LEVEL) {
                $lusername = $lname;
            }
            $data = $database->getLenderDetails($leid);
            $hide_karma = $data['hide_karma'];
            //=0 means show karma score
            if ($hide_karma != 1) {
                $karma_score = "(" . number_format($database->getKarmaScore($leid)) . ")";
                $karma_tooltip = $lang['profile']['karma_tooltip'];
            } else {
                $karma_score = "";
            }
            $kamount = $rows['bidamount'];
            $bidint = $rows['bidint'];
            $lendprurl = getUserProfileUrl($leid);
            $lamt = convertToDollar($brw2['AmountGot'], $CurrencyRate);
            $percentFinanced = $bidamount * 100 / $lamt;
            echo "<tr>";
            echo "<td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<a href='{$lendprurl}'>{$lusername}</a> <br/><a style='cursor:pointer' class='tt'>{$karma_score}<span class='tooltip'><span class='top'></span><span class='middle'>{$karma_tooltip}</span><span class='bottom'></span></span></a>\n\t\t\t\t\t\t\t\t\t\t\t\t</td>";
            echo "<td>" . number_format($bidamount, 2, ".", ",") . "</td>";
            echo "<td>" . number_format($bidint, 2, ".", ",") . " %</td>";
            echo "</tr>";
        }
        ?>
								</tbody>
							</table>
						</div>
					
				<?php 
    }
}
Example #3
0
File: Save.php Project: hardikk/HNH
    $focus->column_fields['expectedrevenue'] = $value;
}
if (isset($_REQUEST['budgetcost'])) {
    $value = convertToDollar($_REQUEST['budgetcost'], $rate);
    $focus->column_fields['budgetcost'] = $value;
}
if (isset($_REQUEST['actualcost'])) {
    $value = convertToDollar($_REQUEST['actualcost'], $rate);
    $focus->column_fields['actualcost'] = $value;
}
if (isset($_REQUEST['actualroi'])) {
    $value = convertToDollar($_REQUEST['actualroi'], $rate);
    $focus->column_fields['actualroi'] = $value;
}
if (isset($_REQUEST['expectedroi'])) {
    $value = convertToDollar($_REQUEST['expectedroi'], $rate);
    $focus->column_fields['expectedroi'] = $value;
}
if ($_REQUEST['assigntype'] == 'U') {
    $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id'];
} elseif ($_REQUEST['assigntype'] == 'T') {
    $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id'];
}
$focus->save("Campaigns");
$return_id = $focus->id;
$parenttab = getParentTab();
if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") {
    $return_module = vtlib_purify($_REQUEST['return_module']);
} else {
    $return_module = "Campaigns";
}
Example #4
0
     $params['commentscredit'] = $tmpcurr . ' ' . number_format($commentcreditdetail['loanamt_limit'], 0, ".", ",");
     $params['commentcharlimit'] = $commentcreditdetail['character_limit'];
     $params['commentposted'] = $creditCurrent['commentposted'];
     $params['MinRepayRate'] = $database->getAdminSetting('MinRepayRate');
     $params['brwr_RepayRate'] = number_format($brwr_repayrate);
     $params['newmembercrdt_link'] = 'index.php?p=97';
     $params['invite_credit'] = $tmpcurr . ' ' . number_format($invitecredit);
     $params['vm_credit'] = $tmpcurr . ' ' . number_format($vmcredit);
 }
 $firstloan = $database->getBorrowerFirstLoan($userid);
 $disbdate = $database->getLoanDisburseDate($currentloan);
 $currenttime = time();
 $months = $database->IntervalMonths($disbdate, $currenttime);
 $loanData = $database->getLoanApplic($currentloan);
 $currentloanamt = $loanData['AmountGot'];
 $currentloanamt_usd = convertToDollar($currentloanamt, $rate);
 if ($currentloanamt_usd <= 200) {
     $timethrshld = $database->getAdminSetting('TimeThrshld');
 } elseif ($currentloanamt_usd <= 1000) {
     $timethrshld = $database->getAdminSetting('TimeThrshldMid1');
 } elseif ($currentloanamt_usd <= 3000) {
     $timethrshld = $database->getAdminSetting('TimeThrshldMid2');
 } elseif ($currentloanamt_usd > 3000) {
     $timethrshld = $database->getAdminSetting('TimeThrshld_above');
 }
 $params['TimeThrshld'] = $timethrshld;
 if (empty($firstloan) || $firstloan == 0) {
     $note = $session->formMessage($lang['current_credit']['first_loan'], $params);
 } elseif (empty($currentloan) && $islastrepaid) {
     $ontime = $database->isRepaidOntime($userid, $islastrepaid);
     if ($ontime != 1) {
Example #5
0
                                }
                                $divid = "replybox" . $i;
                                if ($commns['feedback'] == 3) {
                                    $feedbackText = "Neutral";
                                }
                                if ($commns['feedback'] == 4) {
                                    $feedbackText = "Negative";
                                } else {
                                    $feedbackText = "Positive";
                                }
                                /* Changes for zidisha loan feedback by chetan  */
                                if ($commns['loneid']) {
                                    $lendername = "Zidisha Loan";
                                    $loanDetail = $database->getLoanDetails($commns['loneid']);
                                    $amt = $loanDetail['AmountGot'];
                                    $amt_us = convertToDollar($amt, $rate);
                                    $date_disb = $loanDetail['AcceptDate'];
                                    if ($commns['ontime'] == 0) {
                                        $ontime = 'No';
                                    } else {
                                        $ontime = 'Yes';
                                    }
                                    $fully_repd = 'Yes';
                                    $name = $database->getUserNameById($sendid);
                                }
                                ?>
			<script type="text/javascript">
			$(document).ready(function() {		
				$('#partner_comment_desc<?php 
                                echo $i;
                                ?>
Example #6
0
 function loanReport($brid)
 {
     global $db;
     $time = time();
     if (!empty($brid)) {
         $report = array('feedback' => '', 'Totalfeedback' => '');
         $result1 = $this->getPartnerComment($brid);
         $activation_comment = false;
         //$this->getActivationComment($brid);
         $lamount = 0;
         $countt = 0;
         $CPaid = 0;
         /*count for no of loan paid, given by partner   */
         $f = 0;
         $CPaidLate = 0;
         $PaidLate = 0;
         $PaidLate_us = 0;
         $CPaidOntime = 0;
         $PaidOntime = 0;
         $PaidOntime_us = 0;
         $defltdAmt = 0;
         $defltdAmt_us = 0;
         $rate = $this->getCurrentRate($brid);
         if ($result1) {
             $ldate = null;
             foreach ($result1 as $profile1) {
                 if ($profile1['loneid'] == 0) {
                     $ldate = $this->getborrowerActivatedDate($brid);
                     $lamount += $profile1['amount'];
                     $lpaid = $profile1['lpaid'];
                     if ($lpaid == 1) {
                         $CPaid += 1;
                     }
                     $ontime = $profile1['ontime'];
                     if ($profile1['rate'] != null && $profile1['rate'] != "" && $profile1['rate'] != 0) {
                         $rate = $profile1['rate'];
                     }
                     if ($ontime == 1) {
                         $CPaidOntime += 1;
                         $PaidOntime = $PaidOntime + $profile1['amount'];
                         $PaidOntime_us = $PaidOntime_us + convertToDollar($profile1['amount'], $rate);
                     } else {
                         $CPaidLate += 1;
                         $PaidLate = $PaidLate + $profile1['amount'];
                         $PaidLate_us = $PaidLate_us + convertToDollar($profile1['amount'], $rate);
                     }
                     $countt++;
                 }
                 $Pfeedback = $profile1['feedback'];
                 if ($Pfeedback == 2) {
                     $f += 1;
                 }
             }
             $count = count($result1);
             if (false && !$activation_comment) {
                 $f = $f - 1;
                 $count = count($result1) - 1;
                 if ($f == 0) {
                     $report['feedback'] = '';
                 } else {
                     $f = $f * 100 / $count;
                     $report['feedback'] = $f;
                 }
             } else {
                 $f = $f * 100 / $count;
                 $report['feedback'] = $f;
             }
             $partid = $profile1['partid'];
             $report['sincedate'] = $ldate;
             $report['Totalfeedback'] = count($result1);
         }
         $sql = "SELECT Amount, AcceptDate FROM ! WHERE active=?  AND borrowerid = ? AND adminDelete = ?";
         $data = $db->getAll($sql, array('loanapplic', LOAN_DEFAULTED, $brid, 0));
         if (count($data)) {
             for ($i = 0; $i < count($data); $i++) {
                 $defltdAmt += $data[$i]['Amount'];
                 $rate = $this->getExRateById($data[$i]['AcceptDate'], $brid);
                 $defltdAmt_us += convertToDollar($data[$i]['Amount'], $rate);
             }
             $report['Deflted'] = $i;
             $report['AmtDeflted'] = $defltdAmt;
             $report['AmtDeflted_us'] = $defltdAmt_us;
         }
         $sql = "SELECT loanid, AmountGot, period, ActiveDate, RepaidDate,AcceptDate FROM ! WHERE (active =? OR active =?) AND borrowerid = ? AND adminDelete = ?";
         $data = $db->getAll($sql, array('loanapplic', LOAN_REPAID, LOAN_ACTIVE, $brid, 0));
         foreach ($data as $row) {
             $period = $row['period'];
             $loanDate = $this->getMaxLoanDate($brid, $row['loanid']);
             $loneFundDate = $row['ActiveDate'];
             $expectedPayDate = $loanDate['duedateMax'];
             $lonePayDate = $loanDate['paiddateMax'];
             $rate = $this->getExRateById($row['AcceptDate'], $brid);
             if (empty($lonePayDate) && $expectedPayDate < $time) {
                 //late
                 $PaidLate += $row['AmountGot'];
                 $PaidLate_us += convertToDollar($row['AmountGot'], $rate);
                 $CPaidLate += 1;
             } else {
                 if (!empty($lonePayDate) && $expectedPayDate < $lonePayDate) {
                     //late
                     $PaidLate += $row['AmountGot'];
                     $PaidLate_us += convertToDollar($row['AmountGot'], $rate);
                     $CPaidLate += 1;
                 } else {
                     if (!empty($lonePayDate) && $expectedPayDate >= $lonePayDate) {
                         //ontime
                         $PaidOntime += $row['AmountGot'];
                         $PaidOntime_us += convertToDollar($row['AmountGot'], $rate);
                         $CPaidOntime += 1;
                     }
                 }
             }
             $countt++;
         }
         $Deflted = isset($report['Deflted']) ? $report['Deflted'] : 0;
         $report['NoOfLone'] = $countt + $Deflted;
         $AmtDeflted = isset($report['AmtDeflted']) ? $report['AmtDeflted'] : 0;
         $report['Total'] = $PaidLate + $PaidOntime + $AmtDeflted;
         $AmtDeflted_us = isset($report['AmtDeflted_us']) ? $report['AmtDeflted_us'] : 0;
         $report['Total_us'] = $PaidLate_us + $PaidOntime_us + $AmtDeflted_us;
         $report['late'] = $CPaidLate;
         $report['Amtlate'] = $PaidLate;
         $report['Amtlate_us'] = $PaidLate_us;
         $report['PaidonTime'] = $CPaidOntime;
         $report['AmtPaidonTime'] = $PaidOntime;
         $report['AmtPaidonTime_us'] = $PaidOntime_us;
         return $report;
     } else {
         echo "error";
     }
 }
Example #7
0
/**	Function used to retrieve the rate converted into dollar tobe saved into database
 *	The function accepts the price in the current currency
 *	return integer $conv_price  - 
 */
function getConvertedPrice($price)
{
    global $current_user;
    $currencyid = fetchCurrency($current_user->id);
    $rate_symbol = getCurrencySymbolandCRate($currencyid);
    $conv_price = convertToDollar($price, $rate_symbol['rate']);
    return $conv_price;
}
 /**
  * Returns the Currency value without formatting for DB Operations
  * @global Users $current_user
  * @param Users $user
  * @param Boolean $skipConversion
  * @return Number
  */
 public function getDBInsertedValue($user = null, $skipConversion = false)
 {
     global $current_user;
     if (empty($user)) {
         $user = $current_user;
     }
     $this->initialize($user);
     $value = $this->value;
     $currencySeparator = $this->currencySeparator;
     $decimalSeparator = $this->decimalSeparator;
     if (empty($currencySeparator)) {
         $currencySeparator = ' ';
     }
     if (empty($decimalSeparator)) {
         $decimalSeparator = ' ';
     }
     $value = str_replace("{$currencySeparator}", "", $value);
     $value = str_replace("{$decimalSeparator}", ".", $value);
     if ($skipConversion == false) {
         $value = convertToDollar($value, $this->conversionRate);
     }
     $value = round($value, $this->numberOfDecimal);
     return $value;
 }
Example #9
0
 function save_module($module)
 {
     global $current_user, $log, $adb;
     $cypid = $this->id;
     $data = $this->column_fields;
     // Entity has been saved, take next action
     $currencyid = fetchCurrency($current_user->id);
     $rate_symbol = getCurrencySymbolandCRate($currencyid);
     $rate = $rate_symbol['rate'];
     $value = 0;
     if (isset($data['amount']) and isset($data['cost'])) {
         $value = convertToDollar($data['amount'] - $data['cost'], $rate);
     }
     $adb->query("update vtiger_cobropago set benefit='{$value}' where cobropagoid=" . $cypid);
     $relatedId = $this->column_fields['related_id'];
     if (!empty($relatedId) and self::invoice_control_installed()) {
         Invoice::updateAmountDue($relatedId);
     }
     // Calculate related module balance
     $this->calculateRelatedTotals($this->column_fields['parent_id']);
 }
Example #10
0
 function getCurrentCreditLimit($userid, $addCreditearned)
 {
     global $database;
     $firstloan = $database->getBorrowerFirstLoan($userid);
     $loanstatus = $database->getLoanStatus($userid);
     $rate = $database->getCurrentRate($userid);
     $invitecredit = $database->getInviteCredit($userid);
     if ($loanstatus == LOAN_ACTIVE || $loanstatus == LOAN_FUNDED || $loanstatus == LOAN_OPEN) {
         //case where borrower has an active loan or fundraising application - we calculate credit limit based on current loan amount
         $loanid = $database->getCurrentLoanid($userid);
         $ontime = 1;
         //assume current loan will be repaid on time for purpose of displaying future credit limits
     } else {
         //case where borrower has repaid one or more loans and has not yet posted an application for a new one - we calculate credit limit based on most recently repaid loan amount
         $loanid = $database->getLastRepaidloanId($userid);
         $ontime = $database->isRepaidOntime($userid, $loanid);
     }
     $loanData = $database->getLoanApplic($loanid);
     $currentloanamt = $loanData['AmountGot'];
     if ($firstloan == 0) {
         //case where borrower has not yet received first loan disbursement - credit limit should equal admin 1st loan size plus invited borrower credit if applicable
         $val = $database->getAdminSetting('firstLoanValue');
         $invitedstatus = $database->getInvitee($userid);
         $text_length = $database->getTextResponseLength($userid);
         if (!empty($invitedstatus)) {
             $bonuscredit = 100;
             //adds bonus for new members who were invited by eligible existing members
         } elseif (!empty($text_length)) {
             if ($text_length >= 40 && $text_length <= 60) {
                 $bonuscredit = 100;
                 //adds bonus of for new members who entered optimal length of text response to 'How did you hear about Zidisha' optional question in application
             } else {
                 $bonuscredit = 0;
             }
         }
         $totalval = $val + $bonuscredit;
         $currentlimit = ceil(convertToNative($totalval, $rate));
         return $currentlimit;
     } elseif ($ontime != 1) {
         //case where last loan was repaid late - credit limit should equal last loan repaid on time or admin first loan setting, if no loan was ever repaid on time
         $prevamount = $database->getPreviousLoanAmount($userid, $loanid);
         if (!empty($prevamount) && $prevamount > 10) {
             $currentlimit = $prevamount;
         } else {
             $val = $database->getAdminSetting('firstLoanValue');
             $val_local = convertToNative($val, $rate);
             if ($addCreditearned == false) {
                 $currentlimit = $val_local;
             } else {
                 $currentlimit = ceil($val_local + $invitecredit);
             }
         }
         return $currentlimit;
     } else {
         //case where last loan was repaid on time, we next check whether monthly installment repayment rate meets threshold
         $repayrate = $this->RepaymentRate($userid);
         $minrepayrate = $database->getAdminSetting('MinRepayRate');
         if ($repayrate < $minrepayrate) {
             //case where last loan repaid on time but monthly installment repayment rate is below admin threshold - loan size stays same
             if ($addCreditearned == false) {
                 $currentlimit = ceil($currentloanamt);
             } else {
                 $currentlimit = ceil($currentloanamt + $invitecredit);
             }
         } else {
             //case where last loan repaid on time and overall repayment is above admin threshold - we next check whether the last loan was held long enough to qualify for credit limit increase, with the amount of time loans need to be held and size of increase both dependent on previous loan amount
             $disbdate = $database->getLoanDisburseDate($loanid);
             $currenttime = time();
             $months = $database->IntervalMonths($disbdate, $currenttime);
             $currentloanamt_usd = convertToDollar($currentloanamt, $rate);
             if ($currentloanamt_usd <= 200) {
                 $timethrshld = $database->getAdminSetting('TimeThrshld');
                 $percentincrease = $database->getAdminSetting('secondLoanPercentage');
             } elseif ($currentloanamt_usd <= 1000) {
                 $timethrshld = $database->getAdminSetting('TimeThrshldMid1');
                 $percentincrease = $database->getAdminSetting('nextLoanPercentage');
             } elseif ($currentloanamt_usd <= 3000) {
                 $timethrshld = $database->getAdminSetting('TimeThrshldMid2');
                 $percentincrease = $database->getAdminSetting('nextLoanPercentage');
             } elseif ($currentloanamt_usd > 3000) {
                 $timethrshld = $this->getAdminSetting('TimeThrshld_above');
                 $percentincrease = $database->getAdminSetting('nextLoanPercentage');
             }
             if ($months < $timethrshld) {
                 //if the loan has not been held long enough then borrower does not yet qualify for credit limit increase
                 if (!$addCreditearned) {
                     $currentlimit = ceil($currentloanamt);
                 } else {
                     $currentlimit = ceil($currentloanamt + $invitecredit);
                 }
             } else {
                 //case where last loan was repaid on time, overall repayment rate is above threshold and loan held for long enough to qualify for credit limit increase
                 $lastinst_amt = $database->getLastInstallmentAmt($userid, $loanid);
                 if ($lastinst_amt > $currentloanamt * 0.1 && convertToDollar($lastinst_amt, $rate) > 100) {
                     //case where more than 30% and $100 of last loan was paid in the last installment
                     if (!$addCreditearned) {
                         $currentlimit = ceil($currentloanamt);
                     } else {
                         $currentlimit = ceil($currentloanamt + $invitecredit);
                     }
                 } else {
                     if ($addCreditearned == false) {
                         $currentlimit = ceil($currentloanamt * $percentincrease / 100);
                         if ($loanstatus == LOAN_OPEN) {
                             $currentlimit = $currentloanamt;
                             // added by mohit to fix credit limit on edit loan page
                         }
                     } else {
                         $currentlimit = ceil($currentloanamt * $percentincrease / 100) + $invitecredit;
                     }
                 }
             }
         }
     }
     return $currentlimit;
 }
 /** Function to insert values in the specifed table for the specified module
  * @param $table_name -- table name:: Type varchar
  * @param $module -- module:: Type varchar
  */
 function insertIntoEntityTable($table_name, $module, $fileid = '')
 {
     global $log;
     global $current_user, $app_strings;
     $log->info("function insertIntoEntityTable " . $module . ' vtiger_table name ' . $table_name);
     global $adb;
     $insertion_mode = $this->mode;
     //Checkin whether an entry is already is present in the vtiger_table to update
     if ($insertion_mode == 'edit') {
         $tablekey = $this->tab_name_index[$table_name];
         // Make selection on the primary key of the module table to check.
         $check_query = "select {$tablekey} from {$table_name} where {$tablekey}=?";
         $check_result = $adb->pquery($check_query, array($this->id));
         $num_rows = $adb->num_rows($check_result);
         if ($num_rows <= 0) {
             $insertion_mode = '';
         }
     }
     $tabid = getTabid($module);
     if ($module == 'Calendar' && $this->column_fields["activitytype"] != null && $this->column_fields["activitytype"] != 'Task') {
         $tabid = getTabid('Events');
     }
     if ($insertion_mode == 'edit') {
         $update = array();
         $update_params = array();
         require 'user_privileges/user_privileges_' . $current_user->id . '.php';
         if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) {
             $sql = "select * from vtiger_field where tabid in (" . generateQuestionMarks($tabid) . ") and tablename=? and displaytype in (1,3) and presence in (0,2) group by columnname";
             $params = array($tabid, $table_name);
         } else {
             $profileList = getCurrentUserProfileList();
             if (count($profileList) > 0) {
                 $sql = "SELECT *\n\t\t\t  \t\t\tFROM vtiger_field\n\t\t\t  \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t  \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t  \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t  \t\t\tAND vtiger_profile2field.visible = 0 \n\t\t\t  \t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\t  \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname";
                 $params = array($tabid, $profileList, $table_name);
             } else {
                 $sql = "SELECT *\n\t\t\t  \t\t\tFROM vtiger_field\n\t\t\t  \t\t\tINNER JOIN vtiger_profile2field\n\t\t\t  \t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tINNER JOIN vtiger_def_org_field\n\t\t\t  \t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid\n\t\t\t  \t\t\tWHERE vtiger_field.tabid = ?\n\t\t\t  \t\t\tAND vtiger_profile2field.visible = 0 \n\t\t\t  \t\t\tAND vtiger_def_org_field.visible = 0 and vtiger_field.tablename=? and vtiger_field.displaytype in (1,3) and vtiger_field.presence in (0,2) group by columnname";
                 $params = array($tabid, $table_name);
             }
         }
     } else {
         $table_index_column = $this->tab_name_index[$table_name];
         if ($table_index_column == 'id' && $table_name == 'vtiger_users') {
             $currentuser_id = $adb->getUniqueID("vtiger_users");
             $this->id = $currentuser_id;
         }
         $column = array($table_index_column);
         $value = array($this->id);
         $sql = "select * from vtiger_field where tabid=? and tablename=? and displaytype in (1,3,4) and vtiger_field.presence in (0,2)";
         $params = array($tabid, $table_name);
     }
     $result = $adb->pquery($sql, $params);
     $noofrows = $adb->num_rows($result);
     for ($i = 0; $i < $noofrows; $i++) {
         $fieldname = $adb->query_result($result, $i, "fieldname");
         $columname = $adb->query_result($result, $i, "columnname");
         $uitype = $adb->query_result($result, $i, "uitype");
         $generatedtype = $adb->query_result($result, $i, "generatedtype");
         $typeofdata = $adb->query_result($result, $i, "typeofdata");
         $typeofdata_array = explode("~", $typeofdata);
         $datatype = $typeofdata_array[0];
         if ($uitype == 4 && $insertion_mode != 'edit') {
             $this->column_fields[$fieldname] = $this->setModuleSeqNumber("increment", $module);
             $fldvalue = $this->column_fields[$fieldname];
         }
         if (isset($this->column_fields[$fieldname])) {
             if ($uitype == 56) {
                 if ($this->column_fields[$fieldname] == 'on' || $this->column_fields[$fieldname] == 1) {
                     $fldvalue = '1';
                 } else {
                     $fldvalue = '0';
                 }
             } elseif ($uitype == 15 || $uitype == 16) {
                 if ($this->column_fields[$fieldname] == $app_strings['LBL_NOT_ACCESSIBLE']) {
                     //If the value in the request is Not Accessible for a picklist, the existing value will be replaced instead of Not Accessible value.
                     $sql = "select {$columname} from  {$table_name} where " . $this->tab_name_index[$table_name] . "=?";
                     $res = $adb->pquery($sql, array($this->id));
                     $pick_val = $adb->query_result($res, 0, $columname);
                     $fldvalue = $pick_val;
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 33) {
                 if (is_array($this->column_fields[$fieldname])) {
                     $field_list = implode(' |##| ', $this->column_fields[$fieldname]);
                 } else {
                     $field_list = $this->column_fields[$fieldname];
                 }
                 $fldvalue = $field_list;
             } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23) {
                 if ($_REQUEST['action'] == 'Import') {
                     $fldvalue = $this->column_fields[$fieldname];
                 } else {
                     //Added to avoid function call getDBInsertDateValue in ajax save
                     if (isset($current_user->date_format)) {
                         $fldvalue = getValidDBInsertDateValue($this->column_fields[$fieldname]);
                     } else {
                         $fldvalue = $this->column_fields[$fieldname];
                     }
                 }
             } elseif ($uitype == 7) {
                 //strip out the spaces and commas in numbers if given ie., in amounts there may be ,
                 $fldvalue = str_replace(",", "", $this->column_fields[$fieldname]);
                 //trim($this->column_fields[$fieldname],",");
             } elseif ($uitype == 26) {
                 if (empty($this->column_fields[$fieldname])) {
                     $fldvalue = 1;
                     //the documents will stored in default folder
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 28) {
                 if ($this->column_fields[$fieldname] == null) {
                     $fileQuery = $adb->pquery("SELECT filename from vtiger_notes WHERE notesid = ?", array($this->id));
                     $fldvalue = null;
                     if (isset($fileQuery)) {
                         $rowCount = $adb->num_rows($fileQuery);
                         if ($rowCount > 0) {
                             $fldvalue = $adb->query_result($fileQuery, 0, 'filename');
                         }
                     }
                 } else {
                     $fldvalue = $this->column_fields[$fieldname];
                 }
             } elseif ($uitype == 8) {
                 $this->column_fields[$fieldname] = rtrim($this->column_fields[$fieldname], ',');
                 $ids = explode(',', $this->column_fields[$fieldname]);
                 $json = new Zend_Json();
                 $fldvalue = $json->encode($ids);
             } elseif ($uitype == 12) {
                 $query = "SELECT email1 FROM vtiger_users WHERE id = ?";
                 $res = $adb->pquery($query, array($current_user->id));
                 $rows = $adb->num_rows($res);
                 if ($rows > 0) {
                     $fldvalue = $adb->query_result($res, 0, 'email1');
                 }
             } elseif ($uitype == 71 && $generatedtype == 2) {
                 // Convert currency to base currency value before saving for custom fields of type currency
                 $currency_id = $current_user->currency_id;
                 $curSymCrate = getCurrencySymbolandCRate($currency_id);
                 $fldvalue = convertToDollar($this->column_fields[$fieldname], $curSymCrate['rate']);
             } else {
                 $fldvalue = $this->column_fields[$fieldname];
             }
             if ($uitype != 33 && $uitype != 8) {
                 $fldvalue = from_html($fldvalue, $insertion_mode == 'edit' ? true : false);
             }
         } else {
             $fldvalue = '';
         }
         if ($fldvalue == '') {
             $fldvalue = $this->get_column_value($columname, $fldvalue, $fieldname, $uitype, $datatype);
         }
         if ($insertion_mode == 'edit') {
             if ($table_name != 'vtiger_ticketcomments' && $uitype != 4) {
                 array_push($update, $columname . "=?");
                 array_push($update_params, $fldvalue);
             }
         } else {
             array_push($column, $columname);
             array_push($value, $fldvalue);
         }
     }
     if ($insertion_mode == 'edit') {
         if ($_REQUEST['module'] == 'Potentials') {
             $dbquery = 'select sales_stage from vtiger_potential where potentialid = ?';
             $sales_stage = $adb->query_result($adb->pquery($dbquery, array($this->id)), 0, 'sales_stage');
             if ($sales_stage != $_REQUEST['sales_stage'] && $_REQUEST['sales_stage'] != '') {
                 $date_var = date('YmdHis');
                 $closingdate = $_REQUEST['ajxaction'] == 'DETAILVIEW' ? $this->column_fields['closingdate'] : getDBInsertDateValue($this->column_fields['closingdate']);
                 $sql = "insert into vtiger_potstagehistory values(?,?,?,?,?,?,?,?)";
                 $params = array('', $this->id, $this->column_fields['amount'], decode_html($sales_stage), $this->column_fields['probability'], 0, $adb->formatDate($closingdate, true), $adb->formatDate($date_var, true));
                 $adb->pquery($sql, $params);
             }
         } elseif ($_REQUEST['module'] == 'PurchaseOrder' || $_REQUEST['module'] == 'SalesOrder' || $_REQUEST['module'] == 'Quotes' || $_REQUEST['module'] == 'Invoice') {
             //added to update the history for PO, SO, Quotes and Invoice
             $history_field_array = array("PurchaseOrder" => "postatus", "SalesOrder" => "sostatus", "Quotes" => "quotestage", "Invoice" => "invoicestatus");
             $inventory_module = $_REQUEST['module'];
             if ($_REQUEST['ajxaction'] == 'DETAILVIEW') {
                 if ($inventory_module == "PurchaseOrder") {
                     $relatedname = getVendorName($this->column_fields['vendor_id']);
                 } else {
                     $relatedname = getAccountName($this->column_fields['account_id']);
                 }
                 $total = $this->column_fields['hdnGrandTotal'];
             } else {
                 if ($inventory_module == "PurchaseOrder") {
                     $relatedname = $_REQUEST["vendor_name"];
                 } else {
                     $relatedname = $_REQUEST["account_name"];
                 }
                 $total = $_REQUEST['total'];
             }
             if ($this->column_fields["{$history_field_array[$inventory_module]}"] == $app_strings['LBL_NOT_ACCESSIBLE']) {
                 //If the value in the request is Not Accessible for a picklist, the existing value will be replaced instead of Not Accessible value.
                 $his_col = $history_field_array[$inventory_module];
                 $his_sql = "select {$his_col} from  {$this->table_name} where " . $this->table_index . "=?";
                 $his_res = $adb->pquery($his_sql, array($this->id));
                 $status_value = $adb->query_result($his_res, 0, $his_col);
                 $stat_value = $status_value;
             } else {
                 $stat_value = $this->column_fields["{$history_field_array[$inventory_module]}"];
             }
             $oldvalue = getSingleFieldValue($this->table_name, $history_field_array[$inventory_module], $this->table_index, $this->id);
             if ($this->column_fields["{$history_field_array[$inventory_module]}"] != '' && $oldvalue != $stat_value) {
                 addInventoryHistory($inventory_module, $this->id, $relatedname, $total, $stat_value);
             }
         }
         //Check done by Don. If update is empty the the query fails
         if (count($update) > 0) {
             $sql1 = "update {$table_name} set " . implode(",", $update) . " where " . $this->tab_name_index[$table_name] . "=?";
             array_push($update_params, $this->id);
             $adb->pquery($sql1, $update_params);
         }
     } else {
         $sql1 = "insert into {$table_name}(" . implode(",", $column) . ") values(" . generateQuestionMarks($value) . ")";
         $adb->pquery($sql1, $value);
     }
 }
Example #12
0
 ********************************************************************************/
require_once 'modules/Potentials/Potentials.php';
require_once 'include/logging.php';
require_once 'include/database/PearDatabase.php';
$local_log =& LoggerManager::getLogger('index');
$focus = new Potentials();
//added to fix 4600
$search = vtlib_purify($_REQUEST['search_url']);
global $current_user;
$currencyid = fetchCurrency($current_user->id);
$rate_symbol = getCurrencySymbolandCRate($currencyid);
$rate = $rate_symbol['rate'];
$curr_symbol = $rate_symbol['symbol'];
setObjectValuesFromRequest($focus);
if (isset($_REQUEST['amount'])) {
    $value = convertToDollar($_REQUEST['amount'], $rate);
    $focus->column_fields['amount'] = $value;
}
if ($_REQUEST['assigntype'] == 'U') {
    $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id'];
} elseif ($_REQUEST['assigntype'] == 'T') {
    $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id'];
}
$focus->save("Potentials");
$pot_id = $return_id = $focus->id;
$parenttab = getParentTab();
if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "") {
    $return_module = vtlib_purify($_REQUEST['return_module']);
} else {
    $return_module = "Potentials";
}
Example #13
0
function vtws_convertlead($leadId, $assignedTo, $accountName, $avoidPotential, $potential, $user)
{
    global $adb, $log;
    if (empty($assignedTo)) {
        $assignedTo = vtws_getWebserviceEntityId('Users', $user->id);
    }
    if ((bool) $avoidPotential !== true) {
        try {
            if (empty($potential)) {
                throw new WebServiceException(WebServiceErrorCode::$INVALID_POTENTIAL_FOR_CONVERT_LEAD, "Invalid lead information given for potential");
            }
        } catch (Zend_Json_Exception $e) {
            throw new WebServiceException(WebServiceErrorCode::$INVALID_POTENTIAL_FOR_CONVERT_LEAD, "Potentail information given is not in valid JSON format");
        }
    }
    $currencyInfo = getCurrencySymbolandCRate($user->currency_id);
    $rate = $currencyInfo['rate'];
    if ($potential['amount'] != '') {
        $potential['amount'] = convertToDollar($potential['amount'], $rate);
    }
    $leadObject = VtigerWebserviceObject::fromName($adb, 'Leads');
    $handlerPath = $leadObject->getHandlerPath();
    $handlerClass = $leadObject->getHandlerClass();
    require_once $handlerPath;
    $leadHandler = new $handlerClass($leadObject, $user, $adb, $log);
    $leadHandler->getMeta()->retrieveMeta();
    $leadInfo = vtws_retrieve($leadId, $user);
    $sql = "select converted from vtiger_leaddetails where converted = 1 and leadid=?";
    $leadIdComponents = vtws_getIdComponents($leadId);
    $result = $adb->pquery($sql, array($leadIdComponents[1]));
    if ($result === false) {
        throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
    }
    $rowCount = $adb->num_rows($result);
    if ($rowCount > 0) {
        throw new WebServiceException(WebServiceErrorCode::$LEAD_ALREADY_CONVERTED, "Lead is already converted");
    }
    $customFieldMapping = vtws_getConvertLeadFieldMapping();
    //check if accountName given in request is empty then default to lead company field.
    if (empty($accountName)) {
        $accountName = $leadInfo['company'];
    }
    $sql = "select vtiger_account.accountid from vtiger_account\n\t\tleft join vtiger_crmentity on vtiger_account.accountid = vtiger_crmentity.crmid\n\t\twhere vtiger_crmentity.deleted=0 and vtiger_account.accountname = ?";
    $result = $adb->pquery($sql, array($accountName));
    if ($result === false) {
        throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
    }
    $rowCount = $adb->num_rows($result);
    if ($rowCount != 0 && vtlib_isModuleActive('Accounts') === true) {
        $crmId = $adb->query_result($result, 0, "accountid");
        $status = vtws_getRelatedNotesAttachments($leadIdComponents[1], $crmId);
        if ($status === false) {
            throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move related Documents to the Account");
        }
        //Retrieve the lead related products and relate them with this new account
        $status = vtws_saveLeadRelatedProducts($leadIdComponents[1], $crmId, "Accounts");
        if ($status === false) {
            throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move related Products to the Account");
        }
        $status = vtws_saveLeadRelations($leadIdComponents[1], $crmId, "Accounts");
        if ($status === false) {
            throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move Records to the Account");
        }
    } else {
        //don't create account if no company name is given in input and lead doest not have
        // company field populated, DONE TO RESPECT B2C model.
        if (!empty($accountName)) {
            $accountObject = VtigerWebserviceObject::fromName($adb, 'Accounts');
            $handlerPath = $accountObject->getHandlerPath();
            $handlerClass = $accountObject->getHandlerClass();
            require_once $handlerPath;
            $accountHandler = new $handlerClass($accountObject, $user, $adb, $log);
            if ($accountHandler->getMeta()->hasWriteAccess()) {
                $account = array();
                if (!empty($leadInfo["annualrevenue"])) {
                    $account['annual_revenue'] = $leadInfo["annualrevenue"];
                }
                if (!empty($leadInfo["noofemployees"])) {
                    $account['employees'] = $leadInfo["noofemployees"];
                }
                $account['accountname'] = $accountName;
                $account['industry'] = $leadInfo["industry"];
                $account['phone'] = $leadInfo["phone"];
                $account['fax'] = $leadInfo["fax"];
                $account['rating'] = $leadInfo["rating"];
                $account['email1'] = $leadInfo["email"];
                $account['website'] = $leadInfo["website"];
                $account['bill_city'] = $leadInfo["city"];
                $account['bill_code'] = $leadInfo["code"];
                $account['bill_country'] = $leadInfo["country"];
                $account['bill_state'] = $leadInfo["state"];
                $account['bill_street'] = $leadInfo["lane"];
                $account['bill_pobox'] = $leadInfo["pobox"];
                $account['ship_city'] = $leadInfo["city"];
                $account['ship_code'] = $leadInfo["code"];
                $account['ship_country'] = $leadInfo["country"];
                $account['ship_state'] = $leadInfo["state"];
                $account['ship_street'] = $leadInfo["lane"];
                $account['ship_pobox'] = $leadInfo["pobox"];
                $account['assigned_user_id'] = $assignedTo;
                $account['description'] = $leadInfo['description'];
                $leadFields = $leadHandler->getMeta()->getModuleFields();
                $accountFields = $accountHandler->getMeta()->getModuleFields();
                foreach ($customFieldMapping as $leadFieldId => $mappingDetails) {
                    $accountFieldId = $mappingDetails['Accounts'];
                    if (empty($accountFieldId)) {
                        continue;
                    }
                    $accountField = vtws_getFieldfromFieldId($accountFieldId, $accountFields);
                    if ($accountField == null) {
                        //user doesn't have access so continue.TODO update even if user doesn't have access
                        continue;
                    }
                    $leadField = vtws_getFieldfromFieldId($leadFieldId, $leadFields);
                    if ($leadField == null) {
                        //user doesn't have access so continue.TODO update even if user doesn't have access
                        continue;
                    }
                    $leadFieldName = $leadField->getFieldName();
                    $accountFieldName = $accountField->getFieldName();
                    $account[$accountFieldName] = $leadInfo[$leadFieldName];
                }
                $account = vtws_create('Accounts', $account, $user);
                $accountIdComponents = vtws_getIdComponents($account['id']);
                $status = vtws_getRelatedNotesAttachments($leadIdComponents[1], $accountIdComponents[1]);
                if ($status === false) {
                    throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move related Documents to the Account");
                }
                //Retrieve the lead related products and relate them with this new account
                $status = vtws_saveLeadRelatedProducts($leadIdComponents[1], $accountIdComponents[1], "Accounts");
                if ($status === false) {
                    throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move related Products to the Account");
                }
                $status = vtws_saveLeadRelations($leadIdComponents[1], $accountIdComponents[1], "Accounts");
                if ($status === false) {
                    throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move Records to the Account");
                }
            }
        }
    }
    $contactObject = VtigerWebserviceObject::fromName($adb, 'Contacts');
    $handlerPath = $contactObject->getHandlerPath();
    $handlerClass = $contactObject->getHandlerClass();
    require_once $handlerPath;
    $contactHandler = new $handlerClass($contactObject, $user, $adb, $log);
    if (!empty($crmId)) {
        $accountId = $crmId;
        $webserviceAccountId = vtws_getWebserviceEntityId('Accounts', $crmId);
    } elseif (!empty($accountName)) {
        if (count($accountIdComponents) === 2) {
            $accountId = $accountIdComponents[1];
            $webserviceAccountId = vtws_getId($accountIdComponents[0], $accountIdComponents[1]);
        }
    } else {
        $accountId = '';
        $webserviceAccountId = '';
    }
    if ($contactHandler->getMeta()->hasWriteAccess()) {
        $contact = array();
        $contact['assigned_user_id'] = $assignedTo;
        $contact['description'] = $leadInfo['description'];
        $contact['account_id'] = $webserviceAccountId;
        $contact['salutationtype'] = $leadInfo["salutationtype"];
        $contact['firstname'] = $leadInfo["firstname"];
        $contact['lastname'] = $leadInfo["lastname"];
        $contact['email'] = $leadInfo["email"];
        $contact['phone'] = $leadInfo["phone"];
        $contact['mobile'] = $leadInfo["mobile"];
        $contact['title'] = $leadInfo["designation"];
        $contact['fax'] = $leadInfo["fax"];
        $contact['yahooid'] = $leadInfo['yahooid'];
        $contact['leadsource'] = $leadInfo['leadsource'];
        $contact['mailingcity'] = $leadInfo["city"];
        $contact['mailingzip'] = $leadInfo["code"];
        $contact['mailingcountry'] = $leadInfo["country"];
        $contact['mailingstate'] = $leadInfo["state"];
        $contact['mailingstreet'] = $leadInfo["lane"];
        $contact['mailingpobox'] = $leadInfo["pobox"];
        $leadFields = $leadHandler->getMeta()->getModuleFields();
        $contactFields = $contactHandler->getMeta()->getModuleFields();
        foreach ($customFieldMapping as $leadFieldId => $mappingDetails) {
            $contactFieldId = $mappingDetails['Contacts'];
            if (empty($contactFieldId)) {
                continue;
            }
            $contactField = vtws_getFieldfromFieldId($contactFieldId, $contactFields);
            if ($contactField == null) {
                //user doesn't have access so continue.TODO update even if user doesn't have access
                continue;
            }
            $leadField = vtws_getFieldfromFieldId($leadFieldId, $leadFields);
            if ($leadField == null) {
                //user doesn't have access so continue.TODO update even if user doesn't have access
                continue;
            }
            $leadFieldName = $leadField->getFieldName();
            $contactFieldName = $contactField->getFieldName();
            $contact[$contactFieldName] = $leadInfo[$leadFieldName];
        }
        $contact = vtws_create('Contacts', $contact, $user);
        $contactIdComponents = vtws_getIdComponents($contact['id']);
        $contactId = $contactIdComponents[1];
        //To convert relates Activites and Email.
        $status = vtws_getRelatedActivities($leadIdComponents[1], $accountId, $contactIdComponents[1]);
        if ($status === false) {
            throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move Related Activities to the Contact");
        }
        $status = vtws_getRelatedNotesAttachments($leadIdComponents[1], $contactIdComponents[1]);
        if ($status === false) {
            throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move related Documents to the Contact");
        }
        //Retrieve the lead related products and relate them with this new contact
        $status = vtws_saveLeadRelatedProducts($leadIdComponents[1], $contactIdComponents[1], "Contacts");
        if ($status === false) {
            throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move related Products to the Contact");
        }
        $status = vtws_saveLeadRelations($leadIdComponents[1], $contactIdComponents[1], "Contacts");
        if ($status === false) {
            throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move Records to the Contact");
        }
        //Retrieve the lead related Campaigns and relate them with this new contact --Minnie
        $status = vtws_saveLeadRelatedCampaigns($leadIdComponents[1], $contactIdComponents[1]);
        if ($status === false) {
            throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move Related Campaigns to the Contact");
        }
    }
    if ((bool) $avoidPotential != true) {
        $potentialObject = VtigerWebserviceObject::fromName($adb, 'Potentials');
        $handlerPath = $potentialObject->getHandlerPath();
        $handlerClass = $potentialObject->getHandlerClass();
        require_once $handlerPath;
        $potentialHandler = new $handlerClass($potentialObject, $user, $adb, $log);
        if ($potentialHandler->getMeta()->hasWriteAccess()) {
            if (!empty($webserviceAccountId)) {
                $relatedTo = $webserviceAccountId;
            } else {
                if (!empty($contactId)) {
                    $relatedTo = vtws_getWebserviceEntityId('Contacts', $contactId);
                }
            }
            $potential['assigned_user_id'] = $assignedTo;
            $potential['description'] = $leadInfo['description'];
            $potential['related_to'] = $relatedTo;
            $potential['leadsource'] = $leadInfo['leadsource'];
            $leadFields = $leadHandler->getMeta()->getModuleFields();
            $potentialFields = $potentialHandler->getMeta()->getModuleFields();
            foreach ($customFieldMapping as $leadFieldId => $mappingDetails) {
                $potentialFieldId = $mappingDetails['Potentials'];
                if (empty($potentialFieldId)) {
                    continue;
                }
                $potentialField = vtws_getFieldfromFieldId($potentialFieldId, $potentialFields);
                if ($potentialField == null) {
                    //user doesn't have access so continue.TODO update even if user doesn't have access
                    continue;
                }
                $leadField = vtws_getFieldfromFieldId($leadFieldId, $leadFields);
                if ($leadField == null) {
                    //user doesn't have access so continue.TODO update even if user doesn't have access
                    continue;
                }
                $leadFieldName = $leadField->getFieldName();
                $potentialFieldName = $potentialField->getFieldName();
                $potential[$potentialFieldName] = $leadInfo[$leadFieldName];
            }
            $potential = vtws_create('Potentials', $potential, $user);
            $potentialIdComponents = vtws_getIdComponents($potential['id']);
            if (!empty($accountId) && !empty($contactId)) {
                $sql = "insert into vtiger_contpotentialrel values(?,?)";
                $result = $adb->pquery($sql, array($contactId, $potentialIdComponents[1]));
                if ($result === false) {
                    throw new WebServiceException(WebServiceErrorCode::$FAILED_TO_CREATE_RELATION, "Failed to related Contact with the Potential");
                }
            }
            //Retrieve the lead related products and relate them with this new potential
            $status = vtws_saveLeadRelatedProducts($leadIdComponents[1], $potentialIdComponents[1], "Potentials");
            if ($status === false) {
                throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move related Products to the Potential");
            }
            $status = vtws_saveLeadRelations($leadIdComponents[1], $potentialIdComponents[1], "Potentials");
            if ($status === false) {
                throw new WebServiceException(WebServiceErrorCode::$LEAD_RELATED_UPDATE_FAILED, "Failed to move Records to the Potential");
            }
            $potentialId = $potentialIdComponents[1];
        }
    }
    //Updating the converted status
    if ($accountId != '' || $contactId != '') {
        $sql = "UPDATE vtiger_leaddetails SET converted = 1 where leadid=?";
        $result = $adb->pquery($sql, array($leadIdComponents[1]));
        if ($result === false) {
            throw new WebServiceException(WebServiceErrorCode::$FAILED_TO_MARK_CONVERTED, "Failed mark lead converted");
        }
        //updating the campaign-lead relation --Minnie
        $sql = "delete from vtiger_campaignleadrel where leadid=?";
        $adb->pquery($sql, array($leadIdComponents[1]));
    }
    $result = array('leadId' => $leadId);
    if (!empty($webserviceAccountId)) {
        $result['accountId'] = $webserviceAccountId;
    } else {
        $result['accountId'] = '';
    }
    if (!empty($contactId)) {
        $result['contactId'] = vtws_getWebserviceEntityId('Contacts', $contactId);
    } else {
        $result['contactId'] = '';
    }
    if (!empty($potentialId)) {
        $result['potentialId'] = $potential['id'];
    } else {
        $result['potentialId'] = '';
    }
    return $result;
}
    $assigned_user_id = $_REQUEST["assigned_group_id"];
}
$accountname = $_REQUEST['account_name'];
$potential_amount = $_REQUEST['potential_amount'];
$potential_sales_stage = $_REQUEST['potential_sales_stage'];
global $log, $current_user;
require 'user_privileges/user_privileges_' . $current_user->id . '.php';
if ($assigned_to == "U") {
    $log->debug("id = {$id} \n assigned_user_id = {$assigned_user_id} \n createpotential = {$createpotential} \n close date = {$close_date} \n current user id = {$current_user_id} \n accountname = {$accountname} \n module = {$module}");
} else {
    $log->debug("id = {$id} \n assigned_user_id = {$assigned_group_id} \n createpotential = {$createpotential} \n close date = {$close_date} \n current user id = {$current_user_id} \n accountname = {$accountname} \n module = {$module}");
}
$rate_symbol = getCurrencySymbolandCRate($user_info['currency_id']);
$rate = $rate_symbol['rate'];
if ($potential_amount != '') {
    $potential_amount = convertToDollar($potential_amount, $rate);
}
//Retrieve info from all the vtiger_tables related to leads
$focus = new Leads();
$focus->retrieve_entity_info($id, "Leads");
//get all the lead related columns
$row = $focus->column_fields;
$date_entered = $adb->formatDate(date('Y-m-d H:i:s'), true);
$date_modified = $adb->formatDate(date('Y-m-d H:i:s'), true);
/** Function for getting the custom values from leads and saving to vtiger_account/contact/potential custom vtiger_fields.
 *  @param string $type - Field Type (eg: text, list)
 *  @param integer $type_id - Field Type ID 
*/
function getInsertValues($type, $type_id)
{
    global $id, $adb, $log;
Example #15
0
 function getInviteCredit($userid)
 {
     global $session;
     $invitees = $this->getInvitedMember($userid);
     $creditearned = 0;
     foreach ($invitees as $invite) {
         $inviterepayrate = $session->RepaymentRate($invite['invitee_id']);
         $invite_lastloan = $this->getLastloan($invite['invitee_id']);
         if (empty($invite_lastloan)) {
             $inviterepayrate = 0;
         }
         $minrepayrate = $this->getAdminSetting('MinRepayRate');
         if ($inviterepayrate >= $minrepayrate) {
             $country = $this->getCountryCodeById($userid);
             $binvitecredit = $this->getcreditsettingbyCountry($country, 3);
             $creditearned += $binvitecredit['loanamt_limit'];
         }
     }
     $rate = $this->getCurrentRate($userid);
     $creditearned_usd = convertToDollar($creditearned, $rate);
     if ($creditearned_usd > 1000) {
         $creditearned_usd = 1000;
     }
     $creditearned = convertToNative($creditearned_usd, $rate);
     return $creditearned;
 }
Example #16
0
				<!--	<tr>
							<td><div id="viewprevloan" style="cursor:pointer;" ><strong><a><?php 
            echo $viewprevloan;
            ?>
</a></strong></div></td><td></td>
						</tr>
						<tr><td>
								<div id="viewprevloan_desc" style="display:none;" class="span16">
								<table class="detail" style="width:350px;">
									<tbody>
									<?php 
            foreach ($allloans as $allloan) {
                if ($allloan['loanid'] != $activeloanid) {
                    $loanDisburseDate = date('M Y', $database->getLoanDisburseDate($allloan['loanid']));
                    $loanRepaidDate = date('M Y', $database->getLoanRepaidDate($allloan['loanid'], $ud));
                    $amountGot = number_format(convertToDollar($allloan['AmountGot'], $currRate), 2, ".", "");
                    $loanprofileurl = getLoanprofileUrl($id, $allloan['loanid']);
                    ?>
										<tr><td>USD&nbsp;<?php 
                    echo $amountGot;
                    ?>
</td><td><?php 
                    echo $loanDisburseDate;
                    ?>
 - <?php 
                    echo $loanRepaidDate;
                    ?>
</td><td><a href="<?php 
                    echo $loanprofileurl;
                    ?>
">View Loan Profile</a></td>