public static function getReportChart($reportid, $chartType) { global $log, $adb; $oReportRun = new ReportRun($reportid); $groupBy = $oReportRun->getGroupingList($reportid); foreach ($groupBy as $key => $value) { // $groupByConditon = explode(" ",$value); //$groupByNew = explode("'",$groupByConditon[0]); list($tablename, $colname, $module_field, $fieldname, $single) = explode(":", $key); list($module, $field) = explode("_", $module_field); $fieldDetails = $key; break; } $queryReports = self::getCustomReportsQuery($reportid); $queryResult = $adb->pquery($queryReports, array()); //ChartUtils::generateChartDataFromReports($queryResult, strtolower($groupByNew[1])); if ($chartType == 'horizontalbarchart') { $Chart = ChartUtils::getReportBarChart($queryResult, strtolower($module_field), $fieldDetails, $reportid); } else { if ($chartType == 'verticalbarchart') { $Chart = ChartUtils::getReportBarChart($queryResult, strtolower($module_field), $fieldDetails, $reportid, 'vertical'); } else { if ($chartType == 'piechart') { $Chart = ChartUtils::getReportPieChart($queryResult, strtolower($module_field), $fieldDetails, $reportid); } } } return $Chart; }
public function process(Vtiger_Request $request) { $mode = $request->getMode(); $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $record = $request->get('record'); $reportModel = Reports_Record_Model::getInstanceById($record); $reportModel->setModule('Reports'); $reportModel->set('advancedFilter', $request->get('advanced_filter')); $page = $request->get('page'); $pagingModel = new Vtiger_Paging_Model(); $pagingModel->set('page', $page); $pagingModel->set('limit', Reports_Detail_View::REPORT_LIMIT); if ($mode === 'save') { $reportModel->saveAdvancedFilters(); $reportData = $reportModel->getReportData($pagingModel); $data = $reportData['data']; } else { if ($mode === 'generate') { $reportData = $reportModel->generateData($pagingModel); $data = $reportData['data']; } } $calculation = $reportModel->generateCalculationData(); $viewer->assign('PRIMARY_MODULE', $reportModel->getPrimaryModule()); $viewer->assign('CALCULATION_FIELDS', $calculation); $viewer->assign('DATA', $data); $viewer->assign('RECORD_ID', $record); $viewer->assign('PAGING_MODEL', $pagingModel); $viewer->assign('MODULE', $moduleName); $viewer->assign('NEW_COUNT', $reportData['count']); $viewer->assign('REPORT_RUN_INSTANCE', ReportRun::getInstance($record)); $viewer->view('ReportContents.tpl', $moduleName); }
public function process(Vtiger_Request $request) { $mode = $request->getMode(); $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $record = $request->get('record'); $reportModel = Reports_Record_Model::getInstanceById($record); $reportModel->setModule('Reports'); $reportModel->set('advancedFilter', $request->get('advanced_filter')); $page = $request->get('page'); $pagingModel = new Vtiger_Paging_Model(); $pagingModel->set('page', $page); $pagingModel->set('limit', Reports_Detail_View::REPORT_LIMIT); if ($mode === 'save') { $reportModel->saveAdvancedFilters(); $reportData = $reportModel->getReportData($pagingModel); $data = $reportData['data']; } else { if ($mode === 'generate') { $reportData = $reportModel->generateData($pagingModel); $data = $reportData['data']; } } $calculation = $reportModel->generateCalculationData(); /*убираем ненужные столбцы*/ $columns = array('SUM' => false, 'AVG' => false, 'MIN' => false, 'MAX' => false); foreach ($calculation as $metriks) { foreach ($metriks as $index => $metrik) { $postfix = substr($index, -3, 3); if ($columns[$postfix]) { continue; } if (!empty($metrik)) { $columns[$postfix] = true; } } } $viewer->assign('COLUMNS', $columns); /*end*/ $viewer->assign('PRIMARY_MODULE', $reportModel->getPrimaryModule()); $viewer->assign('CALCULATION_FIELDS', $calculation); $viewer->assign('DATA', $data); $viewer->assign('RECORD_ID', $record); $viewer->assign('PAGING_MODEL', $pagingModel); $viewer->assign('MODULE', $moduleName); $viewer->assign('NEW_COUNT', $reportData['count']); $viewer->assign('REPORT_RUN_INSTANCE', ReportRun::getInstance($record)); $viewer->view('ReportContents.tpl', $moduleName); }
function getQuery() { $chartModel = $this->getParent(); $reportModel = $chartModel->getParent(); $this->reportRun = ReportRun::getInstance($reportModel->getId()); $advFilterSql = $reportModel->getAdvancedFilterSQL(); $queryColumnsByFieldModel = $this->getQueryColumnsByFieldModel(); if(is_array($queryColumnsByFieldModel)) { foreach($queryColumnsByFieldModel as $field) { $this->reportRun->queryPlanner->addTable($field->get('table')); $columns[] = $field->get('reportcolumn'); } } $groupByColumnsByFieldModel = $this->getGroupbyColumnsByFieldModel(); if(is_array($groupByColumnsByFieldModel)) { foreach($groupByColumnsByFieldModel as $groupField) { $this->reportRun->queryPlanner->addTable($groupField->get('table')); $groupByColumns[] = $groupField->get('reportlabel'); $columns[] = $groupField->get('reportcolumn'); } } $sql = split(' from ', $this->reportRun->sGetSQLforReport($reportModel->getId(), $advFilterSql, 'PDF')); $columnLabels = array(); $chartSQL = "SELECT "; if($this->isRecordCount()) { $chartSQL .= " count(*) AS RECORD_COUNT,"; } // Add other columns if($columns && is_array($columns)) { $columnLabels = array_merge($columnLabels, $groupByColumns); $chartSQL .= implode(',', $columns); } $chartSQL .= " FROM $sql[1] "; if($groupByColumns && is_array($groupByColumns)) { $chartSQL .= " GROUP BY " . implode(',', $groupByColumns); } return $chartSQL; }
/** * Function returns the Advanced filter SQL * @return <String> */ function getAdvancedFilterSQL() { $advancedFilter = $this->get('advancedFilter'); $advancedFilterCriteria = array(); $advancedFilterCriteriaGroup = array(); if (is_array($advancedFilter)) { foreach ($advancedFilter as $groupIndex => $groupInfo) { $groupColumns = $groupInfo['columns']; $groupCondition = $groupInfo['condition']; if (empty($groupColumns)) { unset($advancedFilter[1]['condition']); } else { if (!empty($groupCondition)) { $advancedFilterCriteriaGroup[$groupIndex] = array('groupcondition' => $groupCondition); } } foreach ($groupColumns as $groupColumn) { $groupColumn['groupid'] = $groupIndex; $groupColumn['columncondition'] = $groupColumn['column_condition']; unset($groupColumn['column_condition']); $advancedFilterCriteria[] = $groupColumn; } } } $this->reportRun = ReportRun::getInstance($this->getId()); $filterQuery = $this->reportRun->RunTimeAdvFilter($advancedFilterCriteria, $advancedFilterCriteriaGroup); return $filterQuery; }
require_once "modules/Reports/Reports.php"; global $tmp_dir, $root_directory; $fname = tempnam($root_directory . $tmp_dir, "merge2.xls"); # Write out the data $reportid = vtlib_purify($_REQUEST["record"]); $oReport = new Reports($reportid); $filtercolumn = $_REQUEST['stdDateFilterField']; $startdate = $_REQUEST['startdate']; $enddate = $_REQUEST['enddate']; if (!empty($startdate) && !empty($enddate) && $startdate != "0000-00-00" && $enddate != "0000-00-00") { $filter = $_REQUEST['stdDateFilter']; $date = new DateTimeField($_REQUEST['startdate']); $endDate = new DateTimeField($_REQUEST['enddate']); $startdate = $date->getDBInsertDateValue(); //Convert the user date format to DB date format $enddate = $endDate->getDBInsertDateValue(); //Convert the user date format to DB date format } $oReportRun = new ReportRun($reportid); $filterlist = $oReportRun->RunTimeFilter($filtercolumn, $filter, $startdate, $enddate); $oReportRun->writeReportToExcelFile($fname, $filterlist); if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); } header("Content-Type: application/x-msexcel"); header("Content-Length: " . @filesize($fname)); header('Content-disposition: attachment; filename="Reports.xls"'); $fh = fopen($fname, "rb"); fpassthru($fh); //unlink($fname);
/** Function to get vtiger_fields for the given module and block * This function gets the vtiger_fields for the given module * It accepts the module and the block as arguments and * returns the array column lists * Array module_columnlist[ vtiger_fieldtablename:fieldcolname:module_fieldlabel1:fieldname:fieldtypeofdata]=fieldlabel */ function getColumnsListbyBlock($module, $block) { global $adb, $log, $current_user; if (is_string($block)) { $block = explode(",", $block); } $skipTalbes = array('vtiger_emaildetails', 'vtiger_attachments'); $tabid = getTabid($module); if ($module == 'Calendar') { $tabid = array('9', '16'); } $params = array($tabid, $block); require 'user_privileges/user_privileges_' . $current_user->id . '.php'; //Security Check if ($is_admin == true || $profileGlobalPermission[1] == 0 || $profileGlobalPermission[2] == 0) { $sql = "select * from vtiger_field where vtiger_field.tabid in (" . generateQuestionMarks($tabid) . ") and vtiger_field.block in (" . generateQuestionMarks($block) . ") and vtiger_field.displaytype in (1,2,3) and vtiger_field.presence in (0,2) AND tablename NOT IN (" . generateQuestionMarks($skipTalbes) . ") "; //fix for Ticket #4016 if ($module == "Calendar") { $sql .= " group by vtiger_field.fieldlabel order by sequence"; } else { $sql .= " order by sequence"; } } else { $profileList = getCurrentUserProfileList(); $sql = "select * from vtiger_field inner join vtiger_profile2field on vtiger_profile2field.fieldid=vtiger_field.fieldid inner join vtiger_def_org_field on vtiger_def_org_field.fieldid=vtiger_field.fieldid where vtiger_field.tabid in (" . generateQuestionMarks($tabid) . ") and vtiger_field.block in (" . generateQuestionMarks($block) . ") and vtiger_field.displaytype in (1,2,3) and vtiger_profile2field.visible=0 and vtiger_def_org_field.visible=0 and vtiger_field.presence in (0,2)"; if (count($profileList) > 0) { $sql .= " and vtiger_profile2field.profileid in (" . generateQuestionMarks($profileList) . ")"; array_push($params, $profileList); } $sql .= ' and tablename NOT IN (' . generateQuestionMarks($skipTalbes) . ') '; //fix for Ticket #4016 if ($module == "Calendar") { $sql .= " group by vtiger_field.fieldlabel order by sequence"; } else { $sql .= " group by vtiger_field.fieldid order by sequence"; } } array_push($params, $skipTalbes); $module_columnlist = array(); $result = $adb->pquery($sql, $params); $noofrows = $adb->num_rows($result); for ($i = 0; $i < $noofrows; $i++) { $fieldtablename = $adb->query_result($result, $i, "tablename"); $fieldcolname = $adb->query_result($result, $i, "columnname"); $fieldname = $adb->query_result($result, $i, "fieldname"); $fieldtype = $adb->query_result($result, $i, "typeofdata"); $uitype = $adb->query_result($result, $i, "uitype"); $fieldtype = explode("~", $fieldtype); $fieldtypeofdata = $fieldtype[0]; $blockid = $adb->query_result($result, $i, "block"); //Here we Changing the displaytype of the field. So that its criteria will be displayed correctly in Reports Advance Filter. $fieldtypeofdata = ChangeTypeOfData_Filter($fieldtablename, $fieldcolname, $fieldtypeofdata); if ($uitype == 68 || $uitype == 59) { $fieldtypeofdata = 'V'; } if ($fieldtablename == "vtiger_crmentity") { $fieldtablename = $fieldtablename . $module; } if ($fieldname == "assigned_user_id") { $fieldtablename = "vtiger_users" . $module; $fieldcolname = "user_name"; } if ($fieldname == "assigned_user_id1") { $fieldtablename = "vtiger_usersRel1"; $fieldcolname = "user_name"; } $fieldlabel = $adb->query_result($result, $i, "fieldlabel"); if ($module == 'Emails' and $fieldlabel == 'Date & Time Sent') { $fieldlabel = 'Date Sent'; $fieldtypeofdata = 'D'; } $fieldlabel1 = str_replace(' ', '_', $fieldlabel); $fieldlabel1 = ReportRun::replaceSpecialChar($fieldlabel1); $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $module . "_" . $fieldlabel1 . ":" . $fieldname . ":" . $fieldtypeofdata; $this->adv_rel_fields[$fieldtypeofdata][] = '$' . $module . '#' . $fieldname . '$' . "::" . getTranslatedString($module, $module) . " " . getTranslatedString($fieldlabel, $module); $module_columnlist[$optionvalue] = $fieldlabel; } $blockname = getBlockName($block); if ($blockname == 'LBL_RELATED_PRODUCTS' && in_array($module, getInventoryModules())) { $fieldtablename = 'vtiger_inventoryproductrel'; $fields = array('productid' => getTranslatedString('Product Name', $module), 'serviceid' => getTranslatedString('Service Name', $module), 'listprice' => getTranslatedString('List Price', $module), 'discount' => getTranslatedString('Discount', $module), 'quantity' => getTranslatedString('Quantity', $module), 'comment' => getTranslatedString('Comments', $module)); $fields_datatype = array('productid' => 'V', 'serviceid' => 'V', 'listprice' => 'N', 'discount' => 'N', 'quantity' => 'N', 'comment' => 'V'); foreach ($fields as $fieldcolname => $label) { $fieldtypeofdata = $fields_datatype[$fieldcolname]; if ($fieldcolname != 'productid' || $fieldcolname != 'serviceid') { $optionvalue = $fieldtablename . $module . ":" . $fieldcolname . ":" . $module . "_" . $label . ":" . $fieldcolname . ":" . $fieldtypeofdata; } else { $optionvalue = $fieldtablename . ":" . $fieldcolname . ":" . $module . "_" . $label . ":" . $fieldcolname . ":" . $fieldtypeofdata; } $module_columnlist[$optionvalue] = $label; } } $log->info("Reports :: FieldColumns->Successfully returned ColumnslistbyBlock" . $module . $block); return $module_columnlist; }
$rep_modules = array(); } array_push($rep_modules, $primarymodule); $modules_permitted = true; $modules_export_permitted = true; foreach ($rep_modules as $mod) { if (isPermitted($mod, 'index') != "yes" || vtlib_isModuleActive($mod) == false) { $modules_permitted = false; $restrictedmodules[] = $mod; } if (isPermitted("{$mod}", 'Export', '') != 'yes') { $modules_export_permitted = false; } } if (isPermitted($primarymodule, 'index') == "yes" && $modules_permitted == true) { $oReportRun = new ReportRun($reportid); $filterlist = $oReportRun->RunTimeFilter($filtercolumn, $filter, $startdate, $enddate); // Performance Optimization: Direct output of the report result $list_report_form = new vtigerCRM_Smarty(); //$sshtml = $oReportRun->GenerateReport("HTML",$filterlist); //if(is_array($sshtml))$totalhtml = $oReportRun->GenerateReport("TOTALHTML",$filterlist); $sshtml = array(); $totalhtml = ''; $list_report_form->assign("DIRECT_OUTPUT", true); $list_report_form->assign_by_ref("__REPORT_RUN_INSTANCE", $oReportRun); $list_report_form->assign_by_ref("__REPORT_RUN_FILTER_LIST", $filterlist); // END $ogReport->getSelectedStandardCriteria($reportid); //commented to omit dashboards for vtiger_reports //require_once('modules/Dashboard/ReportsCharts.php'); //$image = get_graph_by_type('Report','Report',$primarymodule,'',$sshtml[2]);
public function sendEmail() { $currentModule = vglobal('currentModule'); require_once 'vtlib/Vtiger/Mailer.php'; $vtigerMailer = new Vtiger_Mailer(); $recipientEmails = $this->getRecipientEmails(); foreach ($recipientEmails as $name => $email) { $vtigerMailer->AddAddress($email, $name); } $currentTime = date('Y-m-d H:i:s'); $subject = $this->reportname . ' - ' . $currentTime . ' (' . DateTimeField::getDBTimeZone() . ')'; $contents = getTranslatedString('LBL_AUTO_GENERATED_REPORT_EMAIL', $currentModule) . '<br/><br/>'; $contents .= '<b>' . getTranslatedString('LBL_REPORT_NAME', $currentModule) . ' :</b> ' . $this->reportname . '<br/>'; $contents .= '<b>' . getTranslatedString('LBL_DESCRIPTION', $currentModule) . ' :</b><br/>' . $this->reportdescription . '<br/><br/>'; $vtigerMailer->Subject = $subject; $vtigerMailer->Body = $contents; $vtigerMailer->ContentType = "text/html"; $baseFileName = preg_replace('/[^a-zA-Z0-9_-\\s]/', '', $this->reportname) . '__' . preg_replace('/[^a-zA-Z0-9_-\\s]/', '', $currentTime); $oReportRun = ReportRun::getInstance($this->id); $reportFormat = $this->scheduledFormat; $attachments = array(); if ($reportFormat == 'pdf' || $reportFormat == 'both') { $fileName = $baseFileName . '.pdf'; $filePath = 'storage/' . $fileName; $attachments[$fileName] = $filePath; $pdf = $oReportRun->getReportPDF(); $pdf->Output($filePath, 'F'); } if ($reportFormat == 'excel' || $reportFormat == 'both') { $fileName = $baseFileName . '.xls'; $filePath = 'storage/' . $fileName; $attachments[$fileName] = $filePath; $oReportRun->writeReportToExcelFile($filePath); } foreach ($attachments as $attachmentName => $path) { $vtigerMailer->AddAttachment($path, $attachmentName); } $vtigerMailer->Send(true); foreach ($attachments as $attachmentName => $path) { unlink($path); } }
//Put a hyperlink $this->SetTextColor(0,0,255); $this->SetStyle('U',true); $this->Write(5,$txt,$URL); $this->SetStyle('U',false); $this->SetTextColor(0); } }//end of class */ $reportid = vtlib_purify($_REQUEST["record"]); $oReport = new Reports($reportid); //Code given by Csar Rodrguez for Rwport Filter $filtercolumn = $_REQUEST["stdDateFilterField"]; $filter = $_REQUEST["stdDateFilter"]; $oReportRun = new ReportRun($reportid); $startdate = getDBInsertDateValue($_REQUEST["startdate"]); //Convert the user date format to DB date format $enddate = getDBInsertDateValue($_REQUEST["enddate"]); //Convert the user date format to DB date format $filterlist = $oReportRun->RunTimeFilter($filtercolumn, $filter, $startdate, $enddate); $arr_val = $oReportRun->GenerateReport("PDF", $filterlist); if (isset($arr_val)) { foreach ($arr_val as $wkey => $warray_value) { foreach ($warray_value as $whd => $wvalue) { if (strlen($wvalue) < strlen($whd)) { $w_inner_array[] = strlen($whd); } else { $w_inner_array[] = strlen($wvalue); } }
function replaceReport($content, $reportid) { session_start(); require_once "modules/Reports/ReportRun.php"; require_once "modules/Reports/Reports.php"; require_once 'include/utils/utils.php'; $current_language = Users_Record_Model::getCurrentUserModel()->get('language'); include "modules/OSSPdf/language/" . $current_language . ".lang.php"; $language = $_SESSION['authenticated_user_language'] . '.lang.php'; require_once "include/language/{$language}"; $db = PearDatabase::getInstance(); $oReport = new Reports($reportid); //Code given by Csar Rodrguez for Rwport Filter $filtercolumn = $_REQUEST["stdDateFilterField"]; $filter = $_REQUEST["stdDateFilter"]; $oReportRun = new ReportRun($reportid); $startdate = $_REQUEST['startdate']; $enddate = $_REQUEST['enddate']; if (!empty($startdate) && !empty($enddate) && $startdate != "0000-00-00" && $enddate != "0000-00-00") { $date = new DateTimeField($_REQUEST['startdate']); $endDate = new DateTimeField($_REQUEST['enddate']); $startdate = $date->getDBInsertDateValue(); //Convert the user date format to DB date format $enddate = $endDate->getDBInsertDateValue(); //Convert the user date format to DB date format } $filterlist = $oReportRun->RunTimeFilter($filtercolumn, $filter, $startdate, $enddate); ############///////////////////////////////######################### $sql = $oReportRun->sGetSQLforReport($reportid, $filterlist); $result = $db->query($sql, true); $modules_selected = array(); $modules_selected[] = $oReportRun->primarymodule; if (!empty($oReportRun->secondarymodule)) { $sec_modules = split(":", $oReportRun->secondarymodule); for ($i = 0; $i < count($sec_modules); $i++) { $modules_selected[] = $sec_modules[$i]; } } $y = $db->num_fields($result); $report = '<table border="1" cellpadding="2"><tr width="500px" bgcolor="lightgrey">'; $arrayHeaders = array(); for ($x = 0; $x < $y; $x++) { $fld = $db->field_name($result, $x); if (in_array($oReportRun->getLstringforReportHeaders($fld->name), $arrayHeaders)) { $headerLabel = str_replace("_", " ", $fld->name); $arrayHeaders[] = $headerLabel; } else { $headerLabel = str_replace($modules, " ", $oReportRun->getLstringforReportHeaders($fld->name)); $headerLabel = str_replace("_", " ", $oReportRun->getLstringforReportHeaders($fld->name)); $arrayHeaders[] = $headerLabel; } /*STRING TRANSLATION starts */ $mod_name = split(' ', $headerLabel, 2); $moduleLabel = ''; if (in_array($mod_name[0], $modules_selected)) { $moduleLabel = getTranslatedString($mod_name[0], $mod_name[0]); } if (!empty($oReportRun->secondarymodule)) { if ($moduleLabel != '') { $headerLabel_tmp = getTranslatedString($mod_name[1], $mod_name[0]); } else { $headerLabel_tmp = getTranslatedString($mod_name[0] . " " . $mod_name[1]); } } else { if ($moduleLabel != '') { $headerLabel_tmp = getTranslatedString($mod_name[1], $mod_name[0]); } else { $headerLabel_tmp = getTranslatedString($mod_name[0] . " " . $mod_name[1]); } } if ($headerLabel == $headerLabel_tmp) { $headerLabel = getTranslatedString($headerLabel_tmp); } else { $headerLabel = $headerLabel_tmp; } /*STRING TRANSLATION ends */ $report .= "<td class='rptCellLabel'><small><b>" . $headerLabel . "</b></small></td>"; // Performance Optimization: If direct output is required // END } $report .= '</tr>'; // END $noofrows = $db->num_rows($result); $custom_field_values = $db->fetch_array($result); $groupslist = $oReportRun->getGroupingList($oReportRun->reportid); $column_definitions = $db->getFieldsDefinition($result); do { $arraylists = array(); if (count($groupslist) == 1) { $newvalue = $custom_field_values[0]; } elseif (count($groupslist) == 2) { $newvalue = $custom_field_values[0]; $snewvalue = $custom_field_values[1]; } elseif (count($groupslist) == 3) { $newvalue = $custom_field_values[0]; $snewvalue = $custom_field_values[1]; $tnewvalue = $custom_field_values[2]; } if ($newvalue == "") { $newvalue = "-"; } if ($snewvalue == "") { $snewvalue = "-"; } if ($tnewvalue == "") { $tnewvalue = "-"; } $report .= '<tr width="500px">'; // Performance Optimization // END for ($i = 0; $i < $y; $i++) { $fld = $db->field_name($result, $i); $fld_type = $column_definitions[$i]->type; $fieldvalue = getReportFieldValue($oReportRun, $picklistarray, $fld, $custom_field_values, $i); //check for Roll based pick list $temp_val = $fld->name; if ($fieldvalue == "") { $fieldvalue = "-"; } else { if ($fld->name == 'LBL_ACTION') { } } if ($lastvalue == $fieldvalue && $oReportRun->reporttype == "summary") { if ($report->reporttype == "summary") { $valtemplate .= "<td class='rptEmptyGrp'> </td>"; } else { $report .= "<td class='rptData'>" . $fieldvalue . "</td>"; } } else { if ($secondvalue === $fieldvalue && $oReportRun->reporttype == "summary") { if ($lastvalue === $newvalue) { $report .= "<td class='rptEmptyGrp'> </td>"; } else { $report .= "<td class='rptGrpHead'>" . $fieldvalue . "</td>"; } } else { if ($thirdvalue === $fieldvalue && $oReportRun->reporttype == "summary") { if ($secondvalue === $snewvalue) { $report .= "<td class='rptEmptyGrp'> </td>"; } else { $report .= "<td class='rptGrpHead'>" . $fieldvalue . "</td>"; } } else { if ($oReportRun->reporttype == "tabular") { $report .= "<td class='rptData'><small>" . $fieldvalue . "</small></td>"; } else { $report .= "<td class='rptGrpHead'><small>" . $fieldvalue . "</small></td>"; } } } } // Performance Optimization: If direct output is required // END } $report .= "</tr>"; // Performance Optimization: If direct output is required // echo $valtemplate; // END $lastvalue = $newvalue; $secondvalue = $snewvalue; $thirdvalue = $tnewvalue; $arr_val[] = $arraylists; set_time_limit($php_max_execution_time); } while ($custom_field_values = $db->fetch_array($result)); $report .= "</table></br>"; $content = str_replace("#report_tag#", $report, $content); ############///////////////////////////////######################### return $content; }
* The Original Code is: vtiger CRM Open Source * The Initial Developer of the Original Code is vtiger. * Portions created by vtiger are Copyright (C) vtiger. * All Rights Reserved. * ********************************************************************************/ require_once 'Smarty_setup.php'; require_once "modules/Reports/ReportRun.php"; require_once "modules/Reports/Reports.php"; global $app_strings; global $mod_strings; $oPrint_smarty = new vtigerCRM_Smarty(); $reportid = vtlib_purify($_REQUEST["record"]); $oReport = new Reports($reportid); $filtercolumn = $_REQUEST["stdDateFilterField"]; $filter = $_REQUEST["stdDateFilter"]; $oReportRun = new ReportRun($reportid); $startdate = DateTimeField::convertToDBFormat($_REQUEST["startdate"]); //Convert the user date format to DB date format $enddate = DateTimeField::convertToDBFormat($_REQUEST["enddate"]); //Convert the user date format to DB date format $filterlist = $oReportRun->RunTimeFilter($filtercolumn, $filter, $startdate, $enddate); $arr_values = $oReportRun->GenerateReport("PRINT", $filterlist); $total_report = $oReportRun->GenerateReport("PRINT_TOTAL", $filterlist); $oPrint_smarty->assign("COUNT", $arr_values[1]); $oPrint_smarty->assign("APP", $app_strings); $oPrint_smarty->assign("MOD", $mod_strings); $oPrint_smarty->assign("REPORT_NAME", $oReport->reportname); $oPrint_smarty->assign("PRINT_CONTENTS", $arr_values[0]); $oPrint_smarty->assign("TOTAL_HTML", $total_report); $oPrint_smarty->display("PrintReport.tpl");
public static function generateChartDataFromReports($queryResult, $groupbyField, $fieldDetails = '', $reportid = '') { require_once 'modules/Reports/CustomReportUtils.php'; require_once 'include/Webservices/Utils.php'; require_once 'include/Webservices/Query.php'; global $adb, $current_user, $theme, $default_charset; $inventorymodules = array('Quotes', 'SalesOrder', 'PurchaseOrder', 'Invoice', 'Products', 'PriceBooks', 'Vendors', 'Services'); $rows = $adb->num_rows($queryResult); $condition = "is"; $current_theme = $theme; $groupByFields = array(); $yaxisArray = array(); $ChartDataArray = array(); $target_val = array(); $report = new ReportRun($reportid); $restrictedModules = array(); if ($report->secondarymodule != '') { $reportModules = explode(":", $report->secondarymodule); } else { $reportModules = array(); } array_push($reportModules, $report->primarymodule); $restrictedModules = false; foreach ($reportModules as $mod) { if (isPermitted($mod, 'index') != "yes" || vtlib_isModuleActive($mod) == false) { if (!is_array($restrictedModules)) { $restrictedModules = array(); } $restrictedModules[] = $mod; } } if (is_array($restrictedModules) && count($restrictedModules) > 0) { $ChartDataArray['error'] = "<h4>" . getTranslatedString('LBL_NO_ACCESS', 'Reports') . ' - ' . implode(',', $restrictedModules) . "</h4>"; return $ChartDataArray; } if ($fieldDetails != '') { list($tablename, $colname, $module_field, $fieldname, $single) = explode(":", $fieldDetails); list($module, $field) = split("_", $module_field); $dateField = false; if ($single == 'D') { $dateField = true; $query = "SELECT * FROM vtiger_reportgroupbycolumn WHERE reportid=? ORDER BY sortid"; $result = $adb->pquery($query, array($reportid)); $criteria = $adb->query_result($result, 0, 'dategroupbycriteria'); } } preg_match('/&/', $groupbyField, $matches); if (!empty($matches)) { $groupfield = str_replace('&', '&', $groupbyField); $groupbyField = $report->replaceSpecialChar($groupfield); } $handler = vtws_getModuleHandlerFromName($module, $current_user); $meta = $handler->getMeta(); $meta->retrieveMeta(); $referenceFields = $meta->getReferenceFieldDetails(); if ($rows > 0) { $resultRow = $adb->query_result_rowdata($queryResult, 0); if (!array_key_exists($groupbyField, $resultRow)) { $ChartDataArray['error'] = "<h4>" . getTranslatedString('LBL_NO_PERMISSION_FIELD', 'Dashboard') . "</h4>"; return $ChartDataArray; } } for ($i = 0; $i < $rows; $i++) { $groupFieldValue = $adb->query_result($queryResult, $i, strtolower($groupbyField)); $decodedGroupFieldValue = html_entity_decode($groupFieldValue, ENT_QUOTES, $default_charset); if (!empty($groupFieldValue)) { if (in_array($module_field, $report->append_currency_symbol_to_value)) { $valueComp = explode('::', $groupFieldValue); $groupFieldValue = $valueComp[1]; } if ($dateField) { if (!empty($groupFieldValue)) { $groupByFields[] = CustomReportUtils::getXAxisDateFieldValue($groupFieldValue, $criteria); } else { $groupByFields[] = "Null"; } } else { if (in_array($fieldname, array_keys($referenceFields))) { if (count($referenceFields[$fieldname]) > 1) { $refenceModule = CustomReportUtils::getEntityTypeFromName($decodedGroupFieldValue, $referenceFields[$fieldname]); } else { $refenceModule = $referenceFields[$fieldname][0]; } $groupByFields[] = $groupFieldValue; if ($fieldname == 'currency_id' && in_array($module, $inventorymodules)) { $tablename = 'vtiger_currency_info'; } elseif ($refenceModule == 'DocumentFolders' && $fieldname == 'folderid') { $tablename = 'vtiger_attachmentsfolder'; $colname = 'foldername'; } else { require_once "modules/{$refenceModule}/{$refenceModule}.php"; $focus = new $refenceModule(); $tablename = $focus->table_name; $colname = $focus->list_link_field; $condition = "c"; } } else { $groupByFields[] = $groupFieldValue; } } $yaxisArray[] = $adb->query_result($queryResult, $i, 'groupby_count'); if ($fieldDetails != '') { if ($dateField) { $advanceSearchCondition = CustomReportUtils::getAdvanceSearchCondition($fieldDetails, $criteria, $groupFieldValue); if ($module == 'Calendar') { $link_val = "index.php?module=" . $module . "&query=true&action=ListView&" . $advanceSearchCondition; } else { $link_val = "index.php?module=" . $module . "&query=true&action=index&" . $advanceSearchCondition; } } else { $cvid = getCvIdOfAll($module); $esc_search_str = urlencode($decodedGroupFieldValue); if ($single == 'DT') { $esc_search_str = urlencode($groupFieldValue); if (strtolower($fieldname) == 'modifiedtime' || strtolower($fieldname) == 'createdtime') { $tablename = 'vtiger_crmentity'; $colname = $fieldname; } } if ($fieldname == 'assigned_user_id') { $tablename = 'vtiger_crmentity'; $colname = 'smownerid'; } if ($fieldname == 'serviceid' && in_array($module, getInventoryModules())) { $fieldname = 'productid'; } if ($module == 'Calendar') { $link_val = "index.php?module=" . $module . "&action=ListView&search_text=" . $esc_search_str . "&search_field=" . $fieldname . "&searchtype=BasicSearch&query=true&operator=e&viewname=" . $cvid; } else { $link_val = "index.php?module=" . $module . "&action=index&search_text=" . $esc_search_str . "&search_field=" . $fieldname . "&searchtype=BasicSearch&query=true&operator=e&viewname=" . $cvid; } } $target_val[] = $link_val; } } } if (count($groupByFields) == 0) { $ChartDataArray['error'] = "<div class='componentName'>" . getTranslatedString('LBL_NO_DATA', 'Reports') . "</div"; } $ChartDataArray['xaxisData'] = $groupByFields; $ChartDataArray['yaxisData'] = $yaxisArray; $ChartDataArray['targetLink'] = $target_val; $theme = $current_theme; return $ChartDataArray; }
$worksheet =& $workbook->addworksheet(); # Set the column width for columns 1, 2, 3 and 4 $worksheet->set_column(0, 3, 15); # Create a format for the column headings $header =& $workbook->addformat(); $header->set_bold(); $header->set_size(12); $header->set_color('blue'); # Write out the data $reportid = vtlib_purify($_REQUEST["record"]); $oReport = new Reports($reportid); $filtercolumn = $_REQUEST['stdDateFilterField']; $filter = $_REQUEST['stdDateFilter']; $startdate = getDBInsertDateValue($_REQUEST['startdate']); $enddate = getDBInsertDateValue($_REQUEST['enddate']); $oReportRun = new ReportRun($reportid); $filterlist = $oReportRun->RunTimeFilter($filtercolumn, $filter, $startdate, $enddate); $arr_val = $oReportRun->GenerateReport("PDF", $filterlist); $totalxls = $oReportRun->GenerateReport("TOTALXLS", $filterlist); if (isset($arr_val)) { foreach ($arr_val[0] as $key => $value) { $worksheet->write(0, $count, $key, $header); $count = $count + 1; } $rowcount = 1; foreach ($arr_val as $key => $array_value) { $dcount = 0; foreach ($array_value as $hdr => $value) { //$worksheet->write($key+1, $dcount, iconv("UTF-8", "ISO-8859-1", $value)); $value = decode_html($value); $worksheet->write($key + 1, $dcount, utf8_decode($value));
protected function fetchValues() { $allValues = parent::fetchValues(); $mergeData = array(); foreach ($this->report->getMergeFields() as $mergeField) { $mergeData[$mergeField] = $allValues[$mergeField]; } for ($i = 0; $i < count($this->substmts); $i++) { $substmt = $this->substmts[$i]; if (!isset($this->lastValues[$i])) { $this->lastValues[$i] = $substmt->fetch(\PDO::FETCH_ASSOC); } while ($this->checkMergeValues($mergeData, $this->lastValues[$i])) { $currValues = $this->lastValues[$i]; $allValues[$currValues["__KEY__"]] = $currValues["__VALUE__"]; $this->lastValues[$i] = $substmt->fetch(\PDO::FETCH_ASSOC); } } return $allValues; }
function getReport(Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $record = $request->get('record'); $page = $request->get('page'); $data = $this->reportData; $calculation = $this->calculationFields; if (empty($data)) { $reportModel = Reports_Record_Model::getInstanceById($record); $reportModel->setModule('Reports'); $reportType = $reportModel->get('reporttype'); $pagingModel = new Vtiger_Paging_Model(); $pagingModel->set('page', $page); $pagingModel->set('limit', self::REPORT_LIMIT + 1); $reportData = $reportModel->getReportData($pagingModel); $data = $reportData['data']; $calculation = $reportModel->getReportCalulationData(); $advFilterSql = $reportModel->getAdvancedFilterSQL(); $query = $reportModel->getReportSQL($advFilterSql, 'PDF'); $countQuery = $reportModel->generateCountQuery($query); $this->count = $reportModel->getReportsCount($countQuery); } $viewer->assign('CALCULATION_FIELDS', $calculation); $viewer->assign('DATA', $data); $viewer->assign('RECORD_ID', $record); $viewer->assign('PAGING_MODEL', $pagingModel); $viewer->assign('COUNT', $this->count); $viewer->assign('MODULE', $moduleName); $viewer->assign('REPORT_RUN_INSTANCE', ReportRun::getInstance($record)); if (count($data) > self::REPORT_LIMIT) { $viewer->assign('LIMIT_EXCEEDED', true); } $viewer->view('ReportContents.tpl', $moduleName); }
* granted by the License. coreBOS distributed by JPL TSolucio S.L. is distributed in * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Unless required by * applicable law or agreed to in writing, software distributed under the License is * distributed on an "AS IS" BASIS, WITHOUT ANY WARRANTIES OR CONDITIONS OF ANY KIND, * either express or implied. See the License for the specific language governing * permissions and limitations under the License. You may obtain a copy of the License * at <http://www.gnu.org/licenses/> ************************************************************************************************* * Module : Reports * Author : Opencubed *************************************************************************************************/ global $php_max_execution_time; set_time_limit($php_max_execution_time); require_once "modules/Reports/ReportRun.php"; require_once "modules/Reports/Reports.php"; global $tmp_dir, $root_directory; $fname = tempnam($root_directory . $tmp_dir, "merge2.csv"); # Write out the data $reportid = vtlib_purify($_REQUEST["record"]); $oReportRun = new ReportRun($reportid); $oReportRun->writeReportToCSVFile($fname, $filterlist); if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); } header("Content-Type: application/csv;charset=utf-8"); header("Content-Length: " . @filesize($fname)); header('Content-disposition: attachment; filename="Reports.csv"'); $fh = fopen($fname, "rb"); fpassthru($fh);
public function sendEmail() { require_once 'modules/Emails/mail.php'; require_once 'modules/Emails/Emails.php'; global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $currentModule; $recipientEmails = $this->getRecipientEmails(); $emails_to = ''; foreach ($recipientEmails as $name => $email) { $emails_to .= $email . ','; } $emails_to = trim($emails_to, ','); $currentTime = date('Y-m-d H:i:s'); $subject = $this->reportname . ' - ' . $currentTime . ' (' . DateTimeField::getDBTimeZone() . ')'; $contents = getTranslatedString('LBL_AUTO_GENERATED_REPORT_EMAIL', $currentModule) . '<br/><br/>'; $contents .= '<b>' . getTranslatedString('LBL_REPORT_NAME', $currentModule) . ' :</b> ' . $this->reportname . '<br/>'; $contents .= '<b>' . getTranslatedString('LBL_DESCRIPTION', $currentModule) . ' :</b><br/>' . $this->reportdescription . '<br/><br/>'; $baseFileName = utf8_decode(preg_replace('/[^a-zA-Z0-9_-\\s]/', '', $this->reportname) . '_' . preg_replace('/[^a-zA-Z0-9_-\\s]/', '', date('YmdHis'))); $oReportRun = new ReportRun($this->id); $reportFormat = $this->scheduledFormat; $attachments = array(); if ($reportFormat == 'pdf' || $reportFormat == 'both') { $fileName = $baseFileName . '.pdf'; $filePath = 'storage/' . $fileName; $attachments[$fileName] = $filePath; $_REQUEST['filename_hidden_pdf'] = $filePath; $pdf = $oReportRun->getReportPDF(NULL); $pdf->Output($filePath, 'F'); } if ($reportFormat == 'excel' || $reportFormat == 'both') { $fileName = $baseFileName . '.xls'; $filePath = 'storage/' . $fileName; $attachments[$fileName] = $filePath; $_REQUEST['filename_hidden_xls'] = $filePath; $oReportRun->writeReportToExcelFile($filePath, NULL); } $sendifempty = GlobalVariable::getVariable('Report_Send_Scheduled_ifEmpty', 1); if ($sendifempty or $oReportRun->number_of_rows > 0) { $mail_status = send_mail('Emails', $emails_to, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $contents, '', '', 'attReports'); foreach ($attachments as $attachmentName => $path) { unlink($path); } } }
* Portions created by vtiger are Copyright (C) vtiger. * All Rights Reserved. * ********************************************************************************/ ini_set('max_execution_time', '1800'); require_once "modules/Reports/ReportRun.php"; require_once "modules/Reports/Reports.php"; //require('include/fpdf/fpdf.php'); require 'include/tcpdf/tcpdf.php'; $language = $_SESSION['authenticated_user_language'] . '.lang.php'; require_once "include/language/{$language}"; $reportid = vtlib_purify($_REQUEST["record"]); $oReport = new Reports($reportid); //Code given by Csar Rodrguez for Rwport Filter $filtercolumn = $_REQUEST["stdDateFilterField"]; $filter = $_REQUEST["stdDateFilter"]; $oReportRun = new ReportRun($reportid); $startdate = $_REQUEST['startdate']; $enddate = $_REQUEST['enddate']; if (!empty($startdate) && !empty($enddate) && $startdate != "0000-00-00" && $enddate != "0000-00-00") { $date = new DateTimeField($_REQUEST['startdate']); $endDate = new DateTimeField($_REQUEST['enddate']); $startdate = $date->getDBInsertDateValue(); //Convert the user date format to DB date format $enddate = $endDate->getDBInsertDateValue(); //Convert the user date format to DB date format } $filterlist = $oReportRun->RunTimeFilter($filtercolumn, $filter, $startdate, $enddate); $pdf = $oReportRun->getReportPDF($filterlist); $pdf->Output('Reports.pdf', 'D'); exit;
$rep_modules = array(); } array_push($rep_modules, $primarymodule); $modules_permitted = true; $modules_export_permitted = true; foreach ($rep_modules as $mod) { if (isPermitted($mod, 'index') != "yes" || vtlib_isModuleActive($mod) == false) { $modules_permitted = false; $restrictedmodules[] = $mod; } if (isPermitted("{$mod}", 'Export', '') != 'yes') { $modules_export_permitted = false; } } if (isPermitted($primarymodule, 'index') == "yes" && $modules_permitted == true) { $oReportRun = new ReportRun($reportid); require_once 'include/Zend/Json.php'; $json = new Zend_Json(); $advft_criteria = $_REQUEST['advft_criteria']; if (!empty($advft_criteria)) { $advft_criteria = $json->decode($advft_criteria); } $advft_criteria_groups = $_REQUEST['advft_criteria_groups']; if (!empty($advft_criteria_groups)) { $advft_criteria_groups = $json->decode($advft_criteria_groups); } if ($_REQUEST['submode'] == 'saveCriteria') { updateAdvancedCriteria($reportid, $advft_criteria, $advft_criteria_groups); } $filtersql = $oReportRun->RunTimeAdvFilter($advft_criteria, $advft_criteria_groups); $list_report_form = new vtigerCRM_Smarty();
$rep_modules = array(); } array_push($rep_modules, $primarymodule); $modules_permitted = true; $modules_export_permitted = true; foreach ($rep_modules as $mod) { if (isPermitted($mod, 'index') != "yes" || vtlib_isModuleActive($mod) == false) { $modules_permitted = false; $restrictedmodules[] = $mod; } if (isPermitted("{$mod}", 'Export', '') != 'yes') { $modules_export_permitted = false; } } if (isPermitted($primarymodule, 'index') == "yes" && $modules_permitted == true) { $oReportRun = ReportRun::getInstance($reportid); require_once 'include/Zend/Json.php'; $json = new Zend_Json(); $advft_criteria = $_REQUEST['advft_criteria']; if (!empty($advft_criteria)) { $advft_criteria = $json->decode($advft_criteria); } $advft_criteria_groups = $_REQUEST['advft_criteria_groups']; if (!empty($advft_criteria_groups)) { $advft_criteria_groups = $json->decode($advft_criteria_groups); } if ($_REQUEST['submode'] == 'saveCriteria') { updateAdvancedCriteria($reportid, $advft_criteria, $advft_criteria_groups); } $filtersql = $oReportRun->RunTimeAdvFilter($advft_criteria, $advft_criteria_groups); $showCharts = $reporttype == 'summary' && $oReportRun->hasGroupingList() ? true : false;
public function sendEmail() { require_once 'vtlib/Vtiger/Mailer.php'; $vtigerMailer = new Vtiger_Mailer(); $recipientEmails = $this->getRecipientEmails(); Vtiger_Utils::ModuleLog('ScheduleReprots', $recipientEmails); foreach ($recipientEmails as $name => $email) { $vtigerMailer->AddAddress($email, $name); } vimport('~modules/Report/models/Record.php'); $reportRecordModel = Reports_Record_Model::getInstanceById($this->get('reportid')); $currentTime = date('Y-m-d.H.i.s'); Vtiger_Utils::ModuleLog('ScheduleReprots Send Mail Start ::', $currentTime); $reportname = decode_html($reportRecordModel->getName()); $subject = $reportname; Vtiger_Utils::ModuleLog('ScheduleReprot Name ::', $reportname); $vtigerMailer->Subject = $subject; $vtigerMailer->Body = $this->getEmailContent($reportRecordModel); $vtigerMailer->IsHTML(); $baseFileName = $reportname . '__' . $currentTime; $oReportRun = ReportRun::getInstance($this->get('reportid')); $reportFormat = $this->scheduledFormat; $attachments = array(); if ($reportFormat == 'CSV') { $fileName = $baseFileName . '.csv'; $filePath = 'storage/' . $fileName; $attachments[$fileName] = $filePath; $oReportRun->writeReportToCSVFile($filePath); } foreach ($attachments as $attachmentName => $path) { $vtigerMailer->AddAttachment($path, decode_html($attachmentName)); } //Added cc to account owner $accountOwnerId = Users::getActiveAdminId(); $vtigerMailer->AddCC(getUserEmail($accountOwnerId), getUserFullName($accountOwnerId)); $status = $vtigerMailer->Send(true); foreach ($attachments as $attachmentName => $path) { unlink($path); } return $status; }
function getReport(Vtiger_Request $request) { $viewer = $this->getViewer($request); $moduleName = $request->getModule(); $record = $request->get('record'); $page = $request->get('page'); //$data = $this->reportData; //TODO $calculation = $this->calculationFields; //if(empty($data)){ $reportModel = Reports_Record_Model::getInstanceById($record); $reportModel->setModule('Reports'); $reportType = $reportModel->get('reporttype'); $pagingModel = new Vtiger_Paging_Model(); $pagingModel->set('page', $page); $pagingModel->set('limit', self::REPORT_LIMIT + 1); $reportData = $reportModel->getReportData($pagingModel); $data = $reportData['data']; $dataRaw = $reportData['data_raw']; $calculation = $reportModel->getReportCalulationData(); $advFilterSql = $reportModel->getAdvancedFilterSQL(); $query = $reportModel->getReportSQL($advFilterSql, 'PDF'); $countQuery = $reportModel->generateCountQuery($query); $this->count = $reportModel->getReportsCount($countQuery); //} /*готовим данные в нужный нам формат для новой таблицы*/ /*получим поле для группировки*/ global $adb; $reportRun = ReportRun::getInstance($record); $fieldRawArr = $reportRun->getGroupingList(); foreach ($fieldRawArr as $value) { $fieldRaw = explode('_', $value, 2); break; } $groupModule = str_replace('`', '', $fieldRaw[0]); $groupLabel = explode(' ', $fieldRaw[1], 2); $groupLabel = str_replace('`', '', $groupLabel[0]); //это системное имя, нужен перевод $fieldInfo = getFieldByReportLabel($groupModule, $groupLabel); $fieldType = null; if (!empty($fieldInfo)) { $field = WebserviceField::fromArray($adb, $fieldInfo); $fieldType = $field->getFieldDataType(); } if (!empty($fieldInfo)) { $translatedLabel = getTranslatedString($field->getFieldLabelKey(), $groupModule); } else { $translatedLabel = getTranslatedString($groupLabel, $groupModule); $translatedLabel = str_replace("_", " ", $translatedLabel); } $groupLabel = $translatedLabel; /*STRING TRANSLATION starts TODO*/ /*$moduleLabel =''; if(in_array($module,$modules_selected)) $moduleLabel = getTranslatedString($module,$module); if(empty($translatedLabel)) { $translatedLabel = getTranslatedString(str_replace('_', " ", $fld->name), $module); }*/ /*if(!empty($this->secondarymodule)) { if($moduleLabel != '') { $headerLabel = $moduleLabel." ". $translatedLabel; } }*/ /*формируем нужный массив*/ $dataGrouped = array(); foreach ($data as $index => $row) { $groupIndex = $row[$groupLabel]; if (!isset($dataGrouped[$groupIndex])) { $dataGrouped[$groupIndex] = array('rows' => array(), 'summary' => array()); } $dataGrouped[$groupIndex]['rows'][] = $row; foreach ($row as $reportField => $value) { $dataRawVal = explode('::', $dataRaw[$index][$reportField]); $dataRawType = empty($dataRawVal[1]) ? 'undefined' : $dataRawVal[1]; $dataRawVal = $dataRawVal[0]; if (!isset($dataGrouped[$groupIndex]['summary'][$reportField])) { if ($dataRawType == 'currency') { $dataRawVal = $dataRawVal + 0; } if (empty($dataRawType)) { $dataRawVal = (string) $dataRawVal; } $dataGrouped[$groupIndex]['summary'][$reportField] = $dataRawVal; } elseif ($dataRawType == 'currency') { /*можно позже добавить другие типы данных*/ $summed = $dataGrouped[$groupIndex]['summary'][$reportField] + $dataRawVal; $dataGrouped[$groupIndex]['summary'][$reportField] = $summed; /*todo переделать в пользовательский формат*/ } } } /*end*/ /*убираем ненужные столбцы*/ $columns = array('SUM' => false, 'AVG' => false, 'MIN' => false, 'MAX' => false); foreach ($calculation as $metriks) { foreach ($metriks as $index => $metrik) { $postfix = substr($index, -3, 3); if ($columns[$postfix]) { continue; } if (!empty($metrik)) { $columns[$postfix] = true; } } } $viewer->assign('COLUMNS', $columns); /*end*/ $viewer->assign('CALCULATION_FIELDS', $calculation); $viewer->assign('DATA', $data); $viewer->assign('DATAGROUPED', $dataGrouped); $viewer->assign('RECORD_ID', $record); $viewer->assign('PAGING_MODEL', $pagingModel); $viewer->assign('COUNT', $this->count); $viewer->assign('MODULE', $moduleName); $viewer->assign('REPORT_RUN_INSTANCE', ReportRun::getInstance($record)); if (count($data) > self::REPORT_LIMIT) { $viewer->assign('LIMIT_EXCEEDED', true); } $viewer->view('ReportContents.tpl', $moduleName); }