forked from extern/egroupware
WIP timesheet timers: create a single working time timesheet per configured periode of day, week or month
This commit is contained in:
parent
2dc50f52cc
commit
664bb86b2a
@ -509,30 +509,32 @@ egw.extend('timer', egw.MODULE_GLOBAL, function()
|
||||
// check if overall working time is not disabled
|
||||
if (state.disable.indexOf('overall') === -1)
|
||||
{
|
||||
// check if we should ask on login to start working time
|
||||
this.preference('workingtime_session', 'timesheet', true).then(pref =>
|
||||
// we need to wait that all JS is loaded
|
||||
window.egw_ready.then(() => { window.setTimeout(() =>
|
||||
{
|
||||
if (pref === 'no') return;
|
||||
// check if we should ask on login to start working time
|
||||
this.preference('workingtime_session', 'timesheet', true).then(pref =>
|
||||
{
|
||||
if (pref === 'no') return;
|
||||
|
||||
// overall timer not running, ask to start
|
||||
if (overall && !overall.start)
|
||||
{
|
||||
Et2Dialog.show_dialog((button) => {
|
||||
if (button === Et2Dialog.YES_BUTTON)
|
||||
{
|
||||
timerAction('overall-start');
|
||||
}
|
||||
}, 'Do you want to start your working time?', 'Working time', {}, Et2Dialog.BUTTONS_YES_NO);
|
||||
}
|
||||
// overall timer running for more than 16 hours, ask to stop
|
||||
else if (overall?.start && (((new Date()).valueOf() - overall.start.valueOf()) / 3600000) >= 16)
|
||||
{
|
||||
// gives a JS error, if called direct
|
||||
window.setTimeout(() => {
|
||||
// overall timer not running, ask to start
|
||||
if (overall && !overall.start)
|
||||
{
|
||||
Et2Dialog.show_dialog((button) => {
|
||||
if (button === Et2Dialog.YES_BUTTON)
|
||||
{
|
||||
timerAction('overall-start');
|
||||
}
|
||||
}, 'Do you want to start your working time?', 'Working time', {}, Et2Dialog.BUTTONS_YES_NO);
|
||||
}
|
||||
// overall timer running for more than 16 hours, ask to stop
|
||||
else if (overall?.start && (((new Date()).valueOf() - overall.start.valueOf()) / 3600000) >= 16)
|
||||
{
|
||||
timerDialog(state.disable, 'Forgot to switch off working time?');
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}, 2000)});
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1596,6 +1596,11 @@ class Db
|
||||
{
|
||||
$value = implode($glue,$value);
|
||||
}
|
||||
// timestamp given das DateTime object stored in string column, e.g. in history-log
|
||||
if (is_object($value) && ($value instanceof \DateTime))
|
||||
{
|
||||
$value = DateTime::user2server($value,'string');
|
||||
}
|
||||
// truncate to long strings for varchar(X) columns as PostgreSQL and newer MySQL/MariaDB given an error otherwise
|
||||
if (!is_null($length) && mb_strlen($value) > $length)
|
||||
{
|
||||
|
@ -181,6 +181,7 @@ class timesheet_bo extends Api\Storage
|
||||
{
|
||||
$GLOBALS['timesheet_bo'] =& $this;
|
||||
}
|
||||
$this->user = (int)$GLOBALS['egw_info']['user']['account_id'];
|
||||
$this->grants = $GLOBALS['egw']->acl->get_grants(TIMESHEET_APP);
|
||||
}
|
||||
|
||||
@ -1044,4 +1045,47 @@ class timesheet_bo extends Api\Storage
|
||||
}
|
||||
return parent::data2db($intern ? null : $data); // important to use null, if $intern!
|
||||
}
|
||||
|
||||
/**
|
||||
* Find working time timesheet for given time and confibured period
|
||||
*
|
||||
* @param DateTime $time time to define the periode
|
||||
* @param string &$periode on return "day", "week" or "month"
|
||||
* @param Api\DateTime|null &$start on return start-time of periode
|
||||
* @param Api\DateTime|null &$end on return end-time of periode
|
||||
* @return array|null ts or null, if there is none yet
|
||||
* @throws Api\Exception
|
||||
*/
|
||||
function periodeWorkingTimesheet(DateTime $time, string &$periode=null, Api\DateTime &$start=null, Api\DateTime &$end=null)
|
||||
{
|
||||
$start = new Api\DateTime($time, Api\DateTime::$user_timezone);
|
||||
$start->setTime(0, 0, 0);
|
||||
$end = new Api\DateTime($start);
|
||||
switch($periode = $this->config_data['working_time_period'] ?? 'day')
|
||||
{
|
||||
case 'day':
|
||||
$end->setDate($start->format('Y'), $start->format('m'), 1+$start->format('d'));
|
||||
break;
|
||||
|
||||
case 'week':
|
||||
$start->setWeekstart();
|
||||
$end = new Api\DateTime($start);
|
||||
$end->setDate($start->format('Y'), $start->format('m'), 7+$start->format('d'));
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
$start->setDate($start->format('Y'), $start->format('m'), 1);
|
||||
$end->setDate($start->format('Y'), 1+$start->format('m'), 1);
|
||||
break;
|
||||
}
|
||||
foreach($this->search('', false, 'ts_id DESC', '', '', false, 'AND', [0, 1], [
|
||||
'cat_id' => Events::workingTimeCat(),
|
||||
'ts_owner' => $this->user,
|
||||
'ts_start BETWEEN '.$this->db->quote($start, 'int').' AND '.$this->db->quote($end, 'int'),
|
||||
]) ?? [] as $row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ changed status timesheet de Status geändert
|
||||
check all timesheet de Alle selektieren
|
||||
choose 'creator' of imported data timesheet de Wählen Sie den 'Ersteller' der Importierten Daten.
|
||||
comment by %1 at %2: timesheet de Übertragen von %1 am %2
|
||||
create a single 'working time' timesheet per timesheet de Erstelle einen einzigen 'Arbeitszeit' Stundenzettel pro
|
||||
create new links timesheet de Neue Verknüpfung erstellen
|
||||
creates a new field timesheet de neues Feld anlegen
|
||||
creating new entry timesheet de neuen Eintrag anlegen
|
||||
|
@ -19,6 +19,7 @@ changed status timesheet en Changed status.
|
||||
check all timesheet en Check all
|
||||
choose 'creator' of imported data timesheet en Choose 'creator' of imported data
|
||||
comment by %1 at %2: timesheet en Comment by %1 at %2:
|
||||
create a single 'working time' timesheet per timesheet en Create a single 'Working time' timesheet per
|
||||
create new links timesheet en Create new links
|
||||
creates a new field timesheet en Creates a new field
|
||||
creating new entry timesheet en Creating new entry
|
||||
|
@ -163,6 +163,13 @@ class Events extends Api\Storage\Base
|
||||
throw new Api\Exception\AssertionFailed("No pending overall events!");
|
||||
}
|
||||
$ids = array_keys($events);
|
||||
$bo = new \timesheet_bo();
|
||||
// check if we already have a timesheet for the current periode
|
||||
if (($period_ts = $bo->periodeWorkingTimesheet(reset($events)['tse_time'])))
|
||||
{
|
||||
$events = array_merge(self::get(['ts_id' => $period_ts['ts_id']], $period_total), $events);
|
||||
$time += $period_total;
|
||||
}
|
||||
$start = array_shift($events)['tse_time'];
|
||||
$timespan = Api\DateTime::to($start, true);
|
||||
$last = array_pop($events);
|
||||
@ -171,8 +178,7 @@ class Events extends Api\Storage\Base
|
||||
$timespan .= ' - '.$end;
|
||||
}
|
||||
$title = lang('Working time from %1', $timespan);
|
||||
$bo = new \timesheet_bo();
|
||||
$bo->init();
|
||||
$bo->init($period_ts);
|
||||
$bo->save([
|
||||
'ts_title' => $title,
|
||||
'cat_id' => self::workingTimeCat(),
|
||||
|
@ -53,6 +53,14 @@
|
||||
<option value="overwrite">Overwriting start or stop time</option>
|
||||
</select>
|
||||
</row>
|
||||
<row>
|
||||
<description value="Create a single 'Working time' timesheet per"/>
|
||||
<select id="newsettings[working_time_period]">
|
||||
<option value="day">Day</option>
|
||||
<option value="week">Week</option>
|
||||
<option value="month">Month</option>
|
||||
</select>
|
||||
</row>
|
||||
<row>
|
||||
<description value="Category for 'Working time'"/>
|
||||
<select-cat empty_label="Will be created when saving ..." id="newsettings[working_time_cat]"/>
|
||||
|
Loading…
Reference in New Issue
Block a user