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'],
'width' => '600px',
'pure' => false,
// true
'date' => $report['datetime'],
'only_image' => $only_image,
'homeurl' => ui_get_full_url(false, false, false, false),
'ttl' => 1,
// 2
'type_graph' => $config['type_module_charts'],
'time_interval' => $content['lapse'],
'server_id' => $id_meta,
@ -4800,323 +4798,104 @@ function reporting_value($report, $content, $type, $pdf=false)
switch ($type) {
case 'max':
case 'min':
case 'avg':
if ($content['lapse_calc'] == 0) {
switch ($type) {
case 'max':
$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':
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':
if ($content['lapse_calc'] == 0) {
$value = reporting_get_agentmodule_data_average(
$content['id_agent_module'],
$content['period'],
$report['datetime']
);
break;
}
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%;">';
$return['visual_format'] = $content['visual_format'];
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;">
'.__('Average').'
</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_average($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit.'
</td>
</tr>
</table>';
}
switch ($type) {
case 'max':
$params['force_interval'] = 'max_only';
$value = format_for_graph(reporting_get_agentmodule_data_max($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit;
break;
$value .= '
</td>
<td rowspan="2" width="150px">
</td>
<td rowspan="2">';
if ($content['visual_format'] == 2 || $content['visual_format'] == 3) {
case 'min':
$params['force_interval'] = 'min_only';
$value = format_for_graph(reporting_get_agentmodule_data_min($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit;
break;
case 'avg':
$params['force_interval'] = 'avg_only';
$value .= grafico_modulo_sparse($params);
$value = format_for_graph(reporting_get_agentmodule_data_average($content['id_agent_module'], $content['period'], $report['datetime']), $config['graph_precision']).' '.$unit;
break;
}
$value .= '
$return['data'][] = [
__('Agent') => $agent_name,
__('Module') => $module_name,
__('Maximun') => $value,
];
</td>
</tr>
<tr>
<td>';
if ($content['visual_format'] != 1) {
$graph = grafico_modulo_sparse($params);
$return['data'][] = ['value' => $graph];
}
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 ($content['visual_format'] != 2) {
$time_begin = db_get_row_sql('select utimestamp from tagente_datos where id_agente_modulo ='.$content['id_agent_module'], true);
for ($i = $report['datetime']; $i > ($report['datetime'] - $content['period']); $i -= $content['lapse']) {
$row = [];
$row[__('Lapse')] = date('Y-m-d H:i:s', ($i - $content['lapse'] + 1)).' to '.date('Y-m-d H:i:s', $i);
if ($i > $time_begin['utimestamp']) {
$value .= format_for_graph(
reporting_get_agentmodule_data_average(
$content['id_agent_module'],
$content['lapse'],
$i
),
$config['graph_precision']
).' '.$unit.'</td></tr>';
switch ($type) {
case 'max':
$row[__('Maximun')] = format_for_graph(reporting_get_agentmodule_data_max($content['id_agent_module'], $content['lapse'], $i), $config['graph_precision']).' '.$unit;
break;
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 {
$value .= 'N/A</td></tr>';
$row[__('Maximun')] = 'N/A';
}
$return['data'][] = $row;
}
}
$value .= '</table>';
if ($config['metaconsole']) {
metaconsole_restore_db();
}
$value .= '
</td>
</tr>
</table>';
$formated_value = $value;
return reporting_check_structure_content($return);
}
break;

View File

@ -2784,6 +2784,115 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
$font_size = '3';
}
if (isset($item['visual_format']) && $item['visual_format'] != 0
&& ($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;
case 'min_value':
$table2->head = [
__('Agent'),
__('Module'),
__('Minimun'),
];
break;
case 'avg_value':
$table2->head = [
__('Agent'),
__('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 {
$table->colspan['data']['cell'] = 3;
$table->cellstyle['data']['cell'] = 'text-align: left;';
@ -2798,6 +2907,7 @@ function reporting_html_value(&$table, $item, $mini, $only_value=false, $check_e
}
$table->data['data']['cell'] .= '</p>';
}
}