W.I.P of holiday report for calendar app

This commit is contained in:
Hadi Nategh 2016-10-31 17:32:47 +01:00
parent 96b39eefe6
commit 6a035feb6f
4 changed files with 126 additions and 12 deletions

View File

@ -26,11 +26,11 @@ use EGroupware\Api\Etemplate;
* days/ or weeks.
*
*/
class calendar_holiday_report {
class calendar_holiday_report extends calendar_ui{
/**
* Public functions allowed to get called
*
*
* @var type
*/
var $public_functions = array(
@ -42,8 +42,8 @@ class calendar_holiday_report {
*/
function __construct()
{
$this->bo = new calendar_bo();
$this->tmpl = new Etemplate('calendar.holiday_report');
parent::__construct(true); // call the parent's constructor
$this->tmpl = new Api\Etemplate('calendar.holiday_report');
}
/**
@ -53,9 +53,9 @@ class calendar_holiday_report {
*/
public function index ($content = null)
{
$cat = new Api\Categories($GLOBALS['egw_info']['user']['account_id'],'calendar');
if (is_null($content))
{
$cat = new Api\Categories($GLOBALS['egw_info']['user']['account_id'],'calendar');
$cats = $cat->return_sorted_array($start=0, false, '', 'ASC', 'cat_name', true, 0, true);
foreach ($cats as &$value)
@ -65,15 +65,80 @@ class calendar_holiday_report {
'user' => '',
'weekend' => '',
'holidays' => '',
'min_days' => 4
'min_days' => 4,
'enable' => true
);
}
}
else
{
list($button) = @each($content['button']);
$categories = array ();
$users_map = $GLOBALS['egw']->accounts->search(array('type'=>'accounts', active=>true));
$users = array_keys($users_map);
$result = array();
// report button pressed
if (!empty($button))
{
Api\Preferences::change_preference($content, $name, $value);
foreach ($content['grid'] as $row)
{
if ($row['enable'])
{
$categories [] = $row['cat_id'];
}
}
$params = array(
'startdate' => $content['start'],
'enddate' => $content['end'],
'users' => $users,
'cat_id' => $categories
);
$events = $this->bo->search($params);
// iterate over found events
foreach($events as $event)
{
$cats = explode(',',$event['category']);
if (is_array($cats))
{
foreach($cats as $val)
{
if (in_array($val, $categories)) $cat_index = (int)$val;
}
}
$result [$event['owner']]['user_name'] = $users_map[$event['owner']]['account_lid'];
// number of days of event (in sec)
$days = $event['end'] - $event['start'];
if (isset($result[$event['owner']][$cat->id2name($cat_index)]))
{
$result[$event['owner']][$cat->id2name($cat_index)] =
$result[$event['owner']][$cat->id2name($cat_index)] + $days;
}
else
{
$result[$event['owner']][$cat->id2name($cat_index)] = $days;
}
}
// calculates total days for each user based on cats
foreach ($result as &$record)
{
$total = 0;
foreach($record as $c => $value)
{
if ($c != 'user_name') $total += (int)$value;
}
$record ['total_days'] = $total;
}
}
}
$this->tmpl->exec('calendar.holiday_report', $content);
$preserv = $content;
$this->tmpl->exec('calendar.calendar_holiday_report.index', $content, array(), array(), $preserv, 2);
}
}

View File

@ -524,7 +524,7 @@ class calendar_ui
);
$GLOBALS['egw']->framework->sidebox($appname,lang('Admin'),$file,'admin');
}
display_sidebox('calendar', lang('Utilities'), array('Holiday report' => Egw::link('/index.php','menuaction=calendar.calendar_holiday_report.index')));
display_sidebox('calendar', lang('Utilities'), array('Holiday report' => Egw::link('/index.php','menuaction=calendar.calendar_holiday_report.index&appname=calendar&ajax=true')));
}
/**

View File

@ -247,6 +247,9 @@ app.classes.calendar = (function(){ "use strict"; return AppJS.extend(
this.filter_change();
},this),0);
break;
case 'calendar.holiday_report':
this.holiday_report_init();
break;
}
// Record the templates for the views so we can switch between them
@ -3736,6 +3739,49 @@ app.classes.calendar = (function(){ "use strict"; return AppJS.extend(
d.setUTCDate(d.getUTCDate() + (7 * delta));
return d;
}
},
/**
* Initialization function in order to set/unset
* categories status.
*
*/
holiday_report_init: function ()
{
var content = this.et2.getArrayMgr('content').data;
for (var i=0;i<content.grid.length;i++)
{
if (content.grid[i] != null) this.holiday_report_enable({name:i+'', checked:content.grid[i]['enable']});
}
},
/**
* Set/unset selected category's row
*
* @param {type} _widget
* @returns {undefined}
*/
holiday_report_enable: function (_widget)
{
var widgets = ['[user]','[weekend]','[holidays]','[min_days]'];
var row_id = _widget.name.match(/\d+/);
var w = {};
for (var i=0;i<widgets.length;i++)
{
w = this.et2.getWidgetById(row_id+widgets[i]);
if (w) w.set_readonly(!_widget.checked);
}
},
/**
*
* @param {type} _widget
* @returns {undefined}
*/
holiday_report_send: function (_widget)
{
var content = this.et2.getArrayMgr('content').data;
egw.set_preference('calendar','holiday_report',JSON.stringify(content.grid));
this.et2._inst.submit(_widget);
}
});}).call(this);

View File

@ -30,9 +30,11 @@ Egroupware
<column/>
<column/>
<column/>
<column/>
</columns>
<rows>
<row class="th">
<description value="Select"/>
<description value="Category"/>
<description align="center" value="User"/>
<description align="center" value="Weekend"/>
@ -40,8 +42,9 @@ Egroupware
<description align="center" value="Min days as week"/>
</row>
<row class="row">
<checkbox id="${row}[enable]" onchange="app.calendar.holiday_report_enable"/>
<taglist-cat id="${row}[cat_id]" readonly="true" width="500" class="select-cat"/>
<checkbox align="center" id="${row}[user]"/>
<checkbox align="center" id="${row}[user]" disable="false"/>
<checkbox align="center" id="${row}[weekend]"/>
<checkbox align="center" id="${row}[holidays]"/>
<number type="integer" align="center" id="${row}[min_days]"/>
@ -52,10 +55,10 @@ Egroupware
</rows>
</grid>
<hbox class="dialogFooterToolbar">
<description value="Range"/>
<description value="Date range"/>
<date id="start" label="Start"/>
<date id="end" label="End"/>
<button id="report" label="Report"/>
<button id="button[report]" label="Report" background_image="1" image="template" onclick="app.calendar.holiday_report_send" />
</hbox>
</template>
</overlay>