Merge branch 'ent-4558-8584-intracom-el-pdf-generado-desde-custom-report-es-ilegible-si-la-tabla-tiene-muchas-filas' into 'develop'

Fixed max,min,avg report

See merge request artica/pandorafms!2720
This commit is contained in:
Alejandro Fraguas 2019-09-12 17:29:09 +02:00
commit 3a85b434ca
2 changed files with 198 additions and 309 deletions

View File

@ -4785,12 +4785,10 @@ function reporting_value($report, $content, $type, $pdf=false)
'period' => $content['period'], 'period' => $content['period'],
'width' => '600px', 'width' => '600px',
'pure' => false, 'pure' => false,
// true
'date' => $report['datetime'], 'date' => $report['datetime'],
'only_image' => $only_image, 'only_image' => $only_image,
'homeurl' => ui_get_full_url(false, false, false, false), 'homeurl' => ui_get_full_url(false, false, false, false),
'ttl' => 1, 'ttl' => 1,
// 2
'type_graph' => $config['type_module_charts'], 'type_graph' => $config['type_module_charts'],
'time_interval' => $content['lapse'], 'time_interval' => $content['lapse'],
'server_id' => $id_meta, 'server_id' => $id_meta,
@ -4800,323 +4798,104 @@ function reporting_value($report, $content, $type, $pdf=false)
switch ($type) { switch ($type) {
case 'max': case 'max':
if ($content['lapse_calc'] == 0) {
$value = reporting_get_agentmodule_data_max(
$content['id_agent_module'],
$content['period'],
$report['datetime']
);
if (!$config['simple_module_value']) {
$formated_value = $value;
} else {
$formated_value = format_for_graph($value, $config['graph_precision']).' '.$unit;
}
} else {
$value = '
<table border="0" style="margin:0 auto;text-align:center;">
<tr>
<td width="400px;" height="20%;">';
if ($content['visual_format'] == 1 || $content['visual_format'] == 2 || $content['visual_format'] == 3) {
$value .= '
<table style="width:90%;margin:0 auto;background-color:#eee;border: solid lightgray 1px;">
<tr>
<th style="padding:5px;background-color:#82b92e;">
'.__('Agent').'
</th>
<th style="padding:5px;background-color:#82b92e;">
'.__('Module').'
</th>
<th style="padding:5px;background-color:#82b92e;">
'.__('Maximum').'
</th>
<tr>
<td style="padding:5px;">
'.$agent_name.'
</td>
<td style="padding:5px;">
'.$module_name.'
</td>
<td style="padding:5px;">
'.format_for_graph(reporting_get_agentmodule_data_max($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit.'
</td>
</tr>
</table>';
}
$value .= '
</td>
<td rowspan="2" width="150px">
</td>
<td rowspan="2">';
if ($content['visual_format'] == 2 || $content['visual_format'] == 3) {
$params['force_interval'] = 'max_only';
$value .= grafico_modulo_sparse($params);
}
$value .= '
</td>
</tr>
<tr>
<td>';
if ($content['visual_format'] == 1 || $content['visual_format'] == 3) {
$value .= '
<table style="width:90%;margin:0 auto;margin-top:30px;background-color:#eee;border: solid lightgray 1px;">
<tr>
<th style="padding:5px;background-color:#82b92e;">
'.__('Lapse').'
</th>
<th style="padding:5px;background-color:#82b92e;">
'.__('Maximum').'
</th>
</tr>
<tr>';
$time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module'], true);
$date_reference = getdate();
for ($i = $date_reference[0]; $i > ($date_reference[0] - $content['period']); $i -= $content['lapse']) {
$value .= '<tr><td style="padding:5px;">'.date('Y-m-d H:i:s', ($i - $content['lapse'] + 1)).' to '.date('Y-m-d H:i:s', $i).'</td><td>';
if ($i > $time_begin['utimestamp']) {
$value .= format_for_graph(
reporting_get_agentmodule_data_max(
$content['id_agent_module'],
$content['lapse'],
$i
),
$config['graph_precision']
).' '.$unit.'</td></tr>';
} else {
$value .= 'N/A</td></tr>';
}
}
$value .= '</table>';
}
$value .= '
</td>
</tr>
</table>';
$formated_value = $value;
}
break;
case 'min': case 'min':
if ($content['lapse_calc'] == 0) {
$value = reporting_get_agentmodule_data_min(
$content['id_agent_module'],
$content['period'],
$report['datetime']
);
if (!$config['simple_module_value']) {
$formated_value = $value;
} else {
$formated_value = format_for_graph($value, $config['graph_precision']).' '.$unit;
}
} else {
$value = '
<table border="0" style="margin:0 auto;text-align:center;">
<tr>
<td width="400px;" height="20%;">';
if ($content['visual_format'] == 1 || $content['visual_format'] == 2 || $content['visual_format'] == 3) {
$value .= '
<table style="width:90%;margin:0 auto;background-color:#eee;border: solid lightgray 1px;">
<tr>
<th style="padding:5px;background-color:#82b92e;">
'.__('Agent').'
</th>
<th style="padding:5px;background-color:#82b92e;">
'.__('Module').'
</th>
<th style="padding:5px;background-color:#82b92e;">
'.__('Minimum').'
</th>
<tr>
<td style="padding:5px;">
'.$agent_name.'
</td>
<td style="padding:5px;">
'.$module_name.'
</td>
<td style="padding:5px;">
'.format_for_graph(reporting_get_agentmodule_data_min($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit.'
</td>
</tr>
</table>';
}
$value .= '
</td>
<td rowspan="2" width="150px">
</td>
<td rowspan="2">';
if ($content['visual_format'] == 2 || $content['visual_format'] == 3) {
$params['force_interval'] = 'min_only';
$value .= grafico_modulo_sparse($params);
}
$value .= '
</td>
</tr>
<tr>
<td>';
if ($content['visual_format'] == 1 || $content['visual_format'] == 3) {
$value .= '
<table style="width:90%;margin:0 auto;margin-top:30px;background-color:#eee;border: solid lightgray 1px;">
<tr>
<th style="padding:5px;background-color:#82b92e;">
'.__('Lapse').'
</th>
<th style="padding:5px;background-color:#82b92e;">
'.__('Minimum').'
</th>
</tr>
<tr>';
$time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module']);
$date_reference = getdate();
for ($i = $date_reference[0]; $i > ($date_reference[0] - $content['period']); $i -= $content['lapse']) {
$value .= '<tr><td style="padding:5px;">'.date('Y-m-d H:i:s', ($i - $content['lapse'] + 1)).' to '.date('Y-m-d H:i:s', $i).'</td><td>';
if ($i > $time_begin['utimestamp']) {
$value .= format_for_graph(
reporting_get_agentmodule_data_min(
$content['id_agent_module'],
$content['lapse'],
$i
),
$config['graph_precision']
).' '.$unit.'</td></tr>';
} else {
$value .= 'N/A</td></tr>';
}
}
$value .= '</table>';
}
$value .= '
</td>
</tr>
</table>';
$formated_value = $value;
}
break;
case 'avg': case 'avg':
if ($content['lapse_calc'] == 0) { if ($content['lapse_calc'] == 0) {
$value = reporting_get_agentmodule_data_average( switch ($type) {
$content['id_agent_module'], case 'max':
$content['period'], $value = reporting_get_agentmodule_data_max(
$report['datetime'] $content['id_agent_module'],
); $content['period'],
$report['datetime']
);
break;
case 'min':
$value = reporting_get_agentmodule_data_min(
$content['id_agent_module'],
$content['period'],
$report['datetime']
);
break;
case 'avg':
$value = reporting_get_agentmodule_data_average(
$content['id_agent_module'],
$content['period'],
$report['datetime']
);
break;
}
if (!$config['simple_module_value']) { if (!$config['simple_module_value']) {
$formated_value = $value; $formated_value = $value;
} else { } else {
$formated_value = format_for_graph($value, $config['graph_precision']).' '.$unit; $formated_value = format_for_graph($value, $config['graph_precision']).' '.$unit;
} }
} else { } else {
$value = ' $return['visual_format'] = $content['visual_format'];
<table border="0" style="margin:0 auto;text-align:center;">
<tr>
<td width="400px;" height="20%;">';
if ($content['visual_format'] == 1 || $content['visual_format'] == 2 || $content['visual_format'] == 3) { switch ($type) {
$value .= ' case 'max':
<table style="width:90%;margin:0 auto;background-color:#eee;border: solid lightgray 1px;"> $params['force_interval'] = 'max_only';
<tr> $value = format_for_graph(reporting_get_agentmodule_data_max($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit;
<th style="padding:5px;background-color:#82b92e;"> break;
'.__('Agent').'
</th> case 'min':
<th style="padding:5px;background-color:#82b92e;"> $params['force_interval'] = 'min_only';
'.__('Module').' $value = format_for_graph(reporting_get_agentmodule_data_min($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit;
</th> break;
<th style="padding:5px;background-color:#82b92e;">
'.__('Average').' case 'avg':
</th> $params['force_interval'] = 'avg_only';
<tr> $value = format_for_graph(reporting_get_agentmodule_data_average($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit;
<td style="padding:5px;"> break;
'.$agent_name.'
</td>
<td style="padding:5px;">
'.$module_name.'
</td>
<td style="padding:5px;">
'.format_for_graph(reporting_get_agentmodule_data_average($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit.'
</td>
</tr>
</table>';
} }
$value .= ' $return['data'][] = [
</td> __('Agent') => $agent_name,
<td rowspan="2" width="150px"> __('Module') => $module_name,
</td> __('Maximun') => $value,
<td rowspan="2">'; ];
if ($content['visual_format'] == 2 || $content['visual_format'] == 3) {
$params['force_interval'] = 'avg_only'; if ($content['visual_format'] != 1) {
$value .= grafico_modulo_sparse($params); $graph = grafico_modulo_sparse($params);
$return['data'][] = ['value' => $graph];
} }
$value .= ' if ($content['visual_format'] != 2) {
$time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module'], true);
</td> for ($i = $report['datetime']; $i > ($report['datetime'] - $content['period']); $i -= $content['lapse']) {
</tr> $row = [];
<tr> $row[__('Lapse')] = date('Y-m-d H:i:s', ($i - $content['lapse'] + 1)).' to '.date('Y-m-d H:i:s', $i);
<td>';
if ($content['visual_format'] == 1 || $content['visual_format'] == 3) {
$value .= '
<table style="width:90%;margin:0 auto;margin-top:30px;background-color:#eee;border: solid lightgray 1px;">
<tr>
<th style="padding:5px;background-color:#82b92e;">
'.__('Lapse').'
</th>
<th style="padding:5px;background-color:#82b92e;">
'.__('Average').'
</th>
</tr>
<tr>';
$time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module']);
$date_reference = getdate();
for ($i = $date_reference[0]; $i > ($date_reference[0] - $content['period']); $i -= $content['lapse']) {
$value .= '<tr><td style="padding:5px;">'.date('Y-m-d H:i:s', ($i - $content['lapse'] + 1)).' to '.date('Y-m-d H:i:s', $i).'</td><td>';
if ($i > $time_begin['utimestamp']) { if ($i > $time_begin['utimestamp']) {
$value .= format_for_graph( switch ($type) {
reporting_get_agentmodule_data_average( case 'max':
$content['id_agent_module'], $row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_max($content['id_agent_module'], $content['lapse'], $i), $config['graph_precision']).' '.$unit;
$content['lapse'], break;
$i
),
$config['graph_precision']
).' '.$unit.'</td></tr>';
} else {
$value .= 'N/A</td></tr>';
}
}
$value .= '</table>'; case 'min':
$row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_min($content['id_agent_module'], $content['lapse'], $i), $config['graph_precision']).' '.$unit;
break;
case 'avg':
$row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_average($content['id_agent_module'], $content['lapse'], $i), $config['graph_precision']).' '.$unit;
break;
}
} else {
$row[__('Maximun')] = 'N/A';
}
$return['data'][] = $row;
}
} }
$value .= ' if ($config['metaconsole']) {
metaconsole_restore_db();
</td> }
</tr>
</table>';
$formated_value = $value; return reporting_check_structure_content($return);
} }
break; break;

View File

@ -2784,20 +2784,130 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
$font_size = '3'; $font_size = '3';
} }
$table->colspan['data']['cell'] = 3; if (isset($item['visual_format']) && $item['visual_format'] != 0
$table->cellstyle['data']['cell'] = 'text-align: left;'; && ($item['type'] == 'max_value' || $item['type'] == 'min_value' || $item['type'] == 'avg_value')
) {
$table2 = new stdClass();
$table2->width = '100%';
switch ($item['type']) {
case 'max_value':
$table2->head = [
__('Agent'),
__('Module'),
__('Maximun'),
];
break;
$table->data['data']['cell'] = '<p style="font: bold '.$font_size.'em Arial, Sans-serif; color: #000000;">'; case 'min_value':
$table2->head = [
__('Agent'),
__('Module'),
__('Minimun'),
];
break;
if ($check_empty && empty($item['data']['value'])) { case 'avg_value':
$table->data['data']['cell'] .= __('Unknown'); $table2->head = [
} else if ($only_value) { __('Agent'),
$table->data['data']['cell'] .= $item['data']['value']; __('Module'),
__('Average'),
];
break;
}
$table2->data = [];
$data = $item['data'][0];
$row = [
$data[__('Agent')],
$data[__('Module')],
$data[__('Maximun')],
];
$table2->data[] = $row;
$table2->title = $item['title'];
$table2->titleclass = 'title_table_pdf';
$table2->titlestyle = 'text-align:left;';
$table->colspan[1][0] = 3;
$table->colspan[2][0] = 3;
$table->colspan[3][0] = 3;
array_push($table->data, html_print_table($table2, true));
unset($item['data'][0]);
if ($item['visual_format'] != 1) {
$value = $item['data'][1]['value'];
array_push($table->data, $value);
unset($item['data'][1]);
}
if ($item['visual_format'] != 2) {
$table1 = new stdClass();
$table1->width = '100%';
switch ($item['type']) {
case 'max_value':
$table1->head = [
__('Lapse'),
__('Maximun'),
];
break;
case 'min_value':
$table1->head = [
__('Lapse'),
__('Minimun'),
];
break;
case 'avg_value':
$table1->head = [
__('Lapse'),
__('Average'),
];
break;
}
$table1->data = [];
foreach ($item['data'] as $data) {
if (!is_numeric($data[__('Maximun')])) {
$row = [
$data[__('Lapse')],
$data[__('Maximun')],
];
} else {
$row = [
$data[__('Lapse')],
remove_right_zeros(number_format($data[__('Maximun')], $config['graph_precision'])),
];
}
$table1->data[] = $row;
}
$table1->title = $item['title'];
$table1->titleclass = 'title_table_pdf';
$table1->titlestyle = 'text-align:left;';
array_push($table->data, html_print_table($table1, true));
}
} else { } else {
$table->data['data']['cell'] .= $item['data']['formated_value']; $table->colspan['data']['cell'] = 3;
} $table->cellstyle['data']['cell'] = 'text-align: left;';
$table->data['data']['cell'] .= '</p>'; $table->data['data']['cell'] = '<p style="font: bold '.$font_size.'em Arial, Sans-serif; color: #000000;">';
if ($check_empty && empty($item['data']['value'])) {
$table->data['data']['cell'] .= __('Unknown');
} else if ($only_value) {
$table->data['data']['cell'] .= $item['data']['value'];
} else {
$table->data['data']['cell'] .= $item['data']['formated_value'];
}
$table->data['data']['cell'] .= '</p>';
}
} }