Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(HumanResources): have attendanceRecorder clock in users(server) Time
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusweiss committed Feb 14, 2023
1 parent 6233544 commit 4aa665c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions tine20/HumanResources/Frontend/Json.php
Expand Up @@ -727,6 +727,7 @@ public function getAttendanceRecorderDeviceStates()
$openRecords['results'][] = $lastRecord;
}
$openRecords['totalcount'] = count($openRecords['results']);
$openRecords['currentTime'] = Tinebase_DateTime::now()->setTimezone(Tinebase_Core::getUserTimezone())->format(Tinebase_Record_Abstract::ISO8601LONG);

return $openRecords;
}
Expand Down
15 changes: 11 additions & 4 deletions tine20/HumanResources/js/AttendanceRecorder.js
Expand Up @@ -69,6 +69,7 @@ const attendanceRecorder = Ext.extend(Ext.Button, {
// properties
ptAllowPause: true,
ptAllowMultiStart: true,
currentTimeDiff: 0,

initComponent() {
const me = this;
Expand Down Expand Up @@ -219,7 +220,7 @@ const attendanceRecorder = Ext.extend(Ext.Button, {
time: a.time + (record[FLD_TYPE] !== TYPE_CLOCK_IN ? Date.parseDate(record[FLD_TIMESTAMP], Date.patterns.ISO8601Long).getTime() - Date.parseDate(lastClockIn, Date.patterns.ISO8601Long).getTime() : 0)
});
}, {time: 0, lastClockIn: 0});
const duration = time + (type === TYPE_CLOCK_IN ? (new Date().getTime() - Date.parseDate(lastClockIn, Date.patterns.ISO8601Long).getTime()) : 0);
const duration = time + (type === TYPE_CLOCK_IN ? (this.getServerDate().getTime() - Date.parseDate(lastClockIn, Date.patterns.ISO8601Long).getTime()) : 0);

window.setTimeout(() => {
me.menu.timeAccountPickerGrid.view.refresh()
Expand Down Expand Up @@ -247,7 +248,7 @@ const attendanceRecorder = Ext.extend(Ext.Button, {
return !((x>box.x && x<box.x+box.width && y>box.y && y<box.y+box.height)
|| Ext.EventObject.getTarget('.x-combo-selected'));
}, this);
this.menu.on('render', () => {
this.menu.on('render', async () => {
this.menu.mon(this.menu.el, { 'click': this.onMenuClick, scope: this });

this.resizer = new Ext.Resizable(this.menu.el, {
Expand Down Expand Up @@ -303,7 +304,9 @@ const attendanceRecorder = Ext.extend(Ext.Button, {

async applyDeviceStates() {
this.autoRefreshTask.delay(this.autoRefreshInterval * 1000);
const { results: deviceRecords } = await Tine.HumanResources.getAttendanceRecorderDeviceStates();
const { results: deviceRecords, currentTime } = await Tine.HumanResources.getAttendanceRecorderDeviceStates();

this.currentTimeDiff = Date.parseDate(currentTime, Date.patterns.ISO8601Long).getTime() - new Date().getTime();

const wtDeviceRecord = _.findLast(deviceRecords, {
[FLD_STATUS]: STATUS_OPEN,
Expand Down Expand Up @@ -371,6 +374,10 @@ const attendanceRecorder = Ext.extend(Ext.Button, {
this.el.addClass(`attendance-clock-menu-button-${this.wtType}`);
},

getServerDate() {
return new Date().add(Date.MILLI, this.currentTimeDiff);
},

async onWTClock(fn, options, btn) {
_.defer(_.bind(btn.setDisabled, btn, true))
this.sounds.shortbeep.play();
Expand Down Expand Up @@ -503,7 +510,7 @@ const attendanceRecorder = Ext.extend(Ext.Button, {
},

showClock() {
const date = new Date();
const date = this.getServerDate();
let wtStatus = this.wtType === TYPE_CLOCK_PAUSED ? `${this.app.i18n._('Away')}: ${this.app.i18n._hidden(this.freeTimeType.name)}` : (this.wtType === TYPE_CLOCK_IN ? this.app.i18n._('Clocked-in') : this.app.i18n._('Clocked-out'));
this.menu.displayPanel.update(`
<div class="attendance-clock-status">${wtStatus}</div>
Expand Down

0 comments on commit 4aa665c

Please sign in to comment.