update file tài sản
This commit is contained in:
227
public/js/app.js
227
public/js/app.js
@@ -64,6 +64,9 @@ class AccountManager {
|
||||
this.applications = [];
|
||||
this.users = [];
|
||||
this.assets = [];
|
||||
this.archivedAssets = [];
|
||||
this.archivedAssetSearchTerm = '';
|
||||
this.archivingAssets = false;
|
||||
this.consumables = [];
|
||||
this.documents = [];
|
||||
this.roles = [];
|
||||
@@ -114,6 +117,7 @@ class AccountManager {
|
||||
this.assetBorrows = [];
|
||||
this.assetBorrowSearchTerm = '';
|
||||
this.assetBorrowTypeFilter = '';
|
||||
this.assetBorrowCatalogFilter = '';
|
||||
this.myBorrowedAssetSearchTerm = '';
|
||||
this.assetBorrowProductSearchTimer = undefined;
|
||||
this.assetBorrowProductItems = [];
|
||||
@@ -1694,6 +1698,26 @@ class AccountManager {
|
||||
} catch (err) {
|
||||
console.error('Fetch assets error:', err);
|
||||
}
|
||||
await this.fetchArchivedAssets();
|
||||
}
|
||||
|
||||
async fetchArchivedAssets() {
|
||||
try {
|
||||
const response = await fetch(`${this.apiBase}/assets?archived=1`, {
|
||||
headers: this.getAuthHeaders(false),
|
||||
cache: 'no-store'
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok || !data.success) {
|
||||
throw new Error(data.message || 'Không tải được tài sản cũ');
|
||||
}
|
||||
this.archivedAssets = (Array.isArray(data.data) ? data.data : [])
|
||||
.map(asset => this.normalizeAssetComputedFields(asset));
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('Fetch archived assets error:', err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async fetchConsumables() {
|
||||
@@ -2786,7 +2810,7 @@ class AccountManager {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.assets
|
||||
return [...this.assets, ...(this.archivedAssets || [])]
|
||||
.map(asset => {
|
||||
const borrowerEntries = this.parseBorrowerEntries(asset?.Borrower);
|
||||
const matchedEntries = borrowerEntries.filter(entry => {
|
||||
@@ -2845,17 +2869,21 @@ class AccountManager {
|
||||
getFilteredAssetBorrows() {
|
||||
const search = String(this.assetBorrowSearchTerm || '').toLowerCase();
|
||||
const typeFilter = String(this.assetBorrowTypeFilter || '').trim().toLowerCase();
|
||||
const catalogFilter = String(this.assetBorrowCatalogFilter || '');
|
||||
const rows = Array.isArray(this.assetBorrows) ? this.assetBorrows : [];
|
||||
|
||||
return rows.filter(item => {
|
||||
const requestType = this.normalizeAssetRequestType(item.RequestType);
|
||||
const requestStatus = this.normalizeAssetRequestStatus(item.RequestStatus);
|
||||
const relatedReturnCount = this.parseNonNegativeInteger(item?.RelatedReturnCount, 0);
|
||||
if (requestType === 'borrow' && (requestStatus === 'returned' || relatedReturnCount > 0 || this.hasActiveReturnForBorrowRequest(item, rows))) {
|
||||
const isArchived = this.isArchivedAsset(item);
|
||||
if ((catalogFilter === 'archived' && !isArchived) || (catalogFilter === 'current' && isArchived)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const matchesType = !typeFilter || requestType === typeFilter;
|
||||
const remainingQuantity = this.parseNonNegativeInteger(item?.RemainingQuantity,
|
||||
Math.max(this.parseNonNegativeInteger(item?.BorrowQuantity, 0) - this.parseNonNegativeInteger(item?.ReturnedQuantity, 0), 0));
|
||||
const matchesType = !typeFilter || requestType === typeFilter
|
||||
|| (typeFilter === 'outstanding' && requestType === 'borrow' && requestStatus === 'approved' && remainingQuantity > 0);
|
||||
if (!matchesType) {
|
||||
return false;
|
||||
}
|
||||
@@ -3403,6 +3431,16 @@ class AccountManager {
|
||||
});
|
||||
}
|
||||
|
||||
isArchivedAsset(item) {
|
||||
return item?.IsArchived === true || Number(item?.IsArchived) === 1;
|
||||
}
|
||||
|
||||
getArchivedAssetBadgeHtml(item) {
|
||||
return this.isArchivedAsset(item)
|
||||
? '<div class="mt-1 text-[11px] font-bold text-amber-700">Tài sản cũ</div>'
|
||||
: '';
|
||||
}
|
||||
|
||||
async handleDocumentUpload(event) {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
@@ -4730,7 +4768,7 @@ class AccountManager {
|
||||
const borrowQuantity = this.parseNonNegativeInteger(item?.BorrowQuantity, 0);
|
||||
const remainingQuantity = this.parseNonNegativeInteger(item?.RemainingQuantity, Math.max(borrowQuantity - returnedQuantity, 0));
|
||||
const canCreateReturn = this.canCreateAssetReturnRequestFromBorrow(item);
|
||||
const returnProgressHtml = requestType === 'borrow' && returnedQuantity > 0 && statusMeta.value !== 'returned'
|
||||
const returnProgressHtml = requestType === 'borrow' && statusMeta.value === 'approved'
|
||||
? `<div class="mt-1 text-[11px] text-slate-500 whitespace-nowrap">Đã trả ${returnedQuantity}/${borrowQuantity}, còn ${remainingQuantity}</div>`
|
||||
: '';
|
||||
const detailActionHtml = `
|
||||
@@ -4763,6 +4801,7 @@ class AccountManager {
|
||||
<td class="px-4 py-3 text-sm text-slate-700">
|
||||
<div>${this.escapeHtml(assetName)}</div>
|
||||
${assetCode}
|
||||
${this.getArchivedAssetBadgeHtml(item)}
|
||||
</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-600 whitespace-nowrap">
|
||||
<span class="inline-flex items-center px-2 py-1 rounded-md text-xs font-bold whitespace-nowrap ${typeMeta.className}">${typeMeta.label}</span>
|
||||
@@ -4794,9 +4833,10 @@ class AccountManager {
|
||||
const borrowQuantity = this.parseNonNegativeInteger(item?.BorrowQuantity, 0);
|
||||
const returnedQuantity = this.parseNonNegativeInteger(item?.ReturnedQuantity, 0);
|
||||
const remainingQuantity = this.parseNonNegativeInteger(item?.RemainingQuantity, Math.max(borrowQuantity - returnedQuantity, 0));
|
||||
const relatedReturnCount = this.parseNonNegativeInteger(item?.RelatedReturnCount, 0);
|
||||
const availableReturnQuantity = this.parseNonNegativeInteger(item?.AvailableReturnQuantity,
|
||||
this.parseNonNegativeInteger(item?.RelatedReturnCount, 0) > 0 ? 0 : remainingQuantity);
|
||||
|
||||
return borrowQuantity > 0 && remainingQuantity > 0 && relatedReturnCount <= 0;
|
||||
return borrowQuantity > 0 && remainingQuantity > 0 && availableReturnQuantity > 0;
|
||||
}
|
||||
|
||||
canCurrentUserCancelAssetRequest(item) {
|
||||
@@ -4906,7 +4946,7 @@ class AccountManager {
|
||||
<tr class="hover:bg-slate-50/80 transition-colors">
|
||||
<td class="px-4 py-3 text-sm text-slate-600">${pageInfo.start + index}</td>
|
||||
<td class="px-4 py-3 text-sm font-semibold text-slate-700">${this.escapeHtml(asset.AssetCode || '-')}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700">${this.escapeHtml(asset.AssetName || '-')}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700">${this.escapeHtml(asset.AssetName || '-')}${this.getArchivedAssetBadgeHtml(asset)}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700 font-bold">${Number(asset.BorrowedQuantityByCurrentUser) || 0}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-600">${this.escapeHtml(asset.Unit || '-')}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-600">${this.escapeHtml(asset.Project || '-')}</td>
|
||||
@@ -4960,7 +5000,7 @@ class AccountManager {
|
||||
<tr class="hover:bg-slate-50/80 transition-colors">
|
||||
<td class="px-4 py-3 text-sm text-slate-600">${pageInfo.start + index}</td>
|
||||
<td class="px-4 py-3 text-sm font-semibold text-slate-700">${this.escapeHtml(asset.AssetCode || '-')}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700">${this.escapeHtml(asset.AssetName || '-')}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700">${this.escapeHtml(asset.AssetName || '-')}${this.getArchivedAssetBadgeHtml(asset)}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700 font-bold">${Number(asset.BorrowedQuantityByCurrentUser) || 0}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-600">${this.escapeHtml(asset.Unit || '-')}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-600">${this.escapeHtml(asset.Project || '-')}</td>
|
||||
@@ -5024,9 +5064,16 @@ class AccountManager {
|
||||
<div class="page-header flex items-center justify-between gap-4 mb-5 shrink-0">
|
||||
<div>
|
||||
<h1 class="text-2xl font-extrabold text-on-surface tracking-tight">Mượn/Trả tài sản</h1>
|
||||
<p class="text-sm text-on-surface-variant">Theo dõi trạng thái đơn mượn và đơn trả tài sản.</p>
|
||||
<p class="text-sm text-on-surface-variant">Lịch sử mượn/trả gồm cả tài sản cũ đã xóa khỏi danh mục.</p>
|
||||
</div>
|
||||
<div class="compact-page-actions flex flex-wrap items-center gap-2">
|
||||
<button
|
||||
id="openArchivedAssetBorrowsBtn"
|
||||
class="border border-amber-300 text-amber-700 px-4 py-2 rounded-lg text-xs font-bold flex items-center gap-1.5 hover:bg-amber-50"
|
||||
>
|
||||
<span class="material-symbols-outlined text-base">history</span>
|
||||
Tài sản cũ còn mượn
|
||||
</button>
|
||||
<button
|
||||
id="addAssetBorrowRequestBtn"
|
||||
class="bg-primary text-on-primary px-4 py-2 rounded-lg text-xs font-bold flex items-center gap-1.5 transition-all active:scale-95 hover:bg-primary-dim"
|
||||
@@ -5056,13 +5103,22 @@ class AccountManager {
|
||||
|
||||
<div class="page-filters compact-page-filters asset-borrow-filter-bar flex items-center gap-3 mb-4 shrink-0">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<span class="text-[10px] font-bold uppercase text-on-surface-variant">Danh mục</span>
|
||||
<span class="text-[10px] font-bold uppercase text-on-surface-variant">Đơn</span>
|
||||
<select id="assetBorrowTypeFilter" class="bg-surface-container-low border-slate-200 rounded-md text-[11px] py-1 px-2 pr-6 focus:ring-1 focus:ring-primary shadow-sm">
|
||||
<option value="" ${!this.assetBorrowTypeFilter ? 'selected' : ''}>Tất cả</option>
|
||||
<option value="outstanding" ${this.assetBorrowTypeFilter === 'outstanding' ? 'selected' : ''}>Còn đang mượn</option>
|
||||
<option value="borrow" ${this.assetBorrowTypeFilter === 'borrow' ? 'selected' : ''}>Mượn tài sản</option>
|
||||
<option value="return" ${this.assetBorrowTypeFilter === 'return' ? 'selected' : ''}>Trả tài sản</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex items-center gap-1.5">
|
||||
<label for="assetBorrowCatalogFilter" class="text-[10px] font-bold uppercase text-on-surface-variant">Tài sản</label>
|
||||
<select id="assetBorrowCatalogFilter" class="bg-surface-container-low border-slate-200 rounded-md text-[11px] py-1 px-2 pr-6 focus:ring-1 focus:ring-primary shadow-sm">
|
||||
<option value="" ${!this.assetBorrowCatalogFilter ? 'selected' : ''}>Tất cả</option>
|
||||
<option value="archived" ${this.assetBorrowCatalogFilter === 'archived' ? 'selected' : ''}>Tài sản cũ</option>
|
||||
<option value="current" ${this.assetBorrowCatalogFilter === 'current' ? 'selected' : ''}>Danh mục hiện tại</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="compact-filter-search flex items-center gap-1.5 flex-1">
|
||||
<span class="text-[10px] font-bold uppercase text-on-surface-variant">Tìm kiếm</span>
|
||||
<input
|
||||
@@ -5216,7 +5272,7 @@ class AccountManager {
|
||||
<div class="min-w-0">
|
||||
<h3 class="text-base font-extrabold text-slate-900">Chi tiết mượn/trả tài sản</h3>
|
||||
<div class="mt-1 flex flex-wrap items-center gap-2 text-xs text-slate-500 min-w-0">
|
||||
<span class="font-bold text-slate-700 break-words min-w-0">${this.escapeHtml(assetName)}</span>
|
||||
<span class="font-bold text-slate-700 break-words min-w-0">${this.escapeHtml(assetName)}${this.getArchivedAssetBadgeHtml(selected)}</span>
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded ${selectedTypeMeta.className}">${selectedTypeMeta.label}</span>
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded ${selectedStatusMeta.className}">${selectedStatusMeta.label}</span>
|
||||
</div>
|
||||
@@ -5266,11 +5322,12 @@ class AccountManager {
|
||||
}
|
||||
|
||||
setupAssetBorrowListeners() {
|
||||
this.setupArchivedAssetListeners();
|
||||
const typeFilter = document.getElementById('assetBorrowTypeFilter');
|
||||
if (typeFilter && typeFilter.dataset.boundChange !== 'true') {
|
||||
typeFilter.addEventListener('change', event => {
|
||||
const nextValue = String(event.target.value || '').trim().toLowerCase();
|
||||
this.assetBorrowTypeFilter = (nextValue === 'borrow' || nextValue === 'return')
|
||||
this.assetBorrowTypeFilter = (nextValue === 'borrow' || nextValue === 'return' || nextValue === 'outstanding')
|
||||
? nextValue
|
||||
: '';
|
||||
this.assetBorrowPage = 1;
|
||||
@@ -5279,6 +5336,16 @@ class AccountManager {
|
||||
typeFilter.dataset.boundChange = 'true';
|
||||
}
|
||||
|
||||
const catalogFilter = document.getElementById('assetBorrowCatalogFilter');
|
||||
if (catalogFilter && catalogFilter.dataset.boundChange !== 'true') {
|
||||
catalogFilter.addEventListener('change', event => {
|
||||
this.assetBorrowCatalogFilter = ['current', 'archived'].includes(event.target.value) ? event.target.value : '';
|
||||
this.assetBorrowPage = 1;
|
||||
this.renderAssetBorrowsTableBody();
|
||||
});
|
||||
catalogFilter.dataset.boundChange = 'true';
|
||||
}
|
||||
|
||||
const searchInput = document.getElementById('assetBorrowSearch');
|
||||
if (searchInput && searchInput.dataset.boundInput !== 'true') {
|
||||
searchInput.addEventListener('input', (event) => {
|
||||
@@ -5561,6 +5628,7 @@ class AccountManager {
|
||||
const dateLabel = typeMeta.value === 'return' ? 'Ngày trả' : 'Ngày mượn';
|
||||
const note = String(item?.RequestNote || '').trim();
|
||||
const requestId = Number(item?.BorrowId) || 0;
|
||||
const blockedArchivedBorrow = this.isArchivedAsset(item) && typeMeta.value === 'borrow';
|
||||
|
||||
return `
|
||||
<div class="rounded-lg border border-slate-200 bg-white p-3 space-y-2 shadow-sm">
|
||||
@@ -5571,12 +5639,14 @@ class AccountManager {
|
||||
<div class="text-xs text-slate-700 space-y-1">
|
||||
<div><span class="font-bold">Tên đầy đủ:</span> ${this.escapeHtml(item?.BorrowerName || '-')}</div>
|
||||
<div><span class="font-bold">Tên tài sản:</span> ${this.escapeHtml(item?.AssetCode || '')} ${item?.AssetCode ? '- ' : ''}${this.escapeHtml(item?.AssetName || '-')}</div>
|
||||
${this.getArchivedAssetBadgeHtml(item)}
|
||||
${blockedArchivedBorrow ? '<p class="text-amber-700">Tài sản đã xóa khỏi danh mục. Vui lòng từ chối hoặc hủy đơn mượn này.</p>' : ''}
|
||||
<div><span class="font-bold">Số lượng:</span> ${Number(item?.BorrowQuantity) || 0} ${this.escapeHtml(item?.Unit || '')}</div>
|
||||
<div><span class="font-bold">Ghi chú:</span> ${this.escapeHtml(note || '-')}</div>
|
||||
<div><span class="font-bold">${dateLabel}:</span> ${this.formatDateOnly(item?.BorrowDate)}</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 pt-1">
|
||||
<button class="asset-request-approve-btn flex-1 min-w-0 px-3 py-1.5 rounded-md bg-primary hover:bg-primary-dim text-on-primary text-xs font-bold whitespace-nowrap" data-request-id="${requestId}">Chấp nhận</button>
|
||||
${blockedArchivedBorrow ? '' : `<button class="asset-request-approve-btn flex-1 min-w-0 px-3 py-1.5 rounded-md bg-primary hover:bg-primary-dim text-on-primary text-xs font-bold whitespace-nowrap" data-request-id="${requestId}">Chấp nhận</button>`}
|
||||
<button class="asset-request-reject-btn flex-1 min-w-0 px-3 py-1.5 rounded-md bg-red-600 hover:bg-red-700 text-white text-xs font-bold whitespace-nowrap" data-request-id="${requestId}">Từ chối</button>
|
||||
<button class="asset-request-delete-btn flex-1 min-w-0 px-3 py-1.5 rounded-md bg-slate-700 hover:bg-slate-800 text-white text-xs font-bold whitespace-nowrap" data-request-id="${requestId}">Xóa đơn</button>
|
||||
</div>
|
||||
@@ -5732,17 +5802,22 @@ class AccountManager {
|
||||
}
|
||||
}
|
||||
|
||||
async confirmBulkAssetDelete(selectedCount) {
|
||||
async confirmBulkAssetDelete(selectedCount, archiveAll = false) {
|
||||
const modal = document.getElementById('bulkDeleteAssetsConfirmModal');
|
||||
const messageNode = document.getElementById('bulkDeleteAssetsConfirmMessage');
|
||||
const countNode = document.getElementById('bulkDeleteAssetsConfirmCount');
|
||||
const titleNode = document.getElementById('bulkDeleteAssetsConfirmTitle');
|
||||
const message = archiveAll
|
||||
? 'Xóa toàn bộ danh mục tài sản hiện tại để nhập dữ liệu mới? Lịch sử và số lượng còn đang mượn được giữ trong tài sản cũ. Dữ liệu nhập mới được quản lý riêng, kể cả khi trùng mã tài sản.'
|
||||
: `Xóa ${selectedCount} tài sản đã chọn khỏi danh mục hiện tại? Lịch sử mượn/trả và số lượng còn đang mượn vẫn được giữ trong tài sản cũ.`;
|
||||
|
||||
if (!modal || !messageNode || !countNode) {
|
||||
return window.confirm(`Bạn có chắc muốn xóa ${selectedCount} tài sản đã chọn?`);
|
||||
return window.confirm(message);
|
||||
}
|
||||
|
||||
countNode.textContent = String(selectedCount);
|
||||
messageNode.textContent = `Bạn có chắc muốn xóa ${selectedCount} tài sản đã chọn?`;
|
||||
messageNode.textContent = message;
|
||||
if (titleNode) titleNode.textContent = archiveAll ? 'Xóa danh mục hiện tại' : 'Xóa tài sản đã chọn';
|
||||
|
||||
if (this.pendingBulkAssetDeleteConfirmResolver) {
|
||||
this.resolveBulkAssetDeleteConfirm(false);
|
||||
@@ -6633,6 +6708,14 @@ class AccountManager {
|
||||
<p class="text-sm text-on-surface-variant">Theo dõi tài sản, kho và trạng thái sử dụng.</p>
|
||||
</div>
|
||||
<div class="asset-header-actions flex flex-wrap items-center gap-2">
|
||||
<button id="archiveAllAssetsBtn" class="border border-red-200 text-red-700 px-3 py-2 rounded-lg text-xs font-bold flex items-center gap-1.5 ${canManageAssets && this.assets.length ? 'hover:bg-red-50' : 'opacity-50 cursor-not-allowed'}" ${canManageAssets && this.assets.length ? '' : 'disabled'}>
|
||||
<span class="material-symbols-outlined text-base">archive</span>
|
||||
Xóa danh mục hiện tại
|
||||
</button>
|
||||
<button id="openArchivedAssetBorrowsBtn" class="border border-amber-300 text-amber-700 px-3 py-2 rounded-lg text-xs font-bold flex items-center gap-1.5 hover:bg-amber-50">
|
||||
<span class="material-symbols-outlined text-base">history</span>
|
||||
Tài sản cũ còn mượn
|
||||
</button>
|
||||
<button id="importAssetBtn" class="border border-slate-300 text-slate-700 px-3 py-2 rounded-lg text-xs font-bold flex items-center gap-1.5 transition-all active:scale-95 ${canManageAssets ? 'hover:bg-slate-100' : 'opacity-50 cursor-not-allowed'}" ${canManageAssets ? '' : 'disabled'}>
|
||||
<span class="material-symbols-outlined text-base">upload_file</span>
|
||||
Nhập Excel
|
||||
@@ -7069,6 +7152,112 @@ class AccountManager {
|
||||
}
|
||||
|
||||
await this.refreshAssetsUI();
|
||||
await this.refreshAssetBorrowsUI();
|
||||
}
|
||||
|
||||
setupArchivedAssetListeners() {
|
||||
const archiveButton = document.getElementById('archiveAllAssetsBtn');
|
||||
if (archiveButton && !archiveButton.dataset.boundClick) {
|
||||
archiveButton.addEventListener('click', () => this.handleArchiveAllAssets());
|
||||
archiveButton.dataset.boundClick = 'true';
|
||||
}
|
||||
const outstandingButton = document.getElementById('openArchivedAssetBorrowsBtn');
|
||||
if (outstandingButton && !outstandingButton.dataset.boundClick) {
|
||||
outstandingButton.addEventListener('click', () => this.openArchivedAssetBorrowsModal());
|
||||
outstandingButton.dataset.boundClick = 'true';
|
||||
}
|
||||
}
|
||||
|
||||
async handleArchiveAllAssets() {
|
||||
if (this.archivingAssets || !this.ensureAssetManagePermission('xóa danh mục tài sản')) return;
|
||||
this.archivingAssets = true;
|
||||
const button = document.getElementById('archiveAllAssetsBtn');
|
||||
if (button) button.disabled = true;
|
||||
try {
|
||||
const confirmed = await this.confirmBulkAssetDelete(this.assets.length, true);
|
||||
if (!confirmed) return;
|
||||
const response = await fetch(`${this.apiBase}/assets/archive-all`, {
|
||||
method: 'POST',
|
||||
headers: this.getAuthHeaders(false)
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok || !data.success) {
|
||||
this.notifyFailure(data.message || 'Xóa danh mục tài sản thất bại');
|
||||
return;
|
||||
}
|
||||
this.selectedAssetIds.clear();
|
||||
this.assetPage = 1;
|
||||
this.assetBorrowPage = 1;
|
||||
this.notifySuccess(`Đã chuyển ${Number(data.data?.archivedCount) || 0} tài sản sang dữ liệu cũ. Lịch sử mượn/trả được giữ lại.`);
|
||||
await this.refreshAssetsUI();
|
||||
await this.refreshAssetBorrowsUI();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
this.notifyFailure('Xóa danh mục tài sản thất bại');
|
||||
} finally {
|
||||
this.archivingAssets = false;
|
||||
const activeButton = document.getElementById('archiveAllAssetsBtn');
|
||||
if (activeButton) activeButton.disabled = !this.canCurrentUserManageAssets() || !this.assets.length;
|
||||
}
|
||||
}
|
||||
|
||||
getArchivedOutstandingAssets() {
|
||||
const search = String(this.archivedAssetSearchTerm || '').trim().toLowerCase();
|
||||
return (this.archivedAssets || []).map(asset => {
|
||||
const borrowerQuantity = this.parseBorrowerEntries(asset.Borrower)
|
||||
.reduce((sum, entry) => sum + this.parseNonNegativeInteger(entry.quantity, 0), 0);
|
||||
return {
|
||||
...asset,
|
||||
OutstandingQuantity: Math.max(borrowerQuantity, this.parseNonNegativeInteger(asset.ExportInPeriod, 0))
|
||||
};
|
||||
}).filter(asset => asset.OutstandingQuantity > 0 && (!search || [
|
||||
asset.AssetCode, asset.AssetName, asset.Model, asset.SerialNumber,
|
||||
this.formatBorrowerSummaryText(asset.Borrower), asset.Department, asset.Project, asset.Location
|
||||
].some(value => String(value || '').toLowerCase().includes(search))));
|
||||
}
|
||||
|
||||
renderArchivedAssetBorrowsTable() {
|
||||
const tableBody = document.getElementById('archivedAssetBorrowsTableBody');
|
||||
if (!tableBody) return;
|
||||
const rows = this.getArchivedOutstandingAssets();
|
||||
tableBody.innerHTML = rows.length ? rows.map(asset => `
|
||||
<tr class="border-b border-slate-100">
|
||||
<td class="px-4 py-3 text-sm text-slate-700">${this.escapeHtml(asset.AssetCode || '-')}<div class="text-[11px] text-slate-500">Hồ sơ cũ #${Number(asset.AssetId) || 0}</div></td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700">${this.escapeHtml(asset.AssetName || '-')}<div class="text-[11px] text-slate-500">${this.escapeHtml(asset.SerialNumber || '')}</div></td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700 whitespace-pre-line">${this.escapeHtml(this.formatBorrowerSummaryText(asset.Borrower) || 'Chưa có tên người mượn')}</td>
|
||||
<td class="px-4 py-3 text-sm font-bold text-slate-700">${asset.OutstandingQuantity}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700">${this.escapeHtml(asset.Unit || '-')}</td>
|
||||
<td class="px-4 py-3 text-sm text-slate-700">${this.escapeHtml(asset.Project || asset.Department || '-')}</td>
|
||||
</tr>
|
||||
`).join('') : '<tr><td colspan="6" class="px-4 py-8 text-center text-sm text-slate-500">Không có tài sản cũ còn mượn phù hợp.</td></tr>';
|
||||
const count = document.getElementById('archivedAssetBorrowsCount');
|
||||
if (count) count.textContent = `${rows.length} hồ sơ tài sản cũ còn mượn`;
|
||||
}
|
||||
|
||||
async openArchivedAssetBorrowsModal() {
|
||||
const modal = document.getElementById('archivedAssetBorrowsModal');
|
||||
if (!modal) {
|
||||
this.notifyFailure('Không tìm thấy danh sách tài sản cũ');
|
||||
return;
|
||||
}
|
||||
if (!await this.fetchArchivedAssets()) {
|
||||
this.notifyFailure('Không tải được dữ liệu tài sản cũ. Vui lòng thử lại.');
|
||||
return;
|
||||
}
|
||||
this.archivedAssetSearchTerm = '';
|
||||
const search = document.getElementById('archivedAssetBorrowsSearch');
|
||||
if (search) {
|
||||
search.value = '';
|
||||
if (!search.dataset.boundInput) {
|
||||
search.addEventListener('input', event => {
|
||||
this.archivedAssetSearchTerm = event.target.value;
|
||||
this.renderArchivedAssetBorrowsTable();
|
||||
});
|
||||
search.dataset.boundInput = 'true';
|
||||
}
|
||||
}
|
||||
this.renderArchivedAssetBorrowsTable();
|
||||
modal.classList.add('open');
|
||||
}
|
||||
|
||||
setupAssetPagerListeners() {
|
||||
@@ -9030,6 +9219,7 @@ class AccountManager {
|
||||
}
|
||||
|
||||
setupAssetRowListeners() {
|
||||
this.setupArchivedAssetListeners();
|
||||
this.setupAssetSelectionListeners();
|
||||
const canManageAssets = this.canCurrentUserManageAssets();
|
||||
|
||||
@@ -9103,8 +9293,9 @@ class AccountManager {
|
||||
this.pendingDeleteAssetId = undefined;
|
||||
this.selectedAssetIds.delete(targetDeleteId);
|
||||
this.closeModals();
|
||||
this.notifySuccess('Xóa tài sản thành công');
|
||||
this.notifySuccess('Đã xóa khỏi danh mục. Lịch sử mượn/trả được giữ lại.');
|
||||
await this.refreshAssetsUI();
|
||||
await this.refreshAssetBorrowsUI();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
this.notifyFailure('Xóa tài sản thất bại');
|
||||
|
||||
@@ -1033,6 +1033,36 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Archived asset borrower balances, including imports and direct exports. -->
|
||||
<div class="modal-backdrop fixed inset-0 z-[100] flex items-center justify-center bg-black/40 backdrop-blur-sm" id="archivedAssetBorrowsModal">
|
||||
<div class="modal-content bg-white rounded-xl shadow-2xl border border-slate-200 overflow-hidden flex flex-col m-4" style="width:min(1100px, calc(100vw - 32px));max-height:calc(100vh - 32px);">
|
||||
<div class="px-6 py-4 border-b border-slate-100 bg-slate-50 flex items-center justify-between gap-3">
|
||||
<h3 class="text-base font-extrabold text-slate-800">Tài sản cũ còn mượn</h3>
|
||||
<button type="button" class="p-1.5 rounded-lg hover:bg-slate-200 text-slate-500" data-close-modal="archivedAssetBorrowsModal" aria-label="Đóng">
|
||||
<span class="material-symbols-outlined">close</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="px-6 py-4 border-b border-slate-100">
|
||||
<p class="text-sm text-slate-600">Số dư người mượn của tài sản đã xóa khỏi danh mục, gồm cả dữ liệu nhập Excel và xuất trực tiếp. Các hồ sơ trùng mã được theo dõi riêng.</p>
|
||||
<p class="mt-2 text-xs text-slate-500">Nếu có đơn mượn gốc, tạo đơn trả tại Mượn/Trả tài sản để ghi nhận vào hồ sơ cũ. Dữ liệu chỉ có số dư người mượn cần đối chiếu riêng, cùng với tồn kho danh mục mới.</p>
|
||||
<label for="archivedAssetBorrowsSearch" class="mt-3 block text-xs font-bold text-slate-600">Tìm tài sản hoặc người mượn</label>
|
||||
<input id="archivedAssetBorrowsSearch" class="mt-1 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm" placeholder="Mã, tên, serial, người mượn, dự án...">
|
||||
</div>
|
||||
<div class="overflow-auto flex-1">
|
||||
<table class="w-full text-left border-collapse" style="min-width:780px;">
|
||||
<thead class="sticky top-0 bg-slate-50 text-xs font-bold text-slate-500">
|
||||
<tr><th class="px-4 py-3">Mã</th><th class="px-4 py-3">Tài sản</th><th class="px-4 py-3">Người mượn</th><th class="px-4 py-3">Còn mượn</th><th class="px-4 py-3">Đơn vị</th><th class="px-4 py-3">Dự án / Phòng ban</th></tr>
|
||||
</thead>
|
||||
<tbody id="archivedAssetBorrowsTableBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="px-6 py-4 border-t border-slate-100 flex items-center justify-between gap-3">
|
||||
<span id="archivedAssetBorrowsCount" class="text-xs text-slate-500"></span>
|
||||
<button type="button" class="px-4 py-2 text-xs font-bold text-slate-600 border border-slate-200 rounded-lg" data-close-modal="archivedAssetBorrowsModal">Đóng</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Asset Modal -->
|
||||
<div class="modal-backdrop fixed inset-0 z-[100] flex items-center justify-center bg-black/40 backdrop-blur-sm" id="deleteAssetModal">
|
||||
<div class="modal-content w-full max-w-md bg-white rounded-xl shadow-2xl border border-slate-200 overflow-hidden m-4">
|
||||
@@ -1041,7 +1071,7 @@
|
||||
<h3 class="text-base font-extrabold text-red-700">Xóa tài sản</h3>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<p class="text-sm text-slate-600 mb-6">Bạn có chắc muốn xóa tài sản <strong id="deleteAssetName">-</strong>? Hành động này không thể hoàn tác.</p>
|
||||
<p class="text-sm text-slate-600 mb-6">Xóa tài sản <strong id="deleteAssetName">-</strong> khỏi danh mục hiện tại? Lịch sử mượn/trả và số lượng còn đang mượn vẫn được giữ trong tài sản cũ.</p>
|
||||
<div class="flex gap-3">
|
||||
<button type="button" class="flex-1 px-4 py-2 text-xs font-bold text-slate-600 border border-slate-200 rounded-lg" data-close-modal="deleteAssetModal">Hủy</button>
|
||||
<button type="button" class="flex-1 px-4 py-2 bg-red-600 hover:bg-red-700 text-white rounded-lg text-xs font-bold confirm-delete-asset">Xóa</button>
|
||||
@@ -1055,10 +1085,11 @@
|
||||
<div class="modal-content w-full max-w-md bg-white rounded-xl shadow-2xl border border-slate-200 overflow-hidden m-4">
|
||||
<div class="px-6 py-4 border-b border-slate-100 bg-red-50 flex items-center gap-3">
|
||||
<span class="material-symbols-outlined text-red-600 text-2xl">warning</span>
|
||||
<h3 class="text-base font-extrabold text-red-700">Xóa tài sản đã chọn</h3>
|
||||
<h3 id="bulkDeleteAssetsConfirmTitle" class="text-base font-extrabold text-red-700">Xóa tài sản đã chọn</h3>
|
||||
</div>
|
||||
<div class="p-6">
|
||||
<p id="bulkDeleteAssetsConfirmMessage" class="text-sm text-slate-600 mb-6">Bạn có chắc muốn xóa các tài sản đã chọn?</p>
|
||||
<p class="text-xs text-slate-500 mb-4">Đơn mượn đang chờ của tài sản cũ không thể duyệt sau khi xóa; cần hủy hoặc từ chối. Đơn trả vẫn được xử lý trên hồ sơ cũ. Tồn kho dữ liệu mới cần đối chiếu riêng.</p>
|
||||
<div class="mb-4 rounded-lg border border-red-100 bg-red-50 px-3 py-2 text-xs text-red-700">
|
||||
Số lượng: <strong id="bulkDeleteAssetsConfirmCount">0</strong> tài sản
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user