+19
-14
@@ -463,6 +463,11 @@ function esc(v) {
|
||||
}
|
||||
|
||||
const isAdmin = () => _user?.role === 'admin';
|
||||
// Item Approvals specifically also lets sap_adder and system_admin manage/
|
||||
// approve (matches routes/itemApproval.js's own privileged-role check
|
||||
// server-side) — unlike BOM/Cust/Vendor approvals above, which route through
|
||||
// a configurable per-role approval map instead of a fixed admin-only gate.
|
||||
const canManageItems = () => isAdmin() || _user?.role === 'sap_adder' || _user?.role === 'system_admin';
|
||||
function coLabel(company){const m={[window.__DEFAULT_COMPANY__]:'Oil'};return m[company]||'';}
|
||||
function coBadge(company){const l=coLabel(company);return l&&_activeCompany==='ALL'?`<span style="font-size:9px;font-weight:700;padding:1px 6px;border-radius:4px;background:rgba(159,90,253,.1);color:#9f5afd;border:1px solid rgba(159,90,253,.25)">${l}</span>`:'';}
|
||||
|
||||
@@ -597,7 +602,7 @@ async function loadItemApprovals() {
|
||||
}
|
||||
|
||||
function countMyTurnItem() {
|
||||
if (isAdmin()) return _itemApprovals.filter(r => r.status === 'PENDING').length;
|
||||
if (canManageItems()) return _itemApprovals.filter(r => r.status === 'PENDING').length;
|
||||
return 0; // only admin sees item approvals
|
||||
}
|
||||
|
||||
@@ -1430,11 +1435,11 @@ function renderItemSection(container) {
|
||||
<div class="stat-pill"><span class="stat-n red">${rejected}</span><span style="font-size:11px;color:var(--text3)">Rejected</span></div>`;
|
||||
container.appendChild(sr);
|
||||
|
||||
if (!isAdmin()) {
|
||||
if (!canManageItems()) {
|
||||
const info = document.createElement('div');
|
||||
info.className = 'alert al-info';
|
||||
info.style.margin = '12px 0';
|
||||
info.textContent = 'ℹ Item approvals are managed by admin only.';
|
||||
info.textContent = 'ℹ Item approvals are managed by admin/SAP Adder/system admin only.';
|
||||
container.appendChild(info);
|
||||
return;
|
||||
}
|
||||
@@ -1480,7 +1485,7 @@ function renderItemSection(container) {
|
||||
function buildItemCard(req) {
|
||||
const card = document.createElement('div');
|
||||
const isPending = req.status === 'PENDING';
|
||||
card.className = `req-card border-${isPending ? 'ITEM_PENDING' : req.status}${isPending && isAdmin() ? ' my-turn-card-item' : ''}`;
|
||||
card.className = `req-card border-${isPending ? 'ITEM_PENDING' : req.status}${isPending && canManageItems() ? ' my-turn-card-item' : ''}`;
|
||||
|
||||
const statusLabel = req.status === 'SAP_PUSHED' ? 'In SAP B1' : req.status === 'REJECTED' ? 'Rejected' : 'Pending Review';
|
||||
const statusClass = req.status === 'SAP_PUSHED' ? 'sb-SAP_PUSHED' : req.status === 'REJECTED' ? 'sb-REJECTED' : 'sb-ITEM_PENDING';
|
||||
@@ -1493,7 +1498,7 @@ function buildItemCard(req) {
|
||||
<div class="rc-badges">
|
||||
<span style="font-size:10px;font-weight:700;padding:2px 7px;border-radius:4px;background:rgba(159,90,253,.1);color:var(--purple)">📦 ITEM</span>
|
||||
<span class="status-badge ${statusClass}">${statusLabel}</span>
|
||||
${isPending && isAdmin() ? '<span class="admin-chip">⚡ Review Required</span>' : ''}
|
||||
${isPending && canManageItems() ? '<span class="admin-chip">⚡ Review Required</span>' : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1515,7 +1520,7 @@ function buildItemCard(req) {
|
||||
db.onclick = () => openItemDetail(req.id);
|
||||
actDiv.appendChild(db);
|
||||
|
||||
if (isPending && isAdmin()) {
|
||||
if (isPending && canManageItems()) {
|
||||
const ab = document.createElement('button');
|
||||
ab.className = 'btn b-approve admin-direct'; ab.innerHTML = '⚡ Approve → SAP';
|
||||
ab.onclick = e => { e.stopPropagation(); openItemDetail(req.id); };
|
||||
@@ -1585,7 +1590,7 @@ function buildItemDetailModal(container, req) {
|
||||
<button class="modal-close" id="imc1">✕</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
${isAdmin() && isPending ? `<div class="alert al-gold">⚡ <strong>Admin Review:</strong> Check all details below. Edit any wrong fields, then approve to push to SAP B1.</div>` : ''}
|
||||
${canManageItems() && isPending ? `<div class="alert al-gold">⚡ <strong>Admin Review:</strong> Check all details below. Edit any wrong fields, then approve to push to SAP B1.</div>` : ''}
|
||||
${req.status === 'SAP_PUSHED' ? `<div class="alert al-green">✅ Item <strong>${esc(req.sapItemCode || req.itemCode)}</strong> successfully created in SAP B1 by ${esc(req.approvedBy )} on ${req.approvedAt ? new Date(req.approvedAt).toLocaleString('en-IN') : ''}.</div>` : ''}
|
||||
${req.status === 'REJECTED' ? `<div class="alert al-red">✗ Rejected by ${esc(req.rejectedBy )}. ${req.adminNotes ? `Reason: "${esc(req.adminNotes)}"` : ''}</div>` : ''}
|
||||
|
||||
@@ -1599,7 +1604,7 @@ function buildItemDetailModal(container, req) {
|
||||
|
||||
<!-- TAB: ITEM DETAILS (editable if pending+admin) -->
|
||||
<div class="modal-tab-pane active" id="itab-details">
|
||||
${isPending && isAdmin() ? `
|
||||
${isPending && canManageItems() ? `
|
||||
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px;margin-bottom:12px">
|
||||
${editField('Item Code', 'ItemCode', d.ItemCode || req.itemCode)}
|
||||
${editField('Description *', 'ItemName', d.ItemName || req.itemName)}
|
||||
@@ -1638,7 +1643,7 @@ function buildItemDetailModal(container, req) {
|
||||
|
||||
<!-- TAB: WAREHOUSE & STOCK -->
|
||||
<div class="modal-tab-pane" id="itab-warehouse">
|
||||
${isPending && isAdmin() ? `
|
||||
${isPending && canManageItems() ? `
|
||||
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px">
|
||||
${editField('Default Warehouse', 'DefaultWarehouse', d.DefaultWarehouse || '')}
|
||||
${editField('GL Method', 'GLMethod', d.GLMethod || 'glm_ItemClass')}
|
||||
@@ -1658,7 +1663,7 @@ function buildItemDetailModal(container, req) {
|
||||
|
||||
<!-- TAB: GENERAL (GST/HSN) -->
|
||||
<div class="modal-tab-pane" id="itab-general">
|
||||
${isPending && isAdmin() ? `
|
||||
${isPending && canManageItems() ? `
|
||||
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px">
|
||||
${editField('HSN Code', 'HsnCode', d.HsnCode || '')}
|
||||
${editField('Assessable Value', 'AssessableValue', d.AssessableValue || 0, 'number')}
|
||||
@@ -1681,7 +1686,7 @@ function buildItemDetailModal(container, req) {
|
||||
|
||||
<!-- TAB: PURCHASING -->
|
||||
<div class="modal-tab-pane" id="itab-purchase">
|
||||
${isPending && isAdmin() ? `
|
||||
${isPending && canManageItems() ? `
|
||||
<div style="display:grid;grid-template-columns:1fr 1fr;gap:10px">
|
||||
${editField('Preferred Vendor', 'DefaultVendor', d.DefaultVendor || d.Mainsupplier || '')}
|
||||
${editField('Lead Time (days)', 'LeadTime', d.LeadTime || '', 'number')}
|
||||
@@ -1719,14 +1724,14 @@ function buildItemDetailModal(container, req) {
|
||||
</div>`).join('')}
|
||||
</div>
|
||||
|
||||
${isPending && isAdmin() ? `
|
||||
${isPending && canManageItems() ? `
|
||||
<div style="margin-top:16px;padding-top:16px;border-top:1px solid var(--border)">
|
||||
<label style="font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.4px;color:var(--text3);display:block;margin-bottom:7px">Admin Notes / Comment</label>
|
||||
<textarea class="comment-area" id="item-modal-comment" style="min-height:55px" placeholder="Notes about this item request (optional)…"></textarea>
|
||||
</div>` : ''}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
${isPending && isAdmin() ? `
|
||||
${isPending && canManageItems() ? `
|
||||
<button class="btn b-approve admin-direct" id="item-modal-approve">
|
||||
<span id="item-modal-sp" style="display:none" class="sp"></span>
|
||||
⚡ Approve → Push to SAP B1
|
||||
@@ -1797,7 +1802,7 @@ function buildItemDetailModal(container, req) {
|
||||
|
||||
init();
|
||||
</script>
|
||||
<script src="/sidebar.js?v=25"></script>
|
||||
<script src="/sidebar.js?v=31"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user