Ejemplo n.º 1
0
/**
 * This function updates the stock information once the product is ordered.
 * Param $productid - product id
 * Param $qty - product quantity in no's
 * Param $mode - mode type
 * Param $ext_prod_arr - existing products ** NOT USED: empty **
 * Param $module - module name
 * return type void
 */
function updateStk($product_id, $qty, $mode, $ext_prod_arr, $module)
{
    global $log, $adb, $current_user;
    $log->debug("Entering updateStk({$product_id},{$qty},{$mode},{$module}) method ...");
    $prod_name = getProductName($product_id);
    $qtyinstk = getPrdQtyInStck($product_id);
    $log->debug("Prd Qty in Stock " . $qtyinstk);
    $upd_qty = $qtyinstk - $qty;
    sendPrdStckMail($product_id, $upd_qty, $prod_name, $qtyinstk, $qty, $module);
    $log->debug("Exiting updateStk method ...");
}
Ejemplo n.º 2
0
/**
 * This function updates the stock information once the product is ordered.
 * Param $productid - product id
 * Param $qty - product quantity in no's
 * Param $mode - mode type
 * Param $ext_prod_arr - existing vtiger_products
 * Param $module - module name
 * return type void
 */
function updateStk($product_id, $qty, $mode, $ext_prod_arr, $module)
{
    $log = vglobal('log');
    $log->debug("Entering updateStk(" . $product_id . "," . $qty . "," . $mode . "," . $ext_prod_arr . "," . $module . ") method ...");
    $adb = PearDatabase::getInstance();
    $current_user = vglobal('current_user');
    $log->debug("Inside updateStk function, module=" . $module);
    $log->debug("Product Id = {$product_id} & Qty = {$qty}");
    $prod_name = getProductName($product_id);
    $qtyinstk = getPrdQtyInStck($product_id);
    $log->debug("Prd Qty in Stock " . $qtyinstk);
    $upd_qty = $qtyinstk - $qty;
    $log->debug("Exiting updateStk method ...");
}
Ejemplo n.º 3
0
/**
 * This function updates the stock information once the product is ordered.
 * Param $productid - product id
 * Param $qty - product quantity in no's
 * Param $mode - mode type
 * Param $ext_prod_arr - existing vtiger_products
 * Param $module - module name
 * return type void
 */
function updateStk($product_id, $qty, $mode, $ext_prod_arr, $module)
{
    global $log;
    $log->debug("Entering updateStk(" . $product_id . "," . $qty . "," . $mode . "," . $ext_prod_arr . "," . $module . ") method ...");
    global $adb;
    global $current_user;
    $log->debug("Inside updateStk function, module=" . $module);
    $log->debug("Product Id = {$product_id} & Qty = {$qty}");
    $prod_name = getProductName($product_id);
    $qtyinstk = getPrdQtyInStck($product_id);
    $log->debug("Prd Qty in Stock " . $qtyinstk);
    $upd_qty = $qtyinstk - $qty;
    $log->debug("Exiting updateStk method ...");
}
Ejemplo n.º 4
0
function getArticleIdTime($faqid, $product_id, $faqcategory, $faqcreatedtime, $faqmodifiedtime)
{
    $list .= '<div id="faqDetail" onMouseOver="fnShowDiv(\'faqDetail\')" onMouseOut="fnHideDiv(\'faqDetail\')">
		 <table class="fagView" cellpadding="0" cellspacing="0">
		   <tr>
			<td align="right"><b>' . getTranslatedString('LBL_FAQ_ID') . ': </b></td><td align="left"><b>' . $faqid . '</b></td>
		   </tr>
		   <tr>
			<td align="right">' . getTranslatedString('LBL_PRODUCT') . ': </td><td align="left">' . getProductName($product_id) . '</td>
		   </tr>
		   <tr>
			<td align="right">' . getTranslatedString('LBL_CATEGORY') . ': </td><td align="left">' . $faqcategory . '</td>
		   </tr>
		   <tr>
			<td align="right">' . getTranslatedString('LBL_CREATED_DATE') . ': </td><td align="left">' . substr($faqcreatedtime, 0, 10) . '</td>
		   </tr>
		   <tr>
			<td align="right" nowrap>' . getTranslatedString('LBL_MODIFIED_DATE') . ': </td><td align="left">' . substr($faqmodifiedtime, 0, 10) . '</td>
		   </tr>
		</table>
		</div>';
    return $list;
}
Ejemplo n.º 5
0
 *  Author       : Opencubed
 *************************************************************************************************/
$kaction = $_REQUEST['kaction'];
global $adb;
require_once "modules/Adocdetail/Adocdetail.php";
$content = array();
if ($kaction == 'retrieve') {
    $query = $adb->pquery("Select * from vtiger_adocdetail a \n                    join vtiger_crmentity ce on a.adocdetailid=ce.crmid \n                    where ce.deleted=0 and a.adoctomaster=?", array($_REQUEST['record']));
    $count = $adb->num_rows($query);
    for ($i = 0; $i < $count; $i++) {
        $content[$i]['adocdetailid'] = $adb->query_result($query, $i, 'adocdetailid');
        $content[$i]['adocdetailno'] = $adb->query_result($query, $i, 'adocdetailno');
        $content[$i]['adocdetailname'] = $adb->query_result($query, $i, 'adocdetailname');
        $content[$i]['nrline'] = $adb->query_result($query, $i, 'nrline');
        $product = $adb->query_result($query, $i, 'adoc_product');
        $content[$i]['adoc_product'] = getProductName($product);
        $content[$i]['urlproduct'] = 'index.php?module=Products&action=DetailView&record=' . $product;
        $content[$i]['url'] = 'index.php?module=Adocdetail&action=DetailView&record=' . $content[$i]['adocdetailid'];
        $content[$i]['adoc_quantity'] = $adb->query_result($query, $i, 'adoc_quantity');
        $content[$i]['adoc_price'] = $adb->query_result($query, $i, 'adoc_price');
        $content[$i]['inout_docnr'] = $adb->query_result($query, $i, 'inout_docnr');
        $content[$i]['poteknema'] = $adb->query_result($query, $i, 'poteknema');
        $content[$i]['posupplier'] = $adb->query_result($query, $i, 'posupplier');
        $content[$i]['riferimento'] = $adb->query_result($query, $i, 'riferimento');
        $stockid = $adb->query_result($query, $i, 'adoc_stock');
        $stock = getEntityName('Stock', $stockid);
        $content[$i]['adoc_stock'] = $stock[$stockid];
        $content[$i]['urlstock'] = 'index.php?module=Stock&action=DetailView&record=' . $stockid;
    }
    echo json_encode($content);
} elseif ($kaction == 'update') {
Ejemplo n.º 6
0
/** To get the converted record values which have to be display in duplicates merging tpl*/
function getRecordValues($id_array, $module)
{
    global $adb, $current_user;
    global $app_strings;
    global $mod_strings;
    $tabid = getTabid($module);
    $query = "select fieldname,fieldlabel from ec_field where tabid=" . $tabid . " and fieldname  not in ('createdtime','modifiedtime')";
    $result = $adb->query($query);
    $no_rows = $adb->num_rows($result);
    for ($i = 0; $i < $no_rows; $i++) {
        $fld_name = $adb->query_result($result, $i, "fieldname");
        if (getFieldVisibilityPermission($module, $current_user->id, $fld_name) == '0') {
            $fld_array[] = $fld_name;
        }
    }
    $js_arr = $fld_array;
    $focus = new $module();
    if (isset($id_array) && $id_array != '') {
        foreach ($id_array as $value) {
            $focus->id = $value;
            $focus->retrieve_entity_info($value, $module);
            $field_values[] = $focus->column_fields;
        }
    }
    $tabid = getTabid($module);
    $query = "select fieldname,uitype,fieldlabel from ec_field where tabid=" . $tabid . " and fieldname not in ('createdtime','modifiedtime','lastcontacttime')";
    $result = $adb->query($query);
    $no_rows = $adb->num_rows($result);
    $labl_array = array();
    $value_pair = array();
    $c = 0;
    for ($i = 0; $i < $no_rows; $i++) {
        $fld_name = $adb->query_result($result, $i, "fieldname");
        $fld_label = $adb->query_result($result, $i, "fieldlabel");
        if (isset($mod_strings[$fld_label])) {
            $fld_label = $mod_strings[$fld_label];
        }
        $ui_type = $adb->query_result($result, $i, "uitype");
        if (getFieldVisibilityPermission($module, $current_user->id, $fld_name) == '0') {
            $record_values[$c][$fld_label] = array();
            $ui_value[] = $ui_type;
            for ($j = 0; $j < count($field_values); $j++) {
                if ($ui_type == 56) {
                    if ($field_values[$j][$fld_name] == 0) {
                        $value_pair['disp_value'] = $app_strings['no'];
                    } else {
                        $value_pair['disp_value'] = $app_strings['yes'];
                    }
                } elseif ($ui_type == 51 || $ui_type == 50) {
                    $account_id = $field_values[$j][$fld_name];
                    $account_name = getAccountName($account_id);
                    $value_pair['disp_value'] = $account_name;
                } elseif ($ui_type == 53) {
                    $user_id = $field_values[$j][$fld_name];
                    $username = getUserName($user_id);
                    $group_info = getGroupName($field_values[$j]['record_id'], $module);
                    $groupname = $group_info[0];
                    $groupid = $group_info[1];
                    if ($user_id != 0) {
                        $value_pair['disp_value'] = $username;
                    } else {
                        $value_pair['disp_value'] = $groupname;
                    }
                } elseif ($ui_type == 57) {
                    $contact_id = $field_values[$j][$fld_name];
                    if ($contact_id != '') {
                        $contactname = getContactName($contact_id);
                    }
                    $value_pair['disp_value'] = $contactname;
                } elseif ($ui_type == 75 || $ui_type == 81) {
                    $vendor_id = $field_values[$j][$fld_name];
                    if ($vendor_id != '') {
                        $vendor_name = getVendorName($vendor_id);
                    }
                    $value_pair['disp_value'] = $vendor_name;
                } elseif ($ui_type == 52) {
                    $user_id = $field_values[$j][$fld_name];
                    $user_name = getUserName($user_id);
                    $value_pair['disp_value'] = $user_name;
                } elseif ($ui_type == 68) {
                    $parent_id = $field_values[$j][$fld_name];
                    $value_pair['disp_value'] = getAccountName($parent_id);
                    if ($value_pair['disp_value'] == '' || $value_pair['disp_value'] == NULL) {
                        $value_pair['disp_value'] = getContactName($parent_id);
                    }
                } elseif ($ui_type == 59) {
                    $product_name = getProductName($field_values[$j][$fld_name]);
                    if ($product_name != '') {
                        $value_pair['disp_value'] = $product_name;
                    } else {
                        $value_pair['disp_value'] = '';
                    }
                } elseif ($ui_type == 58) {
                    $campaign_name = getCampaignName($field_values[$j][$fld_name]);
                    if ($campaign_name != '') {
                        $value_pair['disp_value'] = $campaign_name;
                    } else {
                        $value_pair['disp_value'] = '';
                    }
                } else {
                    $value_pair['disp_value'] = $field_values[$j][$fld_name];
                }
                $value_pair['org_value'] = $field_values[$j][$fld_name];
                array_push($record_values[$c][$fld_label], $value_pair);
            }
            $c++;
        }
    }
    $parent_array[0] = $record_values;
    $parent_array[1] = $js_arr;
    $parent_array[2] = $fld_array;
    return $parent_array;
}
Ejemplo n.º 7
0
}
$smarty->assign("TAX_DETAILS", $tax_details);
//Tax handling - ends
$unit_price = $focus->column_fields['unit_price'];
$price_details = getPriceDetailsForProduct($productid, $unit_price, 'available', $currentModule);
$smarty->assign("PRICE_DETAILS", $price_details);
$base_currency = 'curname' . $product_base_currency;
$smarty->assign("BASE_CURRENCY", $base_currency);
if (isset($focus->id) && $_REQUEST['isDuplicate'] != 'true') {
    $is_parent = $focus->isparent_check();
} else {
    $is_parent = 0;
}
$smarty->assign("IS_PARENT", $is_parent);
if ($_REQUEST['return_module'] == 'Products' && isset($_REQUEST['return_action'])) {
    $return_name = getProductName($_REQUEST['return_id']);
    $smarty->assign("RETURN_NAME", $return_name);
}
if ($errormessage == 2) {
    $msg = $mod_strings['LBL_MAXIMUM_LIMIT_ERROR'];
    $errormessage = "<B><font color='red'>" . $msg . "</font></B> <br><br>";
} else {
    if ($errormessage == 3) {
        $msg = $mod_strings['LBL_UPLOAD_ERROR'];
        $errormessage = "<B><font color='red'>" . $msg . "</font></B> <br><br>";
    } else {
        if ($errormessage == "image") {
            $msg = $mod_strings['LBL_IMAGE_ERROR'];
            $errormessage = "<B><font color='red'>" . $msg . "</font></B> <br><br>";
        } else {
            if ($errormessage == "invalid") {
Ejemplo n.º 8
0
/** This function returns a HTML output of associated vtiger_products for a given entity (Quotes,Invoice,Sales order or Purchase order)
 * Param $module - module name
 * Param $focus - module object
 * Return type string
 */
function getDetailAssociatedProducts($module, $focus)
{
    global $log;
    $log->debug("Entering getDetailAssociatedProducts(" . $module . "," . get_class($focus) . ") method ...");
    global $adb;
    global $mod_strings;
    global $theme;
    global $log;
    global $app_strings, $current_user;
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    if (vtlib_isModuleActive("Products")) {
        $hide_stock = 'no';
    } else {
        $hide_stock = 'yes';
    }
    if ($module != 'PurchaseOrder') {
        if (GlobalVariable::getVariable('B2B', '1') == '1') {
            $acvid = $focus->column_fields['account_id'];
        } else {
            $acvid = $focus->column_fields['contact_id'];
        }
        if ($hide_stock == 'no') {
            $colspan = '2';
        } else {
            $colspan = '1';
        }
    } else {
        $acvid = $focus->column_fields['vendor_id'];
        $colspan = '1';
    }
    //Get the taxtype of this entity
    $taxtype = getInventoryTaxType($module, $focus->id);
    $currencytype = getInventoryCurrencyInfo($module, $focus->id);
    $output = '';
    //Header Rows
    $output .= '

	<table width="100%"  border="0" align="center" cellpadding="5" cellspacing="0" class="crmTable" id="proTab">
	   <tr valign="top">
	   	<td colspan="' . $colspan . '" class="dvInnerHeader"><b>' . $app_strings['LBL_ITEM_DETAILS'] . '</b></td>
		<td class="dvInnerHeader" align="center" colspan="2"><b>' . $app_strings['LBL_CURRENCY'] . ' : </b>' . getTranslatedCurrencyString($currencytype['currency_name']) . ' (' . $currencytype['currency_symbol'] . ')
		</td>
		<td class="dvInnerHeader" align="center" colspan="2"><b>' . $app_strings['LBL_TAX_MODE'] . ' : </b>' . $app_strings[$taxtype] . '
		</td>
	   </tr>
	   <tr valign="top">
		<td width=40% class="lvtCol"><font color="red">*</font>
			<b>' . $app_strings['LBL_ITEM_NAME'] . '</b>
		</td>';
    //Add Quantity in Stock column for SO, Quotes and Invoice
    if (($module == 'Quotes' || $module == 'SalesOrder' || $module == 'Invoice') && $hide_stock == 'no') {
        $output .= '<td width=10% class="lvtCol"><b>' . $app_strings['LBL_QTY_IN_STOCK'] . '</b></td>';
    }
    $output .= '

		<td width=10% class="lvtCol"><b>' . $app_strings['LBL_QTY'] . '</b></td>
		<td width=10% class="lvtCol" align="right"><b>' . $app_strings['LBL_LIST_PRICE'] . '</b></td>
		<td width=12% nowrap class="lvtCol" align="right"><b>' . $app_strings['LBL_TOTAL'] . '</b></td>
		<td width=13% valign="top" class="lvtCol" align="right"><b>' . $app_strings['LBL_NET_PRICE'] . '</b></td>
	   </tr>
	   	';
    // DG 15 Aug 2006
    // Add "ORDER BY sequence_no" to retain add order on all inventoryproductrel items
    if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice') {
        $query = "select case when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname," . " case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype," . " case when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price," . " case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock, vtiger_inventoryproductrel.* " . " from vtiger_inventoryproductrel" . " left join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid " . " left join vtiger_service on vtiger_service.serviceid=vtiger_inventoryproductrel.productid " . " where id=? ORDER BY sequence_no";
    }
    $result = $adb->pquery($query, array($focus->id));
    $num_rows = $adb->num_rows($result);
    $netTotal = '0.00';
    for ($i = 1; $i <= $num_rows; $i++) {
        $sub_prod_query = $adb->pquery("SELECT productid from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i));
        $subprodname_str = '';
        if ($adb->num_rows($sub_prod_query) > 0) {
            for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                $sprod_id = $adb->query_result($sub_prod_query, $j, 'productid');
                $sprod_name = getProductName($sprod_id);
                $str_sep = "";
                if ($j > 0) {
                    $str_sep = ":";
                }
                $subprodname_str .= $str_sep . " - " . $sprod_name;
            }
        }
        $subprodname_str = str_replace(":", "<br>", $subprodname_str);
        $productid = $adb->query_result($result, $i - 1, 'productid');
        $entitytype = $adb->query_result($result, $i - 1, 'entitytype');
        $productname = $adb->query_result($result, $i - 1, 'productname');
        $productname = '<a href="index.php?action=DetailView&record=' . $productid . '&module=' . $entitytype . '">' . $productname . '</a>';
        if ($subprodname_str != '') {
            $productname .= "<br/><span style='color:#C0C0C0;font-style:italic;'>" . $subprodname_str . "</span>";
        }
        $comment = $adb->query_result($result, $i - 1, 'comment');
        $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock');
        $qty = $adb->query_result($result, $i - 1, 'quantity');
        $qty = number_format($qty, 2, '.', '');
        //Convert to 2 decimals
        $unitprice = $adb->query_result($result, $i - 1, 'unit_price');
        $listprice = $adb->query_result($result, $i - 1, 'listprice');
        $total = $qty * $listprice;
        $listprice = number_format($listprice, 2, '.', '');
        //Convert to 2 decimals
        //Product wise Discount calculation - starts
        $discount_percent = $adb->query_result($result, $i - 1, 'discount_percent');
        $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount');
        $totalAfterDiscount = $total;
        $productDiscount = '0.00';
        if ($discount_percent != 'NULL' && $discount_percent != '') {
            $productDiscount = $total * $discount_percent / 100;
            $productDiscount = number_format($productDiscount, 2, '.', '');
            $totalAfterDiscount = $total - $productDiscount;
            //if discount is percent then show the percentage
            $discount_info_message = "{$discount_percent} % of " . CurrencyField::convertToUserFormat($total, null, true) . " = " . CurrencyField::convertToUserFormat($productDiscount, null, true);
        } elseif ($discount_amount != 'NULL' && $discount_amount != '') {
            $productDiscount = $discount_amount;
            $productDiscount = number_format($productDiscount, 2, '.', '');
            $totalAfterDiscount = $total - $productDiscount;
            $discount_info_message = $app_strings['LBL_DIRECT_AMOUNT_DISCOUNT'] . " = " . CurrencyField::convertToUserFormat($productDiscount, null, true);
        } else {
            $discount_info_message = $app_strings['LBL_NO_DISCOUNT_FOR_THIS_LINE_ITEM'];
        }
        //Product wise Discount calculation - ends
        $totalAfterDiscount = number_format($totalAfterDiscount, 2, '.', '');
        //Convert to 2 decimals
        $netprice = $totalAfterDiscount;
        //Calculate the individual tax if taxtype is individual
        if ($taxtype == 'individual') {
            $taxtotal = '0.00';
            $tax_info_message = $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . " = " . CurrencyField::convertToUserFormat($totalAfterDiscount, null, true) . " \\n";
            $tax_details = getTaxDetailsForProduct($productid, 'all', $acvid);
            for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                $tax_name = $tax_details[$tax_count]['taxname'];
                $tax_label = $tax_details[$tax_count]['taxlabel'];
                $tax_value = getInventoryProductTaxValue($focus->id, $productid, $tax_name);
                $individual_taxamount = $totalAfterDiscount * $tax_value / 100;
                $individual_taxamount = number_format($individual_taxamount, 2, '.', '');
                //Convert to 2 decimals
                $taxtotal = $taxtotal + $individual_taxamount;
                $taxtotal = number_format($taxtotal, 2, '.', '');
                //Convert to 2 decimals
                $tax_info_message .= "{$tax_label} : {$tax_value} % = " . CurrencyField::convertToUserFormat($individual_taxamount, null, true) . " \\n";
            }
            $tax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = " . CurrencyField::convertToUserFormat($taxtotal, null, true);
            $netprice = $netprice + $taxtotal;
            $netprice = number_format($netprice, 2, '.', '');
            //Convert to 2 decimals
        }
        $sc_image_tag = '';
        if ($module == 'Invoice') {
            switch ($entitytype) {
                case 'Services':
                    if (vtlib_isModuleActive('ServiceContracts')) {
                        $sc_image_tag = '<a href="index.php?module=ServiceContracts&action=EditView&service_id=' . $productid . '&sc_related_to=' . $focus->column_fields['account_id'] . '&start_date=' . DateTimeField::convertToUserFormat($focus->column_fields['invoicedate']) . '&return_module=' . $module . '&return_id=' . $focus->id . '">' . '<img border="0" src="' . vtiger_imageurl('handshake.gif', $theme) . '" title="' . getTranslatedString('LBL_ADD_NEW', $module) . " " . getTranslatedString('ServiceContracts', 'ServiceContracts') . '" style="cursor: pointer;" align="absmiddle" />' . '</a>';
                    }
                    break;
                case 'Products':
                    if (vtlib_isModuleActive('Assets')) {
                        $sc_image_tag = '<a href="index.php?module=Assets&action=EditView&invoiceid=' . $focus->id . '&product=' . $productid . '&account=' . $focus->column_fields['account_id'] . '&datesold=' . DateTimeField::convertToUserFormat($focus->column_fields['invoicedate']) . '&return_module=' . $module . '&return_id=' . $focus->id . '" onmouseout="vtlib_listview.trigger(\'invoiceasset.onmouseout\', $(this))" onmouseover="vtlib_listview.trigger(\'cell.onmouseover\', $(this))">' . '<img border="0" src="' . vtiger_imageurl('barcode.png', $theme) . '" title="' . getTranslatedString('LBL_ADD_NEW', $module) . " " . getTranslatedString('Assets', 'Assets') . '" style="cursor: pointer;" align="absmiddle" />' . '<span style="display:none;" vtmodule="Assets" vtfieldname="invoice_product" vtrecordid="' . $focus->id . '::' . $productid . '::' . $i . '" type="vtlib_metainfo"></span>' . '</a>';
                    }
                    break;
                default:
                    $sc_image_tag = '';
            }
        }
        //For Product Name
        $output .= '
			   <tr valign="top">
				<td class="crmTableRow small lineOnTop">
					' . $productname . '&nbsp;' . $sc_image_tag . '
					<br>' . $comment . '
				</td>';
        //Upto this added to display the Product name and comment
        if ($module != 'PurchaseOrder' && $hide_stock == 'no') {
            $output .= '<td class="crmTableRow small lineOnTop">' . $qtyinstock . '</td>';
        }
        $output .= '<td class="crmTableRow small lineOnTop">' . $qty . '</td>';
        $output .= '
			<td class="crmTableRow small lineOnTop" align="right">
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
				   <tr>
				   	<td align="right">' . CurrencyField::convertToUserFormat($listprice, null, true) . '</td>
				   </tr>
				   <tr>
					   <td align="right">(-)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $discount_info_message . '\'); ">' . $app_strings['LBL_DISCOUNT'] . ' : </a></b></td>
				   </tr>
				   <tr>
				   	<td align="right" nowrap>' . $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . ' : </td>
				   </tr>';
        if ($taxtype == 'individual') {
            $output .= '
				   <tr>
					   <td align="right" nowrap>(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $tax_info_message . '\');">' . $app_strings['LBL_TAX'] . ' : </a></b></td>
				   </tr>';
        }
        $output .= '
				</table>
			</td>';
        $output .= '
			<td class="crmTableRow small lineOnTop" align="right">
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
				   <tr><td align="right">' . CurrencyField::convertToUserFormat($total, null, true) . '</td></tr>
				   <tr><td align="right">' . CurrencyField::convertToUserFormat($productDiscount, null, true) . '</td></tr>
				   <tr><td align="right" nowrap>' . CurrencyField::convertToUserFormat($totalAfterDiscount, null, true) . '</td></tr>';
        if ($taxtype == 'individual') {
            $output .= '<tr><td align="right" nowrap>' . CurrencyField::convertToUserFormat($taxtotal, null, true) . '</td></tr>';
        }
        $output .= '
				</table>
			</td>';
        $output .= '<td class="crmTableRow small lineOnTop" valign="bottom" align="right">' . CurrencyField::convertToUserFormat($netprice, null, true) . '</td>';
        $output .= '</tr>';
        $netTotal = $netTotal + $netprice;
    }
    $output .= '</table>';
    //$netTotal should be equal to $focus->column_fields['hdnSubTotal']
    $netTotal = $focus->column_fields['hdnSubTotal'];
    $netTotal = number_format($netTotal, 2, '.', '');
    //Convert to 2 decimals
    //Display the total, adjustment, S&H details
    $output .= '<table width="100%" border="0" cellspacing="0" cellpadding="5" class="crmTable">';
    $output .= '<tr>';
    $output .= '<td width="88%" class="crmTableRow small" align="right"><b>' . $app_strings['LBL_NET_TOTAL'] . '</td>';
    $output .= '<td width="12%" class="crmTableRow small" align="right"><b>' . CurrencyField::convertToUserFormat($netTotal, null, true) . '</b></td>';
    $output .= '</tr>';
    //Decide discount
    $finalDiscount = '0.00';
    $final_discount_info = '0';
    //if($focus->column_fields['hdnDiscountPercent'] != '') - previously (before changing to prepared statement) the selected option (either percent or amount) will have value and the other remains empty. So we can find the non selected item by empty check. But now with prepared statement, the non selected option stored as 0
    if ($focus->column_fields['hdnDiscountPercent'] != '0') {
        $finalDiscount = $netTotal * $focus->column_fields['hdnDiscountPercent'] / 100;
        $finalDiscount = number_format($finalDiscount, 2, '.', '');
        $final_discount_info = $focus->column_fields['hdnDiscountPercent'] . " % of " . CurrencyField::convertToUserFormat($netTotal, null, true) . " = " . CurrencyField::convertToUserFormat($finalDiscount, null, true);
    } elseif ($focus->column_fields['hdnDiscountAmount'] != '0') {
        $finalDiscount = $focus->column_fields['hdnDiscountAmount'];
        $finalDiscount = number_format($finalDiscount, 2, '.', '');
        $final_discount_info = CurrencyField::convertToUserFormat($finalDiscount, null, true);
    }
    //Alert the Final Discount amount even it is zero
    $final_discount_info = $app_strings['LBL_FINAL_DISCOUNT_AMOUNT'] . " = {$final_discount_info}";
    $final_discount_info = 'onclick="alert(\'' . $final_discount_info . '\');"';
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">(-)&nbsp;<b><a href="javascript:;" ' . $final_discount_info . '>' . $app_strings['LBL_DISCOUNT'] . '</a></b></td>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">' . CurrencyField::convertToUserFormat($finalDiscount, null, true) . '</td>';
    $output .= '</tr>';
    if ($taxtype == 'group') {
        $taxtotal = '0.00';
        $final_totalAfterDiscount = $netTotal - $finalDiscount;
        $tax_info_message = $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . " = " . CurrencyField::convertToUserFormat($final_totalAfterDiscount, null, true) . " \\n";
        //First we should get all available taxes and then retrieve the corresponding tax values
        $tax_details = getAllTaxes('available', '', 'edit', $focus->id);
        $ipr_cols = $adb->getColumnNames('vtiger_inventoryproductrel');
        //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
            $tax_name = $tax_details[$tax_count]['taxname'];
            $tax_label = $tax_details[$tax_count]['taxlabel'];
            if (in_array($tax_name, $ipr_cols)) {
                $tax_value = $adb->query_result($result, 0, $tax_name);
            } else {
                $tax_value = $tax_details[$tax_count]['percentage'];
            }
            if ($tax_value == '' || $tax_value == 'NULL') {
                $tax_value = '0.00';
            }
            $taxamount = ($netTotal - $finalDiscount) * $tax_value / 100;
            $taxtotal = $taxtotal + $taxamount;
            $tax_info_message .= "{$tax_label} : {$tax_value} % = " . CurrencyField::convertToUserFormat($taxtotal, null, true) . " \\n";
        }
        $tax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = " . CurrencyField::convertToUserFormat($taxtotal, null, true);
        $output .= '<tr>';
        $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $tax_info_message . '\');">' . $app_strings['LBL_TAX'] . '</a></b></td>';
        $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($taxtotal, null, true) . '</td>';
        $output .= '</tr>';
    }
    $shAmount = $focus->column_fields['hdnS_H_Amount'] != '' ? $focus->column_fields['hdnS_H_Amount'] : '0.00';
    $shAmount = number_format($shAmount, 2, '.', '');
    //Convert to 2 decimals
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b>' . $app_strings['LBL_SHIPPING_AND_HANDLING_CHARGES'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($shAmount, null, true) . '</td>';
    $output .= '</tr>';
    //calculate S&H tax
    $shtaxtotal = '0.00';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $shtax_details = getAllTaxes('available', 'sh', 'edit', $focus->id);
    //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
    $shtax_info_message = $app_strings['LBL_SHIPPING_AND_HANDLING_CHARGE'] . " = " . CurrencyField::convertToUserFormat($shAmount, null, true) . "\\n";
    for ($shtax_count = 0; $shtax_count < count($shtax_details); $shtax_count++) {
        $shtax_name = $shtax_details[$shtax_count]['taxname'];
        $shtax_label = $shtax_details[$shtax_count]['taxlabel'];
        $shtax_percent = getInventorySHTaxPercent($focus->id, $shtax_name);
        $shtaxamount = $shAmount * $shtax_percent / 100;
        $shtaxamount = number_format($shtaxamount, 2, '.', '');
        $shtaxtotal = $shtaxtotal + $shtaxamount;
        $shtax_info_message .= "{$shtax_label} : {$shtax_percent} % = " . CurrencyField::convertToUserFormat($shtaxamount, null, true) . " \\n";
    }
    $shtax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = " . CurrencyField::convertToUserFormat($shtaxtotal, null, true);
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $shtax_info_message . '\')">' . $app_strings['LBL_TAX_FOR_SHIPPING_AND_HANDLING'] . '</a></b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($shtaxtotal, null, true) . '</td>';
    $output .= '</tr>';
    $adjustment = $focus->column_fields['txtAdjustment'] != '' ? $focus->column_fields['txtAdjustment'] : '0.00';
    $adjustment = number_format($adjustment, 2, '.', '');
    //Convert to 2 decimals
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small">&nbsp;<b>' . $app_strings['LBL_ADJUSTMENT'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . CurrencyField::convertToUserFormat($adjustment, null, true) . '</td>';
    $output .= '</tr>';
    $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0.00';
    $grandTotal = number_format($grandTotal, 2, '.', '');
    //Convert to 2 decimals
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop"><b>' . $app_strings['LBL_GRAND_TOTAL'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">' . CurrencyField::convertToUserFormat($grandTotal, null, true) . '</td>';
    $output .= '</tr>';
    $output .= '</table>';
    $log->debug("Exiting getDetailAssociatedProducts method ...");
    return $output;
}
Ejemplo n.º 9
0
 function getAssociatedProducts($module, $focus, $seid = '')
 {
     $log = vglobal('log');
     $log->debug("Entering Calculations_Record_Model getAssociatedProducts(" . $module . "," . get_class($focus) . "," . $seid . "='') method ...");
     $adb = PearDatabase::getInstance();
     $output = '';
     global $theme;
     $no_of_decimal_places = getCurrencyDecimalPlaces();
     $theme_path = "themes/" . $theme . "/";
     $image_path = $theme_path . "images/";
     $product_Detail = array();
     if ($module == 'Calculations') {
         $query = "SELECT\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,\n\t\t\t\t\t\t\t\t\tvtiger_calculationsproductrel.listprice,\n\t\t\t\t\t\t\t\t\tvtiger_calculationsproductrel.description AS product_description,\n\t\t\t\t\t\t\t\t\tvtiger_calculationsproductrel.*,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_products.usageunit,\n\t\t\t\t\t\t\t\t\tvtiger_service.service_usageunit\n\t\t\t\t\t\t\t\t\tFROM vtiger_calculationsproductrel\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_calculationsproductrel.productid\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_products\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_products.productid=vtiger_calculationsproductrel.productid\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_service\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_service.serviceid=vtiger_calculationsproductrel.productid\n\t\t\t\t\t\t\t\t\tWHERE id=?\n\t\t\t\t\t\t\t\t\tORDER BY sequence_no";
         $params = array($focus->id);
     } elseif ($module == 'Products') {
         $query = "SELECT\n\t\t\t\t\t\t\t\t\tvtiger_products.productid,\n\t\t\t\t\t\t\t\t\tvtiger_products.productcode,\n\t\t\t\t\t\t\t\t\tvtiger_products.productname,\n\t\t\t\t\t\t\t\t\tvtiger_products.unit_price,\n\t\t\t\t\t\t\t\t\tvtiger_products.usageunit,\n\t\t\t\t\t\t\t\t\tvtiger_products.qtyinstock,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_crmentity.description AS product_description,\n\t\t\t\t\t\t\t\t\t'Products' AS entitytype\n\t\t\t\t\t\t\t\t\tFROM vtiger_products\n\t\t\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_crmentity.crmid=vtiger_products.productid\n\t\t\t\t\t\t\t\t\tWHERE vtiger_crmentity.deleted=0\n\t\t\t\t\t\t\t\t\t\t\tAND productid=?";
         $params = array($seid);
     } elseif ($module == 'Services') {
         $query = "SELECT\n\t\t\t\t\t\t\t\t\tvtiger_service.serviceid AS productid,\n\t\t\t\t\t\t\t\t\t'NA' AS productcode,\n\t\t\t\t\t\t\t\t\tvtiger_service.servicename AS productname,\n\t\t\t\t\t\t\t\t\tvtiger_service.unit_price AS unit_price,\n\t\t\t\t\t\t\t\t\tvtiger_service.service_usageunit AS usageunit,\n\t\t\t\t\t\t\t\t\t'NA' AS qtyinstock,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_crmentity.description AS product_description,\n\t\t\t\t\t\t\t\t\t'Services' AS entitytype\n\t\t\t\t\t\t\t\t\tFROM vtiger_service\n\t\t\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_crmentity.crmid=vtiger_service.serviceid\n\t\t\t\t\t\t\t\t\tWHERE vtiger_crmentity.deleted=0\n\t\t\t\t\t\t\t\t\t\t\tAND serviceid=?";
         $params = array($seid);
     }
     $result = $adb->pquery($query, $params);
     $num_rows = $adb->num_rows($result);
     for ($i = 1; $i <= $num_rows; $i++) {
         $deleted = $adb->query_result($result, $i - 1, 'deleted');
         $hdnProductId = $adb->query_result($result, $i - 1, 'productid');
         $hdnProductcode = $adb->query_result($result, $i - 1, 'productcode');
         $productname = $adb->query_result($result, $i - 1, 'productname');
         $productdescription = $adb->query_result($result, $i - 1, 'product_description');
         $comment = decode_html($adb->query_result($result, $i - 1, 'comment'));
         $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock');
         $qty = $adb->query_result($result, $i - 1, 'quantity');
         $unitprice = $adb->query_result($result, $i - 1, 'unit_price');
         $listprice = $adb->query_result($result, $i - 1, 'listprice');
         $entitytype = $adb->query_result($result, $i - 1, 'entitytype');
         if ($entitytype == 'Services') {
             $usageunit = vtranslate($adb->query_result($result, $i - 1, 'service_usageunit'), $entitytype);
         } else {
             $usageunit = vtranslate($adb->query_result($result, $i - 1, 'usageunit'), $entitytype);
         }
         $rbh = $adb->query_result($result, $i - 1, 'rbh');
         $purchase = $adb->query_result($result, $i - 1, 'purchase');
         $margin = $adb->query_result($result, $i - 1, 'margin');
         $marginp = $adb->query_result($result, $i - 1, 'marginp');
         if ($deleted || !isset($deleted)) {
             $product_Detail[$i]['productDeleted' . $i] = true;
         } elseif (!$deleted) {
             $product_Detail[$i]['productDeleted' . $i] = false;
         }
         if (!empty($entitytype)) {
             $product_Detail[$i]['entityType' . $i] = $entitytype;
         }
         if ($listprice == '') {
             $listprice = $unitprice;
         }
         if ($qty == '') {
             $qty = 1;
         }
         //calculate productTotal
         $productTotal = $qty * $listprice;
         //Delete link in First column
         if ($i != 1) {
             $product_Detail[$i]['delRow' . $i] = "Del";
         }
         if (empty($focus->mode) && $seid != '') {
             $sub_prod_query = $adb->pquery("SELECT crmid as prod_id from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($seid));
         } else {
             $sub_prod_query = $adb->pquery("SELECT productid as prod_id from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i));
         }
         $subprodid_str = '';
         $subprodname_str = '';
         $subProductArray = array();
         if ($adb->num_rows($sub_prod_query) > 0) {
             for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                 $sprod_id = $adb->query_result($sub_prod_query, $j, 'prod_id');
                 $sprod_name = $subProductArray[] = getProductName($sprod_id);
                 $str_sep = "";
                 if ($j > 0) {
                     $str_sep = ":";
                 }
                 $subprodid_str .= $str_sep . $sprod_id;
                 $subprodname_str .= $str_sep . " - " . $sprod_name;
             }
         }
         $subprodname_str = str_replace(":", "<br>", $subprodname_str);
         $product_Detail[$i]['subProductArray' . $i] = $subProductArray;
         $product_Detail[$i]['hdnProductId' . $i] = $hdnProductId;
         $product_Detail[$i]['productName' . $i] = from_html($productname);
         /* Added to fix the issue Product Pop-up name display*/
         if ($_REQUEST['action'] == 'CreateSOPDF' || $_REQUEST['action'] == 'CreatePDF' || $_REQUEST['action'] == 'SendPDFMail') {
             $product_Detail[$i]['productName' . $i] = htmlspecialchars($product_Detail[$i]['productName' . $i]);
         }
         $product_Detail[$i]['hdnProductcode' . $i] = $hdnProductcode;
         $product_Detail[$i]['productDescription' . $i] = from_html($productdescription);
         if ($module == 'Potentials' || $module == 'Products' || $module == 'Services') {
             $product_Detail[$i]['comment' . $i] = $productdescription;
         } else {
             $product_Detail[$i]['comment' . $i] = $comment;
         }
         $listprice = number_format($listprice, $no_of_decimal_places, '.', '');
         $product_Detail[$i]['qty' . $i] = decimalFormat($qty);
         $product_Detail[$i]['listPrice' . $i] = $listprice;
         $product_Detail[$i]['unitPrice' . $i] = number_format($unitprice, $no_of_decimal_places, '.', '');
         $product_Detail[$i]['usageUnit' . $i] = $usageunit;
         $product_Detail[$i]['productTotal' . $i] = number_format($productTotal, $no_of_decimal_places, '.', '');
         $product_Detail[$i]['subproduct_ids' . $i] = $subprodid_str;
         $product_Detail[$i]['subprod_names' . $i] = $subprodname_str;
         $product_Detail[$i]['rbh' . $i] = number_format($rbh, $no_of_decimal_places, '.', '');
         $product_Detail[$i]['purchase' . $i] = number_format($purchase, $no_of_decimal_places, '.', '');
         $product_Detail[$i]['margin' . $i] = number_format($margin, $no_of_decimal_places, '.', '');
         $product_Detail[$i]['marginp' . $i] = number_format($marginp, $no_of_decimal_places, '.', '');
     }
     $log->debug("Exiting Calculations_Record_Model getAssociatedProducts method ...");
     return $product_Detail;
 }
Ejemplo n.º 10
0
function getValue($uitype, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, $mode, $popuptype, $returnset = '', $viewid = '')
{
    global $log;
    global $app_strings;
    //changed by dingjianting on 2007-11-05 for php5.2.x
    $log->debug("Entering getValue() method ...");
    global $adb, $current_user;
    if ($uitype == 10) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        if ($temp_val != "") {
            $value = "";
            $module_entityname = "";
            $modulename_lower = substr($fieldname, 0, -2);
            $modulename = ucfirst($modulename_lower);
            $modulesid = $modulename_lower . "id";
            $tablename = "ec_" . $modulename_lower;
            $entityname = substr($fieldname, 0, -3) . "name";
            $query = "SELECT {$entityname} FROM {$tablename} WHERE {$modulesid}='" . $temp_val . "' and deleted=0";
            $fldmod_result = $adb->query($query);
            $rownum = $adb->num_rows($fldmod_result);
            if ($rownum > 0) {
                $value = $adb->query_result($fldmod_result, 0, $entityname);
            }
        } else {
            $value = '';
        }
    } elseif ($uitype == 52 || $uitype == 53 || $uitype == 77) {
        $value = $adb->query_result($list_result, $list_result_count, 'user_name');
    } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23 || $uitype == 70) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        if (isValidDate($temp_val)) {
            $value = getDisplayDate($temp_val);
        } else {
            $value = '';
        }
    } elseif ($uitype == 33) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        $value = str_ireplace(' |##| ', ', ', $temp_val);
    } elseif ($uitype == 17) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        $value = '<a href="http://' . $temp_val . '" target="_blank">' . $temp_val . '</a>';
    } elseif ($uitype == 13 || $uitype == 104) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        $value = '<a href="' . getComposeMailUrl($temp_val) . '" target="_blank">' . $temp_val . '</a>';
    } elseif ($uitype == 56) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        if ($temp_val == 1) {
            $value = 'yes';
        } else {
            $value = 'no';
        }
        //changed by dingjianting on 2006-10-15 for simplized chinese
        if (isset($app_strings[$value])) {
            $value = $app_strings[$value];
        }
    } elseif ($uitype == 51 || $uitype == 73 || $uitype == 50) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        if ($temp_val != '') {
            $value = getAccountName($temp_val);
        } else {
            $value = '';
        }
    } elseif ($uitype == 59) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        if ($temp_val != '') {
            $value = getProductName($temp_val);
        } else {
            $value = '';
        }
    } elseif ($uitype == 76) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        if ($temp_val != '') {
            $value = getPotentialName($temp_val);
        } else {
            $value = '';
        }
    } elseif ($uitype == 80) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        if ($temp_val != '') {
            $value = getSoName($temp_val);
        } else {
            $value = '';
        }
    } elseif ($uitype == 1004) {
        $value = $adb->query_result($list_result, $list_result_count, 'smcreatorid');
        $value = getUserName($value);
    } elseif ($uitype == 1007) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        $value = getApproveStatusById($temp_val);
    } elseif ($uitype == 1008) {
        $value = $adb->query_result($list_result, $list_result_count, 'approvedby');
        $value = getUserName($value);
    } elseif ($uitype == 1004) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        $value = getUserName($temp_val);
    } elseif ($uitype == 1007) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        if ($temp_val == '1') {
            $value = $app_strings["already_approved"];
        } elseif ($temp_val == '-1') {
            $value = $app_strings["unapproved"];
        } elseif ($temp_val == '-2') {
            $value = $app_strings["Rejected"];
        } else {
            $value = $app_strings["approving"];
        }
    } elseif ($uitype == 1008) {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        $value = getUserName($temp_val);
    } else {
        $temp_val = $adb->query_result($list_result, $list_result_count, $fieldname);
        if ($fieldname != $focus->list_link_field) {
            $value = $temp_val;
        } else {
            if ($mode == "list") {
                $tabname = getParentTab();
                $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&parenttab=' . $tabname . '">' . $temp_val . '</a>';
            } elseif ($mode == "search") {
                if ($popuptype == "specific") {
                    $temp_val = str_replace("'", '\\"', $temp_val);
                    $temp_val = popup_from_html($temp_val);
                    //Added to avoid the error when select SO from Invoice through AjaxEdit
                    if ($module == 'Salesorders') {
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_specific("' . $entity_id . '", "' . br2nl($temp_val) . '","' . $_REQUEST['form'] . '");\'>' . $temp_val . '</a>';
                    } else {
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_specific("' . $entity_id . '", "' . br2nl($temp_val) . '");\'>' . $temp_val . '</a>';
                    }
                } elseif ($popuptype == "detailview") {
                    $temp_val = popup_from_html($temp_val);
                    $focus->record_id = $_REQUEST['recordid'];
                    if ($_REQUEST['return_module'] == "Calendar") {
                        $value = '<a href="javascript:window.close();" id="calendarCont' . $entity_id . '" LANGUAGE=javascript onclick=\'add_data_to_relatedlist_incal("' . $entity_id . '","' . $temp_val . '");\'>' . $temp_val . '</a>';
                    } else {
                        $value = '<a href="javascript:window.close();" onclick=\'add_data_to_relatedlist("' . $entity_id . '","' . $focus->record_id . '","' . $module . '");\'>' . $temp_val . '</a>';
                    }
                } elseif ($popuptype == "formname_specific") {
                    $temp_val = popup_from_html($temp_val);
                    $value = '<a href="javascript:window.close();" onclick=\'set_return_formname_specific("' . $_REQUEST['form'] . '", "' . $entity_id . '", "' . br2nl($temp_val) . '");\'>' . $temp_val . '</a>';
                } elseif ($popuptype == "inventory_prod") {
                    $row_id = $_REQUEST['curr_row'];
                    //To get all the tax types and values and pass it to product details
                    $tax_str = '';
                    $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                    $qty_stock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
                    $productcode = $adb->query_result($list_result, $list_result_count, 'productcode');
                    $temp_val = popup_from_html($temp_val);
                    $value = '<a href="javascript:window.close();" onclick=\'set_return_inventory("' . $entity_id . '", "' . br2nl($temp_val) . '", "' . $unitprice . '", "' . $qty_stock . '","' . $tax_str . '","' . $row_id . '","' . $productcode . '");\'>' . $temp_val . '</a>';
                } elseif ($popuptype == "inventory_prods") {
                    $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                    $qty_stock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
                    $productcode = $adb->query_result($list_result, $list_result_count, 'productcode');
                    $serialno = $adb->query_result($list_result, $list_result_count, 'serialno');
                    $temp_val = popup_from_html($temp_val);
                    $value = $temp_val . '<input type="hidden" name="productname_' . $entity_id . '" id="productname_' . $entity_id . '" value="' . $temp_val . '"><input type="hidden" name="listprice_' . $entity_id . '" id="listprice_' . $entity_id . '" value="' . $unitprice . '"><input type="hidden" name="qtyinstock_' . $entity_id . '" id="qtyinstock_' . $entity_id . '" value="' . $qty_stock . '"><input type="hidden" id="productcode_' . $entity_id . '" name="productcode_' . $entity_id . '" value="' . $productcode . '"><input type="hidden" id="serialno_' . $entity_id . '" name="serialno_' . $entity_id . '" value="' . $serialno . '">';
                } elseif ($popuptype == "salesorder_prod") {
                    $row_id = $_REQUEST['curr_row'];
                    $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                    $temp_val = popup_from_html($temp_val);
                    $producttype = $_REQUEST['producttype'];
                    $value = '<a href="javascript:window.close();" onclick=\'set_return_inventory_so("' . $entity_id . '", "' . br2nl($temp_val) . '", "' . $unitprice . '", "' . $row_id . '","' . $producttype . '");\'>' . $temp_val . '</a>';
                } elseif ($popuptype == "inventory_prod_po") {
                    $row_id = $_REQUEST['curr_row'];
                    $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                    $productcode = $adb->query_result($list_result, $list_result_count, 'productcode');
                    $temp_val = popup_from_html($temp_val);
                    $value = '<a href="javascript:window.close();" onclick=\'set_return_inventory_po("' . $entity_id . '", "' . br2nl($temp_val) . '", "' . $unitprice . '", "' . $productcode . '","' . $row_id . '"); \'>' . $temp_val . '</a>';
                } elseif ($popuptype == "inventory_prod_noprice") {
                    $row_id = $_REQUEST['curr_row'];
                    $temp_val = popup_from_html($temp_val);
                    $qtyinstock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
                    $productcode = $adb->query_result($list_result, $list_result_count, 'productcode');
                    $value = '<a href="javascript:window.close();" onclick=\'set_return_inventory_noprice("' . $entity_id . '", "' . br2nl($temp_val) . '","' . $row_id . '","' . $qtyinstock . '","' . $productcode . '");\'>' . $temp_val . '</a>';
                } elseif ($popuptype == "inventory_prod_check") {
                    $row_id = $_REQUEST['curr_row'];
                    $temp_val = popup_from_html($temp_val);
                    $productcode = $adb->query_result($list_result, $list_result_count, 'productcode');
                    $usageunit = $adb->query_result($list_result, $list_result_count, 'usageunit');
                    $qtyinstock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
                    $value = '<a href="javascript:window.close();" onclick=\'set_return_inventory_check("' . $entity_id . '", "' . br2nl($temp_val) . '","' . $row_id . '","' . $productcode . '","' . $usageunit . '","' . $qtyinstock . '"); \'>' . $temp_val . '</a>';
                } elseif ($popuptype == "specific_account_address") {
                    require_once 'modules/Accounts/Accounts.php';
                    $acct_focus = new Accounts();
                    $acct_focus->retrieve_entity_info($entity_id, "Accounts");
                    $temp_val = popup_from_html($temp_val);
                    $value = '<a href="javascript:window.close();" onclick=\'set_return_address("' . $entity_id . '", "' . br2nl($temp_val) . '", "' . br2nl($acct_focus->column_fields['bill_street']) . '", "' . br2nl($acct_focus->column_fields['ship_street']) . '", "' . br2nl($acct_focus->column_fields['bill_city']) . '", "' . br2nl($acct_focus->column_fields['ship_city']) . '", "' . br2nl($acct_focus->column_fields['bill_state']) . '", "' . br2nl($acct_focus->column_fields['ship_state']) . '", "' . br2nl($acct_focus->column_fields['bill_code']) . '", "' . br2nl($acct_focus->column_fields['ship_code']) . '", "' . br2nl($acct_focus->column_fields['bill_country']) . '", "' . br2nl($acct_focus->column_fields['ship_country']) . '","' . br2nl($acct_focus->column_fields['bill_pobox']) . '", "' . br2nl($acct_focus->column_fields['ship_pobox']) . '");\'>' . $temp_val . '</a>';
                } elseif ($popuptype == "specific_contact_account_address") {
                    require_once 'modules/Accounts/Accounts.php';
                    $acct_focus = new Accounts();
                    $acct_focus->retrieve_entity_info($entity_id, "Accounts");
                    $temp_val = popup_from_html($temp_val);
                    $value = '<a href="javascript:window.close();" onclick=\'set_return_contact_address("' . $entity_id . '", "' . br2nl($temp_val) . '", "' . br2nl($acct_focus->column_fields['bill_street']) . '", "' . br2nl($acct_focus->column_fields['ship_street']) . '", "' . br2nl($acct_focus->column_fields['bill_city']) . '", "' . br2nl($acct_focus->column_fields['ship_city']) . '", "' . br2nl($acct_focus->column_fields['bill_state']) . '", "' . br2nl($acct_focus->column_fields['ship_state']) . '", "' . br2nl($acct_focus->column_fields['bill_code']) . '", "' . br2nl($acct_focus->column_fields['ship_code']) . '", "' . br2nl($acct_focus->column_fields['bill_country']) . '", "' . br2nl($acct_focus->column_fields['ship_country']) . '","' . br2nl($acct_focus->column_fields['bill_pobox']) . '", "' . br2nl($acct_focus->column_fields['ship_pobox']) . '");\'>' . $temp_val . '</a>';
                } elseif ($popuptype == "specific_potential_account_address") {
                    $acntid = $adb->query_result($list_result, $list_result_count, "accountid");
                    if ($acntid != "") {
                        //require_once('modules/Accounts/Accounts.php');
                        //$acct_focus = new Accounts();
                        //$acct_focus->retrieve_entity_info($acntid,"Accounts");
                        $account_name = getAccountName($acntid);
                        $temp_val = popup_from_html($temp_val);
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_address("' . $entity_id . '", "' . br2nl($temp_val) . '", "' . $acntid . '", "' . br2nl($account_name) . '");\'>' . $temp_val . '</a>';
                    } else {
                        $temp_val = popup_from_html($temp_val);
                        $value = '<a href="javascript:window.close();" >' . $temp_val . '</a>';
                    }
                } elseif ($popuptype == "set_return_emails") {
                    $name = $adb->query_result($list_result, $list_result_count, "lastname");
                    $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
                    if ($emailaddress == '') {
                        $emailaddress = $adb->query_result($list_result, $list_result_count, "msn");
                    }
                    $where = isset($_REQUEST['where']) ? $_REQUEST['where'] : "";
                    $value = '<a href="javascript:;" onclick=\'return set_return_emails("' . $where . '","' . $name . '","' . $emailaddress . '"); \'>' . $name . '</a>';
                } elseif ($popuptype == "set_return_mobiles") {
                    //$firstname=$adb->query_result($list_result,$list_result_count,"first_name");
                    $contactname = $adb->query_result($list_result, $list_result_count, "lastname");
                    $mobile = $adb->query_result($list_result, $list_result_count, "mobile");
                    //changed by dingjianting on 2006-11-9 for simplized chinese
                    $value = '<a href="#" onclick=\'return set_return_mobiles(' . $entity_id . ',"' . $contactname . '","' . $mobile . '"); \'>' . $contactname . '</a>';
                } elseif ($popuptype == "set_return_usermobiles") {
                    //$firstname=$adb->query_result($list_result,$list_result_count,"first_name");
                    $lastname = $adb->query_result($list_result, $list_result_count, "last_name");
                    $mobile = $adb->query_result($list_result, $list_result_count, "phone_mobile");
                    //changed by dingjianting on 2006-11-9 for simplized chinese
                    $value = '<a href="#" onclick=\'return set_return_mobiles(' . $entity_id . ',"' . $lastname . '","' . $mobile . '"); \'>' . $lastname . '</a>';
                } else {
                    $temp_val = str_replace("'", '\\"', $temp_val);
                    $temp_val = popup_from_html($temp_val);
                    $value = '<a href="javascript:window.close();" onclick=\'set_return("' . $entity_id . '", "' . br2nl($temp_val) . '");\'>' . $temp_val . '</a>';
                }
            }
        }
    }
    $log->debug("Exiting getValue method ...");
    return $value;
}
Ejemplo n.º 11
0
    $smarty->assign("UPDATEINFO", updateInfo($focus->id));
    $associated_prod = getAssociatedProducts("Invoice", $focus);
    $smarty->assign("ASSOCIATEDPRODUCTS", $associated_prod);
    $smarty->assign("MODE", $focus->mode);
} elseif (isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
    $associated_prod = $INVOICE_associated_prod;
    $smarty->assign("AVAILABLE_PRODUCTS", 'true');
    $smarty->assign("MODE", $focus->mode);
} elseif (isset($_REQUEST['product_id']) && $_REQUEST['product_id'] != '' || isset($_REQUEST['opportunity_id']) && $_REQUEST['opportunity_id'] != '') {
    $smarty->assign("ASSOCIATEDPRODUCTS", $associated_prod);
    $InvTotal = getInventoryTotal($_REQUEST['return_module'], $_REQUEST['return_id']);
    $smarty->assign("MODE", $focus->mode);
    //this is to display the Product Details in first row when we create new PO from Product relatedlist
    if ($_REQUEST['return_module'] == 'Products') {
        $smarty->assign("PRODUCT_ID", vtlib_purify($_REQUEST['product_id']));
        $smarty->assign("PRODUCT_NAME", getProductName($_REQUEST['product_id']));
        $smarty->assign("UNIT_PRICE", vtlib_purify($_REQUEST['product_id']));
        $smarty->assign("QTY_IN_STOCK", getPrdQtyInStck($_REQUEST['product_id']));
        $smarty->assign("VAT_TAX", getProductTaxPercentage("VAT", $_REQUEST['product_id']));
        $smarty->assign("SALES_TAX", getProductTaxPercentage("Sales", $_REQUEST['product_id']));
        $smarty->assign("SERVICE_TAX", getProductTaxPercentage("Service", $_REQUEST['product_id']));
    }
}
if (isset($cust_fld)) {
    $smarty->assign("CUSTOMFIELD", $cust_fld);
}
$smarty->assign("ASSOCIATEDPRODUCTS", $associated_prod);
if (isset($_REQUEST['return_module'])) {
    $smarty->assign("RETURN_MODULE", vtlib_purify($_REQUEST['return_module']));
} else {
    $smarty->assign("RETURN_MODULE", "Invoice");
Ejemplo n.º 12
0
function getListViewEntries2($focus, $module, $list_result, $navigation_array, $relatedlist = '', $returnset = '', $edit_action = 'EditView', $del_action = 'Delete', $oCv = '', $page = '', $selectedfields = '', $contRelatedfields = '', $skipActions = false)
{
    global $log;
    global $mod_strings;
    $log->debug("Entering getListViewEntries(" . get_class($focus) . "," . $module . "," . $list_result . "," . $navigation_array . "," . $relatedlist . "," . $returnset . "," . $edit_action . "," . $del_action . "," . (is_object($oCv) ? get_class($oCv) : $oCv) . ") method ...");
    $tabname = getParentTab();
    global $adb, $current_user;
    global $app_strings;
    $noofrows = $adb->num_rows($list_result);
    $list_block = array();
    global $theme;
    $evt_status = '';
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    //getting the vtiger_fieldtable entries from database
    $tabid = getTabid($module);
    //added for vtiger_customview 27/5
    if ($oCv) {
        if (isset($oCv->list_fields)) {
            $focus->list_fields = $oCv->list_fields;
        }
    }
    if (is_array($selectedfields) && $selectedfields != '') {
        $focus->list_fields = $selectedfields;
    }
    // Remove fields which are made inactive
    $focus->filterInactiveFields($module);
    //Added to reduce the no. of queries logging for non-admin user -- by minnie-start
    $field_list = array();
    $j = 0;
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    foreach ($focus->list_fields as $name => $tableinfo) {
        $fieldname = $focus->list_fields_name[$name];
        if ($oCv) {
            if (isset($oCv->list_fields_name)) {
                $fieldname = $oCv->list_fields_name[$name];
            }
        }
        if ($fieldname == 'accountname' && $module != 'Accounts') {
            $fieldname = 'account_id';
        }
        if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
            $fieldname = 'contact_id';
        }
        if ($fieldname == 'productname' && $module != 'Products') {
            $fieldname = 'product_id';
        }
        array_push($field_list, $fieldname);
        $j++;
    }
    $field = array();
    if ($is_admin == false) {
        if ($module == 'Emails') {
            $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
            $params = array($tabid);
        } else {
            $profileList = getCurrentUserProfileList();
            $params = array();
            $query = "SELECT DISTINCT vtiger_field.fieldname\r\n\t\t\t\tFROM vtiger_field\r\n\t\t\t\tINNER JOIN vtiger_profile2field\r\n\t\t\t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\r\n\t\t\t\tINNER JOIN vtiger_def_org_field\r\n\t\t\t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid";
            if ($module == "Calendar") {
                $query .= " WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
            } else {
                $query .= " WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
                array_push($params, $tabid);
            }
            $query .= " AND vtiger_profile2field.visible = 0\r\n\t\t\t\t\tAND vtiger_profile2field.visible = 0\r\n\t\t\t\t\tAND vtiger_def_org_field.visible = 0\r\n\t\t\t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\r\n\t\t\t\t\tAND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ")";
            array_push($params, $profileList, $field_list);
        }
        $result = $adb->pquery($query, $params);
        for ($k = 0; $k < $adb->num_rows($result); $k++) {
            $field[] = $adb->query_result($result, $k, "fieldname");
        }
    }
    //constructing the uitype and columnname array
    $ui_col_array = array();
    $params = array();
    $query = "SELECT uitype, columnname, fieldname FROM vtiger_field ";
    if ($module == "Calendar") {
        $query .= " WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
    } else {
        $query .= " WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
        array_push($params, $tabid);
    }
    $query .= " AND fieldname IN (" . generateQuestionMarks($field_list) . ") ";
    array_push($params, $field_list);
    $result = $adb->pquery($query, $params);
    $num_rows = $adb->num_rows($result);
    for ($i = 0; $i < $num_rows; $i++) {
        $tempArr = array();
        $uitype = $adb->query_result($result, $i, 'uitype');
        $columnname = $adb->query_result($result, $i, 'columnname');
        $field_name = $adb->query_result($result, $i, 'fieldname');
        $tempArr[$uitype] = $columnname;
        $ui_col_array[$field_name] = $tempArr;
    }
    //end
    if ($navigation_array['start'] != 0) {
        for ($i = 1; $i <= $noofrows; $i++) {
            $list_header = array();
            //Getting the entityid
            if ($module != 'Users') {
                $entity_id = $adb->query_result($list_result, $i - 1, "crmid");
                $owner_id = $adb->query_result($list_result, $i - 1, "smownerid");
            } else {
                $entity_id = $adb->query_result($list_result, $i - 1, "id");
            }
            // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
            // begin: Armando Lüscher 05.07.2005 -> §priority
            // Code contri buted by fredy Desc: Set Priority color
            $priority = $adb->query_result($list_result, $i - 1, "priority");
            $font_color_high = "color:#00DD00;";
            $font_color_medium = "color:#DD00DD;";
            $P_FONT_COLOR = "";
            switch ($priority) {
                case 'High':
                    $P_FONT_COLOR = $font_color_high;
                    break;
                case 'Medium':
                    $P_FONT_COLOR = $font_color_medium;
                    break;
                default:
                    $P_FONT_COLOR = "";
            }
            //end: Armando Lüscher 05.07.2005 -> §priority
            foreach ($focus->list_fields as $name => $tableinfo) {
                $fieldname = $focus->list_fields_name[$name];
                //added for vtiger_customview 27/5
                if ($oCv) {
                    if (isset($oCv->list_fields_name)) {
                        $fieldname = $oCv->list_fields_name[$name];
                        if ($fieldname == 'accountname' && $module != 'Accounts') {
                            $fieldname = 'account_id';
                        }
                        if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
                            $fieldname = 'contact_id';
                        }
                        if ($fieldname == 'productname' && $module != 'Products') {
                            $fieldname = 'product_id';
                        }
                    } else {
                        $fieldname = $focus->list_fields_name[$name];
                    }
                } else {
                    $fieldname = $focus->list_fields_name[$name];
                    if ($fieldname == 'accountname' && $module != 'Accounts') {
                        $fieldname = 'account_id';
                    }
                    if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
                        $fieldname = 'contact_id';
                    }
                    if ($fieldname == 'productname' && $module != 'Products') {
                        $fieldname = 'product_id';
                    }
                }
                if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $fieldname == '' || $name == 'Close' && $module == 'Calendar') {
                    if ($fieldname == '') {
                        $table_name = '';
                        $column_name = '';
                        foreach ($tableinfo as $tablename => $colname) {
                            $table_name = $tablename;
                            $column_name = $colname;
                        }
                        $value = $adb->query_result($list_result, $i - 1, $colname);
                    } else {
                        if ($module == 'Calendar') {
                            $act_id = $adb->query_result($list_result, $i - 1, "activityid");
                            $cal_sql = "select activitytype from vtiger_activity where activityid=?";
                            $cal_res = $adb->pquery($cal_sql, array($act_id));
                            if ($adb->num_rows($cal_res) >= 0) {
                                $activitytype = $adb->query_result($cal_res, 0, "activitytype");
                            }
                        }
                        if (($module == 'Calendar' || $module == 'Emails' || $module == 'HelpDesk' || $module == 'Invoice' || $module == 'Leads' || $module == 'Contacts') && ($fieldname == 'parent_id' || $name == 'Contact Name' || $name == 'Close' || $fieldname == 'firstname')) {
                            if ($module == 'Calendar') {
                                if ($fieldname == 'status') {
                                    if ($activitytype == 'Task') {
                                        $fieldname = 'taskstatus';
                                    } else {
                                        $fieldname = 'eventstatus';
                                    }
                                }
                                if ($activitytype == 'Task') {
                                    if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
                                        $has_permission = 'yes';
                                    } else {
                                        $has_permission = 'no';
                                    }
                                } else {
                                    if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
                                        $has_permission = 'yes';
                                    } else {
                                        $has_permission = 'no';
                                    }
                                }
                            }
                            if ($module != 'Calendar' || $module == 'Calendar' && $has_permission == 'yes') {
                                if ($fieldname == 'parent_id') {
                                    $value = getRelatedTo($module, $list_result, $i - 1);
                                }
                                if ($name == 'Contact Name') {
                                    $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                    $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                    $value = "";
                                    //Added to get the contactname for activities custom view - t=2190
                                    if ($contact_id != '' && !empty($contact_name)) {
                                        $contact_name = getContactName($contact_id);
                                    }
                                    if ($contact_name != "" && $contact_id != 'NULL') {
                                        // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
                                        $value = "<a href='index.php?module=Contacts&action=DetailView&parenttab=" . $tabname . "&record=" . $contact_id . "' style='" . $P_FONT_COLOR . "'>" . $contact_name . "</a>";
                                        // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
                                    }
                                }
                                if ($fieldname == "firstname") {
                                    $first_name = textlength_check($adb->query_result($list_result, $i - 1, "firstname"));
                                    $value = '<a href="index.php?action=DetailView&module=' . $module . '&parenttab=' . $tabname . '&record=' . $entity_id . '">' . $first_name . '</a>';
                                }
                                if ($name == 'Close') {
                                    $status = $adb->query_result($list_result, $i - 1, "status");
                                    $activityid = $adb->query_result($list_result, $i - 1, "activityid");
                                    if (empty($activityid)) {
                                        $activityid = $adb->query_result($list_result, $i - 1, "tmp_activity_id");
                                    }
                                    $activitytype = $adb->query_result($list_result, $i - 1, "activitytype");
                                    // TODO - Picking activitytype when it is not present in the Custom View.
                                    // Going forward, this column should be added to the select list if not already present as a performance improvement.
                                    if (empty($activitytype)) {
                                        $activitytypeRes = $adb->pquery('SELECT activitytype FROM vtiger_activity WHERE activityid=?', array($activityid));
                                        if ($adb->num_rows($activitytypeRes) > 0) {
                                            $activitytype = $adb->query_result($activitytypeRes, 0, 'activitytype');
                                        }
                                    }
                                    if ($activitytype != 'Task' && $activitytype != 'Emails') {
                                        $eventstatus = $adb->query_result($list_result, $i - 1, "eventstatus");
                                        if (isset($eventstatus)) {
                                            $status = $eventstatus;
                                        }
                                    }
                                    if ($status == 'Deferred' || $status == 'Completed' || $status == 'Held' || $status == '') {
                                        $value = "";
                                    } else {
                                        if ($activitytype == 'Task') {
                                            $evt_status = '&status=Completed';
                                        } else {
                                            $evt_status = '&eventstatus=Held';
                                        }
                                        if (isPermitted("Calendar", 'EditView', $activityid) == 'yes') {
                                            if ($returnset == '') {
                                                $returnset = '&return_module=Calendar&return_action=ListView&return_id=' . $activityid . '&return_viewname=' . $oCv->setdefaultviewid;
                                            }
                                            // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
                                            $value = "<a href='index.php?action=Save&module=Calendar&record=" . $activityid . "&parenttab=" . $tabname . "&change_status=true" . $returnset . $evt_status . "&start=" . $navigation_array['current'] . "' style='" . $P_FONT_COLOR . "'>X</a>";
                                            // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
                                        } else {
                                            $value = "";
                                        }
                                    }
                                }
                            } else {
                                $value = "";
                            }
                        } elseif ($module == "Documents" && ($fieldname == 'filelocationtype' || $fieldname == 'filename' || $fieldname == 'filesize' || $fieldname == 'filestatus' || $fieldname == 'filetype')) {
                            $value = $adb->query_result($list_result, $i - 1, $fieldname);
                            if ($fieldname == 'filelocationtype') {
                                if ($value == 'I') {
                                    $value = getTranslatedString('LBL_INTERNAL', $module);
                                } elseif ($value == 'E') {
                                    $value = getTranslatedString('LBL_EXTERNAL', $module);
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filename') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                if ($downloadtype == 'I') {
                                    $fld_value = $value;
                                    $ext_pos = strrpos($fld_value, ".");
                                    $ext = substr($fld_value, $ext_pos + 1);
                                    $ext = strtolower($ext);
                                    if ($value != '') {
                                        if ($ext == 'bin' || $ext == 'exe' || $ext == 'rpm') {
                                            $fileicon = "<img src='" . vtiger_imageurl('fExeBin.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                                        } elseif ($ext == 'jpg' || $ext == 'gif' || $ext == 'bmp') {
                                            $fileicon = "<img src='" . vtiger_imageurl('fbImageFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                                        } elseif ($ext == 'txt' || $ext == 'doc' || $ext == 'xls') {
                                            $fileicon = "<img src='" . vtiger_imageurl('fbTextFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                                        } elseif ($ext == 'zip' || $ext == 'gz' || $ext == 'rar') {
                                            $fileicon = "<img src='" . vtiger_imageurl('fbZipFile.gif', $theme) . "' hspace='3' align='absmiddle'\tborder='0'>";
                                        } else {
                                            $fileicon = "<img src='" . vtiger_imageurl('fbUnknownFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                                        }
                                    }
                                } elseif ($downloadtype == 'E') {
                                    if (trim($value) != '') {
                                        $fld_value = $value;
                                        $fileicon = "<img src='" . vtiger_imageurl('fbLink.gif', $theme) . "' alt='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' title='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' hspace='3' align='absmiddle' border='0'>";
                                    } else {
                                        $fld_value = '--';
                                        $fileicon = '';
                                    }
                                } else {
                                    $fld_value = ' --';
                                    $fileicon = '';
                                }
                                $file_name = $adb->query_result($list_result, $i - 1, 'filename');
                                $notes_id = $adb->query_result($list_result, $i - 1, 'crmid');
                                $folder_id = $adb->query_result($list_result, $i - 1, 'folderid');
                                $download_type = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                $file_status = $adb->query_result($list_result, $i - 1, 'filestatus');
                                $fileidQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
                                $fileidres = $adb->pquery($fileidQuery, array($notes_id));
                                $fileid = $adb->query_result($fileidres, 0, 'attachmentsid');
                                if ($file_name != '' && $file_status == 1) {
                                    if ($download_type == 'I') {
                                        $fld_value = "<a href='index.php?module=uploads&action=downloadfile&entityid={$notes_id}&fileid={$fileid}' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "' onclick='javascript:dldCntIncrease({$notes_id});'>" . $fld_value . "</a>";
                                    } elseif ($download_type == 'E') {
                                        $fld_value = "<a target='_blank' href='{$file_name}' onclick='javascript:dldCntIncrease({$notes_id});' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "'>" . $fld_value . "</a>";
                                    } else {
                                        $fld_value = ' --';
                                    }
                                }
                                $value = $fileicon . $fld_value;
                            }
                            if ($fieldname == 'filesize') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                if ($downloadtype == 'I') {
                                    $filesize = $value;
                                    if ($filesize < 1024) {
                                        $value = $filesize . ' B';
                                    } elseif ($filesize > 1024 && $filesize < 1048576) {
                                        $value = round($filesize / 1024, 2) . ' KB';
                                    } else {
                                        if ($filesize > 1048576) {
                                            $value = round($filesize / (1024 * 1024), 2) . ' MB';
                                        }
                                    }
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filestatus') {
                                $filestatus = $value;
                                if ($filestatus == 1) {
                                    $value = getTranslatedString('yes', $module);
                                } elseif ($filestatus == 0) {
                                    $value = getTranslatedString('no', $module);
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filetype') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                $filetype = $adb->query_result($list_result, $i - 1, 'filetype');
                                if ($downloadtype == 'E' || $downloadtype != 'I') {
                                    $value = ' --';
                                } else {
                                    $value = $filetype;
                                }
                            }
                            if ($fieldname == 'notecontent') {
                                $value = decode_html($value);
                                $value = textlength_check($value);
                            }
                        } elseif ($module == "Products" && $name == "Related to") {
                            $value = getRelatedTo($module, $list_result, $i - 1);
                        } elseif ($name == 'Contact Name' && ($module == 'SalesOrder' || $module == 'Quotes' || $module == 'PurchaseOrder')) {
                            if ($name == 'Contact Name') {
                                $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                $value = "";
                                if ($contact_name != "" && $contact_id != 'NULL') {
                                    $value = "<a href='index.php?module=Contacts&action=DetailView&parenttab=" . $tabname . "&record=" . $contact_id . "' style='" . $P_FONT_COLOR . "'>" . $contact_name . "</a>";
                                }
                            }
                        } elseif ($name == 'Product') {
                            $product_id = textlength_check($adb->query_result($list_result, $i - 1, "productname"));
                            $value = $product_id;
                        } elseif ($name == 'Account Name') {
                            //modified for vtiger_customview 27/5
                            if ($module == 'Accounts') {
                                $account_id = $adb->query_result($list_result, $i - 1, "crmid");
                                //$account_name = getAccountName($account_id);
                                $account_name = textlength_check($adb->query_result($list_result, $i - 1, "accountname"));
                                // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
                                $value = '<a href="index.php?module=Accounts&action=DetailView&record=' . $account_id . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $account_name . '</a>';
                                // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
                            } elseif ($module == 'Potentials' || $module == 'Contacts' || $module == 'Invoice' || $module == 'SalesOrder' || $module == 'Quotes') {
                                //Potential,Contacts,Invoice,SalesOrder & Quotes  records   sort by Account Name
                                $accountname = textlength_check($adb->query_result($list_result, $i - 1, "accountname"));
                                $accountid = $adb->query_result($list_result, $i - 1, "accountid");
                                $value = '<a href="index.php?module=Accounts&action=DetailView&record=' . $accountid . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $accountname . '</a>';
                            } else {
                                $account_id = $adb->query_result($list_result, $i - 1, "accountid");
                                $account_name = getAccountName($account_id);
                                $acc_name = textlength_check($account_name);
                                // Fredy Klammsteiner, 4.8.2005: changes from 4.0.1 migrated to 4.2
                                $value = '<a href="index.php?module=Accounts&action=DetailView&record=' . $account_id . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $acc_name . '</a>';
                                // Armando Lüscher 05.07.2005 -> §priority -> Desc: inserted style="$P_FONT_COLOR"
                            }
                        } elseif (($module == 'HelpDesk' || $module == 'PriceBook' || $module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'Faq') && $name == 'Product Name') {
                            if ($module == 'HelpDesk' || $module == 'Faq') {
                                $product_id = $adb->query_result($list_result, $i - 1, "product_id");
                            } else {
                                $product_id = $adb->query_result($list_result, $i - 1, "productid");
                            }
                            if ($product_id != '') {
                                $product_name = getProductName($product_id);
                            } else {
                                $product_name = '';
                            }
                            $value = '<a href="index.php?module=Products&action=DetailView&parenttab=' . $tabname . '&record=' . $product_id . '">' . textlength_check($product_name) . '</a>';
                        } elseif ($module == 'Quotes' && $name == 'Potential Name' || $module == 'SalesOrder' && $name == 'Potential Name') {
                            $potential_id = $adb->query_result($list_result, $i - 1, "potentialid");
                            $potential_name = getPotentialName($potential_id);
                            $value = '<a href="index.php?module=Potentials&action=DetailView&parenttab=' . $tabname . '&record=' . $potential_id . '">' . textlength_check($potential_name) . '</a>';
                        } elseif ($module == 'Emails' && $relatedlist != '' && ($name == 'Subject' || $name == 'Date Sent' || $name == 'To')) {
                            $list_result_count = $i - 1;
                            $tmp_value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                            $value = '<a href="javascript:;" onClick="ShowEmail(\'' . $entity_id . '\');">' . textlength_check($tmp_value) . '</a>';
                            if ($name == 'Date Sent') {
                                $sql = "select email_flag from vtiger_emaildetails where emailid=?";
                                $result = $adb->pquery($sql, array($entity_id));
                                $email_flag = $adb->query_result($result, 0, "email_flag");
                                if ($email_flag != 'SAVED') {
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                                } else {
                                    $value = '';
                                }
                            }
                        } elseif ($module == 'Calendar' && ($fieldname != 'taskstatus' && $fieldname != 'eventstatus')) {
                            if ($activitytype == 'Task') {
                                if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
                                    $list_result_count = $i - 1;
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                                } else {
                                    $value = '';
                                }
                            } else {
                                if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
                                    $list_result_count = $i - 1;
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                                } else {
                                    $value = '';
                                }
                            }
                        } elseif ($module == "Accounting" && $fieldname == "accounting_id") {
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                            $value = '<a href="index.php?action=DetailView&module=' . $module . '&parenttab=' . $tabname . '&record=' . $entity_id . '">' . $value . '</a>';
                        } else {
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid);
                        }
                    }
                    // vtlib customization: For listview javascript triggers
                    $value = "{$value} <span type='vtlib_metainfo' vtrecordid='{$entity_id}' vtfieldname='{$fieldname}' vtmodule='{$module}' style='display:none;'></span>";
                    // END
                    if ($module == "Calendar" && $name == $app_strings['Close']) {
                        if (isPermitted("Calendar", "EditView") == 'yes') {
                            if (getFieldVisibilityPermission('Events', $current_user->id, 'eventstatus') == '0' || getFieldVisibilityPermission('Calendar', $current_user->id, 'taskstatus') == '0') {
                                array_push($list_header, $value);
                            }
                        }
                    } else {
                        $list_header[] = $value;
                    }
                }
            }
            $varreturnset = '';
            if ($returnset == '') {
                $varreturnset = '&return_module=' . $module . '&return_action=index';
            } else {
                $varreturnset = $returnset;
            }
            if ($module == 'Calendar') {
                $actvity_type = $adb->query_result($list_result, $list_result_count, 'activitytype');
                if ($actvity_type == 'Task') {
                    $varreturnset .= '&activity_mode=Task';
                } else {
                    $varreturnset .= '&activity_mode=Events';
                }
            }
            //Added for Actions ie., edit and delete links in listview
            $links_info = "";
            if (!(is_array($selectedfields) && $selectedfields != '')) {
                if (isPermitted($module, "EditView", "") == 'yes') {
                    $edit_link = getListViewEditLink($module, $entity_id, $relatedlist, $varreturnset, $list_result, $list_result_count);
                    if (isset($_REQUEST['start']) && $_REQUEST['start'] > 1 && $module != 'Emails') {
                        $links_info .= "<a href=\"{$edit_link}&start=" . vtlib_purify($_REQUEST['start']) . "\">" . $app_strings["LNK_EDIT"] . "</a> ";
                    } else {
                        $links_info .= "<a href=\"{$edit_link}\">" . $app_strings["LNK_EDIT"] . "</a> ";
                    }
                }
                if (isPermitted($module, "Delete", "") == 'yes') {
                    $del_link = getListViewDeleteLink($module, $entity_id, $relatedlist, $varreturnset);
                    if ($links_info != "" && $del_link != "") {
                        $links_info .= " | ";
                    }
                    if ($del_link != "") {
                        $links_info .= "<a href='javascript:confirmdelete(\"" . addslashes(urlencode($del_link)) . "\")'>" . $app_strings["LNK_DELETE"] . "</a>";
                    }
                }
            }
            // Record Change Notification
            if (method_exists($focus, 'isViewed') && PerformancePrefs::getBoolean('LISTVIEW_RECORD_CHANGE_INDICATOR', true)) {
                if (!$focus->isViewed($entity_id)) {
                    $links_info .= " | <img src='" . vtiger_imageurl('important1.gif', $theme) . "' border=0>";
                }
            }
            // END
            if ($links_info != "" && !$skipActions) {
                $list_header[] = $links_info;
            }
            //	$list_block[$entity_id] = $list_header;
            if (isset($_SESSION['partialpaymentview']) && $_SESSION['partialpaymentview'] == "true") {
                $list_block[$entity_id . "_" . $i] = $list_header;
            } else {
                $list_block[$entity_id] = $list_header;
            }
        }
    }
    $log->debug("Exiting getListViewEntries method ...");
    return $list_block;
}
Ejemplo n.º 13
0
 private function x15()
 {
     global $x0b, $x0c, $x0d, $x0e, $x0f, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x1a, $x1b, $x1c, $x1d, $x1e, $x1f, $x20, $x21, $x22, $x23, $x24, $x25, $x26;
     $taxtype = $this->x1d();
     $currencytype = $this->x1c();
     $query = "select case when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname," . " case when vtiger_products.productid != '' then vtiger_products.productid else vtiger_service.serviceid end as psid," . " case when vtiger_products.productid != '' then vtiger_products.product_no else vtiger_service.service_no end as psno," . " case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype," . " case when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price," . " case when vtiger_products.productid != '' then vtiger_products.usageunit else vtiger_service.service_usageunit end as usageunit," . " case when vtiger_products.productid != '' then vtiger_products.qty_per_unit else vtiger_service.qty_per_unit end as qty_per_unit," . " case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock," . " case when vtiger_products.productid != '' then c1.description else c2.description end as psdescription, vtiger_inventoryproductrel.* " . " from vtiger_inventoryproductrel" . " left join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid " . " left join vtiger_crmentity as c1 on c1.crmid = vtiger_products.productid " . " left join vtiger_service on vtiger_service.serviceid=vtiger_inventoryproductrel.productid " . " left join vtiger_crmentity as c2 on c2.crmid = vtiger_service.serviceid " . " where id=? ORDER BY sequence_no";
     $result = $this->db->pquery($query, array($this->focus->id));
     $num_rows = $this->db->num_rows($result);
     $netTotal = "0.00";
     $totalAfterDiscount_subtotal = 0;
     $total_subtotal = 0;
     $totalsum_subtotal = 0;
     $images = $this->x17();
     $Total_Tax_Values = array();
     for ($i = 1; $i <= $num_rows; $i++) {
         $sub_prod_query = $this->db->pquery("SELECT productid from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($this->focus->id, $i));
         $subprodname_str = '';
         if ($this->db->num_rows($sub_prod_query) > 0) {
             for ($j = 0; $j < $this->db->num_rows($sub_prod_query); $j++) {
                 $sprod_id = $this->db->query_result($sub_prod_query, $j, "productid");
                 $sprod_name = getProductName($sprod_id);
                 $str_sep = "";
                 if ($j > 0) {
                     $str_sep = ":";
                 }
                 $subprodname_str .= $str_sep . " - " . $sprod_name;
             }
         }
         $subprodname_str = $x1e(":", "<br>", $subprodname_str);
         $psid = $this->db->query_result($result, $i - 1, "psid");
         $psno = $this->db->query_result($result, $i - 1, "psno");
         $productid = $this->db->query_result($result, $i - 1, "productid");
         $entitytype = $this->db->query_result($result, $i - 1, "entitytype");
         $producttitle = $productname = $this->db->query_result($result, $i - 1, "productname");
         if ($subprodname_str != "") {
             $productname .= "<br/><span style='color:#C0C0C0;font-style:italic;'>" . $subprodname_str . "</span>";
         }
         $comment = $this->db->query_result($result, $i - 1, "comment");
         $psdescription = $this->db->query_result($result, $i - 1, "psdescription");
         $inventory_prodrel_desc = $this->db->query_result($result, $i - 1, "description");
         $qtyinstock = $this->db->query_result($result, $i - 1, "qtyinstock");
         $qty = $this->db->query_result($result, $i - 1, "quantity");
         $qty_per_unit = $this->db->query_result($result, $i - 1, "qty_per_unit");
         $usageunit = $this->db->query_result($result, $i - 1, "usageunit");
         $unitprice = $this->db->query_result($result, $i - 1, "unit_price");
         $listprice = $this->db->query_result($result, $i - 1, "listprice");
         $total = $qty * $listprice;
         $discount_percent = $this->db->query_result($result, $i - 1, "discount_percent");
         $discount_amount = $this->db->query_result($result, $i - 1, "discount_amount");
         $totalAfterDiscount = $total;
         $productDiscount = "0.00";
         $productDiscountPercent = "";
         if ($discount_percent != "NULL" && $discount_percent != "") {
             $productDiscount = $total * $discount_percent / 100;
             $totalAfterDiscount = $total - $productDiscount;
             $productDiscountPercent = $discount_percent;
         } elseif ($discount_amount != "NULL" && $discount_amount != "") {
             $productDiscount = $discount_amount;
             $totalAfterDiscount = $total - $productDiscount;
         }
         $netprice = $totalAfterDiscount;
         if ($taxtype == "individual") {
             $taxtotal = "0.00";
             $tax_info_message = $mod_strings["LBL_TOTAL_AFTER_DISCOUNT"] . " = {$totalAfterDiscount} \\n";
             $tax_details = getTaxDetailsForProduct($productid, "all");
             $Tax_Values = array();
             for ($tax_count = 0; $tax_count < $x0f($tax_details); $tax_count++) {
                 $tax_name = $tax_details[$tax_count]["taxname"];
                 $tax_label = $tax_details[$tax_count]["taxlabel"];
                 $tax_value = getInventoryProductTaxValue($this->focus->id, $productid, $tax_name);
                 $individual_taxamount = $totalAfterDiscount * $tax_value / 100;
                 $taxtotal = $taxtotal + $individual_taxamount;
                 if ($tax_name != "" && $tax_value > 0) {
                     $vatblock[$tax_name . "-" . $tax_value]["label"] = $tax_label;
                     $vatblock[$tax_name . "-" . $tax_value]["netto"] += $totalAfterDiscount;
                     $vatblock[$tax_name . "-" . $tax_value]["vat"] += $x1c($individual_taxamount, $this->decimals);
                     $vatblock[$tax_name . "-" . $tax_value]["value"] = $tax_value;
                     $x0c($Tax_Values, $tax_value);
                     $x0c($Total_Tax_Values, $tax_value);
                 }
                 $netprice = $netprice + $taxtotal;
             }
             if ($x0f($Tax_Values) > 0) {
                 $tax_avg_value = $x0e($Tax_Values);
             } else {
                 $tax_avg_value = "0.00";
             }
             $Details["P"][$i]["PRODUCTVATPERCENT"] = $this->x1e($tax_avg_value);
             $Details["P"][$i]["PRODUCTVATSUM"] = $this->x1e($taxtotal);
         }
         if ($entitytype == "Products") {
             $Details["P"][$i]["PRODUCTS_CRMID"] = $psid;
             $Details["P"][$i]["SERVICES_CRMID"] = "";
         } else {
             $Details["P"][$i]["PRODUCTS_CRMID"] = "";
             $Details["P"][$i]["SERVICES_CRMID"] = $psid;
         }
         $Details["P"][$i]["PS_CRMID"] = $psid;
         $Details["P"][$i]["PS_NO"] = $psno;
         if ($comment != "") {
             $comment = $x1e("\\n", "<br>", $x1a($comment));
             $comment = $x14($comment, ENT_QUOTES, "utf-8");
             $productname .= "<br /><small>" . $comment . "</small>";
         }
         $Details["P"][$i]["PRODUCTNAME"] = $productname;
         $Details["P"][$i]["PRODUCTTITLE"] = $producttitle;
         $psdescription = $x1e("\\n", "<br>", $x1a($psdescription));
         $Details["P"][$i]["PRODUCTDESCRIPTION"] = $x14($psdescription, ENT_QUOTES, "utf-8");
         $Details["P"][$i]["PRODUCTEDITDESCRIPTION"] = $comment;
         $inventory_prodrel_desc = $x1e("\\n", "<br>", $x1a($inventory_prodrel_desc));
         $Details["P"][$i]["CRMNOWPRODUCTDESCRIPTION"] = $x14($inventory_prodrel_desc, ENT_QUOTES, "utf-8");
         $Details["P"][$i]["PRODUCTLISTPRICE"] = $this->x1e($listprice);
         $Details["P"][$i]["PRODUCTTOTAL"] = $this->x1e($total);
         $Details["P"][$i]["PRODUCTQUANTITY"] = $this->x1e($qty);
         $Details["P"][$i]["PRODUCTQINSTOCK"] = $this->x1e($qtyinstock);
         $Details["P"][$i]["PRODUCTPRICE"] = $this->x1e($unitprice);
         $Details["P"][$i]["PRODUCTPOSITION"] = $i;
         $Details["P"][$i]["PRODUCTQTYPERUNIT"] = $this->x1e($qty_per_unit);
         $Details["P"][$i]["PRODUCTUSAGEUNIT"] = $this->x1b($usageunit, "Products/Services");
         $Details["P"][$i]["PRODUCTDISCOUNT"] = $this->x1e($productDiscount);
         $Details["P"][$i]["PRODUCTDISCOUNTPERCENT"] = $this->x1e($productDiscountPercent);
         $Details["P"][$i]["PRODUCTSTOTALAFTERDISCOUNTSUM"] = $totalAfterDiscount;
         $Details["P"][$i]["PRODUCTSTOTALAFTERDISCOUNT"] = $this->x1e($totalAfterDiscount);
         $Details["P"][$i]["PRODUCTTOTALSUM"] = $this->x1e($totalAfterDiscount + $taxtotal);
         $totalAfterDiscount_subtotal += $totalAfterDiscount;
         $total_subtotal += $total;
         $totalsum_subtotal += $totalAfterDiscount + $taxtotal;
         $Details["P"][$i]["PRODUCTSTOTALAFTERDISCOUNT_SUBTOTAL"] = $this->x1e($totalAfterDiscount_subtotal);
         $Details["P"][$i]["PRODUCTTOTAL_SUBTOTAL"] = $this->x1e($total_subtotal);
         $Details["P"][$i]["PRODUCTTOTALSUM_SUBTOTAL"] = $this->x1e($totalsum_subtotal);
         $sequence = $this->db->query_result($result, $i - 1, "sequence_no");
         $Details["P"][$i]["PRODUCTSEQUENCE"] = $sequence;
         if (isset($images[$productid . "_" . $sequence])) {
             $width = "";
             $height = "";
             if ($images[$productid . "_" . $sequence]["width"] > 0) {
                 $width = " width='" . $images[$productid . "_" . $sequence]["width"] . "' ";
             }
             if ($images[$productid . "_" . $sequence]["height"] > 0) {
                 $height = " height='" . $images[$productid . "_" . $sequence]["height"] . "' ";
             }
             $Details["P"][$i]["PRODUCTS_IMAGENAME"] = "<img src='" . $this->site_url . "/" . $images[$productid . "_" . $sequence]["src"] . "' " . $width . $height . "/>";
         }
         $focus_p = CRMEntity::getInstance("Products");
         if ($entitytype == "Products" && $psid != "") {
             $focus_p->id = $psid;
             $this->x1f($focus_p, $psid, "Products");
         }
         $Array_P = $this->x0e("Products", $focus_p, false, true);
         $Details["P"][$i] = $x0d($Array_P, $Details["P"][$i]);
         unset($focus_p);
         $focus_s = CRMEntity::getInstance("Services");
         if ($entitytype == "Services" && $psid != "") {
             $focus_s->id = $psid;
             $this->x1f($focus_s, $psid, "Services");
         }
         $Array_S = $this->x0e("Services", $focus_s, false, true);
         $Details["P"][$i] = $x0d($Array_S, $Details["P"][$i]);
         unset($focus_s);
         $sumwithoutvat += $totalAfterDiscount;
         $netTotal = $netTotal + $netprice;
     }
     $finalDiscount = "0.00";
     $final_discount_info = "0";
     $finalDiscountPercent = "";
     if ($this->focus->column_fields["hdnDiscountPercent"] != "0") {
         $finalDiscount = $netTotal * $this->focus->column_fields["hdnDiscountPercent"] / 100;
         $finalDiscountPercent = $this->focus->column_fields["hdnDiscountPercent"];
     } elseif ($this->focus->column_fields["hdnDiscountAmount"] != "0") {
         $finalDiscount = $this->focus->column_fields["hdnDiscountAmount"];
     }
     $taxtotal = "0.00";
     if ($taxtype == "group") {
         $final_totalAfterDiscount = $netTotal - $finalDiscount;
         $tax_details = getAllTaxes("available", "", "edit", $this->focus->id);
         for ($tax_count = 0; $tax_count < $x0f($tax_details); $tax_count++) {
             $tax_name = $tax_details[$tax_count]["taxname"];
             $tax_label = $tax_details[$tax_count]["taxlabel"];
             $tax_value = $this->db->query_result($result, 0, $tax_name);
             if ($tax_value == "" || $tax_value == "NULL") {
                 $tax_value = "0.00";
             }
             $taxamount = ($netTotal - $finalDiscount) * $tax_value / 100;
             $taxtotal = $taxtotal + $taxamount;
             if ($tax_name != "" && $tax_value > 0) {
                 $vatblock[$tax_name]["label"] = $tax_label;
                 $vatblock[$tax_name]["netto"] = $final_totalAfterDiscount;
                 $vatblock[$tax_name]["vat"] += $taxamount;
                 $vatblock[$tax_name]["value"] = $tax_value;
             }
             $total_vat_percent += $tax_value;
         }
         $vat_value = $taxtotal;
         foreach ($Details["P"] as $keyP => $valueP) {
             $productvatsum = $Details["P"][$keyP]["PRODUCTSTOTALAFTERDISCOUNTSUM"] * $total_vat_percent / 100;
             $producttotalsum = $Details["P"][$keyP]["PRODUCTSTOTALAFTERDISCOUNTSUM"] + $productvatsum;
             $Details["P"][$keyP]["PRODUCTVATPERCENT"] = $this->x1e($total_vat_percent);
             $Details["P"][$keyP]["PRODUCTVATSUM"] = $this->x1e($productvatsum);
             $Details["P"][$keyP]["PRODUCTTOTALSUM"] = $this->x1e($producttotalsum);
         }
     } else {
         if ($x0f($vatblock) > 0) {
             foreach ($vatblock as $keyM => $valueM) {
                 $vat_value += $valueM["vat"];
             }
         } else {
             $vat_value = "0.00";
         }
     }
     $shAmount = $this->focus->column_fields["hdnS_H_Amount"] != "" ? $this->focus->column_fields["hdnS_H_Amount"] : "0.00";
     $shtaxtotal = "0.00";
     $shtax_details = getAllTaxes("available", "sh", "edit", $this->focus->id);
     for ($shtax_count = 0; $shtax_count < $x0f($shtax_details); $shtax_count++) {
         $shtax_name = $shtax_details[$shtax_count]["taxname"];
         $shtax_label = $shtax_details[$shtax_count]["taxlabel"];
         $shtax_percent = getInventorySHTaxPercent($this->focus->id, $shtax_name);
         $shtaxamount = $shAmount * $shtax_percent / 100;
         $shtaxtotal = $shtaxtotal + $shtaxamount;
     }
     $totalafterdiscount = $sumwithoutvat - $finalDiscount;
     $totalwithvat = $sumwithoutvat - $finalDiscount + $vat_value;
     $Details["TOTAL"]["NETTOTAL"] = $this->x1e($netTotal);
     $Details["TOTAL"]["TOTALWITHOUTVAT"] = $this->x1e($sumwithoutvat);
     $Details["TOTAL"]["FINALDISCOUNT"] = $this->x1e($finalDiscount);
     $Details["TOTAL"]["FINALDISCOUNTPERCENT"] = $this->x1e($finalDiscountPercent);
     $Details["TOTAL"]["TOTALAFTERDISCOUNT"] = $this->x1e($totalafterdiscount);
     $Details["TOTAL"]["TAXTOTAL"] = $this->x1e($vat_value);
     $Details["TOTAL"]["TAXTOTALPERCENT"] = $this->x1e($total_vat_percent);
     $Details["TOTAL"]["TOTALWITHVAT"] = $this->x1e($totalwithvat);
     $Details["TOTAL"]["SHTAXAMOUNT"] = $this->x1e($shAmount);
     $Details["TOTAL"]["SHTAXTOTAL"] = $this->x1e($shtaxtotal);
     $Details["TOTAL"]["VATBLOCK"] = $vatblock;
     return $Details;
 }
Ejemplo n.º 14
0
/** This function returns a HTML output of associated vtiger_products for a given entity (Quotes,Invoice,Sales order or Purchase order)
 * Param $module - module name
 * Param $focus - module object
 * Return type string
 */
function getDetailAssociatedProducts($module, $focus)
{
    global $log;
    $log->debug("Entering getDetailAssociatedProducts(" . $module . "," . get_class($focus) . ") method ...");
    global $adb, $default_charset;
    global $mod_strings;
    global $theme;
    global $log;
    global $app_strings, $current_user, $current_language;
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    //crm-now: added to select comma or dot as numberformat
    //European Format
    if ($current_language == 'en_us') {
        //US Format
        $decimal_precision = 2;
        $decimals_separator = '.';
        $thousands_separator = ',';
    } else {
        //European Format
        $decimal_precision = 2;
        $decimals_separator = ',';
        $thousands_separator = '.';
    }
    if ($module != 'PurchaseOrder') {
        $colspan = '2';
    } else {
        $colspan = '1';
    }
    //Get the taxtype of this entity
    $taxtype = getInventoryTaxType($module, $focus->id);
    $currencytype = getInventoryCurrencyInfo($module, $focus->id);
    $output = '';
    //Header Rows
    $output .= '

	<table width="100%"  border="0" align="center" cellpadding="5" cellspacing="0" class="crmTable" id="proTab">
	   <tr valign="top">
	   	<td colspan="' . $colspan . '" class="dvInnerHeader"><b>' . $app_strings['LBL_ITEM_DETAILS'] . '</b></td>
		<td class="dvInnerHeader" align="center" colspan="2"><b>' . $app_strings['LBL_CURRENCY'] . ' : </b>' . getTranslatedCurrencyString($currencytype['currency_name']) . ' (' . $currencytype['currency_symbol'] . ')
		</td>
		<td class="dvInnerHeader" align="center" colspan="2"><b>' . $app_strings['LBL_TAX_MODE'] . ' : </b>' . $app_strings[$taxtype] . '
		</td>
	   </tr>
	   <tr valign="top">
		<td width=40% class="lvtCol"><font color="red">*</font>
			<b>' . $app_strings['LBL_ITEM_NAME'] . '</b>
		</td>';
    //Add Quantity in Stock column for SO, Quotes and Invoice
    if ($module == 'Quotes' || $module == 'SalesOrder' || $module == 'Invoice') {
        $output .= '<td width=10% class="lvtCol"><b>' . $app_strings['LBL_QTY_IN_STOCK'] . '</b></td>';
    }
    $output .= '
	
		<td width=10% class="lvtCol"><b>' . $app_strings['LBL_QTY'] . '</b></td>
		<td width=10% class="lvtCol" align="right"><b>' . $app_strings['LBL_LIST_PRICE'] . '</b></td>
		<td width=12% nowrap class="lvtCol" align="right"><b>' . $app_strings['LBL_TOTAL'] . '</b></td>
		<td width=13% valign="top" class="lvtCol" align="right"><b>' . $app_strings['LBL_NET_PRICE'] . '</b></td>
	   </tr>
	   	';
    // DG 15 Aug 2006
    // Add "ORDER BY sequence_no" to retain add order on all inventoryproductrel items
    if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice') {
        $query = "select case when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname," . " case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype," . " case when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price," . " case when vtiger_products.productid != '' then vtiger_products.productcode else 'NA' end as productcode," . " case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock, vtiger_inventoryproductrel.* " . " from vtiger_inventoryproductrel" . " left join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid " . " left join vtiger_service on vtiger_service.serviceid=vtiger_inventoryproductrel.productid " . " where id=? ORDER BY sequence_no";
    }
    $result = $adb->pquery($query, array($focus->id));
    $num_rows = $adb->num_rows($result);
    $netTotal = '0.00';
    for ($i = 1; $i <= $num_rows; $i++) {
        $sub_prod_query = $adb->pquery("SELECT productid from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i));
        $subprodname_str = '';
        if ($adb->num_rows($sub_prod_query) > 0) {
            for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                $sprod_id = $adb->query_result($sub_prod_query, $j, 'productid');
                $sprod_name = getProductName($sprod_id);
                $str_sep = "";
                if ($j > 0) {
                    $str_sep = ":";
                }
                $subprodname_str .= $str_sep . " - " . $sprod_name;
            }
        }
        $subprodname_str = str_replace(":", "<br>", $subprodname_str);
        $productid = $adb->query_result($result, $i - 1, 'productid');
        $entitytype = $adb->query_result($result, $i - 1, 'entitytype');
        $productname = $adb->query_result($result, $i - 1, 'productname');
        //crm-now added to display product code and description
        $productcode = $adb->query_result($result, $i - 1, 'productcode');
        //html to utf8 conversion (necessary because stored at inventoryproductrel table)
        $productdescription = nl2br($adb->query_result($result, $i - 1, 'description'));
        $productdescription = html_entity_decode($productdescription, ENT_QUOTES, $default_charset);
        $comment = nl2br(from_html($adb->query_result($result, $i - 1, 'comment')));
        if ($subprodname_str != '') {
            $productname .= "<br/><span style='color:#C0C0C0;font-style:italic;'>" . $subprodname_str . "</span>";
        }
        //$comment=$adb->query_result($result,$i-1,'comment');
        $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock');
        $qty = $adb->query_result($result, $i - 1, 'quantity');
        $unitprice = $adb->query_result($result, $i - 1, 'unit_price');
        $listprice = $adb->query_result($result, $i - 1, 'listprice');
        $listpriceformated = number_format($listprice, $decimal_precision, $decimals_separator, $thousands_separator);
        $total = $qty * $listprice;
        $totalformated = number_format($total, $decimal_precision, $decimals_separator, $thousands_separator);
        //Product wise Discount calculation - starts
        $discount_percent = $adb->query_result($result, $i - 1, 'discount_percent');
        $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount');
        $totalAfterDiscount = $total;
        $totalAfterDiscountformated = number_format($total, $decimal_precision, $decimals_separator, $thousands_separator);
        $productDiscount = '0.00';
        $productDiscountformated = number_format($productDiscount, $decimal_precision, $decimals_separator, $thousands_separator);
        if ($discount_percent != 'NULL' && $discount_percent != '') {
            $productDiscount = $total * $discount_percent / 100;
            $productDiscountformated = number_format($productDiscount, $decimal_precision, $decimals_separator, $thousands_separator);
            $totalAfterDiscount = $total - $productDiscount;
            $totalAfterDiscountformated = number_format($totalAfterDiscount, $decimal_precision, $decimals_separator, $thousands_separator);
            //if discount is percent then show the percentage
            $discount_info_message = "{$discount_percent} % " . $app_strings['of_string'] . " {$total} = {$productDiscountformated}";
        } elseif ($discount_amount != 'NULL' && $discount_amount != '') {
            $productDiscount = $discount_amount;
            $productDiscountformated = number_format($productDiscount, $decimal_precision, $decimals_separator, $thousands_separator);
            $totalAfterDiscount = $total - $productDiscount;
            $totalAfterDiscountformated = number_format($totalAfterDiscount, $decimal_precision, $decimals_separator, $thousands_separator);
            $discount_info_message = $app_strings['LBL_DIRECT_AMOUNT_DISCOUNT'] . " = {$productDiscountformated}";
        } else {
            $discount_info_message = $app_strings['LBL_NO_DISCOUNT_FOR_THIS_LINE_ITEM'];
        }
        //Product wise Discount calculation - ends
        $netprice = $totalAfterDiscount;
        //Calculate the individual tax if taxtype is individual
        if ($taxtype == 'individual') {
            $taxtotal = '0.00';
            $tax_info_message = $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . " = {$totalAfterDiscountformated} \\n";
            $tax_details = getTaxDetailsForProduct($productid, 'all');
            for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                $tax_name = $tax_details[$tax_count]['taxname'];
                $tax_label = $tax_details[$tax_count]['taxlabel'];
                $tax_value = getInventoryProductTaxValue($focus->id, $productid, $tax_name);
                $individual_taxamount = $totalAfterDiscount * $tax_value / 100;
                $individual_taxamountformated = number_format(round($individual_taxamount, 2), $decimal_precision, $decimals_separator, $thousands_separator);
                $taxtotal = $taxtotal + $individual_taxamount;
                $taxtotalformated = number_format(round($taxtotal, 2), $decimal_precision, $decimals_separator, $thousands_separator);
                $tax_info_message .= "{$tax_label} : {$tax_value} % = {$individual_taxamountformated} \\n";
            }
            $tax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = {$taxtotalformated}";
            $netprice = $netprice + $taxtotal;
        }
        $sc_image_tag = '';
        if ($entitytype == 'Services') {
            $sc_image_tag = '<a href="index.php?module=ServiceContracts&action=EditView&service_id=' . $productid . '&return_module=' . $module . '&return_id=' . $focus->id . '">' . '<img border="0" src="' . vtiger_imageurl('handshake.gif', $theme) . '" title="' . getTranslatedString('Add Service Contract', $module) . '" style="cursor: pointer;" align="absmiddle" />' . '</a>';
        }
        //For Product Name
        $output .= '
			   <tr valign="top">
				<td class="crmTableRow small lineOnTop">
					<font color="gray">' . $productcode . '</font>
					<br><font color="black">' . $productname . '</font>
					<br><font color="gray">' . $productdescription . '</font>
					<br><font color="gray">' . $comment . '</font>
				</td>';
        //Upto this added to display the Product name and comment
        if ($module != 'PurchaseOrder') {
            $output .= '<td class="crmTableRow small lineOnTop">' . $qtyinstock . '</td>';
        }
        $output .= '<td class="crmTableRow small lineOnTop">' . $qty . '</td>';
        $output .= '
			<td class="crmTableRow small lineOnTop" align="right">
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
				   <tr>
				   	<td align="right">' . $listpriceformated . '</td>
				   </tr>
				   <tr>
					   <td align="right">(-)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $discount_info_message . '\'); ">' . $app_strings['LBL_DISCOUNT'] . ' : </a></b></td>
				   </tr>
				   <tr>
				   	<td align="right" nowrap>' . $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . ' : </td>
				   </tr>';
        if ($taxtype == 'individual') {
            $output .= '
				   <tr>
					   <td align="right" nowrap>(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $tax_info_message . '\');">' . $app_strings['LBL_TAX'] . ' : </a></b></td>
				   </tr>';
        }
        $output .= '
				</table>
			</td>';
        $output .= '
			<td class="crmTableRow small lineOnTop" align="right">
				<table width="100%" border="0" cellpadding="5" cellspacing="0">
				   <tr><td align="right">' . $totalformated . '</td></tr>
				   <tr><td align="right">' . $productDiscountformated . '</td></tr>
				   <tr><td align="right" nowrap>' . $totalAfterDiscountformated . '</td></tr>';
        if ($taxtype == 'individual') {
            $output .= '<tr><td align="right" nowrap>' . $taxtotalformated . '</td></tr>';
        }
        $output .= '		   
				</table>
			</td>';
        $output .= '<td class="crmTableRow small lineOnTop" valign="bottom" align="right">' . number_format(round($netprice, 2), $decimal_precision, $decimals_separator, $thousands_separator) . '</td>';
        $output .= '</tr>';
        $netTotal = $netTotal + $netprice;
    }
    $output .= '</table>';
    //$netTotal should be equal to $focus->column_fields['hdnSubTotal']
    $netTotal = $focus->column_fields['hdnSubTotal'];
    $netTotalformated = number_format($netTotal, $decimal_precision, $decimals_separator, $thousands_separator);
    //Display the total, adjustment, S&H details
    $output .= '<table width="100%" border="0" cellspacing="0" cellpadding="5" class="crmTable">';
    $output .= '<tr>';
    $output .= '<td width="88%" class="crmTableRow small" align="right"><b>' . $app_strings['LBL_NET_TOTAL'] . '</td>';
    $output .= '<td width="12%" class="crmTableRow small" align="right"><b>' . $netTotalformated . '</b></td>';
    $output .= '</tr>';
    //Decide discount
    $finalDiscount = '0.00';
    $final_discount_info = '0';
    //if($focus->column_fields['hdnDiscountPercent'] != '') - previously (before changing to prepared statement) the selected option (either percent or amount) will have value and the other remains empty. So we can find the non selected item by empty check. But now with prepared statement, the non selected option stored as 0
    if ($focus->column_fields['hdnDiscountPercent'] != '0') {
        $finalDiscount = $netTotal * $focus->column_fields['hdnDiscountPercent'] / 100;
        $finalDiscountformated = number_format($finalDiscount, $decimal_precision, $decimals_separator, $thousands_separator);
        $final_discount_info = $focus->column_fields['hdnDiscountPercent'] . " % " . $app_strings['of_string'] . " {$netTotalformated} = {$finalDiscountformated}";
    } elseif ($focus->column_fields['hdnDiscountAmount'] != '0') {
        $finalDiscount = $focus->column_fields['hdnDiscountAmount'];
        $finalDiscountformated = number_format($finalDiscount, $decimal_precision, $decimals_separator, $thousands_separator);
        $final_discount_info = $finalDiscount;
    }
    //Alert the Final Discount amount even it is zero
    $final_discount_info = $app_strings['LBL_FINAL_DISCOUNT_AMOUNT'] . " = {$final_discount_info}";
    $final_discount_info = 'onclick="alert(\'' . $final_discount_info . '\');"';
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">(-)&nbsp;<b><a href="javascript:;" ' . $final_discount_info . '>' . $app_strings['LBL_DISCOUNT'] . '</a></b></td>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">' . $finalDiscountformated . '</td>';
    $output .= '</tr>';
    if ($taxtype == 'group') {
        $taxtotal = '0.00';
        $final_totalAfterDiscount = $netTotal - $finalDiscount;
        $final_totalAfterDiscountformated = number_format($final_totalAfterDiscount, $decimal_precision, $decimals_separator, $thousands_separator);
        $tax_info_message = $app_strings['LBL_TOTAL_AFTER_DISCOUNT'] . " = {$final_totalAfterDiscountformated} \\n";
        //First we should get all available taxes and then retrieve the corresponding tax values
        $tax_details = getAllTaxes('available', '', 'edit', $focus->id);
        //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
            $tax_name = $tax_details[$tax_count]['taxname'];
            $tax_label = $tax_details[$tax_count]['taxlabel'];
            $tax_value = $adb->query_result($result, 0, $tax_name);
            if ($tax_value == '' || $tax_value == 'NULL') {
                $tax_value = '0.00';
            }
            $taxamount = ($netTotal - $finalDiscount) * $tax_value / 100;
            $taxamountformated = number_format($taxamount, $decimal_precision, $decimals_separator, $thousands_separator);
            $taxtotal = $taxtotal + $taxamount;
            $taxtotalformated = number_format($taxtotal, $decimal_precision, $decimals_separator, $thousands_separator);
            $tax_info_message .= "{$tax_label} : {$tax_value} % = {$taxamountformated} \\n";
        }
        $tax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = {$taxtotalformated}";
        $output .= '<tr>';
        $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $tax_info_message . '\');">' . $app_strings['LBL_TAX'] . '</a></b></td>';
        $output .= '<td align="right" class="crmTableRow small">' . $taxtotalformated . '</td>';
        $output .= '</tr>';
    }
    $shAmount = $focus->column_fields['hdnS_H_Amount'] != '' ? $focus->column_fields['hdnS_H_Amount'] : '0.00';
    $shAmountformated = number_format($shAmount, $decimal_precision, $decimals_separator, $thousands_separator);
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b>' . $app_strings['LBL_SHIPPING_AND_HANDLING_CHARGES'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . $shAmountformated . '</td>';
    $output .= '</tr>';
    //calculate S&H tax
    $shtaxtotal = '0.00';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $shtax_details = getAllTaxes('available', 'sh', 'edit', $focus->id);
    //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
    $shtax_info_message = $app_strings['LBL_SHIPPING_AND_HANDLING_CHARGE'] . " = {$shAmountformated} \\n";
    for ($shtax_count = 0; $shtax_count < count($shtax_details); $shtax_count++) {
        $shtax_name = $shtax_details[$shtax_count]['taxname'];
        $shtax_label = $shtax_details[$shtax_count]['taxlabel'];
        $shtax_percent = getInventorySHTaxPercent($focus->id, $shtax_name);
        $shtaxamount = $shAmount * $shtax_percent / 100;
        $shtaxamountformated = number_format($shtaxamount, $decimal_precision, $decimals_separator, $thousands_separator);
        $shtaxtotal = $shtaxtotal + $shtaxamount;
        $shtaxtotalformated = number_format($shtaxtotal, $decimal_precision, $decimals_separator, $thousands_separator);
        $shtax_info_message .= "{$shtax_label} : {$shtax_percent} % = {$shtaxamountformated} \\n";
    }
    $shtax_info_message .= "\\n " . $app_strings['LBL_TOTAL_TAX_AMOUNT'] . " = {$shtaxtotalformated}";
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small">(+)&nbsp;<b><a href="javascript:;" onclick="alert(\'' . $shtax_info_message . '\')">' . $app_strings['LBL_TAX_FOR_SHIPPING_AND_HANDLING'] . '</a></b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . $shtaxtotalformated . '</td>';
    $output .= '</tr>';
    $adjustment = $focus->column_fields['txtAdjustment'] != '' ? $focus->column_fields['txtAdjustment'] : '0.00';
    $adjustmentformated = number_format($adjustment, $decimal_precision, $decimals_separator, $thousands_separator);
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small">&nbsp;<b>' . $app_strings['LBL_ADJUSTMENT'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small">' . $adjustmentformated . '</td>';
    $output .= '</tr>';
    $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0.00';
    $grandTotalformated = number_format($grandTotal, $decimal_precision, $decimals_separator, $thousands_separator);
    $output .= '<tr>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop"><b>' . $app_strings['LBL_GRAND_TOTAL'] . '</b></td>';
    $output .= '<td align="right" class="crmTableRow small lineOnTop">' . $grandTotalformated . '</td>';
    $output .= '</tr>';
    $output .= '</table>';
    $log->debug("Exiting getDetailAssociatedProducts method ...");
    return $output;
}
Ejemplo n.º 15
0
 if ($res) {
     if (mysqli_num_rows($res) > 0) {
         $ksTable = "<table id='ksTable' class='table table-condensed'>\n\t\t\t\t\t\t\t\t\t\t\t<thead>\n\t\t\t\t\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<th width='3%'>No.</th>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<th width='2%'></th>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<th width='2%'></th>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<th>File Name</th>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<th>Upload Date</th>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<th>Product Name</th>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t\t\t\t</thead>\n\t\t\t\t\t\t\t\t\t\t\t<tbody>";
         $c = 1;
         while ($row = mysqli_fetch_array($res)) {
             $ap_filename = $row['ap_filename'];
             $ap_filetype = $row['ap_filetype'];
             if ($ap_filetype == 1) {
                 $ap_filetype = "New Document";
             } else {
                 if ($ap_filetype == 2) {
                     $ap_filetype = "Additional Document";
                 }
             }
             $ap_prdct_id = $row['ap_prdct_id'];
             $productName = getProductName($ap_prdct_id);
             $ap_uploadDate = $row['ap_uploadDate'];
             $ap_uploadDate = date('d-m-Y', strtotime($ap_uploadDate));
             $ap_id = $row['ap_id'];
             $pp_reg_no = $row['pp_reg_no'];
             $ap_ks_comment = $row['ap_ks_comment'];
             $ksTable .= "<tr>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td style='vertical-align:top'> {$c} </td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td style='vertical-align:top'> <input type='checkbox' name='psurID[]' value='{$ap_id}' /> </td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td style='vertical-align:top'> <input type='button' value='+/-' onclick='toggleDetail(\"{$ap_id}\")' class='btn btn-xs btn-info'/> </td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td style='vertical-align:top'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$ap_filename} <br/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div id='{$ap_id}' class='detail'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tRegistration/MAL Number: {$pp_reg_no} <br/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFile Type: {$ap_filetype} <br/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSection Head Comments: {$ap_ks_comment} <br/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href='download_PSUR.php?prdctID={$ap_prdct_id}&&file={$ap_filename}'> Download </a\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td style='vertical-align:top'> {$ap_uploadDate} </td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<td style='vertical-align:top'> {$productName} </td>\n\t\t\t\t\t\t\t\t\t\t\t\t</tr>";
             $c++;
         }
     } else {
         $ksTable .= "<tr><td colspan='6'> <center> No File(s) Found </center> </td></tr>";
     }
     $ksTable .= "</tbody></table>";
     echo $ksTable;
 } else {
     echo "An error occured";
Ejemplo n.º 16
0
/** This function returns the detail view form ec_field and and its properties in array format.
 * Param $uitype - UI type of the ec_field
 * Param $fieldname - Form ec_field name
 * Param $fieldlabel - Form ec_field label name
 * Param $col_fields - array contains the ec_fieldname and values
 * Param $generatedtype - Field generated type (default is 1)
 * Param $tabid - ec_tab id to which the Field belongs to (default is "")
 * Return type is an array
 */
function getDetailViewOutputHtml($uitype, $fieldname, $fieldlabel, $col_fields, $generatedtype, $tabid = '')
{
    global $log;
    $log->debug("Entering getDetailViewOutputHtml() method ...");
    global $adb;
    global $mod_strings;
    global $app_strings;
    global $current_user;
    //$fieldlabel = from_html($fieldlabel);
    $custfld = '';
    $value = '';
    $arr_data = array();
    $label_fld = array();
    $data_fld = array();
    if ($generatedtype == 2) {
        $mod_strings[$fieldlabel] = $fieldlabel;
    }
    if (!isset($mod_strings[$fieldlabel])) {
        $mod_strings[$fieldlabel] = $fieldlabel;
    }
    if ($col_fields[$fieldname] == '--None--') {
        $col_fields[$fieldname] = '';
    }
    if ($uitype == 116) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 13) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $temp_val = $col_fields[$fieldname];
        $label_fld[] = $temp_val;
        $linkvalue = getComposeMailUrl($temp_val);
        $label_fld["link"] = $linkvalue;
    } elseif ($uitype == 5 || $uitype == 23 || $uitype == 70) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $cur_date_val = $col_fields[$fieldname];
        if (!isValidDate($cur_date_val)) {
            $display_val = '';
        } else {
            $display_val = getDisplayDate($cur_date_val);
        }
        $label_fld[] = $display_val;
    } elseif ($uitype == 15 || $uitype == 16 || $uitype == 115 || $uitype == 111) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 10) {
        if (isset($app_strings[$fieldlabel])) {
            $label_fld[] = $app_strings[$fieldlabel];
        } elseif (isset($mod_strings[$fieldlabel])) {
            $label_fld[] = $mod_strings[$fieldlabel];
        } else {
            $label_fld[] = $fieldlabel;
        }
        $value = $col_fields[$fieldname];
        $module_entityname = "";
        if ($value != '') {
            $query = "SELECT ec_entityname.* FROM ec_crmentityrel inner join ec_entityname on ec_entityname.modulename=ec_crmentityrel.relmodule inner join ec_tab on ec_tab.name=ec_crmentityrel.module WHERE ec_tab.tabid='" . $tabid . "' and ec_entityname.entityidfield='" . $fieldname . "'";
            $fldmod_result = $adb->query($query);
            $rownum = $adb->num_rows($fldmod_result);
            if ($rownum > 0) {
                $rel_modulename = $adb->query_result($fldmod_result, 0, 'modulename');
                $rel_tablename = $adb->query_result($fldmod_result, 0, 'tablename');
                $rel_entityname = $adb->query_result($fldmod_result, 0, 'fieldname');
                $rel_entityid = $adb->query_result($fldmod_result, 0, 'entityidfield');
                $module_entityname = getEntityNameForTen($rel_tablename, $rel_entityname, $fieldname, $value);
            }
        }
        $label_fld[] = $module_entityname;
        $label_fld["secid"] = $value;
        $label_fld["link"] = "index.php?module=" . $rel_modulename . "&action=DetailView&record=" . $value;
    } elseif ($uitype == 33) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = str_ireplace(' |##| ', ', ', $col_fields[$fieldname]);
    } elseif ($uitype == 17) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
        //$label_fld[] = '<a href="http://'.$col_fields[$fieldname].'" target="_blank">'.$col_fields[$fieldname].'</a>';
    } elseif ($uitype == 19) {
        //$tmp_value = str_replace("&lt;","<",nl2br($col_fields[$fieldname]));
        //$tmp_value = str_replace("&gt;",">",$tmp_value);
        //$col_fields[$fieldname]= make_clickable($tmp_value);
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 20 || $uitype == 21 || $uitype == 22 || $uitype == 24) {
        //$col_fields[$fieldname]=nl2br($col_fields[$fieldname]);
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 51 || $uitype == 50 || $uitype == 73) {
        $account_id = $col_fields[$fieldname];
        $account_name = "";
        if ($account_id != '') {
            $account_name = getAccountName($account_id);
        }
        //Account Name View
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $account_name;
        $label_fld["secid"] = $account_id;
        $label_fld["link"] = "index.php?module=Accounts&action=DetailView&record=" . $account_id;
    } elseif ($uitype == 52 || $uitype == 77 || $uitype == 101) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $user_id = $col_fields[$fieldname];
        $user_name = getUserName($user_id);
        $label_fld[] = $user_name;
    } elseif ($uitype == 53) {
        $user_id = $col_fields[$fieldname];
        $user_name = getUserName($user_id);
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $user_name;
    } elseif ($uitype == 1004) {
        if (isset($mod_strings[$fieldlabel])) {
            $label_fld[] = $mod_strings[$fieldlabel];
        } else {
            $label_fld[] = $fieldlabel;
        }
        $value = $col_fields[$fieldname];
        $label_fld[] = getUserName($value);
    } elseif ($uitype == 56) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $value = $col_fields[$fieldname];
        if ($value == 1) {
            //Since "yes" is not been translated it is given as app strings here..
            $display_val = $app_strings['yes'];
        } else {
            $display_val = '';
        }
        $label_fld[] = $display_val;
    } elseif ($uitype == 57) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $contact_id = $col_fields[$fieldname];
        $contact_name = "";
        if (trim($contact_id) != '') {
            $contact_name = getContactName($contact_id);
        }
        $label_fld[] = $contact_name;
        $label_fld["secid"] = $contact_id;
        $label_fld["link"] = "index.php?module=Contacts&action=DetailView&record=" . $contact_id;
    } elseif ($uitype == 59) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $product_id = $col_fields[$fieldname];
        if ($product_id != '') {
            $product_name = getProductName($product_id);
        }
        //Account Name View
        $label_fld[] = $product_name;
        $label_fld["secid"] = $product_id;
        $label_fld["link"] = "index.php?module=Products&action=DetailView&record=" . $product_id;
    } elseif ($uitype == 71 || $uitype == 72) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $display_val = $col_fields[$fieldname];
        $label_fld[] = $display_val;
    } elseif ($uitype == 76) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $potential_id = $col_fields[$fieldname];
        if ($potential_id != '') {
            $potential_name = getPotentialName($potential_id);
        }
        $label_fld[] = $potential_name;
        $label_fld["secid"] = $potential_id;
        $label_fld["link"] = "index.php?module=Potentials&action=DetailView&record=" . $potential_id;
    } elseif ($uitype == 80) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $salesorder_id = $col_fields[$fieldname];
        if ($salesorder_id != '') {
            $salesorder_name = getSoName($salesorder_id);
        }
        $label_fld[] = $salesorder_name;
        $label_fld["secid"] = $salesorder_id;
        $label_fld["link"] = "index.php?module=SalesOrder&action=DetailView&record=" . $salesorder_id;
    } elseif ($uitype == 85) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 86) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 87) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 88) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 89) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } else {
        $label_fld[] = $mod_strings[$fieldlabel];
        if ($col_fields[$fieldname] == '0') {
            $col_fields[$fieldname] = '';
        }
        $label_fld[] = $col_fields[$fieldname];
    }
    $label_fld[] = $uitype;
    $log->debug("Exiting getDetailViewOutputHtml method ...");
    return $label_fld;
}
Ejemplo n.º 17
0
/** This function returns the detailed list of vtiger_products associated to a given entity or a record.
* Param $module - module name
* Param $focus - module object
* Param $seid - sales entity id
* Return type is an object array
*/
function getAssociatedProducts($module, $focus, $seid = '')
{
    global $log;
    $log->debug("Entering getAssociatedProducts(" . $module . "," . get_class($focus) . "," . $seid . "='') method ...");
    global $adb;
    $output = '';
    global $theme, $current_user;
    $no_of_decimal_places = getCurrencyDecimalPlaces();
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    $product_Detail = array();
    // DG 15 Aug 2006
    // Add "ORDER BY sequence_no" to retain add order on all inventoryproductrel items
    // SalesPlatform.ru begin Add Act and Consignment modules
    if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') {
        // SalesPlatform.ru begin
        $query = "SELECT \n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,\n \t\t            case when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode, \n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.usageunit else vtiger_service.service_usageunit end as usageunit,\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_code else vtiger_service.unit_code end as unit_code,\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.manuf_country else '--' end as manuf_country,\t\t\t\t\t\t\t\t\t\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.manuf_country_code else '--' end as manuf_country_code,\n\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.customs_id else '--' end as customs_id,\t\t\t\t\t\t\t\t\t\n \t\t            case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,\n \t\t            case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,\n \t\t                        vtiger_inventoryproductrel.listprice, \n \t\t                        vtiger_crmentity.description AS product_description, \n \t\t                        vtiger_inventoryproductrel.* , vtiger_crmentity.deleted\n                                    , attachments.attachment_id, attachments.attachment_name, attachments.attachment_path\n \t                            FROM vtiger_inventoryproductrel \n                                LEFT JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_inventoryproductrel.productid\n \t\t                        LEFT JOIN vtiger_products \n \t\t                                ON vtiger_products.productid=vtiger_inventoryproductrel.productid \n \t\t                        LEFT JOIN vtiger_service \n \t\t                                ON vtiger_service.serviceid=vtiger_inventoryproductrel.productid \n                                        LEFT JOIN (\n                                                    SELECT vtiger_attachments.attachmentsid AS attachment_id,\n                                                        vtiger_seattachmentsrel.crmid AS attachment_crmid, \n                                                        vtiger_attachments.name AS attachment_name, \n                                                        vtiger_attachments.path AS attachment_path \n                                                    FROM vtiger_seattachmentsrel, vtiger_attachments, vtiger_inventoryproductrel \n                                                    WHERE vtiger_seattachmentsrel.crmid=vtiger_inventoryproductrel.productid AND \n                                                        vtiger_attachments.attachmentsid=vtiger_seattachmentsrel.attachmentsid \n                                                    GROUP BY attachment_crmid DESC\n                                                  ) attachments\n                                                ON attachments.attachment_crmid=vtiger_inventoryproductrel.productid                                                \n \t\t                        WHERE id=?\n \t\t                        ORDER BY sequence_no";
        /*		$query="SELECT 
            case when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,
            case when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode, 
            case when vtiger_products.productid != '' then vtiger_products.usageunit else vtiger_service.service_usageunit end as usageunit,									
            case when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,									
            case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,
            case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,
                        vtiger_inventoryproductrel.listprice, 
                        vtiger_inventoryproductrel.description AS product_description, 
                        vtiger_inventoryproductrel.* 
                        FROM vtiger_inventoryproductrel 
                        LEFT JOIN vtiger_products 
                                ON vtiger_products.productid=vtiger_inventoryproductrel.productid 
                        LEFT JOIN vtiger_service 
                                ON vtiger_service.serviceid=vtiger_inventoryproductrel.productid 
                        WHERE id=?
                        ORDER BY sequence_no"; */
        // SalesPlatform.ru end
        $params = array($focus->id);
    } elseif ($module == 'Potentials') {
        $query = "SELECT\n \t\t                        vtiger_products.productname,\n \t\t                        vtiger_products.productcode,\n \t\t                        vtiger_products.unit_price,\n \t\t                        vtiger_products.qtyinstock,\n \t\t                        vtiger_seproductsrel.*,vtiger_crmentity.deleted,\n \t\t                        vtiger_crmentity.description AS product_description\n \t\t                        FROM vtiger_products\n \t\t                        INNER JOIN vtiger_crmentity\n \t\t                                ON vtiger_crmentity.crmid=vtiger_products.productid\n \t\t                        INNER JOIN vtiger_seproductsrel\n \t\t                                ON vtiger_seproductsrel.productid=vtiger_products.productid\n \t\t                        WHERE vtiger_seproductsrel.crmid=?";
        $params = array($seid);
    } elseif ($module == 'Products') {
        $query = "SELECT\n \t\t                        vtiger_products.productid,\n \t\t                        vtiger_products.productcode,\n \t\t                        vtiger_products.productname,\n \t\t                        vtiger_products.unit_price,\n \t\t                        vtiger_products.qtyinstock,vtiger_crmentity.deleted,\n \t\t                        vtiger_crmentity.description AS product_description,\n \t\t                        'Products' AS entitytype\n \t\t                        FROM vtiger_products\n \t\t                        INNER JOIN vtiger_crmentity\n \t\t                                ON vtiger_crmentity.crmid=vtiger_products.productid\n \t\t                        WHERE vtiger_crmentity.deleted=0\n \t\t                                AND productid=?";
        $params = array($seid);
    } elseif ($module == 'Services') {
        $query = "SELECT\n \t\t                        vtiger_service.serviceid AS productid,\n \t\t                        'NA' AS productcode,\n \t\t                        vtiger_service.servicename AS productname,\n \t\t                        vtiger_service.unit_price AS unit_price,\n \t\t                        'NA' AS qtyinstock,vtiger_crmentity.deleted,\n \t\t                        vtiger_crmentity.description AS product_description,\n \t\t                       \t'Services' AS entitytype\n \t\t\t\t\t\t\t\tFROM vtiger_service\n \t\t                        INNER JOIN vtiger_crmentity\n \t\t                                ON vtiger_crmentity.crmid=vtiger_service.serviceid\n \t\t                        WHERE vtiger_crmentity.deleted=0\n \t\t                                AND serviceid=?";
        $params = array($seid);
    }
    $result = $adb->pquery($query, $params);
    $num_rows = $adb->num_rows($result);
    for ($i = 1; $i <= $num_rows; $i++) {
        $deleted = $adb->query_result($result, $i - 1, 'deleted');
        $hdnProductId = $adb->query_result($result, $i - 1, 'productid');
        $hdnProductcode = $adb->query_result($result, $i - 1, 'productcode');
        $productname = $adb->query_result($result, $i - 1, 'productname');
        $productdescription = $adb->query_result($result, $i - 1, 'product_description');
        $comment = $adb->query_result($result, $i - 1, 'comment');
        $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock');
        $qty = $adb->query_result($result, $i - 1, 'quantity');
        $unitprice = $adb->query_result($result, $i - 1, 'unit_price');
        $listprice = $adb->query_result($result, $i - 1, 'listprice');
        $entitytype = $adb->query_result($result, $i - 1, 'entitytype');
        // SalesPlatform.ru begin
        if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') {
            $manuf_country = $adb->query_result($result, $i - 1, 'manuf_country');
            $customs_id = $adb->query_result($result, $i - 1, 'customs_id');
            $manuf_country_code = $adb->query_result($result, $i - 1, 'manuf_country_code');
            $unit_code = $adb->query_result($result, $i - 1, 'unit_code');
            $usageunit = $adb->query_result($result, $i - 1, 'usageunit');
            $attachment_id = $adb->query_result($result, $i - 1, 'attachment_id');
            $attachment_name = $adb->query_result($result, $i - 1, 'attachment_name');
            $attachment_path = $adb->query_result($result, $i - 1, 'attachment_path');
        }
        // SalesPlatform.ru end
        if ($deleted || !isset($deleted)) {
            $product_Detail[$i]['productDeleted' . $i] = true;
        } elseif (!$deleted) {
            $product_Detail[$i]['productDeleted' . $i] = false;
        }
        if (!empty($entitytype)) {
            $product_Detail[$i]['entityType' . $i] = $entitytype;
        }
        if ($listprice == '') {
            $listprice = $unitprice;
        }
        if ($qty == '') {
            $qty = 1;
        }
        //calculate productTotal
        $productTotal = $qty * $listprice;
        //Delete link in First column
        if ($i != 1) {
            $product_Detail[$i]['delRow' . $i] = "Del";
        }
        if (empty($focus->mode) && $seid != '') {
            $sub_prod_query = $adb->pquery("SELECT crmid as prod_id from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($seid));
        } else {
            $sub_prod_query = $adb->pquery("SELECT productid as prod_id from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i));
        }
        $subprodid_str = '';
        $subprodname_str = '';
        $subProductArray = array();
        if ($adb->num_rows($sub_prod_query) > 0) {
            for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                $sprod_id = $adb->query_result($sub_prod_query, $j, 'prod_id');
                $sprod_name = $subProductArray[] = getProductName($sprod_id);
                $str_sep = "";
                if ($j > 0) {
                    $str_sep = ":";
                }
                $subprodid_str .= $str_sep . $sprod_id;
                if (isset($sprod_name)) {
                    $subprodname_str .= $str_sep . " - " . $sprod_name;
                }
            }
        }
        $subprodname_str = str_replace(":", "<br>", $subprodname_str);
        $product_Detail[$i]['subProductArray' . $i] = $subProductArray;
        $product_Detail[$i]['hdnProductId' . $i] = $hdnProductId;
        $product_Detail[$i]['productName' . $i] = from_html($productname);
        /* Added to fix the issue Product Pop-up name display*/
        if ($_REQUEST['action'] == 'CreateSOPDF' || $_REQUEST['action'] == 'CreatePDF' || $_REQUEST['action'] == 'SendPDFMail') {
            $product_Detail[$i]['productName' . $i] = htmlspecialchars($product_Detail[$i]['productName' . $i]);
        }
        $product_Detail[$i]['hdnProductcode' . $i] = $hdnProductcode;
        $product_Detail[$i]['productDescription' . $i] = from_html($productdescription);
        if ($module == 'Potentials' || $module == 'Products' || $module == 'Services') {
            $product_Detail[$i]['comment' . $i] = $productdescription;
        } else {
            $product_Detail[$i]['comment' . $i] = $comment;
        }
        // SalesPlatform.ru begin Added acts and consignments
        if ($module != 'PurchaseOrder' && $focus->object_name != 'Order' && $module != 'Act' && $module != 'Consignment') {
            $product_Detail[$i]['qtyInStock' . $i] = decimalFormat($qtyinstock);
        }
        $listprice = number_format($listprice, $no_of_decimal_places, '.', '');
        $product_Detail[$i]['qty' . $i] = decimalFormat($qty);
        $product_Detail[$i]['listPrice' . $i] = $listprice;
        $product_Detail[$i]['unitPrice' . $i] = number_format($unitprice, $no_of_decimal_places, '.', '');
        $product_Detail[$i]['productTotal' . $i] = $productTotal;
        $product_Detail[$i]['subproduct_ids' . $i] = $subprodid_str;
        $product_Detail[$i]['subprod_names' . $i] = $subprodname_str;
        $discount_percent = decimalFormat($adb->query_result($result, $i - 1, 'discount_percent'));
        $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount');
        $discount_amount = decimalFormat(number_format($discount_amount, $no_of_decimal_places, '.', ''));
        $discountTotal = '0';
        //Based on the discount percent or amount we will show the discount details
        //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(for Each Product)
        $product_Detail[$i]['discount_percent' . $i] = 0;
        $product_Detail[$i]['discount_amount' . $i] = 0;
        if (!empty($discount_percent)) {
            $product_Detail[$i]['discount_type' . $i] = "percentage";
            $product_Detail[$i]['discount_percent' . $i] = $discount_percent;
            $product_Detail[$i]['checked_discount_percent' . $i] = ' checked';
            $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:visible"';
            $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:hidden"';
            $discountTotal = $productTotal * $discount_percent / 100;
        } elseif (!empty($discount_amount)) {
            $product_Detail[$i]['discount_type' . $i] = "amount";
            $product_Detail[$i]['discount_amount' . $i] = $discount_amount;
            $product_Detail[$i]['checked_discount_amount' . $i] = ' checked';
            $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:visible"';
            $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:hidden"';
            $discountTotal = $discount_amount;
        } else {
            $product_Detail[$i]['checked_discount_zero' . $i] = ' checked';
        }
        $totalAfterDiscount = $productTotal - $discountTotal;
        $totalAfterDiscount = number_format($totalAfterDiscount, $no_of_decimal_places, '.', '');
        $discountTotal = number_format($discountTotal, $no_of_decimal_places, '.', '');
        $product_Detail[$i]['discountTotal' . $i] = $discountTotal;
        $product_Detail[$i]['totalAfterDiscount' . $i] = $totalAfterDiscount;
        // SalesPlatform.ru begin
        if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') {
            $product_Detail[$i]['manufCountry' . $i] = $manuf_country;
            $product_Detail[$i]['customsId' . $i] = $customs_id;
            $product_Detail[$i]['manufCountryCode' . $i] = $manuf_country_code;
            $product_Detail[$i]['unitCode' . $i] = $unit_code;
            $product_Detail[$i]['usageunit' . $i] = $usageunit;
            $product_Detail[$i]['attachmentId' . $i] = $attachment_id;
            $product_Detail[$i]['attachmentName' . $i] = $attachment_name;
            $product_Detail[$i]['attachmentPath' . $i] = $attachment_path;
        }
        // SalesPlatform.ru end
        $taxTotal = '0.00';
        $taxTotal = number_format($taxTotal, $no_of_decimal_places, '.', '');
        $product_Detail[$i]['taxTotal' . $i] = $taxTotal;
        //Calculate netprice
        $netPrice = $totalAfterDiscount + $taxTotal;
        //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module
        // SalesPlatform.ru begin Added acts and consignments
        if ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') {
            $taxtype = getInventoryTaxType($module, $focus->id);
            if ($taxtype == 'individual') {
                //Add the tax with product total and assign to netprice
                $netPrice = $netPrice + $taxTotal;
            }
        }
        $product_Detail[$i]['netPrice' . $i] = $netPrice;
        //First we will get all associated taxes as array
        $tax_details = getTaxDetailsForProduct($hdnProductId, 'all');
        //Now retrieve the tax values from the current query with the name
        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
            $tax_name = $tax_details[$tax_count]['taxname'];
            $tax_label = $tax_details[$tax_count]['taxlabel'];
            $tax_value = '0';
            //condition to avoid this function call when create new PO/SO/Quotes/Invoice from Product module
            if ($focus->id != '') {
                if ($taxtype == 'individual') {
                    //if individual then show the entered tax percentage
                    $tax_value = getInventoryProductTaxValue($focus->id, $hdnProductId, $tax_name);
                } else {
                    //if group tax then we have to show the default value when change to individual tax
                    $tax_value = $tax_details[$tax_count]['percentage'];
                }
            } else {
                //if the above function not called then assign the default associated value of the product
                $tax_value = $tax_details[$tax_count]['percentage'];
            }
            $product_Detail[$i]['taxes'][$tax_count]['taxname'] = $tax_name;
            $product_Detail[$i]['taxes'][$tax_count]['taxlabel'] = $tax_label;
            $product_Detail[$i]['taxes'][$tax_count]['percentage'] = $tax_value;
        }
    }
    //set the taxtype
    $product_Detail[1]['final_details']['taxtype'] = $taxtype;
    //Get the Final Discount, S&H charge, Tax for S&H and Adjustment values
    //To set the Final Discount details
    $finalDiscount = '0';
    $product_Detail[1]['final_details']['discount_type_final'] = 'zero';
    $subTotal = $focus->column_fields['hdnSubTotal'] != '' ? $focus->column_fields['hdnSubTotal'] : '0';
    $subTotal = number_format($subTotal, $no_of_decimal_places, '.', '');
    $product_Detail[1]['final_details']['hdnSubTotal'] = $subTotal;
    $discountPercent = $focus->column_fields['hdnDiscountPercent'] != '' ? $focus->column_fields['hdnDiscountPercent'] : '0';
    $discountAmount = $focus->column_fields['hdnDiscountAmount'] != '' ? $focus->column_fields['hdnDiscountAmount'] : '0';
    if ($discountPercent != '0') {
        $discountAmount = $product_Detail[1]['final_details']['hdnSubTotal'] * $discountPercent / 100;
    }
    //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(For Final Discount)
    $discount_amount_final = '0';
    $discount_amount_final = number_format($discount_amount_final, $no_of_decimal_places, '.', '');
    $product_Detail[1]['final_details']['discount_percentage_final'] = 0;
    $product_Detail[1]['final_details']['discount_amount_final'] = $discount_amount_final;
    //fix for opensource issue not saving invoice data properly
    if (!empty($focus->column_fields['hdnDiscountPercent'])) {
        $finalDiscount = $subTotal * $discountPercent / 100;
        $product_Detail[1]['final_details']['discount_type_final'] = 'percentage';
        $product_Detail[1]['final_details']['discount_percentage_final'] = $discountPercent;
        $product_Detail[1]['final_details']['checked_discount_percentage_final'] = ' checked';
        $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:visible"';
        $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:hidden"';
    } elseif (!empty($focus->column_fields['hdnDiscountAmount'])) {
        $finalDiscount = $focus->column_fields['hdnDiscountAmount'];
        $product_Detail[1]['final_details']['discount_type_final'] = 'amount';
        $product_Detail[1]['final_details']['discount_amount_final'] = $discountAmount;
        $product_Detail[1]['final_details']['checked_discount_amount_final'] = ' checked';
        $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:visible"';
        $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:hidden"';
    }
    $finalDiscount = number_format($finalDiscount, $no_of_decimal_places, '.', '');
    $product_Detail[1]['final_details']['discountTotal_final'] = $finalDiscount;
    //To set the Final Tax values
    //we will get all taxes. if individual then show the product related taxes only else show all taxes
    //suppose user want to change individual to group or vice versa in edit time the we have to show all taxes. so that here we will store all the taxes and based on need we will show the corresponding taxes
    $taxtotal = '0';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $tax_details = getAllTaxes('available', '', 'edit', $focus->id);
    for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
        $tax_name = $tax_details[$tax_count]['taxname'];
        $tax_label = $tax_details[$tax_count]['taxlabel'];
        //if taxtype is individual and want to change to group during edit time then we have to show the all available taxes and their default values
        //Also taxtype is group and want to change to individual during edit time then we have to provide the asspciated taxes and their default tax values for individual products
        // SalesPlatform.ru begin
        if ($taxtype == 'group' || $taxtype == 'group_tax_inc') {
            //if($taxtype == 'group')
            // SalesPlatform.ru end
            $tax_percent = $adb->query_result($result, 0, $tax_name);
        } else {
            $tax_percent = $tax_details[$tax_count]['percentage'];
        }
        //$adb->query_result($result,0,$tax_name);
        if ($tax_percent == '' || $tax_percent == 'NULL') {
            $tax_percent = '0.00';
        }
        // SalesPlatform.ru begin
        if ($taxtype == 'group_tax_inc') {
            $taxamount = ($subTotal - $finalDiscount) * $tax_percent / (100.0 + $tax_percent);
        } else {
            // SalesPlatform.ru end
            $taxamount = ($subTotal - $finalDiscount) * $tax_percent / 100;
        }
        $taxamount = number_format($taxamount, $no_of_decimal_places, '.', '');
        $taxtotal = $taxtotal + $taxamount;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['taxname'] = $tax_name;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['taxlabel'] = $tax_label;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['percentage'] = $tax_percent;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['amount'] = $taxamount;
    }
    $product_Detail[1]['final_details']['tax_totalamount'] = $taxtotal;
    //To set the Shipping & Handling charge
    $shCharge = $focus->column_fields['hdnS_H_Amount'] != '' ? $focus->column_fields['hdnS_H_Amount'] : '0    ';
    $shCharge = number_format($shCharge, $no_of_decimal_places, '.', '');
    $product_Detail[1]['final_details']['shipping_handling_charge'] = $shCharge;
    //To set the Shipping & Handling tax values
    //calculate S&H tax
    $shtaxtotal = '0';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $shtax_details = getAllTaxes('available', 'sh', 'edit', $focus->id);
    //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
    for ($shtax_count = 0; $shtax_count < count($shtax_details); $shtax_count++) {
        $shtax_name = $shtax_details[$shtax_count]['taxname'];
        $shtax_label = $shtax_details[$shtax_count]['taxlabel'];
        $shtax_percent = '0';
        //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module
        // SalesPlatform.ru begin Added acts and consignments
        if ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice' || $module == 'Act' || $module == 'Consignment') {
            $shtax_percent = getInventorySHTaxPercent($focus->id, $shtax_name);
        }
        // SalesPlatform.ru begin
        if ($taxtype == 'group_tax_inc') {
            $shtaxamount = $shCharge * $shtax_percent / (100 + $shtax_percent);
        } else {
            // SalesPlatform.ru end
            $shtaxamount = $shCharge * $shtax_percent / 100;
        }
        $shtaxtotal = $shtaxtotal + $shtaxamount;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxname'] = $shtax_name;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxlabel'] = $shtax_label;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['percentage'] = $shtax_percent;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['amount'] = $shtaxamount;
    }
    $shtaxtotal = number_format($shtaxtotal, $no_of_decimal_places, '.', '');
    $product_Detail[1]['final_details']['shtax_totalamount'] = $shtaxtotal;
    //To set the Adjustment value
    $adjustment = $focus->column_fields['txtAdjustment'] != '' ? $focus->column_fields['txtAdjustment'] : '0';
    $adjustment = number_format($adjustment, $no_of_decimal_places, '.', '');
    $product_Detail[1]['final_details']['adjustment'] = $adjustment;
    //To set the grand total
    $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0';
    $grandTotal = number_format($grandTotal, $no_of_decimal_places, '.', '');
    $product_Detail[1]['final_details']['grandTotal'] = $grandTotal;
    $log->debug("Exiting getAssociatedProducts method ...");
    return $product_Detail;
}
Ejemplo n.º 18
0
function getSearchingListViewEntries($focus, $module, $list_result, $navigation_array, $relatedlist = '', $returnset = '', $edit_action = 'EditView', $del_action = 'Delete', $oCv = '', $page = '', $selectedfields = '', $contRelatedfields = '', $skipActions = false, $linksallowed = false)
{
    global $log;
    global $mod_strings;
    $log->debug("Entering getSearchingListViewEntries(" . get_class($focus) . "," . $module . "," . $list_result . "," . $navigation_array . "," . $relatedlist . "," . $returnset . "," . $edit_action . "," . $del_action . "," . (is_object($oCv) ? get_class($oCv) : $oCv) . ") method ...");
    $tabname = getParentTab();
    global $adb, $current_user;
    global $app_strings;
    $noofrows = $adb->num_rows($list_result);
    $list_block = array();
    global $theme;
    $evt_status = '';
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    //getting the vtiger_fieldtable entries from database
    $tabid = getTabid($module);
    //added for vtiger_customview 27/5
    if ($oCv) {
        if (isset($oCv->list_fields)) {
            $focus->list_fields = $oCv->list_fields;
        }
    }
    if (is_array($selectedfields) && $selectedfields != '') {
        $focus->list_fields = $selectedfields;
    }
    // Remove fields which are made inactive
    $focus->filterInactiveFields($module);
    //Added to reduce the no. of queries logging for non-admin user -- by minnie-start
    $field_list = array();
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    foreach ($focus->list_fields as $name => $tableinfo) {
        $fieldname = $focus->list_fields_name[$name];
        if ($oCv) {
            if (isset($oCv->list_fields_name)) {
                $fieldname = $oCv->list_fields_name[$name];
            }
        }
        if ($fieldname == 'accountname' && $module != 'Accounts') {
            $fieldname = 'account_id';
        }
        if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
            $fieldname = 'contact_id';
        }
        if ($fieldname == 'productname' && $module != 'Products') {
            $fieldname = 'product_id';
        }
        array_push($field_list, $fieldname);
    }
    $field = array();
    if ($is_admin == false) {
        if ($module == 'Emails') {
            $query = "SELECT fieldname FROM vtiger_field WHERE tabid = ? and vtiger_field.presence in (0,2)";
            $params = array($tabid);
        } else {
            $profileList = getCurrentUserProfileList();
            $params = array();
            $query = "SELECT DISTINCT vtiger_field.fieldname\n\t\t\tFROM vtiger_field\n\t\t\tINNER JOIN vtiger_profile2field\n\t\t\tON vtiger_profile2field.fieldid = vtiger_field.fieldid\n\t\t\tINNER JOIN vtiger_def_org_field\n\t\t\tON vtiger_def_org_field.fieldid = vtiger_field.fieldid";
            if ($module == "Calendar") {
                $query .= " WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
            } else {
                $query .= " WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
                array_push($params, $tabid);
            }
            $query .= " AND vtiger_profile2field.visible = 0\n\t\t\tAND vtiger_profile2field.visible = 0\n\t\t\tAND vtiger_def_org_field.visible = 0\n\t\t\tAND vtiger_profile2field.profileid IN (" . generateQuestionMarks($profileList) . ")\n\t\t\tAND vtiger_field.fieldname IN (" . generateQuestionMarks($field_list) . ")";
            array_push($params, $profileList, $field_list);
        }
        $result = $adb->pquery($query, $params);
        for ($k = 0; $k < $adb->num_rows($result); $k++) {
            $field[] = $adb->query_result($result, $k, "fieldname");
        }
    }
    //constructing the uitype and columnname array
    $ui_col_array = array();
    $params = array();
    $query = "SELECT uitype, columnname, fieldname FROM vtiger_field ";
    if ($module == "Calendar") {
        $query .= " WHERE vtiger_field.tabid in (9,16) and vtiger_field.presence in (0,2)";
    } else {
        $query .= " WHERE vtiger_field.tabid = ? and vtiger_field.presence in (0,2)";
        array_push($params, $tabid);
    }
    $query .= " AND fieldname IN (" . generateQuestionMarks($field_list) . ") ";
    array_push($params, $field_list);
    $result = $adb->pquery($query, $params);
    $num_rows = $adb->num_rows($result);
    for ($i = 0; $i < $num_rows; $i++) {
        $tempArr = array();
        $uitype = $adb->query_result($result, $i, 'uitype');
        $columnname = $adb->query_result($result, $i, 'columnname');
        $field_name = $adb->query_result($result, $i, 'fieldname');
        $tempArr[$uitype] = $columnname;
        $ui_col_array[$field_name] = $tempArr;
    }
    //end
    if ($navigation_array['start'] != 0) {
        for ($i = 1; $i <= $noofrows; $i++) {
            $list_header = array();
            //Getting the entityid
            if ($module != 'Users') {
                $entity_id = $adb->query_result($list_result, $i - 1, "crmid");
                $owner_id = $adb->query_result($list_result, $i - 1, "smownerid");
            } else {
                $entity_id = $adb->query_result($list_result, $i - 1, "id");
            }
            foreach ($focus->list_fields as $name => $tableinfo) {
                $fieldname = $focus->list_fields_name[$name];
                //added for vtiger_customview 27/5
                if ($oCv) {
                    if (isset($oCv->list_fields_name)) {
                        $fieldname = $oCv->list_fields_name[$name];
                        if ($fieldname == 'accountname' && $module != 'Accounts') {
                            $fieldname = 'account_id';
                        }
                        if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
                            $fieldname = 'contact_id';
                        }
                        if ($fieldname == 'productname' && $module != 'Products') {
                            $fieldname = 'product_id';
                        }
                    } else {
                        $fieldname = $focus->list_fields_name[$name];
                    }
                } else {
                    $fieldname = $focus->list_fields_name[$name];
                    if ($fieldname == 'accountname' && $module != 'Accounts') {
                        $fieldname = 'account_id';
                    }
                    if ($fieldname == 'lastname' && ($module == 'SalesOrder' || $module == 'PurchaseOrder' || $module == 'Invoice' || $module == 'Quotes' || $module == 'Calendar')) {
                        $fieldname = 'contact_id';
                    }
                    if ($fieldname == 'productname' && $module != 'Products') {
                        $fieldname = 'product_id';
                    }
                }
                if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0 || in_array($fieldname, $field) || $fieldname == '' || $name == 'Close' && $module == 'Calendar') {
                    if ($fieldname == '') {
                        $table_name = '';
                        $column_name = '';
                        foreach ($tableinfo as $tablename => $colname) {
                            $table_name = $tablename;
                            $column_name = $colname;
                        }
                        $value = $adb->query_result($list_result, $i - 1, $colname);
                    } else {
                        if ($module == 'Calendar') {
                            $act_id = $adb->query_result($list_result, $i - 1, "activityid");
                            $cal_sql = "select activitytype from vtiger_activity where activityid=?";
                            $cal_res = $adb->pquery($cal_sql, array($act_id));
                            if ($adb->num_rows($cal_res) >= 0) {
                                $activitytype = $adb->query_result($cal_res, 0, "activitytype");
                            }
                        }
                        if (($module == 'Calendar' || $module == 'Emails' || $module == 'HelpDesk' || $module == 'Invoice' || $module == 'Leads' || $module == 'Contacts') && ($fieldname == 'parent_id' || $name == 'Contact Name' || $name == 'Close' || $fieldname == 'firstname')) {
                            if ($module == 'Calendar') {
                                if ($fieldname == 'status') {
                                    if ($activitytype == 'Task') {
                                        $fieldname = 'taskstatus';
                                    } else {
                                        $fieldname = 'eventstatus';
                                    }
                                }
                                if ($activitytype == 'Task') {
                                    if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
                                        $has_permission = 'yes';
                                    } else {
                                        $has_permission = 'no';
                                    }
                                } else {
                                    if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
                                        $has_permission = 'yes';
                                    } else {
                                        $has_permission = 'no';
                                    }
                                }
                            }
                            if ($module != 'Calendar' || $module == 'Calendar' && $has_permission == 'yes') {
                                if ($fieldname == 'parent_id') {
                                    $value = getRelatedTo($module, $list_result, $i - 1);
                                }
                                if ($name == 'Contact Name') {
                                    $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                    $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                    $value = "";
                                    //Added to get the contactname for activities custom view - t=2190
                                    if ($contact_id != '' && !empty($contact_name)) {
                                        $contact_name = getContactName($contact_id);
                                    }
                                    if ($contact_name != "" && $contact_id != 'NULL') {
                                        $value = $contact_name;
                                    }
                                }
                                if ($fieldname == "firstname") {
                                    $first_name = textlength_check($adb->query_result($list_result, $i - 1, "firstname"));
                                    $value = $first_name;
                                }
                                if ($name == 'Close') {
                                    $status = $adb->query_result($list_result, $i - 1, "status");
                                    $activityid = $adb->query_result($list_result, $i - 1, "activityid");
                                    if (empty($activityid)) {
                                        $activityid = $adb->query_result($list_result, $i - 1, "tmp_activity_id");
                                    }
                                    $activitytype = $adb->query_result($list_result, $i - 1, "activitytype");
                                    // TODO - Picking activitytype when it is not present in the Custom View.
                                    // Going forward, this column should be added to the select list if not already present as a performance improvement.
                                    if (empty($activitytype)) {
                                        $activitytypeRes = $adb->pquery('SELECT activitytype FROM vtiger_activity WHERE activityid=?', array($activityid));
                                        if ($adb->num_rows($activitytypeRes) > 0) {
                                            $activitytype = $adb->query_result($activitytypeRes, 0, 'activitytype');
                                        }
                                    }
                                    if ($activitytype != 'Task' && $activitytype != 'Emails') {
                                        $eventstatus = $adb->query_result($list_result, $i - 1, "eventstatus");
                                        if (isset($eventstatus)) {
                                            $status = $eventstatus;
                                        }
                                    }
                                    if ($status == 'Deferred' || $status == 'Completed' || $status == 'Held' || $status == '') {
                                        $value = "";
                                    } else {
                                        if ($activitytype == 'Task') {
                                            $evt_status = '&status=Completed';
                                        } else {
                                            $evt_status = '&eventstatus=Held';
                                        }
                                    }
                                }
                            } else {
                                $value = "";
                            }
                        } elseif ($module == "Documents" && ($fieldname == 'filelocationtype' || $fieldname == 'filename' || $fieldname == 'filesize' || $fieldname == 'filestatus' || $fieldname == 'filetype')) {
                            $value = $adb->query_result($list_result, $i - 1, $fieldname);
                            if ($fieldname == 'filelocationtype') {
                                if ($value == 'I') {
                                    $value = getTranslatedString('LBL_INTERNAL', $module);
                                } elseif ($value == 'E') {
                                    $value = getTranslatedString('LBL_EXTERNAL', $module);
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filename') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                if ($downloadtype == 'I') {
                                    $fld_value = $value;
                                    $ext_pos = strrpos($fld_value, ".");
                                    $ext = substr($fld_value, $ext_pos + 1);
                                    $ext = strtolower($ext);
                                    if ($value != '') {
                                        if ($ext == 'bin' || $ext == 'exe' || $ext == 'rpm') {
                                            $fileicon = "<img src='" . vtiger_imageurl('fExeBin.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                                        } elseif ($ext == 'jpg' || $ext == 'gif' || $ext == 'bmp') {
                                            $fileicon = "<img src='" . vtiger_imageurl('fbImageFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                                        } elseif ($ext == 'txt' || $ext == 'doc' || $ext == 'xls') {
                                            $fileicon = "<img src='" . vtiger_imageurl('fbTextFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                                        } elseif ($ext == 'zip' || $ext == 'gz' || $ext == 'rar') {
                                            $fileicon = "<img src='" . vtiger_imageurl('fbZipFile.gif', $theme) . "' hspace='3' align='absmiddle'\tborder='0'>";
                                        } else {
                                            $fileicon = "<img src='" . vtiger_imageurl('fbUnknownFile.gif', $theme) . "' hspace='3' align='absmiddle' border='0'>";
                                        }
                                    }
                                } elseif ($downloadtype == 'E') {
                                    if (trim($value) != '') {
                                        $fld_value = $value;
                                        $fileicon = "<img src='" . vtiger_imageurl('fbLink.gif', $theme) . "' alt='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' title='" . getTranslatedString('LBL_EXTERNAL_LNK', $module) . "' hspace='3' align='absmiddle' border='0'>";
                                    } else {
                                        $fld_value = '--';
                                        $fileicon = '';
                                    }
                                } else {
                                    $fld_value = ' --';
                                    $fileicon = '';
                                }
                                $file_name = $adb->query_result($list_result, $i - 1, 'filename');
                                $notes_id = $adb->query_result($list_result, $i - 1, 'crmid');
                                $folder_id = $adb->query_result($list_result, $i - 1, 'folderid');
                                $download_type = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                $file_status = $adb->query_result($list_result, $i - 1, 'filestatus');
                                $fileidQuery = "select attachmentsid from vtiger_seattachmentsrel where crmid=?";
                                $fileidres = $adb->pquery($fileidQuery, array($notes_id));
                                $fileid = $adb->query_result($fileidres, 0, 'attachmentsid');
                                if ($file_name != '' && $file_status == 1) {
                                    if ($download_type == 'I') {
                                        $fld_value = "<a href='index.php?module=uploads&action=downloadfile&entityid={$notes_id}&fileid={$fileid}' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "' onclick='javascript:dldCntIncrease({$notes_id});'>" . $fld_value . "</a>";
                                    } elseif ($download_type == 'E') {
                                        $fld_value = "<a target='_blank' href='{$file_name}' onclick='javascript:dldCntIncrease({$notes_id});' title='" . getTranslatedString("LBL_DOWNLOAD_FILE", $module) . "'>" . $fld_value . "</a>";
                                    } else {
                                        $fld_value = ' --';
                                    }
                                }
                                $value = $fileicon . $fld_value;
                            }
                            if ($fieldname == 'filesize') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                if ($downloadtype == 'I') {
                                    $filesize = $value;
                                    if ($filesize < 1024) {
                                        $value = $filesize . ' B';
                                    } elseif ($filesize > 1024 && $filesize < 1048576) {
                                        $value = round($filesize / 1024, 2) . ' KB';
                                    } else {
                                        if ($filesize > 1048576) {
                                            $value = round($filesize / (1024 * 1024), 2) . ' MB';
                                        }
                                    }
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filestatus') {
                                $filestatus = $value;
                                if ($filestatus == 1) {
                                    $value = getTranslatedString('yes', $module);
                                } elseif ($filestatus == 0) {
                                    $value = getTranslatedString('no', $module);
                                } else {
                                    $value = ' --';
                                }
                            }
                            if ($fieldname == 'filetype') {
                                $downloadtype = $adb->query_result($list_result, $i - 1, 'filelocationtype');
                                $filetype = $adb->query_result($list_result, $i - 1, 'filetype');
                                if ($downloadtype == 'E' || $downloadtype != 'I') {
                                    $value = ' --';
                                } else {
                                    $value = $filetype;
                                }
                            }
                            if ($fieldname == 'notecontent') {
                                $value = decode_html($value);
                                $value = textlength_check($value);
                            }
                        } elseif ($module == "Products" && $name == "Related to") {
                            $value = getRelatedTo($module, $list_result, $i - 1);
                        } elseif ($name == 'Contact Name' && ($module == 'SalesOrder' || $module == 'Quotes' || $module == 'PurchaseOrder')) {
                            if ($name == 'Contact Name') {
                                $contact_id = $adb->query_result($list_result, $i - 1, "contactid");
                                $contact_name = getFullNameFromQResult($list_result, $i - 1, "Contacts");
                                $value = "";
                                if ($contact_name != "" && $contact_id != 'NULL') {
                                    $value = $contact_name;
                                }
                            }
                        } elseif ($name == 'Product') {
                            $product_id = textlength_check($adb->query_result($list_result, $i - 1, "productname"));
                            $value = $product_id;
                        } elseif ($name == 'Account Name') {
                            //modified for vtiger_customview 27/5
                            if ($module == 'Accounts') {
                                $account_id = $adb->query_result($list_result, $i - 1, "crmid");
                                //$account_name = getAccountName($account_id);
                                $account_name = textlength_check($adb->query_result($list_result, $i - 1, "accountname"));
                                $value = $account_name;
                            } elseif ($module == 'Potentials' || $module == 'Contacts' || $module == 'Invoice' || $module == 'SalesOrder' || $module == 'Quotes') {
                                //Potential,Contacts,Invoice,SalesOrder & Quotes  records   sort by Account Name
                                //$accountname = textlength_check($adb->query_result($list_result,$i-1,"accountname"));
                                $accountid = $adb->query_result($list_result, $i - 1, "accountid");
                                $accountname = textlength_check(getAccountName($accountid));
                                $value = $accountname;
                            } else {
                                $account_id = $adb->query_result($list_result, $i - 1, "accountid");
                                $account_name = getAccountName($account_id);
                                $acc_name = textlength_check($account_name);
                                $value = $acc_name;
                            }
                        } elseif (($module == 'HelpDesk' || $module == 'PriceBook' || $module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'Faq') && $name == 'Product Name') {
                            if ($module == 'HelpDesk' || $module == 'Faq') {
                                $product_id = $adb->query_result($list_result, $i - 1, "product_id");
                            } else {
                                $product_id = $adb->query_result($list_result, $i - 1, "productid");
                            }
                            if ($product_id != '') {
                                $product_name = getProductName($product_id);
                            } else {
                                $product_name = '';
                            }
                            $value = textlength_check($product_name);
                        } elseif ($module == 'Quotes' && $name == 'Potential Name' || $module == 'SalesOrder' && $name == 'Potential Name') {
                            $potential_id = $adb->query_result($list_result, $i - 1, "potentialid");
                            $potential_name = getPotentialName($potential_id);
                            $value = textlength_check($potential_name);
                        } elseif ($module == 'Emails' && $relatedlist != '' && ($name == 'Subject' || $name == 'Date Sent' || $name == 'To')) {
                            $list_result_count = $i - 1;
                            $tmp_value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                            $tmp_value = evvt_strip_html_links($tmp_value);
                            $value = textlength_check($tmp_value);
                            if ($name == 'Date Sent') {
                                $sql = "select email_flag from vtiger_emaildetails where emailid=?";
                                $result = $adb->pquery($sql, array($entity_id));
                                $email_flag = $adb->query_result($result, 0, "email_flag");
                                if ($email_flag != 'SAVED') {
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                                    $value = evvt_strip_html_links($value);
                                } else {
                                    $value = '';
                                }
                            }
                        } elseif ($module == 'Calendar' && ($fieldname != 'taskstatus' && $fieldname != 'eventstatus')) {
                            if ($activitytype == 'Task') {
                                if (getFieldVisibilityPermission('Calendar', $current_user->id, $fieldname) == '0') {
                                    $list_result_count = $i - 1;
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                                    $value = evvt_strip_html_links($value);
                                } else {
                                    $value = '';
                                }
                            } else {
                                if (getFieldVisibilityPermission('Events', $current_user->id, $fieldname) == '0') {
                                    $list_result_count = $i - 1;
                                    $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                                    $value = evvt_strip_html_links($value);
                                } else {
                                    $value = '';
                                }
                            }
                        } else {
                            $list_result_count = $i - 1;
                            $value = getValue($ui_col_array, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, "list", "", $returnset, $oCv->setdefaultviewid, false);
                            $value = evvt_strip_html_links($value);
                        }
                    }
                    // vtlib customization: For listview javascript triggers
                    //$value = "$value <span type='vtlib_metainfo' vtrecordid='{$entity_id}' vtfieldname='{$fieldname}' vtmodule='$module' style='display:none;'></span>";
                    // END
                    if ($module == "Calendar" && $name == $app_strings['Close']) {
                        if (isPermitted("Calendar", "EditView") == 'yes') {
                            if (getFieldVisibilityPermission('Events', $current_user->id, 'eventstatus') == '0' || getFieldVisibilityPermission('Calendar', $current_user->id, 'taskstatus') == '0') {
                                array_push($list_header, $value);
                            }
                        }
                    } else {
                        $list_header[] = $value;
                    }
                }
            }
            $varreturnset = '';
            $varreturnset = $returnset;
            $webserviceEntityId = vtyiicpng_getWSEntityId($module);
            $list_header[] = $webserviceEntityId . $entity_id;
            $list_header[] = $module;
            $list_block[$entity_id] = $list_header;
        }
    }
    $log->debug("Exiting getSearchingListViewEntries method ...");
    return $list_block;
}
Ejemplo n.º 19
0
 //添加订单类型判断
 $arr = $_model->getAll("memberid='{$uid}'  and pid=0 and status=2 {$w}", "addtime desc", "{$offset},{$pagesize}");
 foreach ($arr as $row) {
     if ($row['typeid'] != 2) {
         $totalprice = $row['dingnum'] * $row['price'] + $row['childnum'] * $row['childprice'] + $row['oldnum'] * $row['oldprice'];
     } else {
         if ($row['haschild'] == 1) {
             $childOrder = getChildOrderInfo($row['id']);
             $totalprice = 0;
             foreach ($childOrder as $order) {
                 $p = intval($order['dingnum']) * $order['price'];
                 $totalprice += $p;
             }
         }
     }
     $productname = getProductName($row['productautoid'], $row['typeid'], $row['productname']);
     //预订产品名称
     // $totalprice = $row['dingnum'] * $row['price'] + $row['childnum'] * $row['childprice'];
     $dingdate = Mydate('Y-m-d H:i:s', $row['addtime']);
     $orderurl = "index.php?dopost=vieworder&typeid={$row['typeid']}&orderid={$row['id']}";
     $out .= ' <tr>
         	    <td height="50">' . $row['ordersn'] . '</td>
         	    <td>' . $productname . '</td>
         	    <td align="center">&yen;' . $totalprice . '</td>
         	    <td align="center">' . $dingdate . '</td>
         	    <td align="center">已完成</td>
       	    </tr>';
 }
 $out = !empty($out) ? $head . $out . $foot : $nocontent_msg;
 $totalnum = $_model->getCount("memberid='{$uid}' and status=2 and ispinlun=0 and pid=0");
 $totalpage = ceil($totalnum / $pagesize);
Ejemplo n.º 20
0
    if ($currentModule == 'Accounts' && $_REQUEST['recordid'] != '') {
        $where_relquery .= " and vtiger_account.accountid!=" . $adb->sql_escape_string($_REQUEST['recordid']);
        $smarty->assign("RECORDID", vtlib_purify($_REQUEST['recordid']));
    }
    if ($currentModule == 'Contacts' && $_REQUEST['recordid'] != '') {
        $where_relquery .= " and vtiger_contactdetails.contactid!=" . $adb->sql_escape_string($_REQUEST['recordid']);
        $smarty->assign("RECORDID", vtlib_purify($_REQUEST['recordid']));
    }
    if ($currentModule == 'Users' && $_REQUEST['recordid'] != '') {
        $where_relquery .= " and vtiger_users.id!=" . $adb->sql_escape_string($_REQUEST['recordid']);
        $smarty->assign("RECORDID", vtlib_purify($_REQUEST['recordid']));
    }
    $query = getListQuery($currentModule, $where_relquery);
}
if ($currentModule == 'Products' && $_REQUEST['record_id'] && ($popuptype == 'inventory_prod' || $popuptype == 'inventory_prod_po')) {
    $product_name = getProductName(vtlib_purify($_REQUEST['record_id']));
    $smarty->assign("PRODUCT_NAME", $product_name);
    $smarty->assign("RECORD_ID", vtlib_purify($_REQUEST['record_id']));
}
$listview_header_search = getSearchListHeaderValues($focus, "{$currentModule}", $url_string, $sorder, $order_by);
$smarty->assign("SEARCHLISTHEADER", $listview_header_search);
$smarty->assign("ALPHABETICAL", $alphabetical);
if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true') {
    list($where, $ustring) = explode("#@@#", getWhereCondition($currentModule));
    $url_string .= "&query=true" . $ustring;
}
if (isset($where) && $where != '') {
    $query .= ' and ' . $where;
}
//Added to fix the issue #2307
$order_by = $focus->getOrderBy();
Ejemplo n.º 21
0
 protected function setInfoWoocommerce()
 {
     include_once PLUGIN_PATH_SHIPWORKSWORDPRESS . 'functions/woocommerce/functionsWoocommerce.php';
     $this->itemID = $this->row['order_item_id'];
     $this->productID = getItemInfo($this->row, '_product_id');
     if (null == (int) getItemInfo($this->row, '_variation_id')) {
         // Dans ce cas le variation Id vaut l'id du produit ce qui est bon
         $variationId = getItemInfo($this->row, '_product_id');
     } else {
         // Dans ce cas l'id est celui de la variation qui va permettre d'aller cherche le sku et le prix
         $variationId = getItemInfo($this->row, '_variation_id');
     }
     // On ajoute les attributs
     global $wpdb;
     $table = $wpdb->prefix . "woocommerce_order_itemmeta";
     $results = $wpdb->get_results("SELECT * FROM " . $table . " WHERE order_item_id = " . $this->row['order_item_id'], ARRAY_A);
     foreach ($results as $row) {
         if (substr($row['meta_key'], 0, 1) != "_") {
             // On regarde si pour cet item il existe des extra options : différent de 0
             // Si oui on enlève les champs qui on un id supérieur à celui de la ligne _tmcartepo_data : le plugin est vraiment mal fichu en base de donnée
             if (isAttributeTMOption($this->row['order_item_id']) != 0) {
                 if ($row['meta_id'] < isAttributeTMOption($this->row['order_item_id'])) {
                     array_push($this->attributes, new Attribute($this->software, $this->date, $row['meta_key'], $row['meta_value']));
                 }
             } else {
                 array_push($this->attributes, new Attribute($this->software, $this->date, $row['meta_key'], $row['meta_value']));
             }
         }
     }
     // On ajoute les attributs dans le cas ou on a des Extra product Options
     if (isAttributeTMOption($this->row['order_item_id']) != 0) {
         $tab = getTMOptionTab($this->row['order_item_id']);
         foreach ($tab as $option) {
             array_push($this->attributes, new Attribute($this->software, $this->date, $option['value'], 'Extra Options(s)', $option['price']));
         }
     }
     // On veut dans tous les cas enregistrer l'id du produit original pour avoir le bon nom
     $productId = getItemInfo($this->row, '_product_id');
     if (null != getProductInfo($variationId, '_sku')) {
         $this->code = getProductInfo($variationId, '_sku');
         $this->sku = getProductInfo($variationId, '_sku');
     } else {
         $this->code = getProductInfo($productId, '_sku');
         $this->sku = getProductInfo($productId, '_sku');
     }
     $this->name = getProductName($productId);
     $this->quantity = getItemInfo($this->row, '_qty');
     // Cas ou on a woocommerce Composite Products
     $this->price = getItemInfo($this->row, '_line_total');
     if (isComposed($this->row)) {
         $this->unitprice = 0;
     } else {
         // On regarde si il y a le plugin woocommerce-bulk-discount woocommerce-bulk-discount.php
         if (is_plugin_active_custom("woocommerce-bulk-discount/woocommerce-bulk-discount.php")) {
             //$this->unitprice = getProductInfo( $variationId, '_price' );
             // On met le prix au cas où le variation id ne soit pas présent dans le champ
             $this->unitprice = getProductInfo($variationId, '_price');
             $bulkInfo = getProductInfo($this->row['order_id'], '_woocommerce_t4m_discount_coeffs');
             if ($bulkInfo) {
                 $bulkData = json_decode($bulkInfo);
                 foreach ($bulkData as $key => $value) {
                     if ($key == $variationId && $value->coeff != 1) {
                         // Si le variation id est présent on remplace le prix
                         $this->unitprice = $value->coeff * $value->orig_price;
                         //var_dump( $value->coeff );
                     }
                 }
                 //var_dump( $bulkData );
             }
             //echo 'nico' . $bulkInfo;
         } else {
             $this->unitprice = getProductInfo($variationId, '_price');
         }
     }
     // Si le poid du variation vaut 0 on prend celui du parent
     if (0 != getProductInfo($variationId, '_weight')) {
         $this->weight = wooWeightNormal(getProductInfo($variationId, '_weight'), 'lbs');
     } else {
         $this->weight = wooWeightNormal(getProductInfo($productId, '_weight'), 'lbs');
     }
     // Les images
     $image = wp_get_attachment_image_src(get_post_thumbnail_id($variationId), 'Single Thumbs');
     $imageThumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($variationId), 'Product Thumbs');
     if ($image[0] == null) {
         // Cas ou on a pas d'image pour le variation product
         $image = wp_get_attachment_image_src(get_post_thumbnail_id($this->productID), 'Single Thumbs');
     }
     if ($imageThumbnail[0] == null) {
         // Cas ou on a pas d'image pour le variation product
         $imageThumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($this->productID), 'Product Thumbs');
     }
     $this->image = $image[0];
     $this->imageThumbnail = $imageThumbnail[0];
 }
Ejemplo n.º 22
0
/** Function to return the duplicate records data as a formatted array */
function getDuplicateRecordsArr($module)
{
    global $adb, $app_strings, $list_max_entries_per_page, $theme;
    $field_values_array = getFieldValues($module);
    $field_values = $field_values_array['fieldnames_list'];
    $fld_arr = $field_values_array['fieldnames_array'];
    $col_arr = $field_values_array['columnnames_array'];
    $fld_labl_arr = $field_values_array['fieldlabels_array'];
    $ui_type = $field_values_array['fieldname_uitype'];
    $dup_query = getDuplicateQuery($module, $field_values, $ui_type);
    // added for page navigation
    $dup_count_query = substr($dup_query, stripos($dup_query, 'FROM'), strlen($dup_query));
    $dup_count_query = "SELECT count(*) as count " . $dup_count_query;
    $count_res = $adb->query($dup_count_query);
    $no_of_rows = $adb->query_result($count_res, 0, "count");
    if ($no_of_rows <= $list_max_entries_per_page) {
        $_SESSION['dup_nav_start' . $module] = 1;
    } else {
        if (isset($_REQUEST["start"]) && $_REQUEST["start"] != "" && $_SESSION['dup_nav_start' . $module] != $_REQUEST["start"]) {
            $_SESSION['dup_nav_start' . $module] = ListViewSession::getRequestStartPage();
        }
    }
    $start = $_SESSION['dup_nav_start' . $module] != "" ? $_SESSION['dup_nav_start' . $module] : 1;
    $navigation_array = getNavigationValues($start, $no_of_rows, $list_max_entries_per_page);
    $start_rec = $navigation_array['start'];
    $end_rec = $navigation_array['end_val'];
    $navigationOutput = getTableHeaderNavigation($navigation_array, "", $module, "FindDuplicate", "");
    if ($start_rec == 0) {
        $limit_start_rec = 0;
    } else {
        $limit_start_rec = $start_rec - 1;
    }
    $dup_query .= " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}";
    //ends
    $nresult = $adb->query($dup_query);
    $no_rows = $adb->num_rows($nresult);
    require_once 'modules/Vtiger/layout_utils.php';
    if ($no_rows == 0) {
        if ($_REQUEST['action'] == 'FindDuplicateRecords') {
            //echo "<br><br><center>".$app_strings['LBL_NO_DUPLICATE']." <a href='javascript:window.history.back()'>".$app_strings['LBL_GO_BACK'].".</a></center>";
            //die;
            echo "<link rel='stylesheet' type='text/css' href='themes/{$theme}/style.css'>";
            echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
            echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>\n\n\t\t\t\t<table border='0' cellpadding='5' cellspacing='0' width='98%'>\n\t\t\t\t<tbody><tr>\n\t\t\t\t<td rowspan='2' width='11%'><img src='" . vtiger_imageurl('empty.jpg', $theme) . "' ></td>\n\t\t\t\t<td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>{$app_strings['LBL_NO_DUPLICATE']}</span></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td class='small' align='right' nowrap='nowrap'>\n\t\t\t\t<a href='javascript:window.history.back();'>{$app_strings['LBL_GO_BACK']}</a><br>     </td>\n\t\t\t\t</tr>\n\t\t\t\t</tbody></table>\n\t\t\t\t</div>";
            echo "</td></tr></table>";
            exit;
        } else {
            echo "<br><br><table align='center' class='reportCreateBottom big' width='95%'><tr><td align='center'>" . $app_strings['LBL_NO_DUPLICATE'] . "</td></tr></table>";
            die;
        }
    }
    $rec_cnt = 0;
    $temp = array();
    $sl_arr = array();
    $grp = "group0";
    $gcnt = 0;
    $ii = 0;
    //ii'th record in group
    while ($rec_cnt < $no_rows) {
        $result = $adb->fetchByAssoc($nresult);
        //echo '<pre>';print_r($result);echo '</pre>';
        if ($rec_cnt != 0) {
            $sl_arr = array_slice($result, 2);
            array_walk($temp, 'lower_array');
            array_walk($sl_arr, 'lower_array');
            $arr_diff = array_diff($temp, $sl_arr);
            if (count($arr_diff) > 0) {
                $gcnt++;
                $temp = $sl_arr;
                $ii = 0;
            }
            $grp = "group" . $gcnt;
        }
        $fld_values[$grp][$ii]['recordid'] = $result['recordid'];
        for ($k = 0; $k < count($col_arr); $k++) {
            if ($rec_cnt == 0) {
                $temp[$fld_labl_arr[$k]] = $result[$col_arr[$k]];
            }
            if ($ui_type[$fld_arr[$k]] == 56) {
                if ($result[$col_arr[$k]] == 0) {
                    $result[$col_arr[$k]] = $app_strings['no'];
                } else {
                    $result[$col_arr[$k]] = $app_strings['yes'];
                }
            }
            if ($ui_type[$fld_arr[$k]] == 75 || $ui_type[$fld_arr[$k]] == 81) {
                $vendor_id = $result[$col_arr[$k]];
                if ($vendor_id != '') {
                    $vendor_name = getVendorName($vendor_id);
                }
                $result[$col_arr[$k]] = $vendor_name;
            }
            if ($ui_type[$fld_arr[$k]] == 57) {
                $contact_id = $result[$col_arr[$k]];
                if ($contact_id != '') {
                    $parent_module = 'Contacts';
                    $displayValueArray = getEntityName($parent_module, $contact_id);
                    if (!empty($displayValueArray)) {
                        foreach ($displayValueArray as $key => $field_value) {
                            $contactname = $field_value;
                        }
                    }
                }
                $result[$col_arr[$k]] = $contactname;
            }
            if ($ui_type[$fld_arr[$k]] == 15 || $ui_type[$fld_arr[$k]] == 16) {
                $result[$col_arr[$k]] = getTranslatedString($result[$col_arr[$k]], $module);
            }
            if ($ui_type[$fld_arr[$k]] == 33) {
                $fieldvalue = explode(' |##| ', $result[$col_arr[$k]]);
                $result[$col_arr[$k]] = array();
                foreach ($fieldvalue as $picklistValue) {
                    $result[$col_arr[$k]][] = getTranslatedString($picklistValue, $module);
                }
                $result[$col_arr[$k]] = implode(', ', $result[$col_arr[$k]]);
            }
            if ($ui_type[$fld_arr[$k]] == 68) {
                $parent_id = $result[$col_arr[$k]];
                if ($parent_id != '') {
                    $parentname = getParentName($parent_id);
                }
                $result[$col_arr[$k]] = $parentname;
            }
            if ($ui_type[$fld_arr[$k]] == 53 || $ui_type[$fld_arr[$k]] == 52) {
                if ($result[$col_arr[$k]] != '') {
                    $owner = getOwnerName($result[$col_arr[$k]]);
                }
                $result[$col_arr[$k]] = $owner;
            }
            if ($ui_type[$fld_arr[$k]] == 50 or $ui_type[$fld_arr[$k]] == 51) {
                if ($module != 'Products') {
                    $entity_name = getAccountName($result[$col_arr[$k]]);
                } else {
                    $entity_name = getProductName($result[$col_arr[$k]]);
                }
                if ($entity_name != '') {
                    $result[$col_arr[$k]] = $entity_name;
                } else {
                    $result[$col_arr[$k]] = '';
                }
            }
            if ($ui_type[$fld_arr[$k]] == 58) {
                $campaign_name = getCampaignName($result[$col_arr[$k]]);
                if ($campaign_name != '') {
                    $result[$col_arr[$k]] = $campaign_name;
                } else {
                    $result[$col_arr[$k]] = '';
                }
            }
            if ($ui_type[$fld_arr[$k]] == 59) {
                $product_name = getProductName($result[$col_arr[$k]]);
                if ($product_name != '') {
                    $result[$col_arr[$k]] = $product_name;
                } else {
                    $result[$col_arr[$k]] = '';
                }
            }
            /*uitype 10 handling*/
            if ($ui_type[$fld_arr[$k]] == 10) {
                $result[$col_arr[$k]] = getRecordInfoFromID($result[$col_arr[$k]]);
            }
            if ($ui_type[$fld_arr[$k]] == 5 || $ui_type[$fld_arr[$k]] == 6 || $ui_type[$fld_arr[$k]] == 23) {
                if (${$result}[$col_arr[$k]] != '' && ${$result}[$col_arr[$k]] != '0000-00-00') {
                    $date = new DateTimeField(${$result}[$col_arr[$k]]);
                    $value = $date->getDisplayDate();
                    if (strpos(${$result}[$col_arr[$k]], ' ') > -1) {
                        $value .= ' ' . $date->getDisplayTime();
                    }
                } elseif (${$result}[$col_arr[$k]] == '0000-00-00') {
                    $value = '';
                } else {
                    $value = ${$result}[$col_arr[$k]];
                }
                $result[$col_arr[$k]] = $value;
            }
            if ($ui_type[$fld_arr[$k]] == 71) {
                $result[$col_arr[$k]] = CurrencyField::convertToUserFormat($result[$col_arr[$k]]);
            }
            if ($ui_type[$fld_arr[$k]] == 72) {
                $result[$col_arr[$k]] = CurrencyField::convertToUserFormat($result[$col_arr[$k]], null, true);
            }
            $fld_values[$grp][$ii][$fld_labl_arr[$k]] = $result[$col_arr[$k]];
        }
        $fld_values[$grp][$ii]['Entity Type'] = $result['deleted'];
        $ii++;
        $rec_cnt++;
    }
    $gro = "group";
    for ($i = 0; $i < $no_rows; $i++) {
        $ii = 0;
        $dis_group[] = $fld_values[$gro . $i][$ii];
        $count_group[$i] = count($fld_values[$gro . $i]);
        $ii++;
        $new_group[] = $dis_group[$i];
    }
    $fld_nam = $new_group[0];
    $ret_arr[0] = $fld_values;
    $ret_arr[1] = $fld_nam;
    $ret_arr[2] = $ui_type;
    $ret_arr["navigation"] = $navigationOutput;
    return $ret_arr;
}
Ejemplo n.º 23
0
/** This function returns the detailed list of vtiger_products associated to a given entity or a record.
* Param $module - module name
* Param $focus - module object
* Param $seid - sales entity id
* Return type is an object array
*/
function getAssociatedProducts($module, $focus, $seid = '')
{
    global $log, $adb, $theme, $current_user;
    $log->debug("Entering getAssociatedProducts(" . $module . "," . get_class($focus) . "," . $seid . "='') method ...");
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    $product_Detail = array();
    if ($module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice') {
        $query = "SELECT\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,\n\t\t\tcase when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,\n\t\t\tcase when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,\n\t\t\tvtiger_inventoryproductrel.listprice,\n\t\t\tvtiger_inventoryproductrel.description AS product_description,\n\t\t\tvtiger_inventoryproductrel.*\n\t\t\tFROM vtiger_inventoryproductrel\n\t\t\tLEFT JOIN vtiger_products ON vtiger_products.productid=vtiger_inventoryproductrel.productid\n\t\t\tLEFT JOIN vtiger_service ON vtiger_service.serviceid=vtiger_inventoryproductrel.productid\n\t\t\tWHERE id=? ORDER BY sequence_no";
        $params = array($focus->id);
        if ($module != 'PurchaseOrder') {
            if (GlobalVariable::getVariable('B2B', '1') == '1') {
                $acvid = $focus->column_fields['account_id'];
            } else {
                $acvid = $focus->column_fields['contact_id'];
            }
        } else {
            $acvid = $focus->column_fields['vendor_id'];
        }
    } elseif ($module == 'Potentials') {
        $query = "SELECT vtiger_products.productid, vtiger_products.productname, vtiger_products.productcode,\n\t\t\tvtiger_products.unit_price, vtiger_products.qtyinstock, vtiger_crmentity.description AS product_description,\n\t\t\t'Products' AS entitytype\n\t\t\tFROM vtiger_products\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid\n\t\t\tINNER JOIN vtiger_seproductsrel ON vtiger_seproductsrel.productid=vtiger_products.productid\n\t\t\tWHERE vtiger_seproductsrel.crmid=?";
        $query .= " UNION SELECT vtiger_service.serviceid AS productid, vtiger_service.servicename AS productname,\n\t\t\t'NA' AS productcode, vtiger_service.unit_price AS unit_price, 'NA' AS qtyinstock,\n\t\t\tvtiger_crmentity.description AS product_description, 'Services' AS entitytype\n\t\t\tFROM vtiger_service\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_service.serviceid\n\t\t\tINNER JOIN vtiger_crmentityrel ON vtiger_crmentityrel.relcrmid=vtiger_service.serviceid\n\t\t\tWHERE vtiger_crmentityrel.crmid=?";
        $params = array($seid, $seid);
    } elseif ($module == 'Products') {
        $query = "SELECT vtiger_products.productid, vtiger_products.productcode, vtiger_products.productname,\n\t\t\tvtiger_products.unit_price, vtiger_products.qtyinstock, vtiger_crmentity.description AS product_description,\n\t\t\t'Products' AS entitytype\n\t\t\tFROM vtiger_products\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid\n\t\t\tWHERE vtiger_crmentity.deleted=0 AND productid=?";
        $params = array($seid);
    } elseif ($module == 'Services') {
        $query = "SELECT vtiger_service.serviceid AS productid, 'NA' AS productcode, vtiger_service.servicename AS productname,\n\t\t\tvtiger_service.unit_price AS unit_price, 'NA' AS qtyinstock, vtiger_crmentity.description AS product_description,\n\t\t\t'Services' AS entitytype\n\t\t\tFROM vtiger_service\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_service.serviceid\n\t\t\tWHERE vtiger_crmentity.deleted=0 AND serviceid=?";
        $params = array($seid);
    }
    $cbMap = cbMap::getMapByName($module . 'InventoryDetails', 'MasterDetailLayout');
    $MDMapFound = $cbMap != null;
    if ($MDMapFound) {
        $cbMapFields = $cbMap->MasterDetailLayout();
    }
    $result = $adb->pquery($query, $params);
    $num_rows = $adb->num_rows($result);
    for ($i = 1; $i <= $num_rows; $i++) {
        $hdnProductId = $adb->query_result($result, $i - 1, 'productid');
        $hdnProductcode = $adb->query_result($result, $i - 1, 'productcode');
        $productname = $adb->query_result($result, $i - 1, 'productname');
        $productdescription = $adb->query_result($result, $i - 1, 'product_description');
        $comment = $adb->query_result($result, $i - 1, 'comment');
        $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock');
        $qty = $adb->query_result($result, $i - 1, 'quantity');
        $unitprice = $adb->query_result($result, $i - 1, 'unit_price');
        $listprice = $adb->query_result($result, $i - 1, 'listprice');
        $entitytype = $adb->query_result($result, $i - 1, 'entitytype');
        if (!empty($entitytype)) {
            $product_Detail[$i]['entityType' . $i] = $entitytype;
        }
        $product_Detail[$i]['lineitem_id' . $i] = $adb->query_result($result, $i - 1, 'lineitem_id');
        if ($listprice == '') {
            $listprice = $unitprice;
        }
        if ($qty == '') {
            $qty = 1;
        }
        //calculate productTotal
        $productTotal = $qty * $listprice;
        //Delete link in First column
        if ($i != 1) {
            $product_Detail[$i]['delRow' . $i] = "Del";
        }
        if (empty($focus->mode) && $seid != '') {
            $sub_prod_query = $adb->pquery("SELECT crmid as prod_id from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($seid));
        } else {
            $sub_prod_query = $adb->pquery("SELECT productid as prod_id from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i));
        }
        $subprodid_str = '';
        $subprodname_str = '';
        $subProductArray = array();
        if ($adb->num_rows($sub_prod_query) > 0) {
            for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                $sprod_id = $adb->query_result($sub_prod_query, $j, 'prod_id');
                $sprod_name = $subProductArray[] = getProductName($sprod_id);
                $str_sep = "";
                if ($j > 0) {
                    $str_sep = ":";
                }
                $subprodid_str .= $str_sep . $sprod_id;
                $subprodname_str .= $str_sep . " - " . $sprod_name;
            }
        }
        $subprodname_str = str_replace(":", "<br>", $subprodname_str);
        $product_Detail[$i]['subProductArray' . $i] = $subProductArray;
        $product_Detail[$i]['hdnProductId' . $i] = $hdnProductId;
        $product_Detail[$i]['productName' . $i] = from_html($productname);
        /* Added to fix the issue Product Pop-up name display*/
        if ($_REQUEST['action'] == 'CreateSOPDF' || $_REQUEST['action'] == 'CreatePDF' || $_REQUEST['action'] == 'SendPDFMail') {
            $product_Detail[$i]['productName' . $i] = htmlspecialchars($product_Detail[$i]['productName' . $i]);
        }
        $product_Detail[$i]['hdnProductcode' . $i] = $hdnProductcode;
        $product_Detail[$i]['productDescription' . $i] = from_html($productdescription);
        if ($module == 'Potentials' || $module == 'Products' || $module == 'Services') {
            $product_Detail[$i]['comment' . $i] = $productdescription;
        } else {
            $product_Detail[$i]['comment' . $i] = $comment;
        }
        if ($MDMapFound) {
            foreach ($cbMapFields['detailview']['fields'] as $mdfield) {
                $mdrs = $adb->pquery('select ' . $mdfield['fieldinfo']['name'] . ' from vtiger_inventorydetails
						inner join vtiger_crmentity on crmid=vtiger_inventorydetails.inventorydetailsid
						inner join vtiger_inventorydetailscf on vtiger_inventorydetailscf.inventorydetailsid=vtiger_inventorydetails.inventorydetailsid
						where deleted=0 and related_to=? and lineitem_id=?', array($focus->id, $adb->query_result($result, $i - 1, 'lineitem_id')));
                if ($mdrs) {
                    $col_fields = array();
                    $col_fields[$mdfield['fieldinfo']['name']] = $adb->query_result($mdrs, 0, 0);
                    $foutput = getOutputHtml($mdfield['fieldinfo']['uitype'], $mdfield['fieldinfo']['name'], $mdfield['fieldinfo']['label'], 100, $col_fields, 0, 'InventoryDetails', 'edit', $mdfield['fieldinfo']['typeofdata']);
                    $product_Detail[$i]['moreinfo' . $i][] = $foutput;
                }
            }
        }
        if ($module != 'PurchaseOrder' && $focus->object_name != 'Order') {
            $product_Detail[$i]['qtyInStock' . $i] = $qtyinstock;
        }
        $qty = number_format($qty, 2, '.', '');
        //Convert to 2 decimals
        $listprice = number_format($listprice, 2, '.', '');
        //Convert to 2 decimals
        $product_Detail[$i]['qty' . $i] = $qty;
        $product_Detail[$i]['listPrice' . $i] = $listprice;
        $product_Detail[$i]['unitPrice' . $i] = $unitprice;
        $product_Detail[$i]['productTotal' . $i] = $productTotal;
        $product_Detail[$i]['subproduct_ids' . $i] = $subprodid_str;
        $product_Detail[$i]['subprod_names' . $i] = $subprodname_str;
        $discount_percent = $adb->query_result($result, $i - 1, 'discount_percent');
        $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount');
        $discount_amount = number_format(is_numeric($discount_amount) ? $discount_amount : 0, 2, '.', '');
        //Convert to 2 decimals
        $discountTotal = '0.00';
        //Based on the discount percent or amount we will show the discount details
        //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(for Each Product)
        $product_Detail[$i]['discount_percent' . $i] = 0;
        $product_Detail[$i]['discount_amount' . $i] = 0;
        if ($discount_percent != 'NULL' && $discount_percent != '') {
            $product_Detail[$i]['discount_type' . $i] = "percentage";
            $product_Detail[$i]['discount_percent' . $i] = $discount_percent;
            $product_Detail[$i]['checked_discount_percent' . $i] = ' checked';
            $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:visible"';
            $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:hidden"';
            $discountTotal = $productTotal * $discount_percent / 100;
        } elseif ($discount_amount != 'NULL' && $discount_amount != '') {
            $product_Detail[$i]['discount_type' . $i] = "amount";
            $product_Detail[$i]['discount_amount' . $i] = $discount_amount;
            $product_Detail[$i]['checked_discount_amount' . $i] = ' checked';
            $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:visible"';
            $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:hidden"';
            $discountTotal = $discount_amount;
        } else {
            $product_Detail[$i]['checked_discount_zero' . $i] = ' checked';
        }
        $totalAfterDiscount = $productTotal - $discountTotal;
        $product_Detail[$i]['discountTotal' . $i] = $discountTotal;
        $product_Detail[$i]['totalAfterDiscount' . $i] = $totalAfterDiscount;
        $taxTotal = '0.00';
        $product_Detail[$i]['taxTotal' . $i] = $taxTotal;
        //Calculate netprice
        $netPrice = $totalAfterDiscount + $taxTotal;
        //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module
        if ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice') {
            $taxtype = getInventoryTaxType($module, $focus->id);
            if ($taxtype == 'individual') {
                //Add the tax with product total and assign to netprice
                $netPrice = $netPrice + $taxTotal;
            }
        }
        $product_Detail[$i]['netPrice' . $i] = $netPrice;
        //First we will get all associated taxes as array
        $tax_details = getTaxDetailsForProduct($hdnProductId, 'all', $acvid);
        //Now retrieve the tax values from the current query with the name
        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
            $tax_name = $tax_details[$tax_count]['taxname'];
            $tax_label = $tax_details[$tax_count]['taxlabel'];
            $tax_value = '0.00';
            //condition to avoid this function call when create new PO/SO/Quotes/Invoice from Product module
            if ($focus->id != '') {
                if ($taxtype == 'individual') {
                    //if individual then show the entered tax percentage
                    $tax_value = getInventoryProductTaxValue($focus->id, $hdnProductId, $tax_name);
                } else {
                    //if group tax then we have to show the default value when change to individual tax
                    $tax_value = $tax_details[$tax_count]['percentage'];
                }
            } else {
                //if the above function not called then assign the default associated value of the product
                $tax_value = $tax_details[$tax_count]['percentage'];
            }
            $product_Detail[$i]['taxes'][$tax_count]['taxname'] = $tax_name;
            $product_Detail[$i]['taxes'][$tax_count]['taxlabel'] = $tax_label;
            $product_Detail[$i]['taxes'][$tax_count]['percentage'] = $tax_value;
        }
    }
    //set the taxtype
    $product_Detail[1]['final_details']['taxtype'] = $taxtype;
    //Get the Final Discount, S&H charge, Tax for S&H and Adjustment values
    //To set the Final Discount details
    $finalDiscount = '0.00';
    $product_Detail[1]['final_details']['discount_type_final'] = 'zero';
    $subTotal = $focus->column_fields['hdnSubTotal'] != '' ? $focus->column_fields['hdnSubTotal'] : '0.00';
    $subTotal = number_format($subTotal, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['hdnSubTotal'] = $subTotal;
    $discountPercent = $focus->column_fields['hdnDiscountPercent'] != '' ? $focus->column_fields['hdnDiscountPercent'] : '0.00';
    $discountAmount = $focus->column_fields['hdnDiscountAmount'] != '' ? $focus->column_fields['hdnDiscountAmount'] : '0.00';
    $discountAmount = number_format($discountAmount, 2, '.', '');
    //Convert to 2 decimals
    //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(For Final Discount)
    $product_Detail[1]['final_details']['discount_percentage_final'] = 0;
    $product_Detail[1]['final_details']['discount_amount_final'] = 0;
    if ($focus->column_fields['hdnDiscountPercent'] != '0') {
        $finalDiscount = $subTotal * $discountPercent / 100;
        $product_Detail[1]['final_details']['discount_type_final'] = 'percentage';
        $product_Detail[1]['final_details']['discount_percentage_final'] = $discountPercent;
        $product_Detail[1]['final_details']['checked_discount_percentage_final'] = ' checked';
        $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:visible"';
        $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:hidden"';
    } elseif ($focus->column_fields['hdnDiscountAmount'] != '0') {
        $finalDiscount = $focus->column_fields['hdnDiscountAmount'];
        $product_Detail[1]['final_details']['discount_type_final'] = 'amount';
        $product_Detail[1]['final_details']['discount_amount_final'] = $discountAmount;
        $product_Detail[1]['final_details']['checked_discount_amount_final'] = ' checked';
        $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:visible"';
        $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:hidden"';
    }
    $finalDiscount = number_format($finalDiscount, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['discountTotal_final'] = $finalDiscount;
    //To set the Final Tax values
    //we will get all taxes. if individual then show the product related taxes only else show all taxes
    //suppose user want to change individual to group or vice versa in edit time the we have to show all taxes. so that here we will store all the taxes and based on need we will show the corresponding taxes
    $taxtotal = '0.00';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $tax_details = getAllTaxes('available', '', 'edit', $focus->id);
    $ipr_cols = $adb->getColumnNames('vtiger_inventoryproductrel');
    for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
        $tax_name = $tax_details[$tax_count]['taxname'];
        $tax_label = $tax_details[$tax_count]['taxlabel'];
        //if taxtype is individual and want to change to group during edit time then we have to show the all available taxes and their default values
        //Also taxtype is group and want to change to individual during edit time then we have to provide the asspciated taxes and their default tax values for individual products
        if ($taxtype == 'group') {
            if (in_array($tax_name, $ipr_cols)) {
                $tax_percent = $adb->query_result($result, 0, $tax_name);
            } else {
                $tax_percent = $tax_details[$tax_count]['percentage'];
            }
        } else {
            $tax_percent = $tax_details[$tax_count]['percentage'];
        }
        //$adb->query_result($result,0,$tax_name);
        if ($tax_percent == '' || $tax_percent == 'NULL') {
            $tax_percent = '0.00';
        }
        $taxamount = ($subTotal - $finalDiscount) * $tax_percent / 100;
        $taxamount = number_format($taxamount, 2, '.', '');
        //Convert to 2 decimals
        $taxtotal = $taxtotal + $taxamount;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['taxname'] = $tax_name;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['taxlabel'] = $tax_label;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['percentage'] = $tax_percent;
        $product_Detail[1]['final_details']['taxes'][$tax_count]['amount'] = $taxamount;
    }
    $product_Detail[1]['final_details']['tax_totalamount'] = $taxtotal;
    //To set the Shipping & Handling charge
    $shCharge = $focus->column_fields['hdnS_H_Amount'] != '' ? $focus->column_fields['hdnS_H_Amount'] : '0.00';
    $shCharge = number_format($shCharge, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['shipping_handling_charge'] = $shCharge;
    //To set the Shipping & Handling tax values
    //calculate S&H tax
    $shtaxtotal = '0.00';
    //First we should get all available taxes and then retrieve the corresponding tax values
    $shtax_details = getAllTaxes('available', 'sh', 'edit', $focus->id);
    //if taxtype is group then the tax should be same for all products in vtiger_inventoryproductrel table
    for ($shtax_count = 0; $shtax_count < count($shtax_details); $shtax_count++) {
        $shtax_name = $shtax_details[$shtax_count]['taxname'];
        $shtax_label = $shtax_details[$shtax_count]['taxlabel'];
        $shtax_percent = '0.00';
        //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module
        if ($module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Quotes' || $module == 'Invoice') {
            $shtax_percent = getInventorySHTaxPercent($focus->id, $shtax_name);
        }
        $shtaxamount = $shCharge * $shtax_percent / 100;
        $shtaxtotal = $shtaxtotal + $shtaxamount;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxname'] = $shtax_name;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['taxlabel'] = $shtax_label;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['percentage'] = $shtax_percent;
        $product_Detail[1]['final_details']['sh_taxes'][$shtax_count]['amount'] = $shtaxamount;
    }
    $product_Detail[1]['final_details']['shtax_totalamount'] = $shtaxtotal;
    //To set the Adjustment value
    $adjustment = $focus->column_fields['txtAdjustment'] != '' ? $focus->column_fields['txtAdjustment'] : '0.00';
    $adjustment = number_format($adjustment, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['adjustment'] = $adjustment;
    //To set the grand total
    $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0.00';
    $grandTotal = number_format($grandTotal, 2, '.', '');
    //Convert to 2 decimals
    $product_Detail[1]['final_details']['grandTotal'] = $grandTotal;
    $log->debug("Exiting getAssociatedProducts method ...");
    return $product_Detail;
}
Ejemplo n.º 24
0
function getValue($field_result, $list_result, $fieldname, $focus, $module, $entity_id, $list_result_count, $mode, $popuptype, $returnset = '', $viewid = '')
{
    global $log, $listview_max_textlength, $app_strings, $current_language, $currentModule;
    $log->debug("Entering getValue(" . $field_result . "," . $list_result . "," . $fieldname . "," . get_class($focus) . "," . $module . "," . $entity_id . "," . $list_result_count . "," . $mode . "," . $popuptype . "," . $returnset . "," . $viewid . ") method ...");
    global $adb, $current_user, $default_charset;
    require 'user_privileges/user_privileges_' . $current_user->id . '.php';
    $tabname = getParentTab();
    $tabid = getTabid($module);
    $current_module_strings = return_module_language($current_language, $module);
    $uicolarr = $field_result[$fieldname];
    foreach ($uicolarr as $key => $value) {
        $uitype = $key;
        $colname = $value;
    }
    //added for getting event status in Custom view - Jaguar
    if ($module == 'Calendar' && ($colname == "status" || $colname == "eventstatus")) {
        $colname = "activitystatus";
    }
    //Ends
    $field_val = $adb->query_result($list_result, $list_result_count, $colname);
    if (stristr(html_entity_decode($field_val), "<a href") === false && $uitype != 8) {
        $temp_val = textlength_check($field_val);
    } elseif ($uitype != 8) {
        $temp_val = html_entity_decode($field_val, ENT_QUOTES);
    } else {
        $temp_val = $field_val;
    }
    // vtlib customization: New uitype to handle relation between modules
    if ($uitype == '10') {
        $parent_id = $field_val;
        if (!empty($parent_id)) {
            $parent_module = getSalesEntityType($parent_id);
            $valueTitle = $parent_module;
            if ($app_strings[$valueTitle]) {
                $valueTitle = $app_strings[$valueTitle];
            }
            $displayValueArray = getEntityName($parent_module, $parent_id);
            if (!empty($displayValueArray)) {
                foreach ($displayValueArray as $key => $value) {
                    $displayValue = $value;
                }
            }
            $value = "<a href='index.php?module={$parent_module}&action=DetailView&record={$parent_id}' title='{$valueTitle}'>{$displayValue}</a>";
        } else {
            $value = '';
        }
    } else {
        if ($uitype == 53) {
            $value = textlength_check($adb->query_result($list_result, $list_result_count, 'user_name'));
            // When Assigned To field is used in Popup window
            if ($value == '') {
                $user_id = $adb->query_result($list_result, $list_result_count, 'smownerid');
                if ($user_id != null && $user_id != '') {
                    $value = getOwnerName($user_id);
                }
            }
        } elseif ($uitype == 52) {
            $value = getUserName($adb->query_result($list_result, $list_result_count, $colname));
        } elseif ($uitype == 51) {
            $parentid = $adb->query_result($list_result, $list_result_count, "parentid");
            if ($module == 'Accounts') {
                $entity_name = textlength_check(getAccountName($parentid));
            } elseif ($module == 'Products') {
                $entity_name = textlength_check(getProductName($parentid));
            }
            $value = '<a href="index.php?module=' . $module . '&action=DetailView&record=' . $parentid . '&parenttab=' . $tabname . '" style="' . $P_FONT_COLOR . '">' . $entity_name . '</a>';
        } elseif ($uitype == 77) {
            $value = getUserName($adb->query_result($list_result, $list_result_count, 'inventorymanager'));
        } elseif ($uitype == 5 || $uitype == 6 || $uitype == 23 || $uitype == 70) {
            if ($temp_val != '' && $temp_val != '0000-00-00') {
                $value = getDisplayDate($temp_val);
            } elseif ($temp_val == '0000-00-00') {
                $value = '';
            } else {
                $value = $temp_val;
            }
        } elseif ($uitype == 15 || $uitype == 55 && $fieldname == "salutationtype") {
            $temp_val = decode_html($adb->query_result($list_result, $list_result_count, $colname));
            if ($is_admin == false && $profileGlobalPermission[1] == 1 && $profileGlobalPermission[2] == 1 && $temp_val != '') {
                $temp_acttype = $adb->query_result($list_result, $list_result_count, 'activitytype');
                if ($temp_acttype != 'Task' && $fieldname == "taskstatus") {
                    $temptable = "eventstatus";
                } else {
                    $temptable = $fieldname;
                }
                $roleid = $current_user->roleid;
                $roleids = array();
                $subrole = getRoleSubordinates($roleid);
                if (count($subrole) > 0) {
                    $roleids = $subrole;
                }
                array_push($roleids, $roleid);
                //here we are checking wheather the table contains the sortorder column .If  sortorder is present in the main picklist table, then the role2picklist will be applicable for this table...
                $sql = "select * from vtiger_{$temptable} where {$temptable}=?";
                $res = $adb->pquery($sql, array(decode_html($temp_val)));
                $picklistvalueid = $adb->query_result($res, 0, 'picklist_valueid');
                if ($picklistvalueid != null) {
                    $pick_query = "select * from vtiger_role2picklist where picklistvalueid={$picklistvalueid} and roleid in (" . generateQuestionMarks($roleids) . ")";
                    $res_val = $adb->pquery($pick_query, array($roleids));
                    $num_val = $adb->num_rows($res_val);
                }
                if ($num_val > 0 || $temp_acttype == 'Task' && $fieldname == 'activitytype') {
                    $temp_val = $temp_val;
                } else {
                    $temp_val = "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>";
                }
            }
            $value = $current_module_strings[$temp_val] != '' ? $current_module_strings[$temp_val] : ($app_strings[$temp_val] != '' ? $app_strings[$temp_val] : $temp_val);
            if ($value != "<font color='red'>" . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>") {
                $value = textlength_check($value);
            }
        } elseif ($uitype == 16) {
            $value = getTranslatedString($temp_val, $currentModule);
        } elseif ($uitype == 71 || $uitype == 72) {
            if ($temp_val != '') {
                if ($fieldname == 'unit_price') {
                    $currency_id = getProductBaseCurrency($entity_id, $module);
                    $cursym_convrate = getCurrencySymbolandCRate($currency_id);
                    $value = "<font style='color:grey;'>" . $cursym_convrate['symbol'] . "</font> " . $temp_val;
                } else {
                    $rate = $user_info['conv_rate'];
                    //changes made to remove vtiger_currency symbol infront of each vtiger_potential amount
                    if ($temp_val != 0) {
                        $value = convertFromDollar($temp_val, $rate);
                    } else {
                        $value = $temp_val;
                    }
                }
            } else {
                $value = '';
            }
        } elseif ($uitype == 17) {
            $value = '<a href="http://' . $field_val . '" target="_blank">' . $temp_val . '</a>';
        } elseif ($uitype == 13 || $uitype == 104 && ($_REQUEST['action'] != 'Popup' && $_REQUEST['file'] != 'Popup')) {
            if ($_SESSION['internal_mailer'] == 1) {
                //check added for email link in user detailview
                if ($module == 'Calendar') {
                    if (getActivityType($entity_id) == 'Task') {
                        $tabid = 9;
                    } else {
                        $tabid = 16;
                    }
                } else {
                    $tabid = getTabid($module);
                }
                $fieldid = getFieldid($tabid, $fieldname);
                if (empty($popuptype)) {
                    $value = '<a href="javascript:InternalMailer(' . $entity_id . ',' . $fieldid . ',\'' . $fieldname . '\',\'' . $module . '\',\'record_id\');">' . $temp_val . '</a>';
                } else {
                    $value = $temp_val;
                }
            } else {
                $value = '<a href="mailto:' . $field_val . '">' . $temp_val . '</a>';
            }
        } elseif ($uitype == 56) {
            if ($temp_val == 1) {
                $value = $app_strings['yes'];
            } elseif ($temp_val == 0) {
                $value = $app_strings['no'];
            } else {
                $value = '';
            }
        } elseif ($uitype == 57) {
            if ($temp_val != '') {
                $sql = "SELECT * FROM vtiger_contactdetails WHERE contactid=?";
                $result = $adb->pquery($sql, array($temp_val));
                $value = '';
                if ($adb->num_rows($result)) {
                    $name = getFullNameFromQResult($result, 0, "Contacts");
                    $value = '<a href=index.php?module=Contacts&action=DetailView&record=' . $temp_val . '>' . $name . '</a>';
                }
            } else {
                $value = '';
            }
        } elseif ($uitype == 58) {
            if ($temp_val != '') {
                $sql = "SELECT * FROM vtiger_campaign WHERE campaignid=?";
                $result = $adb->pquery($sql, array($temp_val));
                $campaignname = $adb->query_result($result, 0, "campaignname");
                $value = '<a href=index.php?module=Campaigns&action=DetailView&record=' . $temp_val . '>' . $campaignname . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 59) {
            if ($temp_val != '') {
                $value = getProductName($temp_val);
            } else {
                $value = '';
            }
        } elseif ($uitype == 61) {
            $attachmentid = $adb->query_result($adb->pquery("SELECT * FROM vtiger_seattachmentsrel WHERE crmid = ?", array($entity_id)), 0, 'attachmentsid');
            $value = '<a href = "index.php?module=uploads&action=downloadfile&return_module=' . $module . '&fileid=' . $attachmentid . '&filename=' . $temp_val . '">' . $temp_val . '</a>';
        } elseif ($uitype == 62) {
            $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
            $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
            if ($parenttype == "Leads") {
                $tablename = "vtiger_leaddetails";
                $fieldname = "lastname";
                $idname = "leadid";
            }
            if ($parenttype == "Accounts") {
                $tablename = "vtiger_account";
                $fieldname = "accountname";
                $idname = "accountid";
            }
            if ($parenttype == "Products") {
                $tablename = "vtiger_products";
                $fieldname = "productname";
                $idname = "productid";
            }
            if ($parenttype == "HelpDesk") {
                $tablename = "vtiger_troubletickets";
                $fieldname = "title";
                $idname = "ticketid";
            }
            if ($parenttype == "Invoice") {
                $tablename = "vtiger_invoice";
                $fieldname = "subject";
                $idname = "invoiceid";
            }
            if ($parentid != '') {
                $sql = "SELECT * FROM {$tablename} WHERE {$idname} = ?";
                $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
                $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . $fieldvalue . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 66) {
            $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
            $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
            if ($parenttype == "Leads") {
                $tablename = "vtiger_leaddetails";
                $fieldname = "lastname";
                $idname = "leadid";
            }
            if ($parenttype == "Accounts") {
                $tablename = "vtiger_account";
                $fieldname = "accountname";
                $idname = "accountid";
            }
            if ($parenttype == "HelpDesk") {
                $tablename = "vtiger_troubletickets";
                $fieldname = "title";
                $idname = "ticketid";
            }
            if ($parentid != '') {
                $sql = "SELECT * FROM {$tablename} WHERE {$idname} = ?";
                $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
                $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . $fieldvalue . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 67) {
            $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
            $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
            if ($parenttype == "Leads") {
                $tablename = "vtiger_leaddetails";
                $fieldname = "lastname";
                $idname = "leadid";
            }
            if ($parenttype == "Contacts") {
                $tablename = "vtiger_contactdetails";
                $fieldname = "contactname";
                $idname = "contactid";
            }
            if ($parentid != '') {
                $sql = "SELECT * FROM {$tablename} WHERE {$idname} = ?";
                $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
                $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . $fieldvalue . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 68) {
            $parentid = $adb->query_result($list_result, $list_result_count, "parent_id");
            $parenttype = $adb->query_result($list_result, $list_result_count, "parent_type");
            if ($parenttype == '' && $parentid != '') {
                $parenttype = getSalesEntityType($parentid);
            }
            if ($parenttype == "Contacts") {
                $tablename = "vtiger_contactdetails";
                $fieldname = "contactname";
                $idname = "contactid";
            }
            if ($parenttype == "Accounts") {
                $tablename = "vtiger_account";
                $fieldname = "accountname";
                $idname = "accountid";
            }
            if ($parentid != '') {
                $sql = "SELECT * FROM {$tablename} WHERE {$idname} = ?";
                $fieldvalue = $adb->query_result($adb->pquery($sql, array($parentid)), 0, $fieldname);
                $value = '<a href=index.php?module=' . $parenttype . '&action=DetailView&record=' . $parentid . '&parenttab=' . urlencode($tabname) . '>' . $fieldvalue . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 78) {
            if ($temp_val != '') {
                $quote_name = getQuoteName($temp_val);
                $value = '<a href=index.php?module=Quotes&action=DetailView&record=' . $temp_val . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($quote_name) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 79) {
            if ($temp_val != '') {
                $purchaseorder_name = getPoName($temp_val);
                $value = '<a href=index.php?module=PurchaseOrder&action=DetailView&record=' . $temp_val . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($purchaseorder_name) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 80) {
            if ($temp_val != '') {
                $salesorder_name = getSoName($temp_val);
                $value = "<a href=index.php?module=SalesOrder&action=DetailView&record={$temp_val}&parenttab=" . urlencode($tabname) . ">" . textlength_check($salesorder_name) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 75 || $uitype == 81) {
            if ($temp_val != '') {
                $vendor_name = getVendorName($temp_val);
                $value = '<a href=index.php?module=Vendors&action=DetailView&record=' . $temp_val . '&parenttab=' . urlencode($tabname) . '>' . textlength_check($vendor_name) . '</a>';
            } else {
                $value = '';
            }
        } elseif ($uitype == 98) {
            $value = '<a href="index.php?action=RoleDetailView&module=Settings&parenttab=Settings&roleid=' . $temp_val . '">' . textlength_check(getRoleName($temp_val)) . '</a>';
        } elseif ($uitype == 33) {
            $value = $temp_val != "" ? str_ireplace(' |##| ', ', ', $temp_val) : "";
            if (!$is_admin && $value != '') {
                $value = $field_val != "" ? str_ireplace(' |##| ', ', ', $field_val) : "";
                if ($value != '') {
                    $value_arr = explode(',', trim($value));
                    $roleid = $current_user->roleid;
                    $subrole = getRoleSubordinates($roleid);
                    if (count($subrole) > 0) {
                        $roleids = $subrole;
                        array_push($roleids, $roleid);
                    } else {
                        $roleids = $roleid;
                    }
                    if (count($roleids) > 0) {
                        $pick_query = "select distinct {$fieldname} from vtiger_{$fieldname} inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_{$fieldname}.picklist_valueid where roleid in (" . generateQuestionMarks($roleids) . ") and picklistid in (select picklistid from vtiger_{$fieldname}) order by {$fieldname} asc";
                        $params = array($roleids);
                    } else {
                        $pick_query = "select distinct {$fieldname} from vtiger_{$fieldname} inner join vtiger_role2picklist on vtiger_role2picklist.picklistvalueid = vtiger_{$fieldname}.picklist_valueid where picklistid in (select picklistid from vtiger_{$fieldname}) order by {$fieldname} asc";
                        $params = array();
                    }
                    $pickListResult = $adb->pquery($pick_query, $params);
                    $picklistval = array();
                    for ($i = 0; $i < $adb->num_rows($pickListResult); $i++) {
                        $picklistarr[] = $adb->query_result($pickListResult, $i, $fieldname);
                    }
                    $value_temp = array();
                    $string_temp = '';
                    $str_c = 0;
                    foreach ($value_arr as $ind => $val) {
                        $notaccess = '<font color="red">' . $app_strings['LBL_NOT_ACCESSIBLE'] . "</font>";
                        if (!$listview_max_textlength || !(strlen(preg_replace("/(<\\/?)(\\w+)([^>]*>)/i", "", $string_temp)) > $listview_max_textlength)) {
                            $value_temp1 = in_array(trim($val), $picklistarr) ? $val : $notaccess;
                            if ($str_c != 0) {
                                $string_temp .= ' , ';
                            }
                            $string_temp .= $value_temp1;
                            $str_c++;
                        } else {
                            $string_temp .= '...';
                        }
                    }
                    $value = $string_temp;
                }
            }
        } elseif ($uitype == 85) {
            $value = $temp_val != "" ? "<a href='skype:{$temp_val}?call'>{$temp_val}</a>" : "";
        } elseif ($uitype == 116) {
            $value = $temp_val != "" ? getCurrencyName($temp_val) : "";
        } elseif ($uitype == 117) {
            // NOTE: Without symbol the value could be used for filtering/lookup hence avoiding the translation
            $value = $temp_val != "" ? getCurrencyName($temp_val, false) : "";
        } elseif ($uitype == 26) {
            $sql = "select foldername from vtiger_attachmentsfolder where folderid = ?";
            $res = $adb->pquery($sql, array($temp_val));
            $foldername = $adb->query_result($res, 0, 'foldername');
            $value = $foldername;
        } elseif ($uitype == 11) {
            // Fix added for Trac Id: 6139
            if (vtlib_isModuleActive('PBXManager')) {
                $value = "<a href='javascript:;' onclick='startCall(&quot;{$temp_val}&quot;, &quot;{$entity_id}&quot;)'>" . $temp_val . "</a>";
            } else {
                $value = $temp_val;
            }
        } elseif ($uitype == 25) {
            $contactid = $_REQUEST['record'];
            $emailid = $adb->query_result($list_result, $list_result_count, "activityid");
            $result = $adb->pquery("SELECT access_count FROM vtiger_email_track WHERE crmid=? AND mailid=?", array($contactid, $emailid));
            $value = $adb->query_result($result, 0, "access_count");
            if (!$value) {
                $value = 0;
            }
        } elseif ($uitype == 8) {
            if (!empty($temp_val)) {
                $temp_val = html_entity_decode($temp_val, ENT_QUOTES, $default_charset);
                $json = new Zend_Json();
                $value = vt_suppressHTMLTags(implode(',', $json->decode($temp_val)));
            }
        } else {
            if ($fieldname == $focus->list_link_field) {
                if ($mode == "search") {
                    if ($popuptype == "specific" || $popuptype == "toDospecific") {
                        // Added for get the first name of contact in Popup window
                        if ($colname == "lastname" && $module == 'Contacts') {
                            $temp_val = getFullNameFromQResult($list_result, $list_result_count, "Contacts");
                        }
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        //Added to avoid the error when select SO from Invoice through AjaxEdit
                        if ($module == 'SalesOrder') {
                            $value = '<a href="javascript:window.close();" onclick=\'set_return_specific("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '","' . $_REQUEST['form'] . '");\'>' . $temp_val . '</a>';
                        } elseif ($module == 'Contacts') {
                            require_once 'modules/Contacts/Contacts.php';
                            $cntct_focus = new Contacts();
                            $cntct_focus->retrieve_entity_info($entity_id, "Contacts");
                            $slashes_temp_val = popup_from_html($temp_val);
                            //ADDED TO CHECK THE FIELD PERMISSIONS FOR
                            $xyz = array('mailingstreet', 'mailingcity', 'mailingzip', 'mailingpobox', 'mailingcountry', 'mailingstate', 'otherstreet', 'othercity', 'otherzip', 'otherpobox', 'othercountry', 'otherstate');
                            for ($i = 0; $i < 12; $i++) {
                                if (getFieldVisibilityPermission($module, $current_user->id, $xyz[$i]) == '0') {
                                    $cntct_focus->column_fields[$xyz[$i]] = $cntct_focus->column_fields[$xyz[$i]];
                                } else {
                                    $cntct_focus->column_fields[$xyz[$i]] = '';
                                }
                            }
                            // For ToDo creation the underlying form is not named as EditView
                            $form = !empty($_REQUEST['form']) ? $_REQUEST['form'] : '';
                            if (!empty($form)) {
                                $form = htmlspecialchars($form, ENT_QUOTES, $default_charset);
                            }
                            $value = '<a href="javascript:window.close();" onclick=\'set_return_contact_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingstreet']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherstreet']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingcity']) . '", "' . popup_decode_html($cntct_focus->column_fields['othercity']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingstate']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherstate']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingzip']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherzip']) . '", "' . popup_decode_html($cntct_focus->column_fields['mailingcountry']) . '", "' . popup_decode_html($cntct_focus->column_fields['othercountry']) . '","' . popup_decode_html($cntct_focus->column_fields['mailingpobox']) . '", "' . popup_decode_html($cntct_focus->column_fields['otherpobox']) . '","' . $form . '");\'>' . $temp_val . '</a>';
                        } else {
                            if ($popuptype == 'toDospecific') {
                                $value = '<a href="javascript:window.close();" onclick=\'set_return_toDospecific("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'>' . $temp_val . '</a>';
                            } else {
                                $value = '<a href="javascript:window.close();" onclick=\'set_return_specific("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'>' . $temp_val . '</a>';
                            }
                        }
                    } elseif ($popuptype == "detailview") {
                        if ($colname == "lastname" && ($module == 'Contacts' || $module == 'Leads')) {
                            $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
                        }
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $focus->record_id = $_REQUEST['recordid'];
                        if ($_REQUEST['return_module'] == "Calendar") {
                            $value = '<a href="javascript:window.close();" id="calendarCont' . $entity_id . '" LANGUAGE=javascript onclick=\'add_data_to_relatedlist_incal("' . $entity_id . '","' . decode_html($slashes_temp_val) . '");\'>' . $temp_val . '</a>';
                        } else {
                            $value = '<a href="javascript:window.close();" onclick=\'add_data_to_relatedlist("' . $entity_id . '","' . $focus->record_id . '","' . $module . '");\'>' . $temp_val . '</a>';
                        }
                    } elseif ($popuptype == "formname_specific") {
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_formname_specific("' . $_REQUEST['form'] . '", "' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'>' . $temp_val . '</a>';
                    } elseif ($popuptype == "inventory_prod") {
                        $row_id = $_REQUEST['curr_row'];
                        //To get all the tax types and values and pass it to product details
                        $tax_str = '';
                        $tax_details = getAllTaxes();
                        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                            $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                        }
                        $tax_str = trim($tax_str, ',');
                        $rate = $user_info['conv_rate'];
                        if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') {
                            $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                            if ($_REQUEST['currencyid'] != null) {
                                $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id));
                                $unitprice = $prod_prices[$entity_id];
                            }
                        } else {
                            $unit_price = '';
                        }
                        $sub_products = '';
                        $sub_prod = '';
                        $sub_prod_query = $adb->pquery("SELECT vtiger_products.productid,vtiger_products.productname,vtiger_products.qtyinstock,vtiger_crmentity.description from vtiger_products INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid INNER JOIN vtiger_seproductsrel on vtiger_seproductsrel.crmid=vtiger_products.productid WHERE vtiger_seproductsrel.productid=? and vtiger_seproductsrel.setype='Products'", array($entity_id));
                        for ($i = 0; $i < $adb->num_rows($sub_prod_query); $i++) {
                            //$sub_prod=array();
                            $id = $adb->query_result($sub_prod_query, $i, "productid");
                            $str_sep = '';
                            if ($i > 0) {
                                $str_sep = ":";
                            }
                            $sub_products .= $str_sep . $id;
                            $sub_prod .= $str_sep . " - " . $adb->query_result($sub_prod_query, $i, "productname");
                        }
                        $sub_det = $sub_products . "::" . str_replace(":", "<br>", $sub_prod);
                        $qty_stock = $adb->query_result($list_result, $list_result_count, 'qtyinstock');
                        //fix for T6943
                        $slashes_temp_val = popup_from_html($field_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $description = popup_from_html($adb->query_result($list_result, $list_result_count, 'description'));
                        $slashes_temp_desc = decode_html(htmlspecialchars($description, ENT_QUOTES, $default_charset));
                        $slashes_desc = str_replace(array("\r", "\n"), array('\\r', '\\n'), $slashes_temp_desc);
                        $tmp_arr = array("entityid" => $entity_id, "prodname" => "" . stripslashes(decode_html(nl2br($slashes_temp_val))) . "", "unitprice" => "{$unitprice}", "qtyinstk" => "{$qty_stock}", "taxstring" => "{$tax_str}", "rowid" => "{$row_id}", "desc" => "{$slashes_desc}", "subprod_ids" => "{$sub_det}");
                        require_once 'include/Zend/Json.php';
                        $prod_arr = Zend_Json::encode($tmp_arr);
                        $value = '<a href="javascript:window.close();" id=\'popup_product_' . $entity_id . '\' onclick=\'set_return_inventory("' . $entity_id . '", "' . decode_html(nl2br($slashes_temp_val)) . '", "' . $unitprice . '", "' . $qty_stock . '","' . $tax_str . '","' . $row_id . '","' . $slashes_desc . '","' . $sub_det . '");\' vt_prod_arr=\'' . $prod_arr . '\' >' . $temp_val . '</a>';
                    } elseif ($popuptype == "inventory_prod_po") {
                        $row_id = $_REQUEST['curr_row'];
                        //To get all the tax types and values and pass it to product details
                        $tax_str = '';
                        $tax_details = getAllTaxes();
                        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                            $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                        }
                        $tax_str = trim($tax_str, ',');
                        $rate = $user_info['conv_rate'];
                        if (getFieldVisibilityPermission($module, $current_user->id, 'unit_price') == '0') {
                            $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                            if ($_REQUEST['currencyid'] != null) {
                                $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id), $module);
                                $unitprice = $prod_prices[$entity_id];
                            }
                        } else {
                            $unit_price = '';
                        }
                        $sub_products = '';
                        $sub_prod = '';
                        $sub_prod_query = $adb->pquery("SELECT vtiger_products.productid,vtiger_products.productname,vtiger_products.qtyinstock,vtiger_crmentity.description from vtiger_products INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_products.productid INNER JOIN vtiger_seproductsrel on vtiger_seproductsrel.crmid=vtiger_products.productid WHERE vtiger_seproductsrel.productid=? and vtiger_seproductsrel.setype='Products'", array($entity_id));
                        for ($i = 0; $i < $adb->num_rows($sub_prod_query); $i++) {
                            //$sub_prod=array();
                            $id = $adb->query_result($sub_prod_query, $i, "productid");
                            $str_sep = '';
                            if ($i > 0) {
                                $str_sep = ":";
                            }
                            $sub_products .= $str_sep . $id;
                            $sub_prod .= $str_sep . " - {$id}." . $adb->query_result($sub_prod_query, $i, "productname");
                        }
                        $sub_det = $sub_products . "::" . str_replace(":", "<br>", $sub_prod);
                        $slashes_temp_val = popup_from_html($field_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $description = popup_from_html($adb->query_result($list_result, $list_result_count, 'description'));
                        $slashes_temp_desc = decode_html(htmlspecialchars($description, ENT_QUOTES, $default_charset));
                        $slashes_desc = str_replace(array("\r", "\n"), array('\\r', '\\n'), $slashes_temp_desc);
                        $tmp_arr = array("entityid" => $entity_id, "prodname" => "" . stripslashes(decode_html(nl2br($slashes_temp_val))) . "", "unitprice" => "{$unitprice}", "qtyinstk" => "{$qty_stock}", "taxstring" => "{$tax_str}", "rowid" => "{$row_id}", "desc" => "{$slashes_desc}", "subprod_ids" => "{$sub_det}");
                        require_once 'include/Zend/Json.php';
                        $prod_arr = Zend_Json::encode($tmp_arr);
                        $value = '<a href="javascript:window.close();" id=\'popup_product_' . $entity_id . '\' onclick=\'set_return_inventory_po("' . $entity_id . '", "' . decode_html(nl2br($slashes_temp_val)) . '", "' . $unitprice . '", "' . $tax_str . '","' . $row_id . '","' . $slashes_desc . '","' . $sub_det . '"); \'  vt_prod_arr=\'' . $prod_arr . '\' >' . $temp_val . '</a>';
                    } elseif ($popuptype == "inventory_service") {
                        $row_id = $_REQUEST['curr_row'];
                        //To get all the tax types and values and pass it to product details
                        $tax_str = '';
                        $tax_details = getAllTaxes();
                        for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
                            $tax_str .= $tax_details[$tax_count]['taxname'] . '=' . $tax_details[$tax_count]['percentage'] . ',';
                        }
                        $tax_str = trim($tax_str, ',');
                        $rate = $user_info['conv_rate'];
                        if (getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0') {
                            $unitprice = $adb->query_result($list_result, $list_result_count, 'unit_price');
                            if ($_REQUEST['currencyid'] != null) {
                                $prod_prices = getPricesForProducts($_REQUEST['currencyid'], array($entity_id), $module);
                                $unitprice = $prod_prices[$entity_id];
                            }
                        } else {
                            $unit_price = '';
                        }
                        $slashes_temp_val = popup_from_html($field_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $description = popup_from_html($adb->query_result($list_result, $list_result_count, 'description'));
                        $slashes_temp_desc = decode_html(htmlspecialchars($description, ENT_QUOTES, $default_charset));
                        $slashes_desc = str_replace(array("\r", "\n"), array('\\r', '\\n'), $slashes_temp_desc);
                        $tmp_arr = array("entityid" => $entity_id, "prodname" => "" . stripslashes(decode_html(nl2br($slashes_temp_val))) . "", "unitprice" => "{$unitprice}", "taxstring" => "{$tax_str}", "rowid" => "{$row_id}", "desc" => "{$slashes_desc}");
                        require_once 'include/Zend/Json.php';
                        $prod_arr = Zend_Json::encode($tmp_arr);
                        $value = '<a href="javascript:window.close();" id=\'popup_product_' . $entity_id . '\' onclick=\'set_return_inventory("' . $entity_id . '", "' . decode_html(nl2br($slashes_temp_val)) . '", "' . $unitprice . '", "' . $tax_str . '","' . $row_id . '","' . $slashes_desc . '");\'  vt_prod_arr=\'' . $prod_arr . '\' >' . $temp_val . '</a>';
                    } elseif ($popuptype == "inventory_pb") {
                        $prod_id = $_REQUEST['productid'];
                        $flname = $_REQUEST['fldname'];
                        $listprice = getListPrice($prod_id, $entity_id);
                        $temp_val = popup_from_html($temp_val);
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_inventory_pb("' . $listprice . '", "' . $flname . '"); \'>' . $temp_val . '</a>';
                    } elseif ($popuptype == "specific_account_address") {
                        require_once 'modules/Accounts/Accounts.php';
                        $acct_focus = new Accounts();
                        $acct_focus->retrieve_entity_info($entity_id, "Accounts");
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $xyz = array('bill_street', 'bill_city', 'bill_code', 'bill_pobox', 'bill_country', 'bill_state', 'ship_street', 'ship_city', 'ship_code', 'ship_pobox', 'ship_country', 'ship_state');
                        for ($i = 0; $i < 12; $i++) {
                            if (getFieldVisibilityPermission($module, $current_user->id, $xyz[$i]) == '0') {
                                $acct_focus->column_fields[$xyz[$i]] = $acct_focus->column_fields[$xyz[$i]];
                            } else {
                                $acct_focus->column_fields[$xyz[$i]] = '';
                            }
                        }
                        $bill_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['bill_street']));
                        $ship_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['ship_street']));
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $bill_street . '", "' . $ship_street . '", "' . popup_decode_html($acct_focus->column_fields['bill_city']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_city']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_state']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_state']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_code']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_code']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_country']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_country']) . '","' . popup_decode_html($acct_focus->column_fields['bill_pobox']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_pobox']) . '");\'>' . $temp_val . '</a>';
                    } elseif ($popuptype == "specific_contact_account_address") {
                        require_once 'modules/Accounts/Accounts.php';
                        $acct_focus = new Accounts();
                        $acct_focus->retrieve_entity_info($entity_id, "Accounts");
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $bill_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['bill_street']));
                        $ship_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['ship_street']));
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_contact_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $bill_street . '", "' . $ship_street . '", "' . popup_decode_html($acct_focus->column_fields['bill_city']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_city']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_state']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_state']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_code']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_code']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_country']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_country']) . '","' . popup_decode_html($acct_focus->column_fields['bill_pobox']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_pobox']) . '");\'>' . $temp_val . '</a>';
                    } elseif ($popuptype == "specific_potential_account_address") {
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        // For B2C support, Potential was enabled to be linked to Contacts also.
                        // Hence we need case handling for it.
                        $relatedid = $adb->query_result($list_result, $list_result_count, "related_to");
                        $relatedentity = getSalesEntityType($relatedid);
                        if ($relatedentity == 'Accounts') {
                            require_once 'modules/Accounts/Accounts.php';
                            $acct_focus = new Accounts();
                            $acct_focus->retrieve_entity_info($relatedid, "Accounts");
                            $account_name = getAccountName($relatedid);
                            $slashes_account_name = popup_from_html($account_name);
                            $slashes_account_name = htmlspecialchars($slashes_account_name, ENT_QUOTES, $default_charset);
                            $xyz = array('bill_street', 'bill_city', 'bill_code', 'bill_pobox', 'bill_country', 'bill_state', 'ship_street', 'ship_city', 'ship_code', 'ship_pobox', 'ship_country', 'ship_state');
                            for ($i = 0; $i < 12; $i++) {
                                if (getFieldVisibilityPermission('Accounts', $current_user->id, $xyz[$i]) == '0') {
                                    $acct_focus->column_fields[$xyz[$i]] = $acct_focus->column_fields[$xyz[$i]];
                                } else {
                                    $acct_focus->column_fields[$xyz[$i]] = '';
                                }
                            }
                            $bill_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['bill_street']));
                            $ship_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['ship_street']));
                            $value = '<a href="javascript:window.close();" onclick=\'set_return_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $relatedid . '", "' . nl2br(decode_html($slashes_account_name)) . '", "' . $bill_street . '", "' . $ship_street . '", "' . popup_decode_html($acct_focus->column_fields['bill_city']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_city']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_state']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_state']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_code']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_code']) . '", "' . popup_decode_html($acct_focus->column_fields['bill_country']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_country']) . '","' . popup_decode_html($acct_focus->column_fields['bill_pobox']) . '", "' . popup_decode_html($acct_focus->column_fields['ship_pobox']) . '");\'>' . $temp_val . '</a>';
                        } else {
                            if ($relatedentity == 'Contacts') {
                                require_once 'modules/Contacts/Contacts.php';
                                $contact_name = getContactName($relatedid);
                                $slashes_contact_name = popup_from_html($contact_name);
                                $slashes_contact_name = htmlspecialchars($slashes_contact_name, ENT_QUOTES, $default_charset);
                                $value = '<a href="javascript:window.close();" onclick=\'set_return_contact("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $relatedid . '", "' . nl2br(decode_html($slashes_contact_name)) . '");\'>' . $temp_val . '</a>';
                            } else {
                                $value = $temp_val;
                            }
                        }
                    } elseif ($popuptype == "set_return_emails") {
                        if ($module == 'Accounts') {
                            $name = $adb->query_result($list_result, $list_result_count, 'accountname');
                            $accid = $adb->query_result($list_result, $list_result_count, 'accountid');
                            if (CheckFieldPermission('email1', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email1");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            if ($emailaddress == '') {
                                if (CheckFieldPermission('email2', $module) == 'true') {
                                    $emailaddress2 = $adb->query_result($list_result, $list_result_count, "email2");
                                    $email_check = 2;
                                } else {
                                    if ($email_check == 1) {
                                        $email_check = 4;
                                    } else {
                                        $email_check = 3;
                                    }
                                }
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"); \'>' . textlength_check($name) . '</a>';
                        } elseif ($module == 'Vendors') {
                            $name = $adb->query_result($list_result, $list_result_count, 'vendorname');
                            $venid = $adb->query_result($list_result, $list_result_count, 'vendorid');
                            if (CheckFieldPermission('email', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email1 or email2
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"); \'>' . textlength_check($name) . '</a>';
                        } elseif ($module == 'Contacts' || $module == 'Leads') {
                            $name = getFullNameFromQResult($list_result, $list_result_count, $module);
                            if (CheckFieldPermission('email', $module) == "true") {
                                $emailaddress = $adb->query_result($list_result, $list_result_count, "email");
                                $email_check = 1;
                            } else {
                                $email_check = 0;
                            }
                            if ($emailaddress == '') {
                                if (CheckFieldPermission('yahooid', $module) == 'true') {
                                    $emailaddress2 = $adb->query_result($list_result, $list_result_count, "yahooid");
                                    $email_check = 2;
                                } else {
                                    if ($email_check == 1) {
                                        $email_check = 4;
                                    } else {
                                        $email_check = 3;
                                    }
                                }
                            }
                            $querystr = "SELECT fieldid,fieldlabel,columnname FROM vtiger_field WHERE tabid=? and uitype=13 and vtiger_field.presence in (0,2)";
                            $queryres = $adb->pquery($querystr, array(getTabid($module)));
                            //Change this index 0 - to get the vtiger_fieldid based on email or yahooid
                            $fieldid = $adb->query_result($queryres, 0, 'fieldid');
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',' . $fieldid . ',"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"); \'>' . $name . '</a>';
                        } else {
                            $firstname = $adb->query_result($list_result, $list_result_count, "first_name");
                            $lastname = $adb->query_result($list_result, $list_result_count, "last_name");
                            $name = $lastname . ' ' . $firstname;
                            $emailaddress = $adb->query_result($list_result, $list_result_count, "email1");
                            $slashes_name = popup_from_html($name);
                            $slashes_name = htmlspecialchars($slashes_name, ENT_QUOTES, $default_charset);
                            $email_check = 1;
                            $value = '<a href="javascript:window.close();" onclick=\'return set_return_emails(' . $entity_id . ',-1,"' . decode_html($slashes_name) . '","' . $emailaddress . '","' . $emailaddress2 . '","' . $email_check . '"); \'>' . textlength_check($name) . '</a>';
                        }
                    } elseif ($popuptype == "specific_vendor_address") {
                        require_once 'modules/Vendors/Vendors.php';
                        $acct_focus = new Vendors();
                        $acct_focus->retrieve_entity_info($entity_id, "Vendors");
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $xyz = array('street', 'city', 'postalcode', 'pobox', 'country', 'state');
                        for ($i = 0; $i < 6; $i++) {
                            if (getFieldVisibilityPermission($module, $current_user->id, $xyz[$i]) == '0') {
                                $acct_focus->column_fields[$xyz[$i]] = $acct_focus->column_fields[$xyz[$i]];
                            } else {
                                $acct_focus->column_fields[$xyz[$i]] = '';
                            }
                        }
                        $bill_street = str_replace(array("\r", "\n"), array('\\r', '\\n'), popup_decode_html($acct_focus->column_fields['street']));
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_address("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '", "' . $bill_street . '", "' . popup_decode_html($acct_focus->column_fields['city']) . '", "' . popup_decode_html($acct_focus->column_fields['state']) . '", "' . popup_decode_html($acct_focus->column_fields['postalcode']) . '", "' . popup_decode_html($acct_focus->column_fields['country']) . '","' . popup_decode_html($acct_focus->column_fields['pobox']) . '");\'>' . $temp_val . '</a>';
                    } elseif ($popuptype == "specific_campaign") {
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $value = '<a href="javascript:window.close();" onclick=\'set_return_specific_campaign("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'>' . $temp_val . '</a>';
                    } else {
                        if ($colname == "lastname") {
                            $temp_val = getFullNameFromQResult($list_result, $list_result_count, $module);
                        }
                        $slashes_temp_val = popup_from_html($temp_val);
                        $slashes_temp_val = htmlspecialchars($slashes_temp_val, ENT_QUOTES, $default_charset);
                        $log->debug("Exiting getValue method ...");
                        if ($_REQUEST['maintab'] == 'Calendar') {
                            $value = '<a href="javascript:window.close();" onclick=\'set_return_todo("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'>' . $temp_val . '</a>';
                        } else {
                            $value = '<a href="javascript:window.close();" onclick=\'set_return("' . $entity_id . '", "' . nl2br(decode_html($slashes_temp_val)) . '");\'>' . $temp_val . '</a>';
                        }
                    }
                } else {
                    if ($module == "Leads" && $colname == "lastname" || $module == "Contacts" && $colname == "lastname") {
                        $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&parenttab=' . $tabname . '">' . $temp_val . '</a>';
                    } elseif ($module == "Calendar") {
                        $actvity_type = $adb->query_result($list_result, $list_result_count, 'activitytype');
                        $actvity_type = $actvity_type != '' ? $actvity_type : $adb->query_result($list_result, $list_result_count, 'type');
                        if ($actvity_type == "Task") {
                            $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&activity_mode=Task&parenttab=' . $tabname . '">' . $temp_val . '</a>';
                        } else {
                            $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&activity_mode=Events&parenttab=' . $tabname . '">' . $temp_val . '</a>';
                        }
                    } elseif ($module == "Vendors") {
                        $value = '<a href="index.php?action=DetailView&module=Vendors&record=' . $entity_id . '&parenttab=' . $tabname . '">' . $temp_val . '</a>';
                    } elseif ($module == "PriceBooks") {
                        $value = '<a href="index.php?action=DetailView&module=PriceBooks&record=' . $entity_id . '&parenttab=' . $tabname . '">' . $temp_val . '</a>';
                    } elseif ($module == "SalesOrder") {
                        $value = '<a href="index.php?action=DetailView&module=SalesOrder&record=' . $entity_id . '&parenttab=' . $tabname . '">' . $temp_val . '</a>';
                    } elseif ($module == 'Emails') {
                        $value = $temp_val;
                    } else {
                        $value = '<a href="index.php?action=DetailView&module=' . $module . '&record=' . $entity_id . '&parenttab=' . $tabname . '">' . $temp_val . '</a>';
                    }
                }
            } elseif ($fieldname == 'expectedroi' || $fieldname == 'actualroi' || $fieldname == 'actualcost' || $fieldname == 'budgetcost' || $fieldname == 'expectedrevenue') {
                $rate = $user_info['conv_rate'];
                $value = convertFromDollar($temp_val, $rate);
            } elseif (($module == 'Invoice' || $module == 'Quotes' || $module == 'PurchaseOrder' || $module == 'SalesOrder') && ($fieldname == 'hdnGrandTotal' || $fieldname == 'hdnSubTotal' || $fieldname == 'txtAdjustment' || $fieldname == 'hdnDiscountAmount' || $fieldname == 'hdnS_H_Amount')) {
                $currency_info = getInventoryCurrencyInfo($module, $entity_id);
                $currency_id = $currency_info['currency_id'];
                $currency_symbol = $currency_info['currency_symbol'];
                $value = $currency_symbol . $temp_val;
            } else {
                $value = $temp_val;
            }
        }
    }
    // Mike Crowe Mod --------------------------------------------------------Make right justified and vtiger_currency value
    if (in_array($uitype, array(71, 72, 7, 9, 90))) {
        $value = '<span align="right">' . $value . '</div>';
    }
    $log->debug("Exiting getValue method ...");
    return $value;
}
Ejemplo n.º 25
0
/** This function returns the ec_field details for a given ec_fieldname.
 * Param $uitype - UI type of the ec_field
 * Param $fieldname - Form ec_field name
 * Param $fieldlabel - Form ec_field label name
 * Param $maxlength - maximum length of the ec_field
 * Param $col_fields - array contains the ec_fieldname and values
 * Param $generatedtype - Field generated type (default is 1)
 * Param $module_name - module name
 * Return type is an array
 */
function getOutputHtml($uitype, $fieldname, $fieldlabel, $maxlength, $col_fields, $generatedtype, $module_name, $mode = '', $mandatory = 0, $typeofdata = "")
{
    global $log;
    $log->debug("Entering getOutputHtml() method ...");
    global $adb, $log;
    global $theme;
    global $mod_strings;
    global $app_strings;
    global $current_user;
    global $noof_group_rows;
    $theme_path = "themes/" . $theme . "/";
    $image_path = $theme_path . "images/";
    //$fieldlabel = from_html($fieldlabel);
    $fieldvalue = array();
    $final_arr = array();
    $value = $col_fields[$fieldname];
    $custfld = '';
    $ui_type[] = $uitype;
    $editview_fldname[] = $fieldname;
    if ($generatedtype == 2) {
        $mod_strings[$fieldlabel] = $fieldlabel;
    }
    if (!isset($mod_strings[$fieldlabel])) {
        $mod_strings[$fieldlabel] = $fieldlabel;
    }
    if ($uitype == 5) {
        if ($value == '') {
            if ($mandatory == 1) {
                $disp_value = getNewDisplayDate();
            }
        } else {
            $disp_value = getDisplayDate($value);
        }
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $disp_value;
    } elseif ($uitype == 15 || $uitype == 16 || $uitype == 111) {
        $editview_label[] = $mod_strings[$fieldlabel];
        //changed by dingjianting on 2007-10-3 for cache pickListResult
        $key = "picklist_array_" . $fieldname;
        $picklist_array = getSqlCacheData($key);
        if (!$picklist_array) {
            $pick_query = "select colvalue from ec_picklist where colname='" . $fieldname . "' order by sequence asc";
            $pickListResult = $adb->getList($pick_query);
            $picklist_array = array();
            foreach ($pickListResult as $row) {
                $picklist_array[] = $row['colvalue'];
            }
            setSqlCacheData($key, $picklist_array);
        }
        //Mikecrowe fix to correctly default for custom pick lists
        $options = array();
        $found = false;
        foreach ($picklist_array as $pickListValue) {
            if ($value == $pickListValue) {
                $chk_val = "selected";
                $found = true;
            } else {
                $chk_val = '';
            }
            $options[] = array($pickListValue => $chk_val);
        }
        $fieldvalue[] = $options;
    } elseif ($uitype == '1021' || $uitype == '1022' || $uitype == '1023') {
        $typearr = explode("::", $typeofdata);
        $multifieldid = $typearr[1];
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = getMultiFieldEditViewValue($multifieldid, $uitype, $col_fields);
        $fieldvalue[] = $multifieldid;
        //print_r($fieldvalue);
    } elseif ($uitype == 10) {
        $query = "SELECT ec_entityname.* FROM ec_crmentityrel inner join ec_entityname on ec_entityname.modulename=ec_crmentityrel.relmodule WHERE ec_crmentityrel.module='" . $module_name . "' and ec_entityname.entityidfield='" . $fieldname . "'";
        $fldmod_result = $adb->query($query);
        $rownum = $adb->num_rows($fldmod_result);
        if ($rownum > 0) {
            $rel_modulename = $adb->query_result($fldmod_result, 0, 'modulename');
            $rel_tablename = $adb->query_result($fldmod_result, 0, 'tablename');
            $rel_entityname = $adb->query_result($fldmod_result, 0, 'fieldname');
            $rel_entityid = $adb->query_result($fldmod_result, 0, 'entityidfield');
        }
        if ($value != '') {
            $module_entityname = getEntityNameForTen($rel_tablename, $rel_entityname, $fieldname, $value);
        } elseif (isset($_REQUEST[$fieldname]) && $_REQUEST[$fieldname] != '') {
            if ($_REQUEST['module'] == $rel_modulename) {
                $module_entityname = '';
            } else {
                $value = $_REQUEST[$fieldname];
                $module_entityname = getEntityNameForTen($rel_tablename, $rel_entityname, $fieldname, $value);
            }
        }
        if (isset($app_strings[$fieldlabel])) {
            $editview_label[] = $app_strings[$fieldlabel];
        } elseif (isset($mod_strings[$fieldlabel])) {
            $editview_label[] = $mod_strings[$fieldlabel];
        } else {
            $editview_label[] = $fieldlabel;
        }
        $fieldvalue[] = $module_entityname;
        $fieldvalue[] = $value;
        $fieldvalue[] = $rel_entityname;
        $fieldvalue[] = $rel_modulename;
    } elseif ($uitype == 17) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    } elseif ($uitype == 85) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    } elseif ($uitype == 86) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    } elseif ($uitype == 87) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    } elseif ($uitype == 88) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    } elseif ($uitype == 89) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    } elseif ($uitype == 33) {
        $pick_query = "select colvalue from ec_picklist where colname='" . $fieldname . "' order by sequence asc";
        $pickListResult = $adb->getList($pick_query);
        $picklist_array = array();
        foreach ($pickListResult as $row) {
            $picklist_array[] = $row['colvalue'];
        }
        $editview_label[] = $mod_strings[$fieldlabel];
        $mulsel = "select colvalue from ec_picklist where colname='" . $fieldname . "' order by sequence asc";
        $multiselect_result = $adb->query($mulsel);
        $noofoptions = $adb->num_rows($multiselect_result);
        $options = array();
        $found = false;
        $valur_arr = explode(' |##| ', $value);
        for ($j = 0; $j < $noofoptions; $j++) {
            $multiselect_combo = $adb->query_result($multiselect_result, $j, "colvalue");
            if (in_array($multiselect_combo, $valur_arr)) {
                $chk_val = "selected";
                $found = true;
            } else {
                $chk_val = '';
            }
            $options[] = array($multiselect_combo => $chk_val);
        }
        $fieldvalue[] = $options;
    } elseif ($uitype == 19 || $uitype == 20) {
        if (isset($_REQUEST['body'])) {
            $value = $_REQUEST['body'];
        }
        $editview_label[] = $mod_strings[$fieldlabel];
        //$value = to_html($value);
        //$value = htmlspecialchars($value, ENT_QUOTES, "UTF-8");
        $fieldvalue[] = $value;
    } elseif ($uitype == 21 || $uitype == 24) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    } elseif ($uitype == 22) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    } elseif ($uitype == 52) {
        $editview_label[] = $mod_strings[$fieldlabel];
        global $current_user;
        if ($value != '') {
            $assigned_user_id = $value;
        } else {
            $assigned_user_id = $current_user->id;
        }
        $combo_lbl_name = 'assigned_user_id';
        if ($fieldlabel == 'Assigned To') {
            $user_array = get_user_array(FALSE, "Active", $assigned_user_id);
            $users_combo = get_select_options_array($user_array, $assigned_user_id);
        } else {
            $user_array = get_user_array(FALSE, "Active", $assigned_user_id);
            $users_combo = get_select_options_array($user_array, $assigned_user_id);
        }
        $fieldvalue[] = $users_combo;
    } elseif ($uitype == 77) {
        $editview_label[] = $mod_strings[$fieldlabel];
        global $current_user;
        if ($value != '') {
            $assigned_user_id = $value;
        } else {
            $assigned_user_id = $current_user->id;
        }
        $combo_lbl_name = 'assigned_user_id';
        $user_array = get_user_array(FALSE, "Active", $assigned_user_id);
        $users_combo = get_select_options_array($user_array, $assigned_user_id);
        $fieldvalue[] = $users_combo;
    } elseif ($uitype == 53) {
        $editview_label[] = $mod_strings[$fieldlabel];
        global $current_user;
        if ($value != '' && $value != 0) {
            $assigned_user_id = $value;
        } else {
            $assigned_user_id = $current_user->id;
        }
        if ($fieldlabel == 'Assigned To') {
            $user_array = get_user_array(FALSE, "Active", $assigned_user_id);
            $users_combo = get_select_options_array($user_array, $assigned_user_id);
        } else {
            $user_array = get_user_array(FALSE, "Active", $assigned_user_id);
            $users_combo = get_select_options_array($user_array, $assigned_user_id);
        }
        $fieldvalue[] = $users_combo;
    } elseif ($uitype == 1004) {
        if (isset($mod_strings[$fieldlabel])) {
            $editview_label[] = $mod_strings[$fieldlabel];
        } else {
            $editview_label[] = $fieldlabel;
        }
        if (empty($value)) {
            global $current_user;
            $value = $current_user->id;
        }
        $fieldvalue[] = getUserName($value);
    } elseif ($uitype == 1008) {
        if (isset($mod_strings[$fieldlabel])) {
            $editview_label[] = $mod_strings[$fieldlabel];
        } else {
            $editview_label[] = $fieldlabel;
        }
        if (empty($value)) {
            global $current_user;
            $value = $current_user->id;
        }
        $fieldvalue[] = getUserName($value);
    } elseif ($uitype == 51 || $uitype == 50 || $uitype == 73) {
        $account_name = "";
        /*$convertmode = "";
        		if(isset($_REQUEST['convertmode']))
        		{
        			$convertmode = $_REQUEST['convertmode'];
        		}
        		if($convertmode != 'update_quote_val' && $convertmode != 'update_so_val')
        		{
        			if(isset($_REQUEST['account_id']) && $_REQUEST['account_id'] != '')
        				$value = $_REQUEST['account_id'];	
        		}*/
        if (isset($_REQUEST['account_id']) && $_REQUEST['account_id'] != '') {
            $value = $_REQUEST['account_id'];
        }
        if ($value != '') {
            $account_name = getAccountName($value);
        }
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $account_name;
        $fieldvalue[] = $value;
    } elseif ($uitype == 54) {
        $options = array();
        if ($value == "") {
            $key = "currentuser_group_" . $current_user->id;
            $currentuser_group = getSqlCacheData($key);
            if (!$currentuser_group) {
                $query = "select ec_groups.groupname from ec_groups left join ec_users2group on ec_users2group.groupid=ec_groups.groupid where ec_users2group.userid='" . $current_user->id . "' and ec_users2group.groupid!=0";
                $result = $adb->query($query);
                $noofrows = $adb->num_rows($result);
                if ($noofrows > 0) {
                    $currentuser_group = $adb->query_result($result, 0, "groupname");
                }
                setSqlCacheData($key, $currentuser_group);
            }
            $value = $currentuser_group;
        }
        $key = "picklist_array_group";
        $picklist_array = getSqlCacheData($key);
        if (!$picklist_array) {
            $pick_query = "select * from ec_groups order by groupid";
            $pickListResult = $adb->getList($pick_query);
            $picklist_array = array();
            foreach ($pickListResult as $row) {
                $picklist_array[] = $row["groupname"];
            }
            setSqlCacheData($key, $picklist_array);
        }
        $editview_label[] = $mod_strings[$fieldlabel];
        foreach ($picklist_array as $pickListValue) {
            if ($value == $pickListValue) {
                $chk_val = "selected";
            } else {
                $chk_val = '';
            }
            $options[] = array($pickListValue => $chk_val);
        }
        $fieldvalue[] = $options;
    } elseif ($uitype == 59) {
        if ($value != '') {
            $product_name = getProductName($value);
        }
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $product_name;
        $fieldvalue[] = $value;
    } elseif ($uitype == 64) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $date_format = parse_calendardate($app_strings['NTC_DATE_FORMAT']);
        $fieldvalue[] = $value;
    } elseif ($uitype == 56) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    } elseif ($uitype == 57) {
        $accountid = $col_fields['account_id'];
        if (empty($accountid)) {
            $convertmode = "";
            if (isset($_REQUEST['convertmode'])) {
                $convertmode = $_REQUEST['convertmode'];
            }
            if ($convertmode != 'update_quote_val' && $convertmode != 'update_so_val') {
                if (isset($_REQUEST['account_id']) && $_REQUEST['account_id'] != '') {
                    $accountid = $_REQUEST['account_id'];
                }
            }
        }
        $contact_name = '';
        //		if(trim($value) != '')
        //		{
        //			$contact_name = getContactName($value);
        //		}
        //		elseif(isset($_REQUEST['contact_id']) && $_REQUEST['contact_id'] != '')
        //		{
        //			if(isset($_REQUEST['module']) && $_REQUEST['module'] == 'Contacts' && $fieldname = 'contact_id')
        //			{
        //				$contact_name = '';
        //			}
        //			else
        //			{
        //				$value = $_REQUEST['contact_id'];
        //				$contact_name = getContactName($value);
        //			}
        //
        //		}
        if (trim($value) == '') {
            if (isset($_REQUEST['module']) && $_REQUEST['module'] == 'Contacts' && ($fieldname = 'contact_id')) {
            } else {
                $value = $_REQUEST['contact_id'];
            }
        }
        $contactopts = getContactOptions($accountid, $value);
        //Checking for contacts duplicate
        $editview_label[] = $mod_strings[$fieldlabel];
        //		$fieldvalue[] = $contact_name;
        $fieldvalue[] = $contactopts;
        $fieldvalue[] = $value;
    } elseif ($uitype == 76) {
        if ($value != '') {
            $potential_name = getPotentialName($value);
        } elseif (isset($_REQUEST['potential_id']) && $_REQUEST['potential_id'] != '') {
            $value = $_REQUEST['potental_id'];
            $potential_name = getPotentialName($value);
        } elseif (isset($_REQUEST['potentialid']) && $_REQUEST['potentialid'] != '') {
            $value = $_REQUEST['potentalid'];
            $potential_name = getPotentialName($value);
        }
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $potential_name;
        $fieldvalue[] = $value;
    } elseif ($uitype == 80) {
        if ($value != '') {
            $salesorder_name = getSoName($value);
        } elseif (isset($_REQUEST['salesorder_id']) && $_REQUEST['salesorder_id'] != '') {
            $value = $_REQUEST['salesorder_id'];
            $salesorder_name = getSoName($value);
        }
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $salesorder_name;
        $fieldvalue[] = $value;
    } elseif ($uitype == 101) {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = getUserName($value);
        $fieldvalue[] = $value;
    } else {
        $editview_label[] = $mod_strings[$fieldlabel];
        $fieldvalue[] = $value;
    }
    $final_arr[] = $ui_type;
    $final_arr[] = $editview_label;
    $final_arr[] = $editview_fldname;
    $final_arr[] = $fieldvalue;
    $log->debug("Exiting getOutputHtml method ...");
    return $final_arr;
}
Ejemplo n.º 26
0
    if ($currentModule == 'Accounts' && $_REQUEST['recordid'] != '') {
        $where_relquery .= " and vtiger_account.accountid!=" . $adb->sql_escape_string($_REQUEST['recordid']);
        $smarty->assign("RECORDID", vtlib_purify($_REQUEST['recordid']));
    }
    if ($currentModule == 'Contacts' && $_REQUEST['recordid'] != '') {
        $where_relquery .= " and vtiger_contactdetails.contactid!=" . $adb->sql_escape_string($_REQUEST['recordid']);
        $smarty->assign("RECORDID", vtlib_purify($_REQUEST['recordid']));
    }
    if ($currentModule == 'Users' && $_REQUEST['recordid'] != '') {
        $where_relquery .= " and vtiger_users.id!=" . $adb->sql_escape_string($_REQUEST['recordid']);
        $smarty->assign("RECORDID", vtlib_purify($_REQUEST['recordid']));
    }
    $query = getListQuery($currentModule, $where_relquery);
}
if ($currentModule == 'Products' && $_REQUEST['record_id'] && ($popuptype == 'inventory_prod' || $popuptype == 'inventory_prod_po')) {
    $product_name = getProductName($_REQUEST['record_id']);
    $smarty->assign("PRODUCT_NAME", $product_name);
    $smarty->assign("RECORD_ID", vtlib_purify($_REQUEST['record_id']));
}
$listview_header_search = getSearchListHeaderValues($focus, "{$currentModule}", $url_string, $sorder, $order_by);
$smarty->assign("SEARCHLISTHEADER", $listview_header_search);
$smarty->assign("ALPHABETICAL", $alphabetical);
if (isset($_REQUEST['query']) && $_REQUEST['query'] == 'true') {
    list($where, $ustring) = split("#@@#", getWhereCondition($currentModule));
    $url_string .= "&query=true" . $ustring;
}
if (isset($where) && $where != '') {
    $query .= ' and ' . $where;
}
//Added to fix the issue #2307
$order_by = isset($_REQUEST['order_by']) ? $adb->sql_escape_string($_REQUEST['order_by']) : $focus->default_order_by;
Ejemplo n.º 27
0
 function getAssociatedProducts($module, $focus, $seid = '')
 {
     $adb = PearDatabase::getInstance();
     $current_user = vglobal('current_user');
     $log = vglobal('log');
     $theme = vglobal('theme');
     $log->debug("Entering OSSCosts_Record_Model getAssociatedProducts(" . $module . "," . get_class($focus) . "," . $seid . "='') method ...");
     $output = '';
     $no_of_decimal_places = getCurrencyDecimalPlaces();
     $theme_path = "themes/" . $theme . "/";
     $image_path = $theme_path . "images/";
     $product_Detail = array();
     if ($module == 'OSSCosts') {
         $query = "SELECT\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.productcode else vtiger_service.service_no end as productcode,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock,\n\t\t\t\t\t\tcase when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype,\n\t\t\t\t\t\t\t\t\tvtiger_inventoryproductrel.listprice,\n\t\t\t\t\t\t\t\t\tvtiger_inventoryproductrel.description AS product_description,\n\t\t\t\t\t\t\t\t\tvtiger_inventoryproductrel.*,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_products.usageunit,\n\t\t\t\t\t\t\t\t\tvtiger_service.service_usageunit\n\t\t\t\t\t\t\t\t\tFROM vtiger_inventoryproductrel\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_inventoryproductrel.productid\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_products\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_products.productid=vtiger_inventoryproductrel.productid\n\t\t\t\t\t\t\t\t\tLEFT JOIN vtiger_service\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_service.serviceid=vtiger_inventoryproductrel.productid\n\t\t\t\t\t\t\t\t\tWHERE id=?\n\t\t\t\t\t\t\t\t\tORDER BY sequence_no";
         $params = array($focus->id);
     } elseif ($module == 'Products') {
         $query = "SELECT\n\t\t\t\t\t\t\t\t\tvtiger_products.productid,\n\t\t\t\t\t\t\t\t\tvtiger_products.productcode,\n\t\t\t\t\t\t\t\t\tvtiger_products.productname,\n\t\t\t\t\t\t\t\t\tvtiger_products.unit_price,\n\t\t\t\t\t\t\t\t\tvtiger_products.usageunit,\n\t\t\t\t\t\t\t\t\tvtiger_products.qtyinstock,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_crmentity.description AS product_description,\n\t\t\t\t\t\t\t\t\t'Products' AS entitytype\n\t\t\t\t\t\t\t\t\tFROM vtiger_products\n\t\t\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_crmentity.crmid=vtiger_products.productid\n\t\t\t\t\t\t\t\t\tWHERE vtiger_crmentity.deleted=0\n\t\t\t\t\t\t\t\t\t\t\tAND productid=?";
         $params = array($seid);
     } elseif ($module == 'Services') {
         $query = "SELECT\n\t\t\t\t\t\t\t\t\tvtiger_service.serviceid AS productid,\n\t\t\t\t\t\t\t\t\t'NA' AS productcode,\n\t\t\t\t\t\t\t\t\tvtiger_service.servicename AS productname,\n\t\t\t\t\t\t\t\t\tvtiger_service.unit_price AS unit_price,\n\t\t\t\t\t\t\t\t\tvtiger_service.service_usageunit AS usageunit,\n\t\t\t\t\t\t\t\t\t'NA' AS qtyinstock,vtiger_crmentity.deleted,\n\t\t\t\t\t\t\t\t\tvtiger_crmentity.description AS product_description,\n\t\t\t\t\t\t\t\t\t'Services' AS entitytype\n\t\t\t\t\t\t\t\t\tFROM vtiger_service\n\t\t\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity\n\t\t\t\t\t\t\t\t\t\t\tON vtiger_crmentity.crmid=vtiger_service.serviceid\n\t\t\t\t\t\t\t\t\tWHERE vtiger_crmentity.deleted=0\n\t\t\t\t\t\t\t\t\t\t\tAND serviceid=?";
         $params = array($seid);
     }
     $result = $adb->pquery($query, $params);
     $num_rows = $adb->num_rows($result);
     $finalTaxTotal = '0.00';
     for ($i = 1; $i <= $num_rows; $i++) {
         $deleted = $adb->query_result($result, $i - 1, 'deleted');
         $hdnProductId = $adb->query_result($result, $i - 1, 'productid');
         $hdnProductcode = $adb->query_result($result, $i - 1, 'productcode');
         $productname = $adb->query_result($result, $i - 1, 'productname');
         $productdescription = $adb->query_result($result, $i - 1, 'product_description');
         $comment = $adb->query_result($result, $i - 1, 'comment');
         $qtyinstock = $adb->query_result($result, $i - 1, 'qtyinstock');
         $qty = $adb->query_result($result, $i - 1, 'quantity');
         $unitprice = $adb->query_result($result, $i - 1, 'unit_price');
         $listprice = $adb->query_result($result, $i - 1, 'listprice');
         $entitytype = $adb->query_result($result, $i - 1, 'entitytype');
         if ($entitytype == 'Services') {
             $usageunit = vtranslate($adb->query_result($result, $i - 1, 'service_usageunit'), $entitytype);
         } else {
             $usageunit = vtranslate($adb->query_result($result, $i - 1, 'usageunit'), $entitytype);
         }
         $tax = $adb->query_result($result, $i - 1, 'tax');
         if ($deleted || !isset($deleted)) {
             $product_Detail[$i]['productDeleted' . $i] = true;
         } elseif (!$deleted) {
             $product_Detail[$i]['productDeleted' . $i] = false;
         }
         if (!empty($entitytype)) {
             $product_Detail[$i]['entityType' . $i] = $entitytype;
         }
         if ($listprice == '') {
             $listprice = $unitprice;
         }
         if ($qty == '') {
             $qty = 1;
         }
         //calculate productTotal
         $productTotal = $qty * $listprice;
         //Delete link in First column
         if ($i != 1) {
             $product_Detail[$i]['delRow' . $i] = "Del";
         }
         if (empty($focus->mode) && $seid != '') {
             $sub_prod_query = $adb->pquery("SELECT crmid as prod_id from vtiger_seproductsrel WHERE productid=? AND setype='Products'", array($seid));
         } else {
             $sub_prod_query = $adb->pquery("SELECT productid as prod_id from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($focus->id, $i));
         }
         $subprodid_str = '';
         $subprodname_str = '';
         $subProductArray = array();
         if ($adb->num_rows($sub_prod_query) > 0) {
             for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                 $sprod_id = $adb->query_result($sub_prod_query, $j, 'prod_id');
                 $sprod_name = $subProductArray[] = getProductName($sprod_id);
                 $str_sep = "";
                 if ($j > 0) {
                     $str_sep = ":";
                 }
                 $subprodid_str .= $str_sep . $sprod_id;
                 $subprodname_str .= $str_sep . " - " . $sprod_name;
             }
         }
         $subprodname_str = str_replace(":", "<br>", $subprodname_str);
         $product_Detail[$i]['subProductArray' . $i] = $subProductArray;
         $product_Detail[$i]['hdnProductId' . $i] = $hdnProductId;
         $product_Detail[$i]['productName' . $i] = from_html($productname);
         /* Added to fix the issue Product Pop-up name display*/
         if ($_REQUEST['action'] == 'CreateSOPDF' || $_REQUEST['action'] == 'CreatePDF' || $_REQUEST['action'] == 'SendPDFMail') {
             $product_Detail[$i]['productName' . $i] = htmlspecialchars($product_Detail[$i]['productName' . $i]);
         }
         $product_Detail[$i]['hdnProductcode' . $i] = $hdnProductcode;
         $product_Detail[$i]['productDescription' . $i] = from_html($productdescription);
         if ($module == 'Potentials' || $module == 'Products' || $module == 'Services') {
             $product_Detail[$i]['comment' . $i] = $productdescription;
         } else {
             $product_Detail[$i]['comment' . $i] = $comment;
         }
         if ($module != 'PurchaseOrder' && $focus->object_name != 'Order') {
             $product_Detail[$i]['qtyInStock' . $i] = decimalFormat($qtyinstock);
         }
         $listprice = number_format($listprice, $no_of_decimal_places, '.', '');
         $product_Detail[$i]['qty' . $i] = decimalFormat($qty);
         $product_Detail[$i]['listPrice' . $i] = $listprice;
         $product_Detail[$i]['unitPrice' . $i] = number_format($unitprice, $no_of_decimal_places, '.', '');
         $product_Detail[$i]['usageUnit' . $i] = $usageunit;
         $product_Detail[$i]['productTotal' . $i] = $productTotal;
         $product_Detail[$i]['subproduct_ids' . $i] = $subprodid_str;
         $product_Detail[$i]['subprod_names' . $i] = $subprodname_str;
         $product_Detail[$i]['tax' . $i] = $tax;
         $discount_percent = decimalFormat($adb->query_result($result, $i - 1, 'discount_percent'));
         $discount_amount = $adb->query_result($result, $i - 1, 'discount_amount');
         $discount_amount = decimalFormat(number_format($discount_amount, $no_of_decimal_places, '.', ''));
         $discountTotal = '0.00';
         //Based on the discount percent or amount we will show the discount details
         //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(for Each Product)
         $product_Detail[$i]['discount_percent' . $i] = 0;
         $product_Detail[$i]['discount_amount' . $i] = 0;
         if ($discount_percent != 'NULL' && $discount_percent != '') {
             $product_Detail[$i]['discount_type' . $i] = "percentage";
             $product_Detail[$i]['discount_percent' . $i] = $discount_percent;
             $product_Detail[$i]['checked_discount_percent' . $i] = ' checked';
             $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:visible"';
             $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:hidden"';
             $discountTotal = $productTotal * $discount_percent / 100;
         } elseif ($discount_amount != 'NULL' && $discount_amount != '') {
             $product_Detail[$i]['discount_type' . $i] = "amount";
             $product_Detail[$i]['discount_amount' . $i] = $discount_amount;
             $product_Detail[$i]['checked_discount_amount' . $i] = ' checked';
             $product_Detail[$i]['style_discount_amount' . $i] = ' style="visibility:visible"';
             $product_Detail[$i]['style_discount_percent' . $i] = ' style="visibility:hidden"';
             $discountTotal = $discount_amount;
         } else {
             $product_Detail[$i]['checked_discount_zero' . $i] = ' checked';
         }
         $totalAfterDiscount = $productTotal - $discountTotal;
         $totalAfterDiscount = number_format($totalAfterDiscount, $no_of_decimal_places, '.', '');
         $discountTotal = number_format($discountTotal, $no_of_decimal_places, '.', '');
         $product_Detail[$i]['discountTotal' . $i] = $discountTotal;
         $product_Detail[$i]['totalAfterDiscount' . $i] = $totalAfterDiscount;
         $amount = '0.00';
         $tax_details = getTaxDetailsForProduct($hdnProductId, 'all');
         //First we should get all available taxes and then retrieve the corresponding tax values
         $allTaxes = getAllTaxes('available', '', 'edit', $focus->id);
         $taxtype = $this->getInventoryTaxType($module, $focus->id);
         for ($tax_count = 0; $tax_count < count($tax_details); $tax_count++) {
             $tax_name = $tax_details[$tax_count]['taxname'];
             $tax_label = $tax_details[$tax_count]['taxlabel'];
             $tax_value = '0.00';
             //condition to avoid this function call when create new PO/SO/Quotes/Invoice from Product module
             if ($focus->id != '') {
                 if ($taxtype == 'individual') {
                     //if individual then show the entered tax percentage
                     $tax_value = getInventoryProductTaxValue($focus->id, $hdnProductId, $tax_name);
                 } else {
                     //if group tax then we have to show the default value when change to individual tax
                     $tax_value = $tax_details[$tax_count]['percentage'];
                 }
             } else {
                 //if the above function not called then assign the default associated value of the product
                 $tax_value = $tax_details[$tax_count]['percentage'];
             }
             $product_Detail[$i]['taxes'][$tax_count]['taxname'] = $tax_name;
             $product_Detail[$i]['taxes'][$tax_count]['taxlabel'] = $tax_label;
             $product_Detail[$i]['taxes'][$tax_count]['percentage'] = $tax_value;
             $amount = $totalAfterDiscount * $tax_value / 100;
             $amount = number_format($amount, $no_of_decimal_places, '.', '');
             $product_Detail[$i]['taxes'][$tax_count]['amount'] = $amount;
             if ($tax == $tax_name) {
                 $finalTaxTotal += $amount;
                 $product_Detail[$i]['taxTotal' . $i] = $amount;
             }
         }
         if ($taxtype == 'group') {
             foreach ($allTaxes as $key => $value) {
                 if ($tax == $value['taxname']) {
                     $amount = $totalAfterDiscount * $value['percentage'] / 100;
                     $amount = number_format($amount, $no_of_decimal_places, '.', '');
                     $product_Detail[$i]['taxes'][$tax]['amount'] = $amount;
                     $finalTaxTotal += $amount;
                     $product_Detail[$i]['taxTotal' . $i] = $amount;
                 }
             }
         }
         //Calculate netprice
         $netPrice = $totalAfterDiscount + number_format($product_Detail[$i]['taxTotal' . $i], $no_of_decimal_places, '.', '');
         //if condition is added to call this function when we create PO/SO/Quotes/Invoice from Product module
         $product_Detail[$i]['netPrice' . $i] = $netPrice;
     }
     //set the taxtype
     $product_Detail[1]['final_details']['taxtype'] = $taxtype;
     //Get the Final Discount, S&H charge, Tax for S&H  values
     //To set the Final Discount details
     $finalDiscount = '0.00';
     $product_Detail[1]['final_details']['discount_type_final'] = 'zero';
     $subTotal = $focus->column_fields['hdnSubTotal'] != '' ? $focus->column_fields['hdnSubTotal'] : '0.00';
     $subTotal = number_format($subTotal, $no_of_decimal_places, '.', '');
     $product_Detail[1]['final_details']['hdnSubTotal'] = $subTotal;
     $discountPercent = $focus->column_fields['hdnDiscountPercent'] != '' ? $focus->column_fields['hdnDiscountPercent'] : '0.00';
     $discountAmount = $focus->column_fields['hdnDiscountAmount'] != '' ? $focus->column_fields['hdnDiscountAmount'] : '0.00';
     if ($discountPercent != '0') {
         $discountAmount = $product_Detail[1]['final_details']['hdnSubTotal'] * $discountPercent / 100;
     }
     //To avoid NaN javascript error, here we assign 0 initially to' %of price' and 'Direct Price reduction'(For Final Discount)
     $discount_amount_final = '0.00';
     $discount_amount_final = number_format($discount_amount_final, $no_of_decimal_places, '.', '');
     $product_Detail[1]['final_details']['discount_percentage_final'] = 0;
     $product_Detail[1]['final_details']['discount_amount_final'] = $discount_amount_final;
     if ($focus->column_fields['hdnDiscountPercent'] != '0') {
         $finalDiscount = $subTotal * $discountPercent / 100;
         $product_Detail[1]['final_details']['discount_type_final'] = 'percentage';
         $product_Detail[1]['final_details']['discount_percentage_final'] = $discountPercent;
         $product_Detail[1]['final_details']['checked_discount_percentage_final'] = ' checked';
         $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:visible"';
         $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:hidden"';
     } elseif ($focus->column_fields['hdnDiscountAmount'] != '0' && $focus->column_fields['hdnDiscountAmount'] != '') {
         $finalDiscount = $focus->column_fields['hdnDiscountAmount'];
         $product_Detail[1]['final_details']['discount_type_final'] = 'amount';
         $product_Detail[1]['final_details']['discount_amount_final'] = $discountAmount;
         $product_Detail[1]['final_details']['checked_discount_amount_final'] = ' checked';
         $product_Detail[1]['final_details']['style_discount_amount_final'] = ' style="visibility:visible"';
         $product_Detail[1]['final_details']['style_discount_percentage_final'] = ' style="visibility:hidden"';
     }
     $finalDiscount = number_format($finalDiscount, $no_of_decimal_places, '.', '');
     $product_Detail[1]['final_details']['discountTotal_final'] = $finalDiscount;
     //To set the Final Tax values
     //we will get all taxes. if individual then show the product related taxes only else show all taxes
     //suppose user want to change individual to group or vice versa in edit time the we have to show all taxes. so that here we will store all the taxes and based on need we will show the corresponding taxes
     for ($tax_count = 0; $tax_count < count($allTaxes); $tax_count++) {
         $tax_name = $allTaxes[$tax_count]['taxname'];
         $tax_label = $allTaxes[$tax_count]['taxlabel'];
         //if taxtype is individual and want to change to group during edit time then we have to show the all available taxes and their default values
         //Also taxtype is group and want to change to individual during edit time then we have to provide the asspciated taxes and their default tax values for individual products
         if ($taxtype == 'group') {
             $tax_percent = $adb->query_result($result, 0, $tax_name);
         } else {
             $tax_percent = $allTaxes[$tax_count]['percentage'];
         }
         //$adb->query_result($result,0,$tax_name);
         if ($tax_percent == '' || $tax_percent == 'NULL') {
             $tax_percent = '0.00';
         }
         $taxamount = ($subTotal - $finalDiscount) * $tax_percent / 100;
         $taxamount = number_format($taxamount, $no_of_decimal_places, '.', '');
         $product_Detail[1]['final_details']['taxes'][$tax_count]['taxname'] = $tax_name;
         $product_Detail[1]['final_details']['taxes'][$tax_count]['taxlabel'] = $tax_label;
         $product_Detail[1]['final_details']['taxes'][$tax_count]['percentage'] = $tax_percent;
         $product_Detail[1]['final_details']['taxes'][$tax_count]['amount'] = $taxamount;
     }
     $product_Detail[1]['final_details']['tax_totalamount'] = $finalTaxTotal;
     $product_Detail[1]['final_details']['tax'] = $tax;
     //To set the grand total
     $grandTotal = $focus->column_fields['hdnGrandTotal'] != '' ? $focus->column_fields['hdnGrandTotal'] : '0.00';
     $grandTotal = number_format($grandTotal, $no_of_decimal_places, '.', '');
     $product_Detail[1]['final_details']['grandTotal'] = $grandTotal;
     $log->debug("Exiting OSSCosts_Record_Model getAssociatedProducts method ...");
     return $product_Detail;
 }
Ejemplo n.º 28
0
 private function x18($x0c, $x0e)
 {
     global $x15d, $x15e, $x15f, $x160, $x161, $x162, $x163, $x164, $x165, $x166, $x167, $x168, $x169, $x16a, $x16b, $x16c, $x16d, $x16e, $x16f, $x170, $x171, $x172, $x173, $x174, $x175, $x176, $x177, $x178;
     $xc5 = $this->x22($x0c, $x0e);
     $x6e = "select case when vtiger_products.productid != '' then vtiger_products.productname else vtiger_service.servicename end as productname," . " case when vtiger_products.productid != '' then vtiger_products.productid else vtiger_service.serviceid end as psid," . " case when vtiger_products.productid != '' then vtiger_products.product_no else vtiger_service.service_no end as psno," . " case when vtiger_products.productid != '' then 'Products' else 'Services' end as entitytype," . " case when vtiger_products.productid != '' then vtiger_products.unit_price else vtiger_service.unit_price end as unit_price," . " case when vtiger_products.productid != '' then vtiger_products.usageunit else vtiger_service.service_usageunit end as usageunit," . " case when vtiger_products.productid != '' then vtiger_products.qty_per_unit else vtiger_service.qty_per_unit end as qty_per_unit," . " case when vtiger_products.productid != '' then vtiger_products.qtyinstock else 'NA' end as qtyinstock," . " case when vtiger_products.productid != '' then c1.description else c2.description end as psdescription, vtiger_inventoryproductrel.* " . " from vtiger_inventoryproductrel" . " left join vtiger_products on vtiger_products.productid=vtiger_inventoryproductrel.productid " . " left join vtiger_crmentity as c1 on c1.crmid = vtiger_products.productid " . " left join vtiger_service on vtiger_service.serviceid=vtiger_inventoryproductrel.productid " . " left join vtiger_crmentity as c2 on c2.crmid = vtiger_service.serviceid " . " where id=? ORDER BY sequence_no";
     $x3e = self::$x0f->pquery($x6e, array($x0e->id));
     $x43 = self::$x0f->num_rows($x3e);
     $xc6 = "0.00";
     $xc7 = 0;
     $xc8 = 0;
     $xc9 = 0;
     list($xca, $xcb) = $this->x1a($x0e->id);
     $xcc = array();
     $xcd = array();
     for ($x2d = 1; $x2d <= $x43; $x2d++) {
         $xce = self::$x0f->pquery("SELECT productid from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($x0e->id, $x2d));
         $xcf = '';
         if (self::$x0f->num_rows($xce) > 0) {
             for ($x8d = 0; $x8d < self::$x0f->num_rows($xce); $x8d++) {
                 $xd0 = self::$x0f->query_result($xce, $x8d, "productid");
                 $xd1 = getProductName($xd0);
                 $xd2 = "";
                 if ($x8d > 0) {
                     $xd2 = ":";
                 }
                 $xcf .= $xd2 . " - " . $xd1;
             }
         }
         $xcf = $x172(":", "<br>", $xcf);
         $xd3 = self::$x0f->query_result($x3e, $x2d - 1, "psid");
         $xd4 = self::$x0f->query_result($x3e, $x2d - 1, "psno");
         $xd5 = self::$x0f->query_result($x3e, $x2d - 1, "productid");
         $xd6 = self::$x0f->query_result($x3e, $x2d - 1, "entitytype");
         $xd7 = $xd8 = self::$x0f->query_result($x3e, $x2d - 1, "productname");
         if ($xcf != "") {
             $xd8 .= "<br/><span style='color:#C0C0C0;font-style:italic;'>" . $xcf . "</span>";
         }
         $xd9 = self::$x0f->query_result($x3e, $x2d - 1, "comment");
         $xda = self::$x0f->query_result($x3e, $x2d - 1, "psdescription");
         $xdb = self::$x0f->query_result($x3e, $x2d - 1, "description");
         $xdc = self::$x0f->query_result($x3e, $x2d - 1, "qtyinstock");
         $xdd = self::$x0f->query_result($x3e, $x2d - 1, "quantity");
         $xde = self::$x0f->query_result($x3e, $x2d - 1, "qty_per_unit");
         $xdf = self::$x0f->query_result($x3e, $x2d - 1, "usageunit");
         $xe0 = self::$x0f->query_result($x3e, $x2d - 1, "unit_price");
         $xe1 = self::$x0f->query_result($x3e, $x2d - 1, "listprice");
         $xe2 = $xdd * $xe1;
         $xe3 = self::$x0f->query_result($x3e, $x2d - 1, "discount_percent");
         $xe4 = self::$x0f->query_result($x3e, $x2d - 1, "discount_amount");
         $xe5 = $xe2;
         $xe6 = "0.00";
         $xe7 = "";
         if ($xe3 != "NULL" && $xe3 != "") {
             $xe6 = $xe2 * $xe3 / 100;
             $xe5 = $xe2 - $xe6;
             $xe7 = $xe3;
         } elseif ($xe4 != "NULL" && $xe4 != "") {
             $xe6 = $xe4;
             $xe5 = $xe2 - $xe6;
         }
         $xe8 = $xe5;
         if ($xc5 == "individual") {
             $xe9 = "0.00";
             $xea = $x10["LBL_TOTAL_AFTER_DISCOUNT"] . " = {$xe5} \\n";
             $xeb = getTaxDetailsForProduct($xd5, "all");
             $xec = array();
             for ($xed = 0; $xed < $x161($xeb); $xed++) {
                 $xee = $xeb[$xed]["taxname"];
                 $xef = $xeb[$xed]["taxlabel"];
                 $xf0 = getInventoryProductTaxValue($x0e->id, $xd5, $xee);
                 $xf1 = $xe5 * $xf0 / 100;
                 $xe9 = $xe9 + $xf1;
                 if ($xee != "" && $xf0 > 0) {
                     $xf2[$xee . "-" . $xf0]["label"] = $xef;
                     $xf2[$xee . "-" . $xf0]["netto"] += $xe5;
                     $xf2[$xee . "-" . $xf0]["vat"] += $x16f($xf1, self::$x15);
                     $xf2[$xee . "-" . $xf0]["value"] = $xf0;
                     $x15e($xec, $xf0);
                     $x15e($xcd, $xf0);
                 }
             }
             $xe8 = $xe8 + $xe9;
             if ($x161($xec) > 0) {
                 $xf3 = $x160($xec);
             } else {
                 $xf3 = "0.00";
             }
             $xf4["P"][$x2d]["PRODUCTVATPERCENT"] = $this->x23($xf3);
             $xf4["P"][$x2d]["PRODUCTVATSUM"] = $this->x23($xe9);
         }
         if ($xd6 == "Products") {
             $xf4["P"][$x2d]["PRODUCTS_CRMID"] = $xd3;
             $xf4["P"][$x2d]["SERVICES_CRMID"] = "";
         } else {
             $xf4["P"][$x2d]["PRODUCTS_CRMID"] = "";
             $xf4["P"][$x2d]["SERVICES_CRMID"] = $xd3;
         }
         $xf4["P"][$x2d]["PS_CRMID"] = $xd3;
         $xf4["P"][$x2d]["PS_NO"] = $xd4;
         if ($xd9 != "") {
             $xd9 = $x172("\\n", "<br>", $x16d($xd9));
             $xd9 = $x165($xd9, ENT_QUOTES, self::$x11);
             $xd8 .= "<br /><small>" . $xd9 . "</small>";
         }
         $xf4["P"][$x2d]["PRODUCTNAME"] = $xd8;
         $xf4["P"][$x2d]["PRODUCTTITLE"] = $xd7;
         $xda = $x172("\\n", "<br>", $x16d($xda));
         $xf4["P"][$x2d]["PRODUCTDESCRIPTION"] = $x165($xda, ENT_QUOTES, self::$x11);
         $xf4["P"][$x2d]["PRODUCTEDITDESCRIPTION"] = $xd9;
         $xdb = $x172("\\n", "<br>", $x16d($xdb));
         $xf4["P"][$x2d]["CRMNOWPRODUCTDESCRIPTION"] = $x165($xdb, ENT_QUOTES, self::$x11);
         $xf4["P"][$x2d]["PRODUCTLISTPRICE"] = $this->x23($xe1);
         $xf4["P"][$x2d]["PRODUCTTOTAL"] = $this->x23($xe2);
         $xf4["P"][$x2d]["PRODUCTQUANTITY"] = $this->x23($xdd);
         $xf4["P"][$x2d]["PRODUCTQINSTOCK"] = $this->x23($xdc);
         $xf4["P"][$x2d]["PRODUCTPRICE"] = $this->x23($xe0);
         $xf4["P"][$x2d]["PRODUCTPOSITION"] = $x2d;
         $xf4["P"][$x2d]["PRODUCTQTYPERUNIT"] = $this->x23($xde);
         $x83 = $xdf;
         if (!$x168($x178($x83), self::$x18)) {
             $x83 = $this->x20($x83, "Products/Services");
         } else {
             $x83 = "";
         }
         $xf4["P"][$x2d]["PRODUCTUSAGEUNIT"] = $x83;
         $xf4["P"][$x2d]["PRODUCTDISCOUNT"] = $this->x23($xe6);
         $xf4["P"][$x2d]["PRODUCTDISCOUNTPERCENT"] = $this->x23($xe7);
         $xf4["P"][$x2d]["PRODUCTSTOTALAFTERDISCOUNTSUM"] = $xe5;
         $xf4["P"][$x2d]["PRODUCTSTOTALAFTERDISCOUNT"] = $this->x23($xe5);
         $xf4["P"][$x2d]["PRODUCTTOTALSUM"] = $this->x23($xe5 + $xe9);
         $xc7 += $xe5;
         $xc8 += $xe2;
         $xc9 += $xe5 + $xe9;
         $xf4["P"][$x2d]["PRODUCTSTOTALAFTERDISCOUNT_SUBTOTAL"] = $this->x23($xc7);
         $xf4["P"][$x2d]["PRODUCTTOTAL_SUBTOTAL"] = $this->x23($xc8);
         $xf4["P"][$x2d]["PRODUCTTOTALSUM_SUBTOTAL"] = $this->x23($xc9);
         $xcc[$x2d]["\$" . "TOTALAFTERDISCOUNT_SUBTOTAL\$"] = $xf4["P"][$x2d]["PRODUCTSTOTALAFTERDISCOUNT_SUBTOTAL"];
         $xcc[$x2d]["\$" . "TOTAL_SUBTOTAL\$"] = $xf4["P"][$x2d]["PRODUCTTOTAL_SUBTOTAL"];
         $xcc[$x2d]["\$" . "TOTALSUM_SUBTOTAL\$"] = $xf4["P"][$x2d]["PRODUCTTOTALSUM_SUBTOTAL"];
         $xf5 = self::$x0f->query_result($x3e, $x2d - 1, "sequence_no");
         $xf4["P"][$x2d]["PRODUCTSEQUENCE"] = $xf5;
         if (isset($xca[$xd5 . "_" . $xf5])) {
             $xf6 = "";
             $xf7 = "";
             if ($xca[$xd5 . "_" . $xf5]["width"] > 0) {
                 $xf6 = " width='" . $xca[$xd5 . "_" . $xf5]["width"] . "' ";
             }
             if ($xca[$xd5 . "_" . $xf5]["height"] > 0) {
                 $xf7 = " height='" . $xca[$xd5 . "_" . $xf5]["height"] . "' ";
             }
             $xf4["P"][$x2d]["PRODUCTS_IMAGENAME"] = "<img src='" . self::$x12 . "/" . $xca[$xd5 . "_" . $xf5]["src"] . "' " . $xf6 . $xf7 . "/>";
         } elseif (isset($xcb[$xd5 . "_" . $xf5])) {
             $xf4["P"][$x2d]["PRODUCTS_IMAGENAME"] = "<img src='" . self::$x12 . "/" . $xcb[$xd5 . "_" . $xf5]["src"] . "' width='83' />";
         }
         $xf8 = CRMEntity::getInstance("Products");
         if ($xd6 == "Products" && $xd3 != "") {
             $xf8->id = $xd3;
             $this->x24($xf8, $xd3, "Products");
         }
         $xf9 = $this->x21($x0c, $x0e);
         $xfa = $this->x10("Products", $xf8, false, $xf9);
         $xf4["P"][$x2d] = $x15f($xfa, $xf4["P"][$x2d]);
         unset($xf8);
         $xfb = CRMEntity::getInstance("Services");
         if ($xd6 == "Services" && $xd3 != "") {
             $xfb->id = $xd3;
             $this->x24($xfb, $xd3, "Services");
         }
         $xfc = $this->x10("Services", $xfb, false, $xf9);
         $xf4["P"][$x2d] = $x15f($xfc, $xf4["P"][$x2d]);
         unset($xfb);
         $xfd += $xe5;
         $xc6 = $xc6 + $xe8;
     }
     if (self::$x0c == $x0c) {
         self::$x26["subtotalsArray"] = $xcc;
     }
     $xfe = "0.00";
     $xff = "0";
     $x100 = "";
     if ($x0e->column_fields["hdnDiscountPercent"] != "0") {
         $xfe = $xc6 * $x0e->column_fields["hdnDiscountPercent"] / 100;
         $x100 = $x0e->column_fields["hdnDiscountPercent"];
     } elseif ($x0e->column_fields["hdnDiscountAmount"] != "0") {
         $xfe = $x0e->column_fields["hdnDiscountAmount"];
     }
     $xe9 = "0.00";
     if ($xc5 == "group") {
         $x101 = $xc6 - $xfe;
         $xeb = getAllTaxes("available", "", "edit", $x0e->id);
         for ($xed = 0; $xed < $x161($xeb); $xed++) {
             $xee = $xeb[$xed]["taxname"];
             $xef = $xeb[$xed]["taxlabel"];
             $xf0 = self::$x0f->query_result($x3e, 0, $xee);
             if ($xf0 == "" || $xf0 == "NULL") {
                 $xf0 = "0.00";
             }
             $x102 = ($xc6 - $xfe) * $xf0 / 100;
             $xe9 = $xe9 + $x102;
             if ($xee != "" && $xf0 > 0) {
                 $xf2[$xee]["label"] = $xef;
                 $xf2[$xee]["netto"] = $x101;
                 $xf2[$xee]["vat"] += $x102;
                 $xf2[$xee]["value"] = $xf0;
             }
             $x103 += $xf0;
         }
         $x104 = $xe9;
         foreach ($xf4["P"] as $x105 => $x106) {
             $x107 = $xf4["P"][$x105]["PRODUCTSTOTALAFTERDISCOUNTSUM"] * $x103 / 100;
             $x108 = $xf4["P"][$x105]["PRODUCTSTOTALAFTERDISCOUNTSUM"] + $x107;
             $xf4["P"][$x105]["PRODUCTVATPERCENT"] = $this->x23($x103);
             $xf4["P"][$x105]["PRODUCTVATSUM"] = $this->x23($x107);
             $xf4["P"][$x105]["PRODUCTTOTALSUM"] = $this->x23($x108);
         }
     } else {
         if ($x161($xf2) > 0) {
             foreach ($xf2 as $x109 => $x10a) {
                 $x104 += $x10a["vat"];
             }
         } else {
             $x104 = "0.00";
         }
     }
     $x10b = $x0e->column_fields["hdnS_H_Amount"] != "" ? $x0e->column_fields["hdnS_H_Amount"] : "0.00";
     $x10c = "0.00";
     $x10d = getAllTaxes("available", "sh", "edit", $x0e->id);
     for ($x10e = 0; $x10e < $x161($x10d); $x10e++) {
         $x10f = $x10d[$x10e]["taxname"];
         $x110 = $x10d[$x10e]["taxlabel"];
         $x111 = getInventorySHTaxPercent($x0e->id, $x10f);
         $x112 = $x10b * $x111 / 100;
         $x10c = $x10c + $x112;
     }
     $x113 = $xfd - $xfe;
     $x114 = $xfd - $xfe + $x104;
     $xf4["TOTAL"]["NETTOTAL"] = $this->x23($xc6);
     $xf4["TOTAL"]["TOTALWITHOUTVAT"] = $this->x23($xfd);
     $xf4["TOTAL"]["FINALDISCOUNT"] = $this->x23($xfe);
     $xf4["TOTAL"]["FINALDISCOUNTPERCENT"] = $this->x23($x100);
     $xf4["TOTAL"]["TOTALAFTERDISCOUNT"] = $this->x23($x113);
     $xf4["TOTAL"]["TAXTOTAL"] = $this->x23($x104);
     $xf4["TOTAL"]["TAXTOTALPERCENT"] = $this->x23($x103);
     $xf4["TOTAL"]["TOTALWITHVAT"] = $this->x23($x114);
     $xf4["TOTAL"]["SHTAXAMOUNT"] = $this->x23($x10b);
     $xf4["TOTAL"]["SHTAXTOTAL"] = $this->x23($x10c);
     $xf4["TOTAL"]["VATBLOCK"] = $xf2;
     return $xf4;
 }
Ejemplo n.º 29
0
/** This function returns the detail view form ec_field and and its properties in array format.
 * Param $uitype - UI type of the ec_field
 * Param $fieldname - Form ec_field name
 * Param $fieldlabel - Form ec_field label name
 * Param $col_fields - array contains the ec_fieldname and values
 * Param $generatedtype - Field generated type (default is 1)
 * Param $tabid - ec_tab id to which the Field belongs to (default is "")
 * Return type is an array
 */
function getDetailViewOutputHtml($uitype, $fieldname, $fieldlabel, $col_fields, $generatedtype, $tabid = '')
{
    global $log;
    $log->debug("Entering getDetailViewOutputHtml() method ...");
    global $adb;
    global $mod_strings;
    global $app_strings;
    global $current_user;
    //$fieldlabel = from_html($fieldlabel);
    $custfld = '';
    $value = '';
    $arr_data = array();
    $label_fld = array();
    $data_fld = array();
    if ($generatedtype == 2) {
        $mod_strings[$fieldlabel] = $fieldlabel;
    }
    if (!isset($mod_strings[$fieldlabel])) {
        $mod_strings[$fieldlabel] = $fieldlabel;
    }
    if ($col_fields[$fieldname] == '--None--') {
        $col_fields[$fieldname] = '';
    }
    if ($uitype == 116) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 13) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $temp_val = $col_fields[$fieldname];
        $label_fld[] = $temp_val;
        $linkvalue = getComposeMailUrl($temp_val);
        $label_fld["link"] = $linkvalue;
    } elseif ($uitype == 15 || $uitype == 16 || $uitype == 115 || $uitype == 111) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 10) {
        if (isset($app_strings[$fieldlabel])) {
            $label_fld[] = $app_strings[$fieldlabel];
        } elseif (isset($mod_strings[$fieldlabel])) {
            $label_fld[] = $mod_strings[$fieldlabel];
        } else {
            $label_fld[] = $fieldlabel;
        }
        $value = $col_fields[$fieldname];
        $module_entityname = "";
        if ($value != '') {
            $query = "SELECT ec_entityname.* FROM ec_crmentityrel inner join ec_entityname on ec_entityname.modulename=ec_crmentityrel.relmodule inner join ec_tab on ec_tab.name=ec_crmentityrel.module WHERE ec_tab.tabid='" . $tabid . "' and ec_entityname.entityidfield='" . $fieldname . "'";
            $fldmod_result = $adb->query($query);
            $rownum = $adb->num_rows($fldmod_result);
            if ($rownum > 0) {
                $rel_modulename = $adb->query_result($fldmod_result, 0, 'modulename');
                $rel_tablename = $adb->query_result($fldmod_result, 0, 'tablename');
                $rel_entityname = $adb->query_result($fldmod_result, 0, 'fieldname');
                $rel_entityid = $adb->query_result($fldmod_result, 0, 'entityidfield');
                $module_entityname = getEntityNameForTen($rel_tablename, $rel_entityname, $fieldname, $value);
            }
        }
        $label_fld[] = $module_entityname;
        $label_fld["secid"] = $value;
        $label_fld["link"] = "index.php?module=" . $rel_modulename . "&action=DetailView&record=" . $value;
    } elseif ($uitype == 33) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = str_ireplace(' |##| ', ', ', $col_fields[$fieldname]);
    } elseif ($uitype == 17) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
        //$label_fld[] = '<a href="http://'.$col_fields[$fieldname].'" target="_blank">'.$col_fields[$fieldname].'</a>';
    } elseif ($uitype == 19) {
        //$tmp_value = str_replace("&lt;","<",nl2br($col_fields[$fieldname]));
        //$tmp_value = str_replace("&gt;",">",$tmp_value);
        //$col_fields[$fieldname]= make_clickable($tmp_value);
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 20 || $uitype == 21 || $uitype == 22 || $uitype == 24) {
        //$col_fields[$fieldname]=nl2br($col_fields[$fieldname]);
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 51 || $uitype == 50 || $uitype == 73) {
        $account_id = $col_fields[$fieldname];
        $account_name = "";
        if ($account_id != '') {
            $account_name = getAccountName($account_id);
        }
        //Account Name View
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $account_name;
        $label_fld["secid"] = $account_id;
        $label_fld["link"] = "index.php?module=Accounts&action=DetailView&record=" . $account_id;
    } elseif ($uitype == 52 || $uitype == 77 || $uitype == 101) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $user_id = $col_fields[$fieldname];
        $user_name = getUserName($user_id);
        $label_fld[] = $user_name;
    } elseif ($uitype == 53) {
        $user_id = $col_fields[$fieldname];
        $user_name = getUserName($user_id);
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $user_name;
    } elseif ($uitype == 1004) {
        if (isset($mod_strings[$fieldlabel])) {
            $label_fld[] = $mod_strings[$fieldlabel];
        } else {
            $label_fld[] = $fieldlabel;
        }
        $value = $col_fields[$fieldname];
        $label_fld[] = getUserName($value);
    } elseif ($uitype == 55) {
        if ($tabid == 4) {
            $query = "select ec_contactdetails.imagename from ec_contactdetails where contactid=" . $col_fields['record_id'];
            $result = $adb->query($query);
            $imagename = $adb->query_result($result, 0, 'imagename');
            if ($imagename != '') {
                $imgpath = "test/contact/" . $imagename;
                $label_fld[] = $mod_strings[$fieldlabel];
                //This is used to show the contact image as a thumbnail near First Name field
                //$label_fld["cntimage"] ='<div style="position:absolute;height=100px"><img class="thumbnail" src="'.$imgpath.'" width="60" height="60" border="0"></div>&nbsp;'.$mod_strings[$fieldlabel];
            } else {
                $label_fld[] = $mod_strings[$fieldlabel];
            }
        } else {
            $label_fld[] = $mod_strings[$fieldlabel];
        }
        $value = $col_fields[$fieldname];
        $sal_value = $col_fields["salutationtype"];
        if ($sal_value == '--None--') {
            $sal_value = '';
        }
        $label_fld["salut"] = $sal_value;
        $label_fld[] = $value;
        //$label_fld[] =$sal_value.' '.$value;
    } elseif ($uitype == 56) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $value = $col_fields[$fieldname];
        if ($value == 1) {
            //Since "yes" is not been translated it is given as app strings here..
            $display_val = $app_strings['yes'];
        } else {
            $display_val = '';
        }
        $label_fld[] = $display_val;
    } elseif ($uitype == 57) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $contact_id = $col_fields[$fieldname];
        $contact_name = "";
        if (trim($contact_id) != '') {
            $contact_name = getContactName($contact_id);
        }
        $label_fld[] = $contact_name;
        $label_fld["secid"] = $contact_id;
        $label_fld["link"] = "index.php?module=Contacts&action=DetailView&record=" . $contact_id;
    } elseif ($uitype == 154) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $cangkusid = $col_fields[$fieldname];
        $cangkuname = "";
        if (trim($cangkusid) != '') {
            $cangkuname = getCangkuName($cangkusid);
        }
        $label_fld[] = $cangkuname;
        $label_fld["secid"] = $cangkusid;
        $label_fld["link"] = "index.php?module=Cangkus&action=DetailView&record=" . $cangkusid;
    } elseif ($uitype == 155) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $cangkusid = $col_fields[$fieldname];
        $cangkuname = "";
        if (trim($cangkusid) != '') {
            $cangkuname = getCangkuName($cangkusid);
        }
        $label_fld[] = $cangkuname;
        $label_fld["secid"] = $cangkusid;
        //		 $label_fld["link"] = "index.php?module=Cangkus&action=DetailView&record=".$cangkusid;
    } elseif ($uitype == 58) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $campaign_id = $col_fields[$fieldname];
        if ($campaign_id != '') {
            $campaign_name = getCampaignName($campaign_id);
        }
        $label_fld[] = $campaign_name;
        $label_fld["secid"] = $campaign_id;
        $label_fld["link"] = "index.php?module=Campaigns&action=DetailView&record=" . $campaign_id;
    } elseif ($uitype == 59) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $product_id = $col_fields[$fieldname];
        if ($product_id != '') {
            $product_name = getProductName($product_id);
        }
        //Account Name View
        $label_fld[] = $product_name;
        $label_fld["secid"] = $product_id;
        $label_fld["link"] = "index.php?module=Products&action=DetailView&record=" . $product_id;
    } elseif ($uitype == 61) {
        global $adb;
        $label_fld[] = $mod_strings[$fieldlabel];
        if ($tabid == 10) {
            $attach_result = $adb->query("select * from ec_seattachmentsrel where crmid = " . $col_fields['record_id']);
            for ($ii = 0; $ii < $adb->num_rows($attach_result); $ii++) {
                $attachmentid = $adb->query_result($attach_result, $ii, 'attachmentsid');
                if ($attachmentid != '') {
                    $attachquery = "select * from ec_attachments where attachmentsid=" . $attachmentid;
                    $result = $adb->query($attachquery);
                    $attachmentsname = $adb->query_result($result, 0, 'name');
                    if ($attachmentsname != '') {
                        $custfldval = '<a href = "index.php?module=uploads&action=downloadfile&return_module=' . $col_fields['record_module'] . '&fileid=' . $attachmentid . '&entityid=' . $col_fields['record_id'] . '">' . $attachmentsname . '</a>';
                    } else {
                        $custfldval = '';
                    }
                }
                $label_fld['options'][] = $custfldval;
            }
        } else {
            $result = $adb->query("select * from ec_seattachmentsrel where crmid = " . $col_fields['record_id']);
            $attachmentid = $adb->query_result($result, 0, 'attachmentsid');
            if ($col_fields[$fieldname] == '' && $attachmentid != '') {
                $attachquery = "select * from ec_attachments where attachmentsid=" . $attachmentid;
                $result = $adb->query($attachquery);
                $col_fields[$fieldname] = $adb->query_result($result, 0, 'name');
            }
            //This is added to strip the crmid and _ from the file name and show the original filename
            $org_filename = ltrim($col_fields[$fieldname], $col_fields['record_id'] . '_');
            if ($org_filename != '') {
                $custfldval = '<a href = "index.php?module=uploads&action=downloadfile&return_module=' . $col_fields['record_module'] . '&fileid=' . $attachmentid . '&entityid=' . $col_fields['record_id'] . '">' . $org_filename . '</a>';
            } else {
                $custfldval = '';
            }
        }
        $label_fld[] = $custfldval;
    } elseif ($uitype == 69) {
        $label_fld[] = $mod_strings[$fieldlabel];
        if ($tabid == 14) {
            $images = array();
            $image_array = array();
            $imagepath_array = array();
            $query = "select productname, ec_attachments.path, ec_attachments.attachmentsid, ec_attachments.name from ec_products left join ec_seattachmentsrel on ec_seattachmentsrel.crmid=ec_products.productid inner join ec_attachments on ec_attachments.attachmentsid=ec_seattachmentsrel.attachmentsid where (ec_attachments.type like '%image%' or ec_attachments.type like '%img%') and productid=" . $col_fields['record_id'];
            $result_image = $adb->query($query);
            for ($image_iter = 0; $image_iter < $adb->num_rows($result_image); $image_iter++) {
                $image_id_array[] = $adb->query_result($result_image, $image_iter, 'attachmentsid');
                $image_array[] = $adb->query_result($result_image, $image_iter, 'name');
                $imagepath_array[] = $adb->query_result($result_image, $image_iter, 'path');
            }
            if (count($image_array) > 1) {
                //				if(count($image_array) < 4)
                //					$sides=count($image_array)*2;
                //				else
                //					$sides=8;
                //
                //				$image_lists = '<div id="Carousel" style="position:relative;vertical-align: middle;">
                //					<img src="modules/Products/placeholder.gif" width="571" height="117" style="position:relative;">
                //					</div><script>var Car_NoOfSides='.$sides.'; Car_Image_Sources=new Array(';
                //
                //				for($image_iter=0;$image_iter < count($image_array);$image_iter++)
                //				{
                //					$images[]='"'.$imagepath_array[$image_iter].$image_id_array[$image_iter]."_".base64_encode_filename($image_array[$image_iter]).'","'.$imagepath_array[$image_iter].$image_id_array[$image_iter]."_".base64_encode_filename($image_array[$image_iter]).'"';
                //				}
                //				$image_lists .=implode(',',$images).');
                /**</script><script language="JavaScript" type="text/javascript" src="modules/Products/Productsslide.js"></script><script language="JavaScript" type="text/javascript">Carousel();</script>';**/
                //				$label_fld[] =$image_lists;
                $num = count($image_array);
                for ($image_iter = 0; $image_iter < count($image_array); $image_iter++) {
                    $images[] = $imagepath_array[$image_iter] . $image_id_array[$image_iter] . "_" . base64_encode_filename($image_array[$image_iter]);
                }
                for ($i = 0; $i < $num; $i++) {
                    $image_lists .= '<a href="' . $images[$i] . '" target="_blank"><img src="' . $images[$i] . '"  border="0" width="150" height="150" ></a> &nbsp;&nbsp;';
                }
                //end
                $label_fld[] = $image_lists;
            } elseif (count($image_array) == 1) {
                $label_fld[] = '<a href="' . $imagepath_array[0] . $image_id_array[0] . "_" . base64_encode_filename($image_array[0]) . '" target="_blank" ><img src="' . $imagepath_array[0] . $image_id_array[0] . "_" . base64_encode_filename($image_array[0]) . '" border="0" width="150" height="150"></a>';
            } else {
                $label_fld[] = '';
            }
        }
        if ($tabid == 4) {
            //$imgpath = getModuleFileStoragePath('Contacts').$col_fields[$fieldname];
            $sql = "select ec_attachments.* from ec_attachments inner join ec_seattachmentsrel on ec_seattachmentsrel.attachmentsid = ec_attachments.attachmentsid where (ec_attachments.type like '%image%' or ec_attachments.type like '%img%') and ec_seattachmentsrel.crmid='" . $col_fields['record_id'] . "'";
            $image_res = $adb->query($sql);
            $image_id = $adb->query_result($image_res, 0, 'attachmentsid');
            $image_path = $adb->query_result($image_res, 0, 'path');
            $image_name = $adb->query_result($image_res, 0, 'name');
            $imgpath = $image_path . $image_id . "_" . base64_encode_filename($image_name);
            $width = 160;
            $height = get_scale_height($imgpath, $width);
            if ($image_name != '') {
                $label_fld[] = '<img src="' . $imgpath . '" width="' . $width . '" height="' . $height . '" class="reflect" alt="">';
            } else {
                $label_fld[] = '';
            }
        }
    } elseif ($uitype == 63) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname] . 'h&nbsp; ' . $col_fields['duration_minutes'] . 'm';
    } elseif ($uitype == 6) {
        $label_fld[] = $mod_strings[$fieldlabel];
        if ($col_fields[$fieldname] == '0') {
            $col_fields[$fieldname] = '';
        }
        if ($col_fields['time_start'] != '') {
            $start_time = $col_fields['time_start'];
        }
        if (!isValidDate($col_fields[$fieldname])) {
            $displ_date = '';
        } else {
            $displ_date = getDisplayDate($col_fields[$fieldname]);
        }
        $label_fld[] = $displ_date . '&nbsp;' . $start_time;
    } elseif ($uitype == 5 || $uitype == 23 || $uitype == 70) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $cur_date_val = $col_fields[$fieldname];
        $end_time = "";
        if (isset($col_fields['time_end']) && $col_fields['time_end'] != '' && ($tabid == 9 || $tabid == 16) && $uitype == 23) {
            $end_time = $col_fields['time_end'];
        }
        if (!isValidDate($cur_date_val)) {
            $display_val = '';
        } else {
            $display_val = getDisplayDate($cur_date_val);
        }
        $label_fld[] = $display_val . '&nbsp;' . $end_time;
    } elseif ($uitype == 1007) {
        $label_fld[] = isset($mod_strings[$fieldlabel]) ? $mod_strings[$fieldlabel] : $fieldlabel;
        $cur_approve_val = $col_fields[$fieldname];
        $label_fld[] = getApproveStatusById($cur_approve_val);
    } elseif ($uitype == 1008) {
        if (isset($mod_strings[$fieldlabel])) {
            $label_fld[] = $mod_strings[$fieldlabel];
        } else {
            $label_fld[] = $fieldlabel;
        }
        $value = $col_fields[$fieldname];
        $label_fld[] = getUserName($value);
    } elseif ($uitype == 71 || $uitype == 72) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $display_val = $col_fields[$fieldname];
        $label_fld[] = $display_val;
    } elseif ($uitype == 75 || $uitype == 81) {
        $vendor_name = "";
        $label_fld[] = $mod_strings[$fieldlabel];
        $vendor_id = $col_fields[$fieldname];
        if ($vendor_id != '') {
            $vendor_name = getVendorName($vendor_id);
        }
        $label_fld[] = $vendor_name;
        $label_fld["secid"] = $vendor_id;
        $label_fld["link"] = "index.php?module=Vendors&action=DetailView&record=" . $vendor_id;
        //$label_fld[] = '<a href="index.php?module=Products&action=VendorDetailView&record='.$vendor_id.'">'.$vendor_name.'</a>';
    } elseif ($uitype == 76) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $potential_id = $col_fields[$fieldname];
        if ($potential_id != '') {
            $potential_name = getPotentialName($potential_id);
        }
        $label_fld[] = $potential_name;
        $label_fld["secid"] = $potential_id;
        $label_fld["link"] = "index.php?module=Potentials&action=DetailView&record=" . $potential_id;
    } elseif ($uitype == 78) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $quote_id = $col_fields[$fieldname];
        if ($quote_id != '') {
            $quote_name = getQuoteName($quote_id);
        }
        $label_fld[] = $quote_name;
        $label_fld["secid"] = $quote_id;
        $label_fld["link"] = "index.php?module=Quotes&action=DetailView&record=" . $quote_id;
    } elseif ($uitype == 79) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $purchaseorder_id = $col_fields[$fieldname];
        if ($purchaseorder_id != '') {
            $purchaseorder_name = getPoName($purchaseorder_id);
        }
        $label_fld[] = $purchaseorder_name;
        $label_fld["secid"] = $purchaseorder_id;
        $label_fld["link"] = "index.php?module=PurchaseOrder&action=DetailView&record=" . $purchaseorder_id;
    } elseif ($uitype == 80) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $salesorder_id = $col_fields[$fieldname];
        if ($salesorder_id != '') {
            $salesorder_name = getSoName($salesorder_id);
        }
        $label_fld[] = $salesorder_name;
        $label_fld["secid"] = $salesorder_id;
        $label_fld["link"] = "index.php?module=SalesOrder&action=DetailView&record=" . $salesorder_id;
    } elseif ($uitype == 1010) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $invoice_id = $col_fields[$fieldname];
        $invoice_name = "";
        if ($invoice_id != '') {
            $invoice_name = getInvoiceName($invoice_id);
        }
        $label_fld[] = $invoice_name;
        $label_fld["secid"] = $invoice_id;
        $label_fld["link"] = "index.php?module=Invoice&action=DetailView&record=" . $invoice_id;
    } elseif ($uitype == 30) {
        $rem_days = 0;
        $rem_hrs = 0;
        $rem_min = 0;
        $reminder_str = "";
        $rem_days = floor($col_fields[$fieldname] / (24 * 60));
        $rem_hrs = floor(($col_fields[$fieldname] - $rem_days * 24 * 60) / 60);
        $rem_min = ($col_fields[$fieldname] - $rem_days * 24 * 60) % 60;
        $label_fld[] = $mod_strings[$fieldlabel];
        if ($col_fields[$fieldname]) {
            $reminder_str = $rem_days . '&nbsp;' . $mod_strings['LBL_DAYS'] . '&nbsp;' . $rem_hrs . '&nbsp;' . $mod_strings['LBL_HOURS'] . '&nbsp;' . $rem_min . '&nbsp;' . $mod_strings['LBL_MINUTES'] . '&nbsp;&nbsp;' . $mod_strings['LBL_BEFORE_EVENT'];
        }
        $label_fld[] = '&nbsp;' . $reminder_str;
    } elseif ($uitype == 85) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 86) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 87) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 88) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 89) {
        $label_fld[] = $mod_strings[$fieldlabel];
        $label_fld[] = $col_fields[$fieldname];
    } elseif ($uitype == 1006) {
        //added by dingjianting on 2007-1-27 for new module Exhibitions
        $catalog_name = "";
        $label_fld[] = $mod_strings[$fieldlabel];
        $catalogid = $col_fields[$fieldname];
        if ($catalogid != '') {
            $catalog_name = getCatalogName($catalogid);
        }
        $label_fld[] = $catalog_name;
        $label_fld["secid"] = $catalogid;
        $label_fld["link"] = "index.php?module=Catalogs&action=CatalogDetailView&parenttab=Product&catalogid=" . $catalogid;
    } elseif ($uitype == 1009) {
        $vcontact_name = "";
        $label_fld[] = $mod_strings[$fieldlabel];
        $vcontactsid = $col_fields[$fieldname];
        if ($vcontactsid != '') {
            $vcontact_name = getVcontactName($vcontactsid);
        }
        $label_fld[] = $vcontact_name;
        $label_fld["secid"] = $vcontactsid;
        $label_fld["link"] = "index.php?module=Vcontacts&action=DetailView&record=" . $vcontactsid;
    } elseif ($uitype == 1013) {
        $faqcategory_name = "";
        $label_fld[] = $mod_strings[$fieldlabel];
        $faqcategoryid = $col_fields[$fieldname];
        if ($faqcategoryid != '') {
            $faqcategory_name = getFaqcategoryName($faqcategoryid);
        }
        $label_fld[] = $faqcategory_name;
        $label_fld["secid"] = $faqcategoryid;
        $label_fld["link"] = "index.php?module=Faqcategorys&action=FaqcategoryDetailView&faqcategoryid=" . $faqcategoryid;
    } else {
        $label_fld[] = $mod_strings[$fieldlabel];
        if ($col_fields[$fieldname] == '0') {
            $col_fields[$fieldname] = '';
        }
        $label_fld[] = $col_fields[$fieldname];
    }
    $label_fld[] = $uitype;
    $log->debug("Exiting getDetailViewOutputHtml method ...");
    return $label_fld;
}