added new asset management poc
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class AssetManagementJournalModel extends TTCrudBaseModel {
|
||||
public int $id;
|
||||
public int $assetId;
|
||||
public int $userId;
|
||||
public string $site;
|
||||
public int $borrowDate;
|
||||
public ?int $returnDate;
|
||||
public string $borrowReason;
|
||||
public ?string $returnReason;
|
||||
public int $createBy;
|
||||
public int $create;
|
||||
|
||||
// Get the latest open journal entry for each asset
|
||||
public static function getLatestOpenEntries($assetIds): array {
|
||||
$db = self::getDB();
|
||||
$table = self::getFullyQualifiedTable();
|
||||
$sql = "SELECT j1.*
|
||||
FROM AssetManagementJournal j1
|
||||
LEFT JOIN AssetManagementJournal j2
|
||||
ON j1.assetId = j2.assetId AND j1.borrowDate < j2.borrowDate
|
||||
WHERE j2.id IS NULL AND j1.assetId IN (" . implode(',', $assetIds) . ")";
|
||||
$result = $db->query($sql);
|
||||
|
||||
$entries = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$entries[] = new self($row);
|
||||
}
|
||||
return $entries;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user