Calendar category report:

- Fix calendar category report not summarizing values
- Add select all checkbox
This commit is contained in:
Hadi Nategh 2016-11-14 12:55:18 +01:00
parent bbb7dbac0e
commit 847352a62c
4 changed files with 40 additions and 42 deletions

View File

@ -214,9 +214,9 @@ class calendar_category_report extends calendar_ui{
{
foreach ($event as $e)
{
$days_output[$user_id][$cat_id][$e['event_id']]['days'] =
$days_output[$user_id][$cat_id][$e['event_id']]['days'] + (int)$e['amount'];
$days_output[$user_id][$cat_id][$e['event_id']]['unit'] = $e['unit'];
$days_output[$user_id][$cat_id]['amount'] =
$days_output[$user_id][$cat_id]['amount'] + (int)$e['amount'];
$days_output[$user_id][$cat_id]['unit'] = $e['unit'];
}
}
}
@ -233,8 +233,8 @@ class calendar_category_report extends calendar_ui{
if ($event_id !== 'min_days')
{
$days = $weeks_sum[$user_id][$week_id][$cat_id][$event_id];
$min_days_output[$user_id][$cat_id][$event_id]['days'] =
$min_days_output[$user_id][$cat_id][$event_id]['days'] +
$min_days_output[$user_id][$cat_id]['amount'] =
$min_days_output[$user_id][$cat_id]['amount'] +
(count($days) >= (int)$events['min_days']?self::add_days($days):0);
}
}
@ -245,14 +245,13 @@ class calendar_category_report extends calendar_ui{
// Replace value of those cats who have min_days set on with regular day calculation
// result array structure:
// [user_ids] =>
// [cat_ids] =>
// [event_ids] => [
// [cat_ids] => [
// days: amount of event in second,
// unit: unit to be shown as output (in second, eg. 3600)
// ]
//
$result = array_replace_recursive($days_output, $min_days_output);
$csv_header = $csv_raw_rows = array ();
$csv_header = array ();
// create csv header
foreach ($categories as $cat_id)
@ -264,26 +263,6 @@ class calendar_category_report extends calendar_ui{
// file pointer
$fp = fopen('php://output', 'w');
// sort out events and categories
foreach ($result as $user_id => $userData)
{
foreach ($userData as $cat_id => $events)
{
foreach ($events as $event_id => $values)
{
$eid = $event_id;
$r = array();
foreach ($userData as $c_id => &$e)
{
if (!$e) continue;
$top = array_shift($e);
$r[$eid][$c_id] = ceil($top['days']? $top['days'] / $top['unit']: 0);
}
if ($r) $csv_raw_rows[$user_id][] = $r;
}
}
}
// printout csv header into file
fputcsv($fp, array_values($csv_header));
@ -293,20 +272,16 @@ class calendar_category_report extends calendar_ui{
header('Content-Disposition: attachment; filename="report.csv"');
// iterate over csv rows for each user to print them out into csv file
foreach ($result as $user_id => $userData)
{
foreach ($csv_raw_rows[$user_id] as &$raw_row)
foreach ($result as $user_id => $cats_data)
{
$cats_row = array();
$raw_row = array_shift($raw_row);
foreach ($categories as $cat_id)
{
$cats_row [$cat_id] = $raw_row[$cat_id]?$raw_row[$cat_id]:0;
$cats_row [$cat_id] = ceil($cats_data[$cat_id]['amount']? $cats_data[$cat_id]['amount'] / $cats_data[$cat_id]['unit']: 0);
}
// printout each row into file
fputcsv($fp, array_values(array(Api\Accounts::id2name($user_id, 'account_fullname')) + $cats_row));
}
}
// echo out csv file
fpassthru($fp);
exit();

View File

@ -526,7 +526,7 @@ class calendar_ui
}
display_sidebox('calendar', lang('Utilities'), array('Category report' => "javascript:egw_openWindowCentered2('".
Egw::link('/index.php',array('menuaction'=>'calendar.calendar_category_report.index','ajax'=>true),false).
"','_blank',870,610,'yes')" ));
"','_blank',870,500,'yes')" ));
}
/**

View File

@ -3751,7 +3751,7 @@ app.classes.calendar = (function(){ "use strict"; return AppJS.extend(
var content = this.et2.getArrayMgr('content').data;
for (var i=1;i<content.grid.length;i++)
{
if (content.grid[i] != null) this.category_report_enable({name:i+'', checked:content.grid[i]['enable']});
if (content.grid[i] != null) this.category_report_enable({id:i+'', checked:content.grid[i]['enable']});
}
},
@ -3764,7 +3764,7 @@ app.classes.calendar = (function(){ "use strict"; return AppJS.extend(
category_report_enable: function (_widget)
{
var widgets = ['[user]','[weekend]','[holidays]','[min_days]'];
var row_id = _widget.name.match(/\d+/);
var row_id = _widget.id.match(/\d+/);
var w = {};
for (var i=0;i<widgets.length;i++)
{
@ -3779,6 +3779,29 @@ app.classes.calendar = (function(){ "use strict"; return AppJS.extend(
category_report_submit: function ()
{
this.et2._inst.postSubmit();
},
/**
* Function to enable/disable categories
*
* @param {object} _widget select all checkbox
*/
category_report_selectAll: function (_widget)
{
var content = this.et2.getArrayMgr('content').data;
var checkbox = {};
for (var i=1;i<content.grid.length;i++)
{
if (content.grid[i] != null)
{
checkbox = this.et2.getWidgetById(i+'[enable]');
if (checkbox)
{
checkbox.set_value(_widget.checked);
this.category_report_enable({id:checkbox.id, checked:checkbox.get_value()});
}
}
}
}
});}).call(this);

View File

@ -34,7 +34,7 @@ Egroupware
</columns>
<rows>
<row class="th">
<description value="Select"/>
<checkbox id="cat_all" label="Select" onchange="app.calendar.category_report_selectAll"/>
<description value="Category"/>
<description align="center" statustext="Exclude weekend events from counting" value="Exclude Weekend"/>
<description align="center" statustext="Include holidays as counting days" value="Holidays"/>