/** Function to display the Products which are related to the PriceBook * @param string $query - query to get the list of products which are related to the current PriceBook * @param object $focus - PriceBook object which contains all the information of the current PriceBook * @param string $returnset - return_module, return_action and return_id which are sequenced with & to pass to the URL which is optional * return array $return_data which will be formed like array('header'=>$header,'entries'=>$entries_list) where as $header contains all the header columns and $entries_list will contain all the Product entries */ function getPriceBookRelatedProducts($query, $focus, $returnset = '') { global $log; $log->debug("Entering getPriceBookRelatedProducts(" . $query . "," . get_class($focus) . "," . $returnset . ") method ..."); global $adb; global $app_strings; global $mod_strings; global $current_language, $current_user; $current_module_strings = return_module_language($current_language, 'PriceBook'); global $list_max_entries_per_page; global $urlPrefix; global $theme; $pricebook_id = vtlib_purify($_REQUEST['record']); $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $noofrows = $adb->query_result($adb->query(mkCountQuery($query)), 0, 'count'); $module = 'PriceBooks'; $relatedmodule = 'Products'; if (!$_SESSION['rlvs'][$module][$relatedmodule]) { $modObj = new ListViewSession(); $modObj->sortby = $focus->default_order_by; $modObj->sorder = $focus->default_sort_order; $_SESSION['rlvs'][$module][$relatedmodule] = get_object_vars($modObj); } if (isset($_REQUEST['relmodule']) && $_REQUEST['relmodule'] != '' && $_REQUEST['relmodule'] == $relatedmodule) { $relmodule = vtlib_purify($_REQUEST['relmodule']); if ($_SESSION['rlvs'][$module][$relmodule]) { setSessionVar($_SESSION['rlvs'][$module][$relmodule], $noofrows, $list_max_entries_per_page, $module, $relmodule); } } $start = $_SESSION['rlvs'][$module][$relatedmodule]['start']; $navigation_array = getNavigationValues($start, $noofrows, $list_max_entries_per_page); $start_rec = $navigation_array['start']; $end_rec = $navigation_array['end_val']; //limiting the query if ($start_rec == 0) { $limit_start_rec = 0; } else { $limit_start_rec = $start_rec - 1; } if ($adb->dbType == "pgsql") { $list_result = $adb->pquery($query . " OFFSET {$limit_start_rec} LIMIT {$list_max_entries_per_page}", array()); } else { $list_result = $adb->pquery($query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); } $header = array(); $header[] = $mod_strings['LBL_LIST_PRODUCT_NAME']; if (getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0') { $header[] = $mod_strings['LBL_PRODUCT_CODE']; } if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') { $header[] = $mod_strings['LBL_PRODUCT_UNIT_PRICE']; } $header[] = $mod_strings['LBL_PB_LIST_PRICE']; if (isPermitted("PriceBooks", "EditView", "") == 'yes' || isPermitted("PriceBooks", "Delete", "") == 'yes') { $header[] = $mod_strings['LBL_ACTION']; } $currency_id = $focus->column_fields['currency_id']; $numRows = $adb->num_rows($list_result); for ($i = 0; $i < $numRows; $i++) { $entity_id = $adb->query_result($list_result, $i, "crmid"); $unit_price = $adb->query_result($list_result, $i, "unit_price"); if ($currency_id != null) { $prod_prices = getPricesForProducts($currency_id, array($entity_id)); $unit_price = $prod_prices[$entity_id]; } $listprice = $adb->query_result($list_result, $i, "listprice"); $field_name = $entity_id . "_listprice"; $entries = array(); $entries[] = textlength_check($adb->query_result($list_result, $i, "productname")); if (getFieldVisibilityPermission('Products', $current_user->id, 'productcode') == '0') { $entries[] = $adb->query_result($list_result, $i, "productcode"); } if (getFieldVisibilityPermission('Products', $current_user->id, 'unit_price') == '0') { $entries[] = $unit_price; } $entries[] = $listprice; $action = ""; if (isPermitted("PriceBooks", "EditView", "") == 'yes') { $action .= '<img style="cursor:pointer;" src="' . vtiger_imageurl('editfield.gif', $theme) . '" border="0" onClick="fnvshobj(this,\'editlistprice\'),editProductListPrice(\'' . $entity_id . '\',\'' . $pricebook_id . '\',\'' . $listprice . '\')" alt="' . $app_strings["LBL_EDIT_BUTTON"] . '" title="' . $app_strings["LBL_EDIT_BUTTON"] . '"/>'; } if (isPermitted("PriceBooks", "Delete", "") == 'yes') { if ($action != "") { $action .= ' | '; } $action .= '<img src="' . vtiger_imageurl('delete.gif', $theme) . '" onclick="if(confirm(\'' . $app_strings['ARE_YOU_SURE'] . '\')) deletePriceBookProductRel(' . $entity_id . ',' . $pricebook_id . ');" alt="' . $app_strings["LBL_DELETE"] . '" title="' . $app_strings["LBL_DELETE"] . '" style="cursor:pointer;" border="0">'; } if ($action != "") { $entries[] = $action; } $entries_list[] = $entries; } if ($numRows > 0) { $module_rel = "{$module}&relmodule={$relatedmodule}&record=" . $focus->id; $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, '', $module_rel); $return_data = array('header' => $header, 'entries' => $entries_list, 'navigation' => $navigationOutput); $log->debug("Exiting getPriceBookRelatedProducts method ..."); return $return_data; } }
/** Function to display the Services which are related to the PriceBook * @param string $query - query to get the list of products which are related to the current PriceBook * @param object $focus - PriceBook object which contains all the information of the current PriceBook * @param string $returnset - return_module, return_action and return_id which are sequenced with & to pass to the URL which is optional * return array $return_data which will be formed like array('header'=>$header,'entries'=>$entries_list) where as $header contains all the header columns and $entries_list will contain all the Service entries */ function getPriceBookRelatedServices($query, $focus, $returnset = '') { global $log; $log->debug("Entering getPriceBookRelatedServices(" . $query . "," . get_class($focus) . "," . $returnset . ") method ..."); global $adb; global $app_strings; global $current_language, $current_user; $current_module_strings = return_module_language($current_language, 'Services'); global $list_max_entries_per_page; global $urlPrefix; global $theme; $pricebook_id = $_REQUEST['record']; $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $computeCount = $_REQUEST['withCount']; if (PerformancePrefs::getBoolean('LISTVIEW_COMPUTE_PAGE_COUNT', false) === true || (bool) $computeCount == true) { $noofrows = $adb->query_result($adb->query(mkCountQuery($query)), 0, 'count'); } else { $noofrows = null; } $module = 'PriceBooks'; $relatedmodule = 'Services'; if (!$_SESSION['rlvs'][$module][$relatedmodule]) { $modObj = new ListViewSession(); $modObj->sortby = $focus->default_order_by; $modObj->sorder = $focus->default_sort_order; $_SESSION['rlvs'][$module][$relatedmodule] = get_object_vars($modObj); } if (isset($_REQUEST['relmodule']) && $_REQUEST['relmodule'] != '' && $_REQUEST['relmodule'] == $relatedmodule) { $relmodule = vtlib_purify($_REQUEST['relmodule']); if ($_SESSION['rlvs'][$module][$relmodule]) { setSessionVar($_SESSION['rlvs'][$module][$relmodule], $noofrows, $list_max_entries_per_page, $module, $relmodule); } } global $relationId; $start = RelatedListViewSession::getRequestCurrentPage($relationId, $query); $navigation_array = VT_getSimpleNavigationValues($start, $list_max_entries_per_page, $noofrows); $limit_start_rec = ($start - 1) * $list_max_entries_per_page; if ($adb->dbType == "pgsql") { $list_result = $adb->pquery($query . " OFFSET {$limit_start_rec} LIMIT {$list_max_entries_per_page}", array()); } else { $list_result = $adb->pquery($query . " LIMIT {$limit_start_rec}, {$list_max_entries_per_page}", array()); } $header = array(); $header[] = $current_module_strings['LBL_LIST_SERVICE_NAME']; if (getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0') { $header[] = $current_module_strings['LBL_SERVICE_UNIT_PRICE']; } $header[] = $current_module_strings['LBL_PB_LIST_PRICE']; if (isPermitted("PriceBooks", "EditView", "") == 'yes' || isPermitted("PriceBooks", "Delete", "") == 'yes') { $header[] = $app_strings['LBL_ACTION']; } $currency_id = $focus->column_fields['currency_id']; $numRows = $adb->num_rows($list_result); for ($i = 0; $i < $numRows; $i++) { $entity_id = $adb->query_result($list_result, $i, "crmid"); $unit_price = $adb->query_result($list_result, $i, "unit_price"); if ($currency_id != null) { $prod_prices = getPricesForProducts($currency_id, array($entity_id), 'Services'); $unit_price = $prod_prices[$entity_id]; } $listprice = $adb->query_result($list_result, $i, "listprice"); $field_name = $entity_id . "_listprice"; $entries = array(); $entries[] = textlength_check($adb->query_result($list_result, $i, "servicename")); if (getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0') { $entries[] = CurrencyField::convertToUserFormat($unit_price, null, true); } $entries[] = CurrencyField::convertToUserFormat($listprice, null, true); $action = ""; if (isPermitted("PriceBooks", "EditView", "") == 'yes' && isPermitted('Services', 'EditView', $entity_id) == 'yes') { $action .= '<img style="cursor:pointer;" src="themes/images/editfield.gif" border="0" onClick="fnvshobj(this,\'editlistprice\'),editProductListPrice(\'' . $entity_id . '\',\'' . $pricebook_id . '\',\'' . $listprice . '\')" alt="' . $app_strings["LBL_EDIT_BUTTON"] . '" title="' . $app_strings["LBL_EDIT_BUTTON"] . '"/>'; } else { $action .= '<img src="' . vtiger_imageurl('blank.gif', $theme) . '" border="0" />'; } if (isPermitted("PriceBooks", "Delete", "") == 'yes' && isPermitted('Services', 'Delete', $entity_id) == 'yes') { if ($action != "") { $action .= ' | '; } $action .= '<img src="themes/images/delete.gif" onclick="if(confirm(\'' . $app_strings['ARE_YOU_SURE'] . '\')) deletePriceBookProductRel(' . $entity_id . ',' . $pricebook_id . ');" alt="' . $app_strings["LBL_DELETE"] . '" title="' . $app_strings["LBL_DELETE"] . '" style="cursor:pointer;" border="0">'; } if ($action != "") { $entries[] = $action; } $entries_list[] = $entries; } $navigationOutput[] = getRecordRangeMessage($list_result, $limit_start_rec, $noofrows); $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, '', $module, $relatedmodule, $focus->id); $return_data = array('header' => $header, 'entries' => $entries_list, 'navigation' => $navigationOutput); $log->debug("Exiting getPriceBookRelatedServices method ..."); return $return_data; }
/** Function to get related list entries in detailed array format * @param $module -- modulename:: Type string * @param $relatedmodule -- relatedmodule:: Type string * @param $focus -- focus:: Type object * @param $query -- query:: Type string * @param $button -- buttons:: Type string * @param $returnset -- returnset:: Type string * @param $id -- id:: Type string * @param $edit_val -- edit value:: Type string * @param $del_val -- delete value:: Type string * @returns $related_entries -- related entires:: Type string array * */ function GetRelatedList($module, $relatedmodule, $focus, $query, $button, $returnset, $id = '', $edit_val = '', $del_val = '') { global $log; //changed by dingjianting on 2007-11-05 for php5.2.x $log->debug("Entering GetRelatedList() method ..."); require_once 'include/CRMSmarty.php'; require_once 'include/DatabaseUtil.php'; global $adb; global $app_strings; global $current_language; $current_module_strings = return_module_language($current_language, $module); global $list_max_entries_per_page; global $urlPrefix; global $currentModule; global $theme; global $theme_path; global $mod_strings; // focus_list is the means of passing data to a ListView. global $focus_list; $smarty = new CRMSmarty(); if (!isset($where)) { $where = ""; } $theme_path = "themes/" . $theme . "/"; $image_path = $theme_path . "images/"; $smarty->assign("MOD", $mod_strings); $smarty->assign("APP", $app_strings); $smarty->assign("IMAGE_PATH", $image_path); $smarty->assign("MODULE", $relatedmodule); if (isset($where) && $where != '') { $query .= ' and ' . $where; } /* if(!isset($_SESSION['rlvs'][$module][$relatedmodule]) || !$_SESSION['rlvs'][$module][$relatedmodule]) { $modObj = new ListViewSession(); $modObj->sortby = $focus->default_order_by; $modObj->sorder = $focus->default_sort_order; $_SESSION['rlvs'][$module][$relatedmodule] = get_object_vars($modObj); } */ if (empty($order_by)) { $order_by = $focus->default_order_by; } if (empty($sorder)) { $sorder = $focus->default_sort_order; } $url_qry = "&order_by=" . $order_by; $count_query = mkCountQuery($query); $count_result = $adb->query($count_query); $noofrows = $adb->query_result($count_result, 0, "count"); //Setting Listview session object while sorting/pagination if (isset($_REQUEST['relmodule']) && $_REQUEST['relmodule'] != '' && $_REQUEST['relmodule'] == $relatedmodule) { if (isset($_REQUEST['start']) && $_REQUEST['start'] != '') { $start = $_REQUEST['start']; } else { $start = 1; } } else { $start = 1; } $navigation_array = getNavigationValues($start, $noofrows, $list_max_entries_per_page); $start_rec = $navigation_array['start']; $end_rec = $navigation_array['end_val']; //limiting the query if ($start_rec <= 0) { $limit_start_rec = 0; } else { $limit_start_rec = $start_rec - 1; } $list_result = $adb->limitQuery2($query, $limit_start_rec, $list_max_entries_per_page, $order_by, $sorder); //Retreive the List View Table Header if ($noofrows == 0) { $smarty->assign('NOENTRIES', $app_strings['LBL_NONE_SCHEDULED']); } else { setRelmodFieldList($relatedmodule, $focus); //set more module field $id = $_REQUEST['record']; $listview_header = getListViewHeader($focus, $relatedmodule, '', $sorder, $order_by, $id, '', $module); //"Accounts"); if ($noofrows > 15) { $smarty->assign('SCROLLSTART', '<div style="overflow:auto;height:315px;width:100%;">'); $smarty->assign('SCROLLSTOP', '</div>'); } $smarty->assign("LISTHEADER", $listview_header); if ($module == 'PriceBook' && $relatedmodule == 'Products') { $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, $edit_val, $del_val); } if ($module == 'Products' && $relatedmodule == 'PriceBook') { $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, 'EditListPrice', 'DeletePriceBookProductRel'); } elseif ($relatedmodule == 'SalesOrder') { $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset, 'SalesOrderEditView', 'DeleteSalesOrder'); } else { $listview_entries = getListViewEntries($focus, $relatedmodule, $list_result, $navigation_array, 'relatedlist', $returnset); } $navigationOutput = array(); $navigationOutput[] = $app_strings['LBL_SHOWING'] . " " . $start_rec . " - " . $end_rec . " " . $app_strings['LBL_LIST_OF'] . " " . $noofrows; $module_rel = $module . '&relmodule=' . $relatedmodule . '&record=' . $id; $navigationOutput[] = getRelatedTableHeaderNavigation($navigation_array, $url_qry, $module_rel); $related_entries = array('header' => $listview_header, 'entries' => $listview_entries, 'navigation' => $navigationOutput); $log->debug("Exiting GetRelatedList method ..."); return $related_entries; } }