Skip to content

Commit

Permalink
feat: HR Setting to enable geolocation tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed May 7, 2024
1 parent 405f469 commit 74eeb3e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 39 deletions.
53 changes: 31 additions & 22 deletions frontend/src/components/CheckInPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
Hey, {{ employee?.data?.first_name }} 👋
</h2>

<template v-if="allowCheckinFromMobile.data">
<template v-if="HRSettings.doc?.allow_employee_checkin_from_mobile_app">
<div class="font-medium text-sm text-gray-500 mt-1.5" v-if="lastLog">
Last {{ lastLogType }} was at {{ lastLogTime }}
</div>
<Button
class="mt-4 mb-1 drop-shadow-sm py-5 text-base"
id="open-checkin-modal"
@click="fetchLocation"
@click="handleEmployeeCheckin"
>
<template #prefix>
<FeatherIcon
Expand All @@ -32,6 +32,7 @@
</div>

<ion-modal
v-if="HRSettings.doc?.allow_employee_checkin_from_mobile_app"
ref="modal"
trigger="open-checkin-modal"
:initial-breakpoint="1"
Expand All @@ -49,25 +50,27 @@
</div>
</div>

<span v-if="locationStatus" class="font-medium text-gray-500 text-sm">
{{ locationStatus }}
</span>
<template v-if="HRSettings.doc?.allow_geolocation_tracking">
<span v-if="locationStatus" class="font-medium text-gray-500 text-sm">
{{ locationStatus }}
</span>

<div
class="rounded border-4 translate-z-0 block overflow-hidden w-full h-170"
>
<iframe
width="100%"
height="170"
frameborder="0"
scrolling="no"
marginheight="0"
marginwidth="0"
style="border: 0"
:src="`https://maps.google.com/maps?q=${latitude},${longitude}&hl=en&z=15&amp;output=embed`"
<div
class="rounded border-4 translate-z-0 block overflow-hidden w-full h-170"
>
</iframe>
</div>
<iframe
width="100%"
height="170"
frameborder="0"
scrolling="no"
marginheight="0"
marginwidth="0"
style="border: 0"
:src="`https://maps.google.com/maps?q=${latitude},${longitude}&hl=en&z=15&amp;output=embed`"
>
</iframe>
</div>
</template>

<Button
variant="solid"
Expand All @@ -84,7 +87,7 @@
import { createListResource, toast, FeatherIcon } from "frappe-ui"
import { computed, inject, ref, onMounted, onBeforeUnmount } from "vue"
import { IonModal, modalController } from "@ionic/vue"
import { allowCheckinFromMobile } from "@/data/settings"
import { HRSettings } from "@/data/HRSettings"

const DOCTYPE = "Employee Checkin"

Expand Down Expand Up @@ -156,8 +159,6 @@ function handleLocationError(error) {
}

const fetchLocation = () => {
checkinTimestamp.value = dayjs().format("YYYY-MM-DD HH:mm:ss")

if (!navigator.geolocation) {
locationStatus.value =
"Geolocation is not supported by your current browser"
Expand All @@ -170,6 +171,14 @@ const fetchLocation = () => {
}
}

const handleEmployeeCheckin = () => {
checkinTimestamp.value = dayjs().format("YYYY-MM-DD HH:mm:ss")

if (HRSettings.doc?.allow_geolocation_tracking) {
fetchLocation()
}
}

const submitLog = (logType) => {
const action = logType === "IN" ? "Check-in" : "Check-out"

Expand Down
7 changes: 7 additions & 0 deletions frontend/src/data/HRSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createDocumentResource } from "frappe-ui"

export const HRSettings = createDocumentResource({
doctype: "HR Settings",
name: "HR Settings",
auto: true,
})
6 changes: 0 additions & 6 deletions frontend/src/data/settings.js

This file was deleted.

6 changes: 0 additions & 6 deletions hrms/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from frappe.model.workflow import get_workflow_name
from frappe.query_builder import Order
from frappe.utils import getdate
from frappe.utils.data import cint

SUPPORTED_FIELD_TYPES = [
"Link",
Expand Down Expand Up @@ -637,8 +636,3 @@ def get_allowed_states_for_workflow(workflow: dict, user_id: str) -> list[str]:
return [
transition.state for transition in workflow.transitions if transition.allowed in user_roles
]


@frappe.whitelist()
def is_employee_checkin_allowed():
return cint(frappe.db.get_single_value("HR Settings", "allow_employee_checkin_from_mobile_app"))
21 changes: 16 additions & 5 deletions hrms/hr/doctype/hr_settings/hr_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@
"exit_questionnaire_web_form",
"column_break_34",
"exit_questionnaire_notification_template",
"mobile_settings_section",
"allow_employee_checkin_from_mobile_app"
"attendance_settings_section",
"allow_employee_checkin_from_mobile_app",
"allow_geolocation_tracking"
],
"fields": [
{
Expand Down Expand Up @@ -306,16 +307,22 @@
"label": "Allow Employee Checkin from Mobile App"
},
{
"fieldname": "mobile_settings_section",
"default": "0",
"fieldname": "allow_geolocation_tracking",
"fieldtype": "Check",
"label": "Allow Geolocation Tracking"
},
{
"fieldname": "attendance_settings_section",
"fieldtype": "Section Break",
"label": "Mobile Settings"
"label": "Attendance Settings"
}
],
"icon": "fa fa-cog",
"idx": 1,
"issingle": 1,
"links": [],
"modified": "2024-04-10 14:25:29.958973",
"modified": "2024-05-08 00:40:32.809157",
"modified_by": "Administrator",
"module": "HR",
"name": "HR Settings",
Expand All @@ -329,6 +336,10 @@
"role": "System Manager",
"share": 1,
"write": 1
},
{
"read": 1,
"role": "Employee"
}
],
"sort_field": "creation",
Expand Down

0 comments on commit 74eeb3e

Please sign in to comment.