WIP timesheet timer: storing working time now w/o user interation when it is stopped

This commit is contained in:
ralf 2022-10-03 10:01:28 +02:00
parent 4416198973
commit 7dc781acd5
4 changed files with 135 additions and 3 deletions

View File

@ -10,7 +10,9 @@ applies the changes timesheet de Änderungen durchführen
apply the action on the whole query, not only the shown timesheets!!! timesheet de Wendet den Befehl auf die gesamte Abfrage an, NICHT nur die angezeigten Stundenzettel!!
both: allow to use projectmanager and free project-names admin de Beides: verwende Projektmanager und freie Projektnamen
by timesheet de von
category for 'working time' admin de Kategorie für 'Arbeitszeit'
change category timesheet de Kategorie ändern
change owner when updating timesheet de Ändere Eigentümer beim aktualisieren
changed category to %1 timesheet de Kategorie geändert zu %1
changed status timesheet de Status geändert
check all timesheet de Alle selektieren
@ -35,6 +37,7 @@ entry deleted timesheet de Eintrag gelöscht
entry saved timesheet de Eintrag gespeichert
error deleting the entry!!! timesheet de Fehler beim Löschen des Eintrags!!!
error saving the entry!!! timesheet de Fehler beim Speichern des Eintrags!!!
events timesheet de Ereignisse
example {{if n_prefix~mr~hello mr.~hello ms.}} - search the field "n_prefix", for "mr", if found, write hello mr., else write hello ms. timesheet de Beispiel: {{IF n_prefix~Herr~sehr geehrter Herr~sehr geehrte Frau}} - wenn im Feld 'n_prefix' 'Herr' steht wird 'sehr geehrter Herr' geschrieben, ansonsten 'sehr geehrte Frau'.
example {{letterprefixcustom n_prefix title n_family}} - example: mr dr. james miller timesheet de Beispiel: {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Herr Dr. Müller
example {{nelf role}} - if field role is not empty, you will get a new line with the value of field role timesheet de Beispiel: {{NELF role}} - wenn das Feld 'role' nicht leer ist wird der Inhalt des Feldes in eine neue Zeile geschrieben
@ -75,7 +78,9 @@ links timesheet de Verknüpfungen
links and attached files timesheet de Verknüpfungen und angehangene Dateien
links to specified application. example: {{links/infolog}} timesheet de Verknüpfung zu Anwendungen. Beispiel: {{links/infolog}}
list of files linked to the current record timesheet de Liste der zum aktuellen Eintrag verknüpften Dateien.
manage mapping timesheet de Zuordnungen verwalten
max length of the input [, length of the inputfield (optional)] timesheet de maximale Länge der Eingabe[,Länge des Eingabefeldes (optional)]
mode timesheet de Modus
modified timesheet de Geändert
modify status timesheet de Status ändern
name of current user, all other contact fields are valid too timesheet de Name des aktuellen Benutzers, all anderen Kontaktfelder sind weiterhin gültig.
@ -100,6 +105,7 @@ projectmanager integration admin de Integration des Projektmanagers
quantity timesheet de Menge
recovered timesheet de wiederhergestellt
replacements for inserting entries into documents timesheet de Platzhalter für das Einfügen in Dokumente
restore this entry timesheet de Diesen Eintrag wiederherstellen
save & new timesheet de Speichern & Neu
saves the changes made timesheet de Speichert die Änderungen
saves the changes made and leaves timesheet de Änderungen speichern und beenden
@ -115,6 +121,7 @@ set to timesheet de Änderungen anwenden für
show a quantity sum (eg. to sum up negative overtime) admin de Zeige eine Mengensumme (z.B. um negative Überstunden zu summieren)
skip record timesheet de Eintrag überspringen
start timesheet de Start
start & stop timer common de Zeitnehmer starten & stoppen
starttime timesheet de Startzeit
starttime has to be before endtime !!! timesheet de Startzeit muss vor der Endzeit liegen !!!
status timesheet de Status
@ -144,12 +151,18 @@ timesheet-%1 '%2' updated. timesheet de Stundenzettel Status %1 '%2' geändert
timesheet-%1 deleted. timesheet de Stundenzettel %1 gelöscht
titles of any entries linked to the current record, excluding attached files timesheet de Titel der zum aktuellen Eintrag verknüpften Einträge, ausgenommen angehangene Dateien.
unable to convert "%1" to account id. using plugin setting (%2) for %3. timesheet de Das System konnte "%1" nicht in die Benutzer-ID umwandeln. Verwenden Sie besser die Einstellung (%2) für %3.
undelete timesheet de Wiederherstellen
unitprice timesheet de Preis pro Einheit
use field from csv if possible timesheet de Benutze Feld vom CSV, wenn möglich
use this tag for addresslabels. put the content, you want to repeat, between two tags. timesheet de Verwenden Sie diesen Platzhalter für den den Seriendruck. Fügen Sie den Inhalt, der wiederholt werden soll, zwischen zwei Platzhaltern ein.
values for selectbox timesheet de Werte der Auswahlbox
view this entry timesheet de Diesen Eintrag anzeigen
week timesheet de Woche
what should be done with unknown values? timesheet de Was soll mit unbekannten Werte passieren?
when you merge entries into documents, they will be stored here. if no directory is provided, they will be stored in your home directory (/home/ralf) timesheet de Wenn Sie Einträge in Dokumente einfügen, werden diese hier gespeichert. Wenn kein Verzeichnis angegeben ist, werden sie in Ihrem Home Verzeichnis gespeichert.
will be created when saving ... common de Wird beim Speichern angelegt ...
working time common de Arbeitszeit
yes, only admins can purge deleted items admin de Ja, nur Administratoren dürfen gelöschte Einträge endgültig löschen
yes, users can purge their deleted items admin de Ja, Benutzer dürfen ihre gelöschten Einträge endgültig löschen
yesterday timesheet de Gestern
your database is not up to date (%1 vs. %2), please run %3setup%4 to update your database. timesheet de Ihre Datenbank ist NICHT aktuell (%1 statt %2), bitte rufen sie %3setup%4 auf um die Datenbank zu aktualisieren.
your database is not up to date (%1 vs. %2), please run %3setup%4 to update your database. timesheet de Ihre Datenbank ist NICHT aktuell (%1 statt %2), bitte rufen sie %3setup%4 auf um die Datenbank zu aktualisieren.

View File

@ -10,7 +10,9 @@ applies the changes timesheet en Applies the changes
apply the action on the whole query, not only the shown timesheets!!! timesheet en Apply the action on the whole query, NOT only the shown timesheets!
both: allow to use projectmanager and free project-names admin en Both: allow to use Project Manager and free project names
by timesheet en by
category for 'working time' admin en Category for 'Working time'
change category timesheet en Change category
change owner when updating timesheet en Change owner when updating
changed category to %1 timesheet en Changed category to %1
changed status timesheet en Changed status.
check all timesheet en Check all
@ -35,6 +37,7 @@ entry deleted timesheet en Entry deleted.
entry saved timesheet en Entry saved.
error deleting the entry!!! timesheet en Error deleting the entry!
error saving the entry!!! timesheet en Error saving the entry!
events timesheet en Events
example {{if n_prefix~mr~hello mr.~hello ms.}} - search the field "n_prefix", for "mr", if found, write hello mr., else write hello ms. timesheet en Example {{IF n_prefix~Mr~Hello Mr.~Hello Ms.}} - search the field "n_prefix", for "Mr", if found, write Hello Mr., else write Hello Ms.
example {{letterprefixcustom n_prefix title n_family}} - example: mr dr. james miller timesheet en Example {{LETTERPREFIXCUSTOM n_prefix title n_family}} - Example: Mr Dr. James Miller
example {{nelf role}} - if field role is not empty, you will get a new line with the value of field role timesheet en Example {{NELF role}} - if field role is not empty, you will get a new line with the value of field role
@ -75,7 +78,9 @@ links timesheet en Links
links and attached files timesheet en Links and attached files
links to specified application. example: {{links/infolog}} timesheet en Links to specified application. Example: {{links/infolog}}
list of files linked to the current record timesheet en List of files linked to the current record
manage mapping timesheet en Manage mapping
max length of the input [, length of the inputfield (optional)] timesheet en Max length of the input [, length of the input field (optional)]
mode timesheet en Mode
modified timesheet en Modified
modify status timesheet en Modify status
name of current user, all other contact fields are valid too timesheet en Name of current user, all other contact fields are valid too
@ -100,6 +105,7 @@ projectmanager integration admin en Project Manager integration
quantity timesheet en Quantity
recovered timesheet en recovered
replacements for inserting entries into documents timesheet en Replacements for inserting entries into documents
restore this entry timesheet en Restore this entry
save & new timesheet en Save & New
saves the changes made timesheet en Saves the changes made
saves the changes made and leaves timesheet en Saves the changes made and leaves
@ -115,6 +121,7 @@ set to timesheet en Set to
show a quantity sum (eg. to sum up negative overtime) admin en Show a quantity sum e.g. to sum up negative overtime
skip record timesheet en Skip record
start timesheet en Start
start & stop timer common en Start & stop timer
starttime timesheet en Start time
starttime has to be before endtime !!! timesheet en Start time has to be before endtime!
status timesheet en Status
@ -144,12 +151,18 @@ timesheet-%1 '%2' updated. timesheet en TimeSheet-%1 '%2' updated.
timesheet-%1 deleted. timesheet en TimeSheet-%1 deleted.
titles of any entries linked to the current record, excluding attached files timesheet en Titles of any entries linked to the current record, excluding attached files
unable to convert "%1" to account id. using plugin setting (%2) for %3. timesheet en Unable to convert "%1" to account ID. Using plugin setting (%2) for %3.
undelete timesheet en Undelete
unitprice timesheet en Unit price
use field from csv if possible timesheet en Use field from CSV if possible
use this tag for addresslabels. put the content, you want to repeat, between two tags. timesheet en Use this tag for address labels. Put the content, you want to repeat, between two tags.
values for selectbox timesheet en Values for select box
view this entry timesheet en View this entry
week timesheet en Week
what should be done with unknown values? timesheet en What should be done with unknown values?
when you merge entries into documents, they will be stored here. if no directory is provided, they will be stored in your home directory (/home/ralf) timesheet en When you merge entries into documents, they will be stored here. If no directory is provided, they will be stored in your home directory (/home/ralf)
will be created when saving ... common en Will be created when saving ...
working time common en Working time
yes, only admins can purge deleted items admin en Yes, only admins can purge deleted items
yes, users can purge their deleted items admin en Yes, users can purge their deleted items
yesterday timesheet en Yesterday
your database is not up to date (%1 vs. %2), please run %3setup%4 to update your database. timesheet en Your database is NOT up to date (%1 vs. %2), please run %3setup%4 to update.
your database is not up to date (%1 vs. %2), please run %3setup%4 to update your database. timesheet en Your database is NOT up to date (%1 vs. %2), please run %3setup%4 to update.

View File

@ -100,6 +100,56 @@ class Events extends Api\Storage\Base
'tse_modifier' => $this->user,
'tse_type' => $type,
]);
// create timesheet for stopped working time
if ($timer === 'overall' && $action === 'stop')
{
try {
$minutes = $this->storeWorkingTime();
Api\Json\Response::get()->message(lang('Working time of %1 hours stored',
sprintf('%d:%02d', intdiv($minutes, 60), $minutes % 60)), 'success');
}
catch(\Exception $e) {
Api\Json\Response::get()->message(lang('Error storing working time').': '.$e->getMessage(), 'error');
}
}
}
/**
* Store pending overall timer events as a working time timesheet
*
* @return int minutes
*/
public function storeWorkingTime()
{
if (!($events = self::getPending(true, $time)) || !$time)
{
throw new Api\Exception\AssertionFailed("No pending overall events!");
}
$ids = array_keys($events);
$start = array_shift($events)['tse_time'];
$timespan = Api\DateTime::to($start, true);
$last = array_pop($events);
if ($timespan !== ($end = Api\DateTime::to($last['tse_time'], true)))
{
$timespan .= ' - '.$end;
}
$title = lang('Working time from %1', $timespan);
$bo = new \timesheet_bo();
$bo->init();
$bo->save([
'ts_title' => $title,
'cat_id' => self::workingTimeCat(),
'ts_start' => $start,
'start_time' => Api\DateTime::server2user($start, 'H:s'),
'end_time' => '',
'ts_duration' => $minutes = round($time / 60),
'ts_quantity' => $minutes / 60.0,
'ts_owner' => $this->user,
]);
self::addToTimesheet($bo->data['ts_id'], $ids);
return $minutes;
}
public static function timerState()
@ -201,6 +251,10 @@ class Events extends Api\Storage\Base
$timer = $init_timer;
$open = 0;
}
elseif ($row['tse_type'] & self::PAUSE)
{
$row['total'] = $time + $timer['offset'] / 1000;
}
$events[$row['tse_id']] = $row;
}
// remove open / unstopped timer events
@ -241,4 +295,49 @@ class Events extends Api\Storage\Base
{
return self::getInstance()->db->update(self::TABLE, ['ts_id' => $ts_id], ['tse_id' => $events], __LINE__, __FILE__, self::APP);
}
/**
* Register site config validation hooks
*/
public static function config_validate()
{
$GLOBALS['egw_info']['server']['found_validation_hook'] = [
'final_validation' => self::class.'::final_validation',
];
}
/**
* Final validation called after storing the config
*
* @param array $config
* @param Api\Config $c
*/
public static function final_validation($config, Api\Config $c)
{
// check if category for 'working time' is configured, otherwise create and store it
if ($config['working_time_cat'] === '')
{
$c->config_data['working_time_cat'] = self::workingTimeCat();
}
}
/**
* Get working time category, create it if not yet configured
*
* @return int
*/
public static function workingTimeCat()
{
$config = Api\Config::read(self::APP);
if (empty($config['working_time_cat']))
{
$cats = new Api\Categories(Api\Categories::GLOBAL_ACCOUNT, Api\Categories::GLOBAL_APPNAME);
Api\Config::save_value('working_time_cat', $config['working_time_cat'] = $cats->add([
'name' => lang('Working time'),
//'data' => ['color' => '#ffb6c1'],
'description' => lang('Created by TimeSheet configuration'),
]), self::APP);
}
return $config['working_time_cat'];
}
}

View File

@ -42,7 +42,14 @@
<option value="userpurge">Yes, users can purge their deleted items</option>
</select>
</row>
<row>
<description value="Working time" span="all" class="subHeader"/>
</row>
<row>
<description value="Category for 'Working time'"/>
<select-cat empty_label="Will be created when saving ..." id="newsettings[working_time_cat]"/>
</row>
</rows>
</grid>
</template>
</overlay>
</overlay>