« Back to History
asset_history.php
|
20260920_164915.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================================================= File: /erp/asset_history.php Purpose: Complete Assignment & Transfer History for a Specific Asset ============================================================================= */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('asset_master'); if (!function_exists('h')) { function h($value) { return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'); } } $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $asset_id = (int)($_GET['asset_id'] ?? 0); if ($asset_id <= 0) { header('Location: asset_master.php'); exit; } // Fetch Asset Basic Information $asset_stmt = $pdo->prepare(" SELECT am.*, ac.category_name FROM asset_master am INNER JOIN asset_category_master ac ON ac.id = am.category_id WHERE am.id = ? AND am.company_id = ? "); $asset_stmt->execute([$asset_id, $company_id]); $asset = $asset_stmt->fetch(PDO::FETCH_ASSOC); if (!$asset) { header('Location: asset_master.php'); exit; } // Fetch Assignment History for this Asset $hist_stmt = $pdo->prepare(" SELECT aah.*, u_emp.name AS employee_name, d.department_name, u_iss.name AS issued_by_name, u_ret.name AS returned_by_name FROM asset_assignment_history aah INNER JOIN users u_emp ON u_emp.id = aah.employee_id LEFT JOIN department_master d ON d.id = aah.department_id LEFT JOIN users u_iss ON u_iss.id = aah.issued_by LEFT JOIN users u_ret ON u_ret.id = aah.returned_by WHERE aah.asset_id = ? AND aah.company_id = ? ORDER BY aah.id DESC "); $hist_stmt->execute([$asset_id, $company_id]); $history_rows = $hist_stmt->fetchAll(PDO::FETCH_ASSOC); require_once __DIR__ . '/partials/header.php'; ?> <div class="container-fluid py-4"> <div class="d-flex justify-content-between align-items-center mb-4"> <h4 class="mb-0 fw-bold">📜 Asset History & Timeline</h4> <a href="asset_master.php" class="btn btn-sm btn-outline-dark">Back to Asset Master</a> </div> <!-- Asset Profile Summary Card --> <div class="card shadow-sm border-0 mb-4"> <div class="card-header bg-dark text-white py-2"> <h5 class="mb-0">Asset Details: <?= h($asset['asset_code']) ?></h5> </div> <div class="card-body"> <div class="row g-3"> <div class="col-md-3"> <small class="text-muted d-block fw-bold">Category</small> <span class="fw-bold text-primary"><?= h($asset['category_name']) ?></span> </div> <div class="col-md-3"> <small class="text-muted d-block fw-bold">Brand & Model</small> <span><?= h($asset['brand'] ?: '-') ?> <?= h($asset['model'] ?: '') ?></span> </div> <div class="col-md-3"> <small class="text-muted d-block fw-bold">Serial / IMEI / SIM</small> <span><?= h($asset['serial_no'] ?: $asset['imei_1'] ?: $asset['sim_no'] ?: '-') ?></span> </div> <div class="col-md-3"> <small class="text-muted d-block fw-bold">Current Status / Condition</small> <span class="badge bg-success"><?= h($asset['asset_status']) ?></span> <span class="badge bg-light text-dark border"><?= h($asset['condition_status']) ?></span> </div> </div> </div> </div> <!-- Assignment History Table --> <div class="card shadow-sm border-0"> <div class="card-header bg-secondary text-white py-2"> <h6 class="mb-0">Assignment & Transfer Timeline</h6> </div> <div class="card-body p-0"> <div class="table-responsive"> <table class="table table-bordered table-hover align-middle mb-0" style="font-size: 13px;"> <thead class="table-dark text-nowrap"> <tr> <th>Employee</th> <th>Department</th> <th class="text-center">Issue Date</th> <th class="text-center">Return Date</th> <th class="text-center">Conditions (Issue / Return)</th> <th class="text-center">Status</th> <th>Remarks</th> </tr> </thead> <tbody> <?php if (!empty($history_rows)): ?> <?php foreach ($history_rows as $row): ?> <tr> <td class="fw-bold text-dark"><?= h($row['employee_name']) ?></td> <td><?= h($row['department_name'] ?: '-') ?></td> <td class="text-center text-nowrap"><?= date('d-m-Y', strtotime($row['issue_date'])) ?></td> <td class="text-center text-nowrap"><?= $row['return_date'] ? date('d-m-Y', strtotime($row['return_date'])) : '<span class="text-success fw-bold">— (Current)</span>' ?></td> <td class="text-center text-nowrap"> <span class="badge bg-light text-dark border"><?= h($row['issue_condition']) ?></span> → <span class="badge bg-light text-dark border"><?= h($row['return_condition'] ?: 'N/A') ?></span> </td> <td class="text-center"> <?php $st_bg = 'bg-success'; if ($row['assignment_status'] === 'RETURNED') $st_bg = 'bg-secondary'; elseif ($row['assignment_status'] === 'TRANSFERRED') $st_bg = 'bg-warning text-dark'; ?> <span class="badge <?= $st_bg ?>"><?= h($row['assignment_status']) ?></span> </td> <td> <?php if ($row['issue_remark']): ?><div><small><strong>Issue:</strong> <?= h($row['issue_remark']) ?></small></div><?php endif; ?> <?php if ($row['return_remark']): ?><div><small><strong>Return:</strong> <?= h($row['return_remark']) ?></small></div><?php endif; ?> <?php if (!$row['issue_remark'] && !$row['return_remark']): ?>-<?php endif; ?> </td> </tr> <?php endforeach; ?> <?php else: ?> <tr> <td colspan="7" class="text-center text-muted py-4">No assignment history found for this asset.</td> </tr> <?php endif; ?> </tbody> </table> </div> </div> </div> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>