update export

This commit is contained in:
2026-11-11 10:48:31 +07:00
parent 00122e5b4a
commit 03a481f20d
7 changed files with 741 additions and 90 deletions

View File

@@ -2104,6 +2104,7 @@ class AccountManager {
<div class="compact-page-actions flex flex-wrap gap-2">
<button id="refreshAssetExportsBtn" class="border border-slate-200 rounded-lg px-3 py-2 text-xs font-bold">Làm mới</button>
<button id="createAssetExportBtn" class="bg-primary text-on-primary rounded-lg px-4 py-2 text-xs font-bold">Tạo đơn xuất dự án</button>
${manager ? '<button id="createAssetExportForOthersBtn" class="border border-primary text-primary rounded-lg px-4 py-2 text-xs font-bold">Xuất cho người khác</button>' : ''}
</div>
</div>
<div class="flex flex-wrap items-center gap-2 mb-4 shrink-0" role="tablist" aria-label="Danh sách xuất tài sản">
@@ -2221,6 +2222,11 @@ class AccountManager {
document.getElementById('assetExportSearchInput').oninput = event => { this.assetExportSearchTerm = event.target.value; this.assetExportPage = 1; this.renderAssetExportsTable(); };
document.getElementById('refreshAssetExportsBtn').onclick = () => this.refreshAssetExportsPage();
document.getElementById('createAssetExportBtn').onclick = () => { location.hash = '#assets'; this.notifyWarning('Chọn một hoặc nhiều tài sản, sau đó bấm Tạo đơn xuất dự án.'); };
const exportForOthersButton = document.getElementById('createAssetExportForOthersBtn');
if (exportForOthersButton) exportForOthersButton.onclick = () => {
location.hash = '#assets';
this.notifyWarning('Chọn một hoặc nhiều tài sản, sau đó bấm Xuất cho người khác.');
};
for (const [id, tab] of [['assetExportRequestsTab', 'requests'], ['assetExportHistoryTab', 'history']]) {
document.getElementById(id).onclick = () => { this.assetExportTab = tab; this.assetExportPage = 1; this.renderAssetExportsTable(); };
}
@@ -7872,48 +7878,30 @@ class AccountManager {
return `
<div class="assets-page flex flex-col p-4 md:p-6 overflow-hidden h-full">
<div class="page-header flex items-center justify-between gap-4 mb-5 shrink-0">
<div class="page-header asset-page-heading flex items-center justify-between gap-4 mb-5 shrink-0">
<div>
<h1 class="text-2xl font-extrabold text-on-surface tracking-tight">Quản lý tài sản</h1>
<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ũ
</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
</button>
<button id="exportAssetBtn" class="border border-slate-300 hover:bg-slate-100 text-slate-700 px-3 py-2 rounded-lg text-xs font-bold flex items-center gap-1.5 transition-all active:scale-95">
<span class="material-symbols-outlined text-base">download</span>
Xuất Excel
</button>
<button id="openAssetExportHistoryBtn" class="border border-amber-300 text-amber-700 px-3 py-2 rounded-lg text-xs font-bold flex items-center gap-1.5 transition-all active:scale-95 hover:bg-amber-50">
<span class="material-symbols-outlined text-base">history</span>
Lịch sử xuất
</button>
<button id="openAssetDamageHistoryBtn" class="border border-red-200 text-red-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-red-50' : 'opacity-50 cursor-not-allowed'}" ${canManageAssets ? '' : 'disabled'}>
<span class="material-symbols-outlined text-base">inventory_2</span>
DS hỏng/TL
</button>
<button id="addAssetBtn" 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 ${canManageAssets ? 'hover:bg-primary-dim' : 'opacity-50 cursor-not-allowed'}" ${canManageAssets ? '' : 'disabled'}>
<span class="material-symbols-outlined text-base">add_box</span>
Thêm tài sản
</button>
<button id="borrowAssetBtn" class="border border-primary text-primary px-4 py-2 rounded-lg text-xs font-bold flex items-center gap-1.5 transition-all active:scale-95 ${(selectedCount > 0) ? 'hover:bg-primary/5' : 'opacity-50 cursor-not-allowed'}" ${(selectedCount > 0) ? '' : 'disabled'}>
<span class="material-symbols-outlined text-base">handshake</span>
Tạo đơn xuất dự án
</button>
<button id="damageAssetBtn" class="border border-red-300 text-red-700 px-4 py-2 rounded-lg text-xs font-bold flex items-center gap-1.5 transition-all active:scale-95 ${(canManageAssets && selectedCount === 1) ? 'hover:bg-red-50' : 'opacity-50 cursor-not-allowed'}" ${(canManageAssets && selectedCount === 1) ? '' : 'disabled'}>
<span class="material-symbols-outlined text-base">broken_image</span>
Hỏng/Thanh lý
<div class="asset-page-actions" aria-label="Quản lý danh mục tài sản">
<button type="button" id="openAssetExportHistoryBtn" class="asset-action-button">
<span class="material-symbols-outlined" aria-hidden="true">history</span><span>Lịch sử xuất</span>
</button>
<details class="asset-action-menu">
<summary class="asset-action-button"><span class="material-symbols-outlined" aria-hidden="true">tune</span>Tiện ích<span class="material-symbols-outlined asset-menu-chevron" aria-hidden="true">expand_more</span></summary>
<div class="asset-menu-panel">
<p class="asset-menu-label">Dữ liệu Excel</p>
${canManageAssets ? `<button type="button" id="importAssetBtn" class="asset-menu-item"><span class="material-symbols-outlined" aria-hidden="true">upload_file</span><span>Nhập Excel<small>Thêm tài sản từ bảng tính</small></span></button>` : ''}
<button type="button" id="exportAssetBtn" class="asset-menu-item"><span class="material-symbols-outlined" aria-hidden="true">download</span><span>Xuất Excel<small>Tải danh sách tài sản</small></span></button>
<p class="asset-menu-label asset-menu-divider">Tra cứu</p>
<button type="button" id="openArchivedAssetBorrowsBtn" class="asset-menu-item"><span class="material-symbols-outlined" aria-hidden="true">inventory_2</span><span>Tài sản cũ<small>Xem danh mục đã lưu trữ</small></span></button>
${canManageAssets ? `<button type="button" id="openAssetDamageHistoryBtn" class="asset-menu-item"><span class="material-symbols-outlined" aria-hidden="true">assignment</span><span>Danh sách hỏng / thanh lý</span></button>
<div class="asset-menu-divider"><button type="button" id="archiveAllAssetsBtn" class="asset-menu-item asset-menu-danger" ${this.assets.length ? '' : 'disabled'}><span class="material-symbols-outlined" aria-hidden="true">archive</span><span>Xóa danh mục hiện tại<small>Chuyển sang tài sản cũ, giữ lại lịch sử</small></span></button></div>` : ''}
</div>
</details>
${canManageAssets ? `<button type="button" id="addAssetBtn" class="asset-action-button asset-action-primary">
<span class="material-symbols-outlined" aria-hidden="true">add</span>Thêm tài sản
</button>` : ''}
<input id="assetImportInput" type="file" accept=".xlsx,.xls" class="hidden" />
</div>
</div>
@@ -7932,10 +7920,30 @@ class AccountManager {
<span class="text-[10px] font-bold uppercase text-on-surface-variant">Tìm kiếm</span>
<input id="assetSearch" class="flex-1 bg-surface-container-low border-slate-200 rounded-md text-[11px] py-1 px-2 focus:ring-1 focus:ring-primary shadow-sm" placeholder="Mã, tên, model, serial, dự án, vị trí...">
</div>
<button id="bulkDeleteAssetsBtn" class="compact-filter-action border border-red-200 text-red-600 px-3 py-1.5 rounded-md text-[11px] font-bold flex items-center gap-1.5 transition-colors ${(selectedCount === 0 || !canManageAssets) ? 'opacity-50 cursor-not-allowed' : 'hover:bg-red-50'}" ${(selectedCount === 0 || !canManageAssets) ? 'disabled' : ''}>
<span class="material-symbols-outlined text-base">delete_sweep</span>
Xóa đã chọn (<span id="selectedAssetCount">${selectedCount}</span>)
</button>
</div>
<div id="assetSelectionToolbar" class="asset-selection-toolbar" data-has-selection="${selectedCount > 0}" role="region" aria-label="Thao tác với tài sản đã chọn">
<div class="asset-selection-info">
<div class="asset-selection-status" role="status" aria-live="polite" aria-atomic="true"><span id="selectedAssetCount" class="asset-selection-count">${selectedCount}</span><span>Tài sản đã chọn</span></div>
<span id="assetSelectionHint" class="asset-selection-hint">${selectedCount ? 'Chọn thao tác áp dụng cho các tài sản này.' : 'Đánh dấu ô chọn trong danh sách để thao tác.'}</span>
<button type="button" id="clearAssetSelectionBtn" class="asset-selection-clear" ${selectedCount ? '' : 'hidden'}>Bỏ chọn</button>
</div>
<div class="asset-selection-actions">
<button type="button" id="borrowAssetBtn" class="asset-action-button asset-export-action asset-action-proposal" ${selectedCount ? '' : 'disabled'}>
<span class="material-symbols-outlined" aria-hidden="true">assignment_add</span><span>Tạo đơn xuất dự án<small>Chờ duyệt</small></span>
</button>
${canManageAssets ? `<button type="button" id="exportAssetForOthersBtn" class="asset-action-button asset-export-action" ${selectedCount ? '' : 'disabled'}>
<span class="material-symbols-outlined" aria-hidden="true">person_add</span><span>Xuất cho người khác<small>Trừ kho ngay</small></span>
</button>
<details class="asset-action-menu asset-selection-menu">
<summary class="asset-action-button" aria-label="Thao tác khác với tài sản đã chọn"><span class="material-symbols-outlined" aria-hidden="true">more_horiz</span><span>Khác</span></summary>
<div class="asset-menu-panel">
<p class="asset-menu-label">Với tài sản đã chọn</p>
<button type="button" id="damageAssetBtn" class="asset-menu-item" ${selectedCount === 1 ? '' : 'disabled'}><span class="material-symbols-outlined" aria-hidden="true">broken_image</span><span>Hỏng / Thanh lý<small>Áp dụng cho 1 tài sản</small></span></button>
<div class="asset-menu-divider"><button type="button" id="bulkDeleteAssetsBtn" class="asset-menu-item asset-menu-danger" ${selectedCount ? '' : 'disabled'}><span class="material-symbols-outlined" aria-hidden="true">delete_sweep</span><span>Xóa tài sản đã chọn<small>Chuyển các tài sản này sang tài sản cũ</small></span></button></div>
</div>
</details>` : ''}
</div>
</div>
<div class="flex-1 bg-white rounded-xl border border-slate-200 shadow-sm flex flex-col overflow-hidden min-h-0">
@@ -8195,9 +8203,50 @@ class AccountManager {
bulkDeleteBtn.dataset.boundClick = 'true';
}
const clearSelectionButton = document.getElementById('clearAssetSelectionBtn');
if (clearSelectionButton && !clearSelectionButton.dataset.boundClick) {
clearSelectionButton.addEventListener('click', () => {
this.selectedAssetIds.clear();
document.querySelectorAll('.asset-row-checkbox').forEach(checkbox => { checkbox.checked = false; });
this.updateAssetBulkActionState();
});
clearSelectionButton.dataset.boundClick = 'true';
}
this.updateAssetBulkActionState();
}
setupAssetActionMenus() {
document.querySelectorAll('.assets-page .asset-action-menu').forEach(menu => {
if (menu.dataset.boundMenu) return;
menu.addEventListener('toggle', () => {
if (menu.open) document.querySelectorAll('.assets-page .asset-action-menu[open]').forEach(other => {
if (other !== menu) other.open = false;
});
});
menu.addEventListener('click', event => {
const button = event.target.closest('button');
if (button && !button.disabled) menu.open = false;
});
menu.addEventListener('keydown', event => {
if (event.key === 'Escape' && menu.open) {
menu.open = false;
menu.querySelector('summary').focus();
event.stopPropagation();
}
});
menu.dataset.boundMenu = 'true';
});
if (!this.assetActionMenusBound) {
document.addEventListener('click', event => {
document.querySelectorAll('.assets-page .asset-action-menu[open]').forEach(menu => {
if (!menu.contains(event.target)) menu.open = false;
});
});
this.assetActionMenusBound = true;
}
}
updateAssetBulkActionState() {
const canManageAssets = this.canCurrentUserManageAssets();
const rowCheckboxes = Array.from(document.querySelectorAll('.asset-row-checkbox'));
@@ -8227,30 +8276,21 @@ class AccountManager {
selectedCountNode.textContent = String(selectedCount);
}
const bulkDeleteBtn = document.getElementById('bulkDeleteAssetsBtn');
if (bulkDeleteBtn) {
const disabled = !canManageAssets || selectedCount === 0;
bulkDeleteBtn.disabled = disabled;
bulkDeleteBtn.classList.toggle('opacity-50', disabled);
bulkDeleteBtn.classList.toggle('cursor-not-allowed', disabled);
}
const toolbar = document.getElementById('assetSelectionToolbar');
if (toolbar) toolbar.dataset.hasSelection = String(selectedCount > 0);
const hint = document.getElementById('assetSelectionHint');
if (hint) hint.textContent = selectedCount ? 'Chọn thao tác áp dụng cho các tài sản này.' : 'Đánh dấu ô chọn trong danh sách để thao tác.';
const clearSelectionButton = document.getElementById('clearAssetSelectionBtn');
if (clearSelectionButton) clearSelectionButton.hidden = selectedCount === 0;
const borrowAssetBtn = document.getElementById('borrowAssetBtn');
if (borrowAssetBtn) {
const disabled = selectedCount === 0;
borrowAssetBtn.disabled = disabled;
borrowAssetBtn.classList.toggle('opacity-50', disabled);
borrowAssetBtn.classList.toggle('cursor-not-allowed', disabled);
borrowAssetBtn.classList.toggle('hover:bg-primary/5', !disabled);
}
const damageAssetBtn = document.getElementById('damageAssetBtn');
if (damageAssetBtn) {
const disabled = !canManageAssets || selectedCount !== 1;
damageAssetBtn.disabled = disabled;
damageAssetBtn.classList.toggle('opacity-50', disabled);
damageAssetBtn.classList.toggle('cursor-not-allowed', disabled);
damageAssetBtn.classList.toggle('hover:bg-red-50', !disabled);
for (const [id, disabled, title] of [
['bulkDeleteAssetsBtn', !canManageAssets || selectedCount === 0, 'Chọn ít nhất 1 tài sản để xóa.'],
['borrowAssetBtn', selectedCount === 0, 'Chọn ít nhất 1 tài sản để tạo đơn xuất dự án.'],
['exportAssetForOthersBtn', !canManageAssets || selectedCount === 0, 'Chọn ít nhất 1 tài sản để xuất cho người khác.'],
['damageAssetBtn', !canManageAssets || selectedCount !== 1, 'Chọn đúng 1 tài sản để ghi nhận hỏng hoặc thanh lý.']
]) {
const button = document.getElementById(id);
if (button) { button.disabled = disabled; button.title = disabled ? title : ''; }
}
}
@@ -8995,7 +9035,29 @@ class AccountManager {
if (summary) summary.textContent = `${items.length} tài sản đã chọn · 1 phiếu Excel chung`;
}
async openBatchAssetExportModal() {
configureAssetExportForm(prefix, forOthers) {
const form = document.getElementById(`${prefix}Form`);
form.dataset.exportForOthers = String(forOthers);
document.getElementById(`${prefix}RequesterField`).hidden = forOthers;
document.getElementById(`${prefix}RecipientField`).hidden = !forOthers;
const recipient = document.getElementById(`${prefix}RecipientInput`);
recipient.disabled = !forOthers;
recipient.required = forOthers;
if (forOthers) this.populateUserSelectOptions(recipient.id, { emptyLabel: '-- Chọn người nhận --' });
else recipient.value = '';
const batch = prefix === 'batchAssetExport';
document.getElementById(`${prefix}Title`).textContent = forOthers
? (batch ? 'Xuất nhiều tài sản cho người khác' : 'Xuất tài sản cho người khác')
: (batch ? 'Tạo đơn xuất nhiều tài sản vào dự án' : 'Tạo đơn xuất tài sản vào dự án');
document.getElementById(`${prefix}Description`).textContent = forOthers
? 'Chọn người nhận và dự án. Xác nhận sẽ trừ kho ngay và tạo phiếu Excel; tài sản xuất không hoàn lại kho.'
: (batch ? 'Chọn số lượng và dự án cho từng tài sản. Chỉ trừ kho khi được duyệt; tài sản xuất không hoàn lại kho.'
: 'Xuất vào dự án, không hoàn lại kho. Số lượng chỉ trừ khi admin/asset duyệt đơn.');
form.querySelector('button[type="submit"]').textContent = forOthers ? 'Xuất và tải Excel' : 'Gửi đơn chờ duyệt';
}
async openBatchAssetExportModal(forOthers = false) {
if (forOthers && !this.ensureAssetManagePermission('xuất tài sản cho người khác')) return;
const assets = this.assets.filter(asset => this.selectedAssetIds.has(Number(asset.AssetId)));
if (!assets.length || assets.length > 100) {
this.notifyWarning('Vui lòng chọn từ 1 đến 100 tài sản để xuất.');
@@ -9006,10 +9068,12 @@ class AccountManager {
this.notifyWarning(`${unavailable.AssetCode || unavailable.AssetName}: đã hết tồn, hãy bỏ chọn tài sản này.`);
return;
}
if (forOthers && !this.users.length) await this.fetchUsers();
if (!this.assetProjects.length) await this.fetchAssetProjects();
const modal = document.getElementById('batchAssetExportModal');
const form = document.getElementById('batchAssetExportForm');
if (!modal || !form) { this.notifyFailure('Không tìm thấy biểu mẫu xuất nhiều tài sản.'); return; }
this.configureAssetExportForm('batchAssetExport', forOthers);
document.getElementById('batchAssetExportUserInput').value = this.getCurrentUserDisplayName();
const commonProject = document.getElementById('batchAssetExportCommonProject');
commonProject.innerHTML = '<option value="">-- Áp dụng dự án cho tất cả --</option>'
@@ -9033,10 +9097,12 @@ class AccountManager {
async handleBatchAssetExportSubmit(event) {
event.preventDefault();
if (this.assetExportSubmitting) return;
const forOthers = document.getElementById('batchAssetExportForm')?.dataset.exportForOthers === 'true';
if (forOthers && !this.ensureAssetManagePermission('xuất tài sản cho người khác')) return;
const items = this.collectBatchAssetExportItems();
const borrowerName = String(document.getElementById('batchAssetExportUserInput')?.value || '').trim();
const borrowerName = String(document.getElementById(forOthers ? 'batchAssetExportRecipientInput' : 'batchAssetExportUserInput')?.value || '').trim();
const note = String(document.getElementById('batchAssetExportNoteInput')?.value || '').trim();
if (!borrowerName) { this.notifyWarning('Không xác định được người đề xuất.'); return; }
if (!borrowerName) { this.notifyWarning(forOthers ? 'Vui lòng chọn người nhận.' : 'Không xác định được người đề xuất.'); return; }
if (!items.length || items.length > 100) { this.notifyWarning('Vui lòng chọn từ 1 đến 100 tài sản.'); return; }
for (const item of items) {
const asset = this.assets.find(asset => Number(asset.AssetId) === item.assetId);
@@ -9051,13 +9117,20 @@ class AccountManager {
if (button) button.disabled = true;
let exportSucceeded = false;
try {
const response = await fetch(`${this.apiBase}/asset-export-requests`, {
const response = await fetch(`${this.apiBase}/${forOthers ? 'assets/export' : 'asset-export-requests'}`, {
method: 'POST', headers: this.getAuthHeaders(true), body: JSON.stringify({ borrowerName, note, items })
});
const data = await response.json();
if (!response.ok || !data.success) { this.notifyFailure(data.message || 'Xuất tài sản thất bại.'); return; }
exportSucceeded = true;
this.selectedAssetIds.clear();
if (forOthers) {
this.notifySuccess(`Đã xuất ${items.length} tài sản cho ${borrowerName} và lưu phiếu Excel vào lịch sử.`);
this.closeModals();
this.showExportRequestDocument(data.document);
await this.refreshAssetsUI();
return;
}
this.notifySuccess('Đã gửi đơn xuất vào dự án, chờ admin/asset duyệt.');
this.closeModals();
this.assetExportTab = 'requests';
@@ -9067,7 +9140,9 @@ class AccountManager {
location.hash = '#asset-exports';
} catch (err) {
console.error(err);
if (exportSucceeded) this.notifyWarning('Đã gửi đơn xuất. Hãy mở danh sách đơn xuất để kiểm tra.');
if (exportSucceeded) this.notifyWarning(forOthers
? 'Đã xuất tài sản thành công. Hãy mở lịch sử xuất để kiểm tra hoặc tải lại phiếu Excel.'
: 'Đã gửi đơn xuất. Hãy mở danh sách đơn xuất để kiểm tra.');
else this.notifyFailure('Xuất tài sản thất bại.');
} finally {
this.assetExportSubmitting = false;
@@ -9118,13 +9193,15 @@ class AccountManager {
this.updateBorrowAllocationSummary();
}
async openBorrowAssetModal() {
if (this.selectedAssetIds.size > 1) return this.openBatchAssetExportModal();
async openBorrowAssetModal(forOthers = false) {
if (forOthers && !this.ensureAssetManagePermission('xuất tài sản cho người khác')) return;
if (this.selectedAssetIds.size > 1) return this.openBatchAssetExportModal(forOthers);
const asset = this.getSingleSelectedAssetForBorrowing(true);
if (!asset) {
return;
}
if (forOthers && !this.users.length) await this.fetchUsers();
if (!this.assetProjects.length) {
await this.fetchAssetProjects();
}
@@ -9150,6 +9227,8 @@ class AccountManager {
return;
}
this.configureAssetExportForm('borrowAsset', forOthers);
if (assetIdInput) {
assetIdInput.value = String(asset.AssetId || '');
}
@@ -9176,8 +9255,10 @@ class AccountManager {
async handleBorrowAssetSubmit(e) {
e.preventDefault();
const forOthers = document.getElementById('borrowAssetForm')?.dataset.exportForOthers === 'true';
if (forOthers && !this.ensureAssetManagePermission('xuất tài sản cho người khác')) return;
const assetIdInput = document.getElementById('borrowAssetIdInput');
const borrowerInput = document.getElementById('borrowAssetUserInput');
const borrowerInput = document.getElementById(forOthers ? 'borrowAssetRecipientInput' : 'borrowAssetUserInput');
const noteInput = document.getElementById('borrowAssetNoteInput');
const selectedAssetId = Number(assetIdInput?.value || this.pendingBorrowAssetId);
@@ -9194,7 +9275,7 @@ class AccountManager {
const borrowerName = String(borrowerInput?.value || '').trim();
if (!borrowerName) {
this.notifyWarning('Không xác định được người đề xuất.');
this.notifyWarning(forOthers ? 'Vui lòng chọn người nhận.' : 'Không xác định được người đề xuất.');
return;
}
@@ -9227,11 +9308,11 @@ class AccountManager {
if (submitButton) submitButton.disabled = true;
let exportSucceeded = false;
try {
const response = await fetch(`${this.apiBase}/asset-export-requests`, {
const response = await fetch(`${this.apiBase}/${forOthers ? `assets/${selectedAssetId}/export` : 'asset-export-requests'}`, {
method: 'POST',
headers: this.getAuthHeaders(true),
body: JSON.stringify({
items: [{ assetId: selectedAssetId, allocations }],
...(forOthers ? { borrowerName, allocations } : { items: [{ assetId: selectedAssetId, allocations }] }),
note: exportNote
})
});
@@ -9245,6 +9326,13 @@ class AccountManager {
exportSucceeded = true;
this.pendingBorrowAssetId = undefined;
this.selectedAssetIds.clear();
if (forOthers) {
this.notifySuccess(`Đã xuất tài sản cho ${borrowerName} và lưu phiếu Excel vào lịch sử.`);
this.closeModals();
this.showExportRequestDocument(data.document);
await this.refreshAssetsUI();
return;
}
this.notifySuccess('Đã gửi đơn xuất vào dự án, chờ admin/asset duyệt.');
this.closeModals();
this.assetExportTab = 'requests';
@@ -9254,7 +9342,9 @@ class AccountManager {
location.hash = '#asset-exports';
} catch (err) {
console.error(err);
if (exportSucceeded) this.notifyWarning('Đã gửi đơn xuất. Hãy mở danh sách đơn xuất để kiểm tra.');
if (exportSucceeded) this.notifyWarning(forOthers
? 'Đã xuất tài sản thành công. Hãy mở lịch sử xuất để kiểm tra hoặc tải lại phiếu Excel.'
: 'Đã gửi đơn xuất. Hãy mở danh sách đơn xuất để kiểm tra.');
else this.notifyFailure('Xuất tài sản thất bại');
} finally {
this.assetExportSubmitting = false;
@@ -10584,6 +10674,7 @@ class AccountManager {
setupAssetRowListeners() {
this.setupArchivedAssetListeners();
this.setupAssetSelectionListeners();
this.setupAssetActionMenus();
const canManageAssets = this.canCurrentUserManageAssets();
document.querySelectorAll('.view-asset').forEach(btn => {
@@ -12000,6 +12091,11 @@ class AccountManager {
borrowAssetBtn.addEventListener('click', () => this.openBorrowAssetModal());
borrowAssetBtn.dataset.boundClick = 'true';
}
const exportForOthersButton = document.getElementById('exportAssetForOthersBtn');
if (exportForOthersButton && !exportForOthersButton.dataset.boundClick) {
exportForOthersButton.addEventListener('click', () => this.openBorrowAssetModal(true));
exportForOthersButton.dataset.boundClick = 'true';
}
const damageAssetBtn = document.getElementById('damageAssetBtn');
if (damageAssetBtn && !damageAssetBtn.dataset.boundClick) {