From 59a99f4638126c6133ac19a5d174a3134231646c Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Thu, 11 Sep 2025 13:06:06 +0200 Subject: [PATCH] fixed showing closest reservation --- public/js/pages/AssetManagement/AssetManagement.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/public/js/pages/AssetManagement/AssetManagement.js b/public/js/pages/AssetManagement/AssetManagement.js index 31be0529f..9bc533915 100644 --- a/public/js/pages/AssetManagement/AssetManagement.js +++ b/public/js/pages/AssetManagement/AssetManagement.js @@ -311,9 +311,16 @@ Vue.component('asset-borrow-return-widget', { }, nextReservation() { if (!this.rowData.reservations || this.rowData.reservations.length === 0) return null; + const now = window.moment().unix(); - return this.rowData.reservations.find(r => r.startDate > now); + return this.rowData.reservations.reduce((closest, current) => { + const closestDiff = Math.abs(closest.startDate - now); + const currentDiff = Math.abs(current.startDate - now); + + return currentDiff < closestDiff ? current : closest; + }); } + }, methods: { formatDate(timestamp, format) {