Asset management/fix last bugs

This commit is contained in:
Luca Haid
2025-06-29 10:43:06 +00:00
parent 4e18891afc
commit dffd2698bd
3 changed files with 30 additions and 6 deletions

View File

@@ -119,12 +119,7 @@ class AssetManagementController extends TTCrud
// Check for conflicting reservations if not forced
if (empty($post['force'])) {
$now = time();
$conflictingReservations = AssetManagementReservationModel::dbSelect("
SELECT * FROM AssetManagementReservation
WHERE assetId = {$post['assetId']} AND startDate <= $now AND (endDate IS NULL OR endDate >= $now)
");
$conflictingReservations = AssetManagementReservationModel::getConflictingReservations($post['assetId']);
if (!empty($conflictingReservations)) {
$res = $conflictingReservations[0];
$user = UserModel::getOne($res->userId);

View File

@@ -9,4 +9,22 @@ class AssetManagementReservationModel extends TTCrudBaseModel {
public ?string $notes;
public int $createBy;
public int $create;
public static function getConflictingReservations($assetId): array
{
$db = self::getDB();
$table = self::getFullyQualifiedTable();
$now = time();
$sql = "SELECT * FROM $table
WHERE assetId = $assetId AND startDate <= $now AND (endDate IS NULL OR endDate >= $now)
";
$result = $db->query($sql);
$reservations = [];
while ($row = $result->fetch_assoc()) {
$reservations[] = new self($row);
}
return $reservations;
}
}

View File

@@ -152,6 +152,12 @@ Vue.component('asset-borrow-return-widget', {
<div v-if="activeReservation" class="text-warning small">
<i class="fas fa-clock"></i> Reserviert für {{ activeReservation.userName }}
</div>
<div v-if="nextReservation" class="text-danger small">
<i class="fas fa-calendar-alt"></i> Nächste Reservierung: {{ formatDate(nextReservation.startDate, 'DD.MM.YYYY') }}
<span v-if="nextReservation.endDate"> bis {{ formatDate(nextReservation.endDate, 'DD.MM.YYYY') }}</span>
<span v-if="nextReservation.notes"><br> ({{ nextReservation.notes }})</span>
<span v-if="nextReservation.userName"><br> für {{ nextReservation.userName }}</span>
</div>
<tt-autocomplete
v-if="window.TT_CONFIG.ASSET_ADMIN === '1'"
:label="null"
@@ -201,6 +207,11 @@ Vue.component('asset-borrow-return-widget', {
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 && (r.endDate === null || r.endDate >= now));
},
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);
}
},
methods: {