id);
$parenttab = htmlspecialchars($_REQUEST['parenttab'],ENT_QUOTES,$default_charset);
$theme_path="themes/".$theme."/";
$image_path=$theme_path."images/";
require_once('modules/Vtiger/layout_utils.php');
if(getFieldVisibilityPermission('Services',$current_user->id,'unit_price') != '0'){
echo "";
echo "
";
exit();
}
$pricebookname = getPriceBookName($pricebook_id);
$smarty= new vtigerCRM_Smarty;
$smarty->assign("MOD", $mod_strings);
$smarty->assign("APP", $app_strings);
$smarty->assign("IMAGE_PATH",$image_path);
$focus = new Services();
if (isset($_REQUEST['order_by']))
$order_by = $adb->sql_escape_string($_REQUEST['order_by']);
$url_string = ''; // assigning http url string
$sorder = 'ASC'; // Default sort order
if(isset($_REQUEST['sorder']) && $_REQUEST['sorder'] != '')
$sorder = $adb->sql_escape_string($_REQUEST['sorder']);
//Retreive the list of Services
$list_query = getListQuery("Services");
if(isset($order_by) && $order_by != '')
{
$list_query .= ' and vtiger_service.discontinued<>0 ORDER BY '.$order_by.' '.$sorder;
}
$list_query .= " and vtiger_service.discontinued<>0 group by vtiger_crmentity.crmid";
$list_result = $adb->query($list_query);
$num_rows = $adb->num_rows($list_result);
$record_string= "Total No of Service Available : ".$num_rows;
//Retreiving the array of already releated services
$sql1 = "select productid as serviceid from vtiger_pricebookproductrel
INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_pricebookproductrel.productid
WHERE vtiger_crmentity.setype='Services' AND vtiger_crmentity.deleted=0 AND pricebookid=?";
$res1 = $adb->pquery($sql1, array($pricebook_id));
$num_prod_rows = $adb->num_rows($res1);
$prod_array = Array();
for($i=0; $i<$num_prod_rows; $i++)
{
$prodid=$adb->query_result($res1,$i,"serviceid");
$prod_array[$prodid] = $prodid;
}
//Buttons Add To PriceBook and Cancel
$other_text = '
';
$smarty->assign("PRODUCTLISTHEADER", get_form_header($current_module_strings['LBL_LIST_FORM_TITLE'], $other_text, false ));
//Retreive the List View Table Header
$list_header = '';
$list_header .= '';
$list_header .=' | ';
$list_header .= ''.$mod_strings['LBL_LIST_SERVICE_NAME'].' | ';
if(getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0')
$list_header .= ''.$mod_strings['LBL_SERVICE_UNIT_PRICE'].' | ';
$list_header .= ''.$mod_strings['LBL_PB_LIST_PRICE'].' | ';
$list_header .= '
';
$smarty->assign("LISTHEADER", $list_header);
//if the service is not associated already then we should display that services
$new_prod_array = array();
$unit_price_array=array();
$field_name_array=array();
$entity_id_array =array();
for($i=0; $i<$num_rows; $i++)
{
$entity_id = $adb->query_result($list_result,$i,"crmid");
if(! array_key_exists($entity_id, $prod_array))
{
$new_prod_array[] = $entity_id;
}
$entity_id_array[$entity_id] = $i;
}
$prod_price_list = getPricesForProducts($currency_id, $new_prod_array, 'Services');
$list_body ='';
for($i=0; $iinfo("Services :: Showing the List of services to be added in price book");
$entity_id = $new_prod_array[$i];
if(isPermitted('Services','EditView',$entity_id) == 'yes') {
$list_body .= '';
$unit_price = $prod_price_list[$entity_id];
$field_name = $entity_id."_listprice";
$unit_price_array[]='"'.CurrencyField::convertToUserFormat($unit_price, null, true).'"';
$field_name_array[]="'".$field_name."'";
$list_body .= ' | ';
$list_body .= ''.$adb->query_result($list_result,$entity_id_array[$entity_id],"servicename").' | ';
if(getFieldVisibilityPermission('Services', $current_user->id, 'unit_price') == '0')
$list_body .= ''.CurrencyField::convertToUserFormat($unit_price, null, true).' | ';
$list_body .='';
if(isPermitted("PriceBooks","EditView","") == 'yes')
$list_body .= '';
else
$list_body .= '';
$list_body .= ' |
';
}
}
$smarty->assign("UNIT_PRICE_ARRAY",implode(",",$unit_price_array));
$smarty->assign("FIELD_NAME_ARRAY",implode(",",$field_name_array));
if($order_by !='')
$url_string .="&order_by=".$order_by;
if($sorder !='')
$url_string .="&sorder=".$sorder;
$smarty->assign("LISTENTITY", $list_body);
$smarty->assign("CATEGORY", $parenttab);
$smarty->display("AddProductsToPriceBook.tpl");
?>