Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"vue": "^3.2.25",
"vue-router": "^4.0.12",
"autoprefixer": "^10.4.2",
"postcss": "^8.4.5",
"postcss": "^8.4.31",
"tailwindcss": "^3.0.15",
"vite": "^5.1.4",
"vite-plugin-pwa": "^0.19.0",
Expand Down
61 changes: 60 additions & 1 deletion frontend/src/components/CheckInPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,29 @@
<div class="font-medium text-sm text-gray-500 mt-1.5" v-if="lastLog">
Last {{ lastLogType }} was at {{ lastLogTime }}
</div>

<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-350 h-170">
<iframe
width="350"
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>

<Button
class="mt-4 mb-1 drop-shadow-sm py-5 text-base"
id="open-checkin-modal"
@click="checkinTimestamp = dayjs().format('YYYY-MM-DD HH:mm:ss')"
@click="fetchLocation"
>
<template #prefix>
<FeatherIcon
Expand Down Expand Up @@ -64,6 +83,9 @@ const socket = inject("$socket")
const employee = inject("$employee")
const dayjs = inject("$dayjs")
const checkinTimestamp = ref(null)
const latitude = ref("")
const longitude = ref("")
const locationStatus = ref("")

const checkins = createListResource({
doctype: DOCTYPE,
Expand Down Expand Up @@ -102,6 +124,43 @@ const lastLogTime = computed(() => {
return `${formattedTime} on ${dayjs(timestamp).format("D MMM, YYYY")}`
})

function success(position) {
latitude.value = position.coords.latitude
longitude.value = position.coords.longitude

locationStatus.value = `
Latitude: ${Number(latitude.value).toFixed(5)} °,
Longitude: ${Number(longitude.value).toFixed(5)} °
`
}

function error() {
locationStatus.value = "Unable to retrieve your location"
}

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"
} else {
locationStatus.value = "Locating..."
navigator.geolocation.getCurrentPosition(success, error)
}

if ("geolocation" in navigator) {
} else {
toast({
title: "Error",
text: "Your current browser does not support geolocation",
icon: "alert-circle",
position: "bottom-center",
iconClasses: "text-red-500",
})
}
}

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

Expand Down
27 changes: 11 additions & 16 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3835,12 +3835,7 @@ mz@^2.7.0:
object-assign "^4.0.1"
thenify-all "^1.0.0"

nanoid@^3.3.6:
version "3.3.6"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==

nanoid@^3.3.7:
nanoid@^3.3.6, nanoid@^3.3.7:
version "3.3.7"
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==
Expand Down Expand Up @@ -4053,16 +4048,7 @@ postcss-value-parser@^4.0.0, postcss-value-parser@^4.2.0:
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==

postcss@^8.1.10, postcss@^8.4.23, postcss@^8.4.5:
version "8.4.23"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.23.tgz#df0aee9ac7c5e53e1075c24a3613496f9e6552ab"
integrity sha512-bQ3qMcpF6A/YjR55xtoTr0jGOlnPOKAIMdOWiv0EIT6HVPEaJiJB4NLljSbiHoC2RX7DN5Uvjtpbg1NPdwv1oA==
dependencies:
nanoid "^3.3.6"
picocolors "^1.0.0"
source-map-js "^1.0.2"

postcss@^8.4.35:
postcss@^8.1.10, postcss@^8.4.23, postcss@^8.4.35:
version "8.4.35"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.35.tgz#60997775689ce09011edf083a549cea44aabe2f7"
integrity sha512-u5U8qYpBCpN13BsiEB0CbR1Hhh4Gc0zLFuedrHJKMctHCHAGrMdG0PRM/KErzAL3CU6/eckEtmHNB3x6e3c0vA==
Expand All @@ -4071,6 +4057,15 @@ postcss@^8.4.35:
picocolors "^1.0.0"
source-map-js "^1.0.2"

postcss@^8.4.31:
version "8.4.31"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.31.tgz#92b451050a9f914da6755af352bdc0192508656d"
integrity sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==
dependencies:
nanoid "^3.3.6"
picocolors "^1.0.0"
source-map-js "^1.0.2"

prelude-ls@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
Expand Down
34 changes: 32 additions & 2 deletions hrms/hr/doctype/employee_checkin/employee_checkin.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
"device_id",
"skip_auto_attendance",
"attendance",
"location_section",
"coordinates",
"geolocation",
"shift_timings_section",
"shift_start",
"shift_end",
"column_break_vyyt",
"shift_actual_start",
"shift_actual_end"
],
Expand Down Expand Up @@ -107,10 +112,35 @@
"fieldtype": "Datetime",
"hidden": 1,
"label": "Shift Actual End"
},
{
"fieldname": "location_section",
"fieldtype": "Section Break",
"label": "Location"
},
{
"fieldname": "coordinates",
"fieldtype": "Data",
"label": "Coordinates",
"read_only": 1
},
{
"fieldname": "geolocation",
"fieldtype": "Geolocation",
"label": "Geolocation"
},
{
"fieldname": "shift_timings_section",
"fieldtype": "Section Break",
"label": "Shift Timings"
},
{
"fieldname": "column_break_vyyt",
"fieldtype": "Column Break"
}
],
"links": [],
"modified": "2024-04-02 01:50:23.150627",
"modified": "2024-04-03 06:36:07.640893",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Checkin",
Expand Down Expand Up @@ -210,4 +240,4 @@
"states": [],
"title_field": "employee_name",
"track_changes": 1
}
}
14 changes: 14 additions & 0 deletions hrms/hr/doctype/employee_checkin/employee_checkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def validate(self):
validate_active_employee(self.employee)
self.validate_duplicate_log()
self.fetch_shift()
self.set_geolocation_coordinates()

def validate_duplicate_log(self):
doc = frappe.db.exists(
Expand Down Expand Up @@ -60,6 +61,19 @@ def fetch_shift(self):
else:
self.shift = None

def set_geolocation_coordinates(self):
if not self.geolocation:
return

try:
self.coordinates = str(get_coordinates_from_geolocation(self.geolocation))
except Exception:
frappe.log_error("Error parsing geolocation field")


def get_coordinates_from_geolocation(geolocation: str):
return frappe.parse_json(geolocation)["features"][0]["geometry"]["coordinates"]


@frappe.whitelist()
def add_log_based_on_employee_field(
Expand Down