Asset management/fix last bugs
This commit is contained in:
@@ -119,12 +119,7 @@ class AssetManagementController extends TTCrud
|
|||||||
|
|
||||||
// Check for conflicting reservations if not forced
|
// Check for conflicting reservations if not forced
|
||||||
if (empty($post['force'])) {
|
if (empty($post['force'])) {
|
||||||
$now = time();
|
$conflictingReservations = AssetManagementReservationModel::getConflictingReservations($post['assetId']);
|
||||||
$conflictingReservations = AssetManagementReservationModel::dbSelect("
|
|
||||||
SELECT * FROM AssetManagementReservation
|
|
||||||
WHERE assetId = {$post['assetId']} AND startDate <= $now AND (endDate IS NULL OR endDate >= $now)
|
|
||||||
");
|
|
||||||
|
|
||||||
if (!empty($conflictingReservations)) {
|
if (!empty($conflictingReservations)) {
|
||||||
$res = $conflictingReservations[0];
|
$res = $conflictingReservations[0];
|
||||||
$user = UserModel::getOne($res->userId);
|
$user = UserModel::getOne($res->userId);
|
||||||
|
|||||||
@@ -9,4 +9,22 @@ class AssetManagementReservationModel extends TTCrudBaseModel {
|
|||||||
public ?string $notes;
|
public ?string $notes;
|
||||||
public int $createBy;
|
public int $createBy;
|
||||||
public int $create;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,6 +152,12 @@ Vue.component('asset-borrow-return-widget', {
|
|||||||
<div v-if="activeReservation" class="text-warning small">
|
<div v-if="activeReservation" class="text-warning small">
|
||||||
<i class="fas fa-clock"></i> Reserviert für {{ activeReservation.userName }}
|
<i class="fas fa-clock"></i> Reserviert für {{ activeReservation.userName }}
|
||||||
</div>
|
</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
|
<tt-autocomplete
|
||||||
v-if="window.TT_CONFIG.ASSET_ADMIN === '1'"
|
v-if="window.TT_CONFIG.ASSET_ADMIN === '1'"
|
||||||
:label="null"
|
:label="null"
|
||||||
@@ -201,6 +207,11 @@ Vue.component('asset-borrow-return-widget', {
|
|||||||
if (!this.rowData.reservations || this.rowData.reservations.length === 0) return null;
|
if (!this.rowData.reservations || this.rowData.reservations.length === 0) return null;
|
||||||
const now = window.moment().unix();
|
const now = window.moment().unix();
|
||||||
return this.rowData.reservations.find(r => r.startDate <= now && (r.endDate === null || r.endDate >= now));
|
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: {
|
methods: {
|
||||||
|
|||||||
Reference in New Issue
Block a user