Update landscape sidebar logo, RMA replacement SN, auto stock

deduction, and cleaner symmetrical UI
This commit is contained in:
Yoga Pratama committed 2026-11-30 11:22:21 +07:00
1 parent efd4de1bc0
commit ef2eb43fbf
15 files changed
+1163 -1030

No files matched your search

+5 -4
View File
@@ -459,10 +459,11 @@ model CustomerProductPrice {
// PENCATATAN RIWAYAT DEVICE: PERNAH DISERVIS, RUSAK TOTAL (AFKIR), & KANIBALAN
// -----------------------------------------------------------------------------
model DeviceRecord {
id String @id @default(uuid())
recordNumber String @unique
serialNumber String
productId String
id String @id @default(uuid())
recordNumber String @unique
serialNumber String
replacementSerialNumber String? // Serial Number (SN) unit pengganti saat Ganti Unit Garansi
productId String
customerId String?
salesOrderId String?
salesOrderNumber String?
+167 -22
View File
@@ -118,6 +118,8 @@ export async function POST(req: Request) {
const {
serialNumbers,
serialNumber,
replacementSerialNumbers,
replacementSerialNumber,
productId,
customerId,
salesOrderNumber,
@@ -158,6 +160,17 @@ export async function POST(req: Request) {
const finalOrigin = VALID_ORIGINS.has(serviceOrigin) ? serviceOrigin : "WAREHOUSE_DEFECT";
const finalCondition = VALID_CONDITIONS.has(condition) ? condition : "IN_SERVICE";
const replSnList = splitSerialNumbers(replacementSerialNumbers || replacementSerialNumber || "");
if (finalOrigin === "WARRANTY_REPLACE" && replSnList.length === 0) {
return NextResponse.json(
{
error:
"Serial Number (SN) unit baru pengganti wajib diisi untuk kategori Ganti Unit (Tukar Unit Garansi).",
},
{ status: 400 }
);
}
// Aturan bisnis: Saat pilih Ganti Unit (WARRANTY_REPLACE), kondisi unit lama HANYA boleh Rusak Total atau Kanibalan!
if (
finalOrigin === "WARRANTY_REPLACE" &&
@@ -196,12 +209,17 @@ export async function POST(req: Request) {
? "OUT_OF_WARRANTY"
: "INTERNAL");
// Jika diminta memotong stok fisik gudang (khusus Gudang/Admin/Manager untuk barang rusak/kanibalan internal)
const shouldDeductStock =
Boolean(deductWarehouseStock) &&
!product.isService &&
["ADMIN", "MANAGER", "INVENTORY"].includes(user.role) &&
// Otomatis tentukan pemotongan stok fisik gudang berdasarkan Kategori & Kondisi unit:
// 1. Ganti Unit Garansi (WARRANTY_REPLACE) -> OTOMATIS potong stok gudang untuk unit pengganti (SN baru)
// 2. Barang Gudang / Internal (WAREHOUSE_DEFECT) yang Rusak Total / Kanibalan -> OTOMATIS potong stok gudang
// 3. Service Garansi (WARRANTY_FREE), Service Berbayar (PAID_SERVICE), atau masih/selesai service -> TIDAK potong stok gudang
const isWarehouseLoss =
finalOrigin === "WAREHOUSE_DEFECT" &&
(finalCondition === "DAMAGED_UNUSABLE" || finalCondition === "CANNIBALIZED");
const isWarrantyReplacement = finalOrigin === "WARRANTY_REPLACE";
const shouldDeductStock = !product.isService && (isWarehouseLoss || isWarrantyReplacement);
const deductQty = isWarrantyReplacement ? Math.max(1, replSnList.length) : snList.length;
if (shouldDeductStock) {
const defaultWh = await prisma.warehouse.findFirst();
@@ -212,12 +230,16 @@ export async function POST(req: Request) {
const stockItem = await prisma.stockItem.findUnique({
where: { productId_warehouseId: { productId: product.id, warehouseId: targetWhId } },
});
if (!stockItem || stockItem.quantity < snList.length) {
if (!stockItem || stockItem.quantity < deductQty) {
return NextResponse.json(
{
error: `Stok gudang untuk ${product.name} tidak mencukupi untuk dipotong (Tersedia: ${
stockItem?.quantity || 0
}, SN dicatat: ${snList.length}). Hilangkan centang potong stok jika barang sudah keluar/bukan dari stok aktif.`,
error: isWarrantyReplacement
? `Stok gudang untuk unit pengganti ${product.name} tidak mencukupi (Tersedia: ${
stockItem?.quantity || 0
}, Dibutuhkan: ${deductQty} unit).`
: `Stok gudang untuk ${product.name} tidak mencukupi untuk dipotong otomatis (Tersedia: ${
stockItem?.quantity || 0
}, SN dicatat: ${deductQty} unit).`,
},
{ status: 400 }
);
@@ -225,28 +247,39 @@ export async function POST(req: Request) {
await prisma.stockItem.update({
where: { id: stockItem.id },
data: { quantity: stockItem.quantity - snList.length },
data: { quantity: stockItem.quantity - deductQty },
});
const outCat = finalCondition === "CANNIBALIZED" ? "KANIBALAN" : "RUSAK_AFKIR";
const outCat = isWarrantyReplacement
? "GANTI_UNIT_GARANSI"
: finalCondition === "CANNIBALIZED"
? "KANIBALAN"
: "RUSAK_AFKIR";
const movementSns = isWarrantyReplacement ? replSnList.join(", ") : snList.join(", ");
await prisma.stockMovement.create({
data: {
productId: product.id,
warehouseId: targetWhId,
type: "OUT",
outboundCategory: outCat,
quantity: snList.length,
quantity: deductQty,
referenceType: "DEVICE_RECORD",
referenceId: salesOrderNumber ? String(salesOrderNumber).trim() : outCat,
companyName: cleanCompany,
serialNumbers: snList.join(", "),
notes: `[${
finalCondition === "CANNIBALIZED"
? "Unit Kanibalan / Sparepart"
: "Barang Rusak Total / Tidak Bisa Dipakai"
}] ${snList.length} ${product.unit} ${product.name}. Kerusakan: ${String(
damageDescription
).trim()}${salvagedParts ? ` | Sparepart Kanibalan: ${String(salvagedParts).trim()}` : ""}`,
serialNumbers: movementSns,
notes: isWarrantyReplacement
? `[Ganti Unit Garansi] Pengeluaran ${deductQty} ${product.unit} ${product.name} (SN Pengganti: ${replSnList.join(
", "
)}) untuk mengganti SN Rusak: ${snList.join(", ")}. Kerusakan: ${String(
damageDescription
).trim()}`
: `[${
finalCondition === "CANNIBALIZED"
? "Unit Kanibalan / Sparepart"
: "Barang Rusak Total / Tidak Bisa Dipakai"
}] ${deductQty} ${product.unit} ${product.name}. Kerusakan: ${String(
damageDescription
).trim()}${salvagedParts ? ` | Sparepart Kanibalan: ${String(salvagedParts).trim()}` : ""}`,
},
});
}
@@ -257,6 +290,18 @@ export async function POST(req: Request) {
for (let idx = 0; idx < snList.length; idx++) {
const sn = snList[idx];
const matchedReplSn =
replSnList.length === 0
? null
: replSnList.length === snList.length
? replSnList[idx]
: replSnList.join(", ");
const defaultAction =
finalOrigin === "WARRANTY_REPLACE" && matchedReplSn && !String(actionTaken || "").trim()
? `Ganti unit garansi — diganti unit baru SN: ${matchedReplSn}`
: actionTaken
? String(actionTaken).trim()
: null;
const recNo = `DEV-${dateStr}-${String(baseCount + idx + 1).padStart(4, "0")}-${Math.floor(
10 + Math.random() * 89
)}`;
@@ -264,6 +309,7 @@ export async function POST(req: Request) {
data: {
recordNumber: recNo,
serialNumber: sn,
replacementSerialNumber: matchedReplSn,
productId: product.id,
customerId: customerId || null,
salesOrderNumber: salesOrderNumber ? String(salesOrderNumber).trim() : null,
@@ -277,7 +323,7 @@ export async function POST(req: Request) {
returnTrackingNumber: cleanReturnTracking,
servicePaymentStatus: finalPayStatus,
damageDescription: String(damageDescription).trim(),
actionTaken: actionTaken ? String(actionTaken).trim() : null,
actionTaken: defaultAction,
salvagedParts: salvagedParts ? String(salvagedParts).trim() : null,
stockAdjusted: shouldDeductStock,
recordedBy: user.name,
@@ -341,6 +387,7 @@ export async function PUT(req: Request) {
actionTaken,
salvagedParts,
serviceOrigin,
replacementSerialNumber,
serviceFee,
returnShippingCost,
returnCourierName,
@@ -380,6 +427,21 @@ export async function PUT(req: Request) {
);
}
const effectiveReplacementSn =
replacementSerialNumber !== undefined
? String(replacementSerialNumber).trim() || null
: existing.replacementSerialNumber || null;
if (effectiveOrigin === "WARRANTY_REPLACE" && !effectiveReplacementSn) {
return NextResponse.json(
{
error:
"Serial Number (SN) unit baru pengganti wajib dimasukkan untuk kategori Ganti Unit (Tukar Unit Garansi).",
},
{ status: 400 }
);
}
const updateData: any = {};
if (condition && VALID_CONDITIONS.has(condition)) {
updateData.condition = condition;
@@ -387,6 +449,9 @@ export async function PUT(req: Request) {
if (serviceOrigin && VALID_ORIGINS.has(serviceOrigin)) {
updateData.serviceOrigin = serviceOrigin;
}
if (replacementSerialNumber !== undefined) {
updateData.replacementSerialNumber = effectiveReplacementSn;
}
if (damageDescription !== undefined) {
updateData.damageDescription = String(damageDescription).trim() || existing.damageDescription;
}
@@ -423,6 +488,82 @@ export async function PUT(req: Request) {
updateData.servicePaymentStatus = nextTotal > 0 ? "UNPAID" : "FREE";
}
// Potong stok fisik gudang otomatis jika belum pernah dipotong (stockAdjusted === false)
const effectiveCondition = updateData.condition || existing.condition;
const shouldAutoDeductOnPut =
!existing.stockAdjusted &&
!existing.product.isService &&
(effectiveOrigin === "WARRANTY_REPLACE" ||
(effectiveOrigin === "WAREHOUSE_DEFECT" &&
(effectiveCondition === "DAMAGED_UNUSABLE" || effectiveCondition === "CANNIBALIZED")));
if (shouldAutoDeductOnPut) {
const defaultWh = await prisma.warehouse.findFirst();
if (!defaultWh) {
return NextResponse.json({ error: "Gudang tidak ditemukan" }, { status: 400 });
}
const replTokens = effectiveReplacementSn ? splitSerialNumbers(effectiveReplacementSn) : [];
const deductQty = effectiveOrigin === "WARRANTY_REPLACE" ? Math.max(1, replTokens.length) : 1;
const stockItem = await prisma.stockItem.findUnique({
where: { productId_warehouseId: { productId: existing.productId, warehouseId: defaultWh.id } },
});
if (!stockItem || stockItem.quantity < deductQty) {
return NextResponse.json(
{
error:
effectiveOrigin === "WARRANTY_REPLACE"
? `Stok gudang untuk unit pengganti ${existing.product.name} tidak mencukupi (Tersedia: ${
stockItem?.quantity || 0
}, Dibutuhkan: ${deductQty} unit).`
: `Stok gudang untuk ${existing.product.name} tidak mencukupi untuk dipotong otomatis (Tersedia: ${
stockItem?.quantity || 0
}).`,
},
{ status: 400 }
);
}
await prisma.stockItem.update({
where: { id: stockItem.id },
data: { quantity: stockItem.quantity - deductQty },
});
const outCat =
effectiveOrigin === "WARRANTY_REPLACE"
? "GANTI_UNIT_GARANSI"
: effectiveCondition === "CANNIBALIZED"
? "KANIBALAN"
: "RUSAK_AFKIR";
await prisma.stockMovement.create({
data: {
productId: existing.productId,
warehouseId: defaultWh.id,
type: "OUT",
outboundCategory: outCat,
quantity: deductQty,
referenceType: "DEVICE_RECORD",
referenceId: existing.salesOrderNumber || existing.recordNumber,
companyName: existing.companyName || "",
serialNumbers:
effectiveOrigin === "WARRANTY_REPLACE"
? replTokens.join(", ") || effectiveReplacementSn
: existing.serialNumber,
notes:
effectiveOrigin === "WARRANTY_REPLACE"
? `[Ganti Unit Garansi] Pengeluaran ${deductQty} ${existing.product.unit} ${existing.product.name} (SN Pengganti: ${
effectiveReplacementSn || "-"
}) untuk mengganti SN Rusak: ${existing.serialNumber} (${existing.recordNumber}).`
: `[${
effectiveCondition === "CANNIBALIZED"
? "Unit Kanibalan / Sparepart"
: "Barang Rusak Total / Tidak Bisa Dipakai"
}] ${deductQty} ${existing.product.unit} ${existing.product.name} (SN: ${existing.serialNumber}).`,
},
});
updateData.stockAdjusted = true;
}
const updated = await prisma.deviceRecord.update({
where: { id },
data: updateData,
@@ -451,6 +592,9 @@ export async function PUT(req: Request) {
...(mappedSoStatus && existing.serviceOrigin !== "WARRANTY_REPLACE"
? { serviceStatus: mappedSoStatus }
: {}),
...(updated.replacementSerialNumber
? { replacementSerialNumbers: updated.replacementSerialNumber }
: {}),
returnShippingCost: updated.returnShippingCost,
returnCourierName: updated.returnCourierName,
returnTrackingNumber: updated.returnTrackingNumber,
@@ -464,10 +608,11 @@ export async function PUT(req: Request) {
userName: user.name,
action: "UPDATE_DEVICE_RECORD",
module: "INVENTORY",
description: `[${user.role}] Memperbarui status device ${existing.recordNumber} (SN: ${existing.serialNumber} - ${existing.product.name}) menjadi ${updated.condition}${updated.returnShippingCost > 0 ? ` | Ongkir Balik (Ditanggung User): Rp ${updated.returnShippingCost.toLocaleString("id-ID")}` : ""}`,
description: `[${user.role}] Memperbarui status device ${existing.recordNumber} (SN: ${existing.serialNumber}${updated.replacementSerialNumber ? ` → SN Pengganti: ${updated.replacementSerialNumber}` : ""} - ${existing.product.name}) menjadi ${updated.condition}${updated.returnShippingCost > 0 ? ` | Ongkir Balik (Ditanggung User): Rp ${updated.returnShippingCost.toLocaleString("id-ID")}` : ""}`,
metadata: {
id,
serialNumber: existing.serialNumber,
replacementSerialNumber: updated.replacementSerialNumber,
condition: updated.condition,
returnShippingCost: updated.returnShippingCost,
returnCourierName: updated.returnCourierName,
+4 -1
View File
@@ -212,6 +212,7 @@ function serializePublicTicket(rec: any) {
return {
recordNumber: rec.recordNumber,
serialNumber: rec.serialNumber,
replacementSerialNumber: rec.replacementSerialNumber || null,
productName: rec.product?.name || "-",
productSku: rec.product?.sku || "-",
companyName: rec.companyName || "PT EnterpriseCore Utama",
@@ -258,6 +259,7 @@ export async function GET(req: Request) {
OR: [
{ recordNumber: ticketParam },
{ serialNumber: ticketParam },
{ replacementSerialNumber: ticketParam },
],
},
include: { product: { select: { name: true, sku: true } } },
@@ -275,7 +277,8 @@ export async function GET(req: Request) {
return recent.filter(
(r) =>
r.recordNumber.toLowerCase() === qLower ||
r.serialNumber.toLowerCase() === qLower
r.serialNumber.toLowerCase() === qLower ||
(r.replacementSerialNumber || "").toLowerCase() === qLower
);
};
+23 -2
View File
@@ -957,6 +957,16 @@ export async function POST(req: Request) {
const cleanReplSn = replacementSerialNumbers ? String(replacementSerialNumbers).trim() : null;
const cleanDamagedSn = damagedSerialNumbers ? String(damagedSerialNumbers).trim() : null;
if (!cleanReplSn) {
return NextResponse.json(
{
error:
"Serial Number (SN) unit baru pengganti wajib dimasukkan saat proses klaim garansi ganti unit.",
},
{ status: 400 }
);
}
// Catat riwayat Mutasi Stok Keluar (OUT)
const fullNotes = `[Ganti Unit Garansi] Penggantian ${replaceQty} ${item.product.unit} baru untuk SO ${item.salesOrder.orderNumber} (${item.product.name}) ${batchDeductedNotes}. Alasan: ${replacementNotes || "Klaim kerusakan garansi"}${cleanDamagedSn ? ` | SN Rusak: ${cleanDamagedSn}` : ""}${cleanReplSn ? ` | SN Unit Pengganti: ${cleanReplSn}` : ""}`;
await prisma.stockMovement.create({
@@ -1005,10 +1015,17 @@ export async function POST(req: Request) {
const damagedSnTokens = cleanDamagedSn
? Array.from(new Set(cleanDamagedSn.split(/[\n,;]+/).map((s) => s.trim()).filter(Boolean)))
: [`RETUR-${item.salesOrder.orderNumber}-${item.product.sku}`];
const replSnTokens = cleanReplSn
? Array.from(new Set(cleanReplSn.split(/[\n,;]+/).map((s) => s.trim()).filter(Boolean)))
: [];
const replDateStr = new Date().toISOString().slice(0, 10).replace(/-/g, "");
const replDevCount = await prisma.deviceRecord.count();
for (let idx = 0; idx < damagedSnTokens.length; idx++) {
const sn = damagedSnTokens[idx];
const matchedReplSn =
replSnTokens.length === damagedSnTokens.length
? replSnTokens[idx]
: cleanReplSn || null;
const existingRec = await prisma.deviceRecord.findFirst({
where: {
serialNumber: sn,
@@ -1016,11 +1033,12 @@ export async function POST(req: Request) {
salesOrderId: item.salesOrderId,
},
});
const actionDesc = `Unit lama retur ganti unit garansi (Diganti unit baru${cleanReplSn ? ` SN: ${cleanReplSn}` : ""})`;
const actionDesc = `Unit lama retur ganti unit garansi (Diganti unit baru${matchedReplSn ? ` SN: ${matchedReplSn}` : ""})`;
if (existingRec) {
await prisma.deviceRecord.update({
where: { id: existingRec.id },
data: {
replacementSerialNumber: matchedReplSn,
condition: finalDamagedCondition,
serviceOrigin: "WARRANTY_REPLACE",
warrantyStatus: isExpired ? "OUT_OF_WARRANTY" : "IN_WARRANTY",
@@ -1032,6 +1050,7 @@ export async function POST(req: Request) {
damageDescription: replacementNotes ? String(replacementNotes).trim() : "Klaim tukar unit garansi",
actionTaken: actionDesc,
salvagedParts: finalDamagedCondition === "CANNIBALIZED" ? cleanSalvagedParts : null,
stockAdjusted: true,
recordedBy: user.name,
},
});
@@ -1042,11 +1061,12 @@ export async function POST(req: Request) {
10 + Math.random() * 89
)}`,
serialNumber: sn,
replacementSerialNumber: matchedReplSn,
productId: item.productId,
customerId: item.salesOrder.customerId,
salesOrderId: item.salesOrderId,
salesOrderNumber: item.salesOrder.orderNumber,
companyName: item.salesOrder.companyName || "PT EnterpriseCore Utama",
companyName: item.salesOrder.companyName || "",
condition: finalDamagedCondition,
serviceOrigin: "WARRANTY_REPLACE",
warrantyStatus: isExpired ? "OUT_OF_WARRANTY" : "IN_WARRANTY",
@@ -1058,6 +1078,7 @@ export async function POST(req: Request) {
damageDescription: replacementNotes ? String(replacementNotes).trim() : "Klaim tukar unit garansi",
actionTaken: actionDesc,
salvagedParts: finalDamagedCondition === "CANNIBALIZED" ? cleanSalvagedParts : null,
stockAdjusted: true,
recordedBy: user.name,
},
});
+29 -26
View File
@@ -357,32 +357,35 @@ export async function PUT(req: Request) {
const effectiveRole = updateData.role || targetRecord?.role || "SALES";
if (telegramChatId !== undefined) updateData.telegramChatId = telegramChatId ? telegramChatId.trim() : null;
if (notifyEmail !== undefined) updateData.notifyEmail = Boolean(notifyEmail);
if (notifyTelegram !== undefined) updateData.notifyTelegram = Boolean(notifyTelegram);
if (notifStockIn !== undefined || updateData.role) {
updateData.notifStockIn =
isRoleAllowedNotifType(effectiveRole, "STOCK_IN") &&
(notifStockIn !== undefined ? Boolean(notifStockIn) : getRoleDefaultNotifications(effectiveRole).notifStockIn);
}
if (notifStockOut !== undefined || updateData.role) {
updateData.notifStockOut =
isRoleAllowedNotifType(effectiveRole, "STOCK_OUT") &&
(notifStockOut !== undefined ? Boolean(notifStockOut) : getRoleDefaultNotifications(effectiveRole).notifStockOut);
}
if (notifMoneyIn !== undefined || updateData.role) {
updateData.notifMoneyIn =
isRoleAllowedNotifType(effectiveRole, "MONEY_IN") &&
(notifMoneyIn !== undefined ? Boolean(notifMoneyIn) : getRoleDefaultNotifications(effectiveRole).notifMoneyIn);
}
if (notifMoneyOut !== undefined || updateData.role) {
updateData.notifMoneyOut =
isRoleAllowedNotifType(effectiveRole, "MONEY_OUT") &&
(notifMoneyOut !== undefined ? Boolean(notifMoneyOut) : getRoleDefaultNotifications(effectiveRole).notifMoneyOut);
}
if (notifRma !== undefined || updateData.role) {
updateData.notifRma =
isRoleAllowedNotifType(effectiveRole, "RMA_SERVICE") &&
(notifRma !== undefined ? Boolean(notifRma) : getRoleDefaultNotifications(effectiveRole).notifRma);
// Hanya Super Admin yang dapat mengubah saluran & topik notifikasi user
if (isAdmin) {
if (notifyEmail !== undefined) updateData.notifyEmail = Boolean(notifyEmail);
if (notifyTelegram !== undefined) updateData.notifyTelegram = Boolean(notifyTelegram);
if (notifStockIn !== undefined || updateData.role) {
updateData.notifStockIn =
isRoleAllowedNotifType(effectiveRole, "STOCK_IN") &&
(notifStockIn !== undefined ? Boolean(notifStockIn) : getRoleDefaultNotifications(effectiveRole).notifStockIn);
}
if (notifStockOut !== undefined || updateData.role) {
updateData.notifStockOut =
isRoleAllowedNotifType(effectiveRole, "STOCK_OUT") &&
(notifStockOut !== undefined ? Boolean(notifStockOut) : getRoleDefaultNotifications(effectiveRole).notifStockOut);
}
if (notifMoneyIn !== undefined || updateData.role) {
updateData.notifMoneyIn =
isRoleAllowedNotifType(effectiveRole, "MONEY_IN") &&
(notifMoneyIn !== undefined ? Boolean(notifMoneyIn) : getRoleDefaultNotifications(effectiveRole).notifMoneyIn);
}
if (notifMoneyOut !== undefined || updateData.role) {
updateData.notifMoneyOut =
isRoleAllowedNotifType(effectiveRole, "MONEY_OUT") &&
(notifMoneyOut !== undefined ? Boolean(notifMoneyOut) : getRoleDefaultNotifications(effectiveRole).notifMoneyOut);
}
if (notifRma !== undefined || updateData.role) {
updateData.notifRma =
isRoleAllowedNotifType(effectiveRole, "RMA_SERVICE") &&
(notifRma !== undefined ? Boolean(notifRma) : getRoleDefaultNotifications(effectiveRole).notifRma);
}
}
if (mfaEnabled !== undefined) {
+67 -69
View File
@@ -708,11 +708,12 @@ export default function FinancePage() {
reader.onload = () => {
const img = new window.Image();
img.onload = () => {
const maxDim = 360;
const maxW = 720;
const maxH = 360;
let w = img.width;
let h = img.height;
if (w > maxDim || h > maxDim) {
const ratio = Math.min(maxDim / w, maxDim / h);
if (w > maxW || h > maxH) {
const ratio = Math.min(maxW / w, maxH / h);
w = Math.round(w * ratio);
h = Math.round(h * ratio);
}
@@ -1310,7 +1311,7 @@ export default function FinancePage() {
return (
<AppShell
title="Keuangan"
subtitle="Laporan Laba Rugi & Neraca, piutang/hutang, payroll per perusahaan, daftar akun (COA), dan jurnal"
subtitle="Laporan, payroll, daftar akun (COA), jurnal, dan perusahaan"
>
{/* Financial Summary KPIs */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-5 mb-8">
@@ -1971,12 +1972,12 @@ export default function FinancePage() {
<table className="w-full text-left border-collapse text-xs">
<thead>
<tr className="bg-slate-50 text-slate-500 font-semibold border-b border-slate-100">
<th className="py-3 px-6">Kode Akun</th>
<th className="py-3 px-4">Nama Akun / Rekening Bank</th>
<th className="py-3 px-4">Entitas PT (Perusahaan)</th>
<th className="py-3 px-4">Klasifikasi</th>
<th className="py-3 px-6 text-right">Saldo Saat Ini</th>
{canCreateJournal && <th className="py-3 px-6 text-center">Tindakan</th>}
<th className="py-3 px-4">Kode</th>
<th className="py-3 px-4">Nama Akun</th>
<th className="py-3 px-4">Perusahaan (PT)</th>
<th className="py-3 px-4 text-center">Tipe</th>
<th className="py-3 px-4 text-right">Saldo</th>
{canCreateJournal && <th className="py-3 px-4 text-right">Aksi</th>}
</tr>
</thead>
<tbody className="divide-y divide-slate-100">
@@ -1995,18 +1996,18 @@ export default function FinancePage() {
return (
<tr key={acc.id} className="hover:bg-slate-50/60 transition-colors">
<td className="py-3.5 px-6 font-mono font-bold text-purple-700">
<td className="py-3 px-4 font-mono font-bold text-purple-700 align-middle">
{acc.code}
</td>
<td className="py-3.5 px-4 font-semibold text-slate-800">
<td className="py-3 px-4 font-semibold text-slate-800 align-middle">
{acc.name}
</td>
<td className="py-3.5 px-4">
<span className="inline-block px-2.5 py-0.5 rounded-md text-[10px] font-bold bg-slate-100 text-slate-700 border border-slate-300">
{acc.companyName || "PT EnterpriseCore Utama"}
<td className="py-3 px-4 align-middle">
<span className="inline-block px-2 py-0.5 rounded-md text-[10px] font-bold bg-slate-100 text-slate-700 border border-slate-300">
{acc.companyName || "-"}
</span>
</td>
<td className="py-3.5 px-4">
<td className="py-3 px-4 text-center align-middle">
<span
className={`inline-block px-2 py-0.5 rounded text-[10px] font-bold ${
acc.type === "ASSET"
@@ -2023,19 +2024,19 @@ export default function FinancePage() {
{acc.type}
</span>
</td>
<td className="py-3.5 px-6 text-right font-bold text-slate-900">
<td className="py-3 px-4 text-right font-bold text-slate-900 align-middle">
{formatRupiah(acc.balance)}
</td>
{canCreateJournal && (
<td className="py-3.5 px-6 text-center">
<div className="inline-flex items-center gap-1.5">
<td className="py-3 px-4 text-right align-middle">
<div className="inline-flex items-center justify-end gap-1.5">
<button
type="button"
onClick={() => openEditAccountModal(acc)}
className="inline-flex items-center gap-1 px-2.5 py-1 rounded-lg bg-slate-100 hover:bg-blue-50 text-slate-700 hover:text-blue-700 border border-slate-200 font-semibold text-[11px] transition-colors"
>
<Pencil className="h-3 w-3" />
<span>Edit Kode / Nama</span>
<span>Edit</span>
</button>
{currentUser?.role === "ADMIN" && !isSystemAccount && (
<button
@@ -2333,7 +2334,7 @@ export default function FinancePage() {
<Modal
isOpen={isPayrollOpen}
onClose={() => setIsPayrollOpen(false)}
title="Hitung Payroll Terpisah per PT, Uang Makan, Absensi & Slip Gaji"
title="Hitung Payroll & Slip Gaji"
>
{payrollError && (
<div className="mb-4 p-3 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
@@ -2484,7 +2485,7 @@ export default function FinancePage() {
{/* 2. Jabatan (Bisa ditambah bebas, berbeda dengan RBAC) & Periode (Dropdown Bulan & Tahun) */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<div className="flex items-center justify-between mb-1">
<div className="h-6 flex items-center justify-between mb-1">
<label className="font-semibold text-slate-700 flex items-center gap-1">
<Briefcase className="h-3 w-3 text-slate-500" />
<span>Jabatan Karyawan *</span>
@@ -2499,8 +2500,8 @@ export default function FinancePage() {
className="text-[11px] font-semibold text-emerald-600 hover:text-emerald-700"
>
{positionInputMode === "SELECT"
? "+ Tambah Jabatan"
: "Pilih Dropdown"}
? "+ Baru"
: "Pilih"}
</button>
</div>
@@ -2508,7 +2509,7 @@ export default function FinancePage() {
<select
value={employeeRole}
onChange={(e) => setEmployeeRole(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
>
{positions.map((pos) => (
<option key={pos} value={pos}>
@@ -2520,15 +2521,15 @@ export default function FinancePage() {
<div className="flex items-center gap-1.5">
<input
type="text"
placeholder="Ketik jabatan baru..."
placeholder="Jabatan baru..."
value={newPositionName}
onChange={(e) => setNewPositionName(e.target.value)}
className="w-full px-3 py-2 border border-emerald-400 rounded-lg font-semibold"
className="w-full h-9 px-3 py-1.5 border border-emerald-400 rounded-lg font-semibold"
/>
<button
type="button"
onClick={handleAddPosition}
className="px-3 py-2 rounded-lg bg-emerald-600 hover:bg-emerald-700 text-white font-semibold shrink-0"
className="h-9 px-3 rounded-lg bg-emerald-600 hover:bg-emerald-700 text-white font-semibold shrink-0"
>
Simpan
</button>
@@ -2538,14 +2539,16 @@ export default function FinancePage() {
{/* Dropdown Periode Bulan & Tahun */}
<div>
<label className="block font-semibold text-slate-700 mb-1">
Periode Gaji (Bulan & Tahun) *
</label>
<div className="h-6 flex items-center mb-1">
<label className="font-semibold text-slate-700">
Periode Gaji *
</label>
</div>
<div className="grid grid-cols-2 gap-2">
<select
value={periodMonth}
onChange={(e) => setPeriodMonth(e.target.value)}
className="w-full px-2.5 py-2 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
className="w-full h-9 px-2.5 py-1.5 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
>
{MONTHS_ID.map((m) => (
<option key={m} value={m}>
@@ -2557,7 +2560,7 @@ export default function FinancePage() {
<select
value={periodYear}
onChange={(e) => setPeriodYear(e.target.value)}
className="w-full px-2.5 py-2 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
className="w-full h-9 px-2.5 py-1.5 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
>
{YEARS_LIST.map((y) => (
<option key={y} value={y}>
@@ -3103,61 +3106,55 @@ export default function FinancePage() {
<Modal
isOpen={isModalOpen}
onClose={() => setIsModalOpen(false)}
title="Catat Jurnal Transaksi Keuangan Baru"
title="Catat Jurnal Umum"
>
{formError && (
<div className="mb-4 p-3 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
<div className="mb-3 p-2.5 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
{formError}
</div>
)}
<form onSubmit={handleCreateJournal} className="space-y-4 text-xs">
<form onSubmit={handleCreateJournal} className="space-y-3 text-xs">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Deskripsi Transaksi / Keperluan *
</label>
<label className="block font-semibold text-slate-700 mb-1">Deskripsi *</label>
<input
type="text"
required
placeholder="misal: Pembayaran Biaya Listrik & Internet Kantor"
placeholder="misal: Biaya Listrik & Internet Kantor"
value={description}
onChange={(e) => setDescription(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg"
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Akun Debit (Bertambah) *
</label>
<label className="block font-semibold text-slate-700 mb-1">Akun Debit *</label>
<select
required
value={debitAccountId}
onChange={(e) => setDebitAccountId(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg bg-white"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white"
>
{accounts.map((a) => (
<option key={a.id} value={a.id}>
[{a.code}] {a.name} ({a.companyName || "PT Utama"})
[{a.code}] {a.name} ({a.companyName || "-"})
</option>
))}
</select>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Akun Kredit (Sumber Dana / Berkurang) *
</label>
<label className="block font-semibold text-slate-700 mb-1">Akun Kredit *</label>
<select
required
value={creditAccountId}
onChange={(e) => setCreditAccountId(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg bg-white"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white"
>
{accounts.map((a) => (
<option key={a.id} value={a.id}>
[{a.code}] {a.name} ({a.companyName || "PT Utama"})
[{a.code}] {a.name} ({a.companyName || "-"})
</option>
))}
</select>
@@ -3166,9 +3163,7 @@ export default function FinancePage() {
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Nominal Transaksi *
</label>
<label className="block font-semibold text-slate-700 mb-1">Nominal *</label>
<CurrencyInput
currency="IDR"
min={1}
@@ -3179,15 +3174,13 @@ export default function FinancePage() {
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Nomor Bukti / Kwitansi / Referensi
</label>
<label className="block font-semibold text-slate-700 mb-1">No. Referensi</label>
<input
type="text"
placeholder="INV-001 / BKK-12"
value={reference}
onChange={(e) => setReference(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg"
/>
</div>
</div>
@@ -3205,20 +3198,20 @@ export default function FinancePage() {
disabled={submitting}
className="px-5 py-2 bg-purple-600 hover:bg-purple-700 text-white rounded-lg font-semibold shadow-xs disabled:opacity-50"
>
{submitting ? "Membukukan..." : "Posting Jurnal Umum"}
{submitting ? "Menyimpan..." : "Simpan Jurnal"}
</button>
</div>
</form>
</Modal>
{/* MODAL TAMBAH / EDIT PERUSAHAAN (PT), UPLOAD LOGO & TEMPLATE DOKUMEN */}
{/* MODAL TAMBAH / EDIT PERUSAHAAN (PT) */}
<Modal
isOpen={isCompanyModalOpen}
onClose={() => setIsCompanyModalOpen(false)}
title={
editingCompanyOriginalName
? `Edit Perusahaan & Template Dokumen — ${editingCompanyOriginalName}`
: "Tambah Perusahaan (PT), Logo & Template Dokumen"
? `Edit Perusahaan — ${editingCompanyOriginalName}`
: "Tambah Perusahaan (PT)"
}
maxWidth="max-w-3xl"
>
@@ -3240,15 +3233,20 @@ export default function FinancePage() {
{/* Upload Logo */}
<div className="sm:col-span-1 flex flex-col items-center justify-center p-3 rounded-lg bg-white border border-slate-200 gap-2">
{compFormLogo ? (
<img
src={compFormLogo}
alt="Preview Logo"
className="h-20 max-w-[160px] object-contain rounded bg-white p-1 border border-slate-200"
/>
<div
style={{ backgroundColor: "#ffffff" }}
className="w-full h-20 rounded-lg p-1.5 border border-slate-200 flex items-center justify-center overflow-hidden"
>
<img
src={compFormLogo}
alt="Preview Logo"
className="w-full h-full object-contain"
/>
</div>
) : (
<div className="h-20 w-20 rounded-lg bg-slate-100 border border-dashed border-slate-300 flex flex-col items-center justify-center text-slate-500">
<div className="w-full h-20 rounded-lg bg-slate-100 border border-dashed border-slate-300 flex flex-col items-center justify-center text-slate-500">
<ImageIcon className="h-6 w-6 mb-1" />
<span className="text-[10px]">Belum ada logo</span>
<span className="text-[10px]">Logo Landscape (Full Width)</span>
</div>
)}
+323 -265
View File
@@ -71,6 +71,7 @@ export default function InventoryPage() {
const [deviceForm, setDeviceForm] = useState<{
productId: string;
serialNumbers: string;
replacementSerialNumber: string;
condition: string;
serviceOrigin: string;
customerId: string;
@@ -86,6 +87,7 @@ export default function InventoryPage() {
}>({
productId: "",
serialNumbers: "",
replacementSerialNumber: "",
condition: "IN_SERVICE",
serviceOrigin: "WAREHOUSE_DEFECT",
customerId: "",
@@ -537,6 +539,7 @@ export default function InventoryPage() {
const q = deviceSearch.toLowerCase();
const hay = [
d.serialNumber,
d.replacementSerialNumber,
d.recordNumber,
d.product?.name,
d.product?.sku,
@@ -599,6 +602,7 @@ export default function InventoryPage() {
setDeviceForm({
productId: products.find((p) => !p.isService)?.id || "",
serialNumbers: "",
replacementSerialNumber: "",
condition: defaultCondition,
serviceOrigin: "WAREHOUSE_DEFECT",
customerId: "",
@@ -626,6 +630,7 @@ export default function InventoryPage() {
setDeviceForm({
productId: rec.productId || "",
serialNumbers: rec.serialNumber || "",
replacementSerialNumber: rec.replacementSerialNumber || "",
condition: safeCondition,
serviceOrigin: rec.serviceOrigin || "WAREHOUSE_DEFECT",
customerId: rec.customerId || "",
@@ -647,6 +652,17 @@ export default function InventoryPage() {
setDeviceSubmitting(true);
setDeviceFormError(null);
try {
if (
deviceForm.serviceOrigin === "WARRANTY_REPLACE" &&
!deviceForm.replacementSerialNumber.trim()
) {
setDeviceFormError(
"Serial Number (SN) unit baru pengganti wajib diisi saat proses Ganti Unit (Tukar Unit Garansi)."
);
setDeviceSubmitting(false);
return;
}
const companyName =
selectedCompanyFilter !== "ALL"
? selectedCompanyFilter
@@ -667,6 +683,10 @@ export default function InventoryPage() {
id: editingDevice.id,
condition: deviceForm.condition,
serviceOrigin: deviceForm.serviceOrigin,
replacementSerialNumber:
deviceForm.serviceOrigin === "WARRANTY_REPLACE"
? deviceForm.replacementSerialNumber.trim()
: deviceForm.replacementSerialNumber.trim() || undefined,
serviceFee:
typeof deviceForm.serviceFee === "string"
? parseFloat(deviceForm.serviceFee) || 0
@@ -681,6 +701,10 @@ export default function InventoryPage() {
: {
productId: deviceForm.productId,
serialNumbers: deviceForm.serialNumbers,
replacementSerialNumbers:
deviceForm.serviceOrigin === "WARRANTY_REPLACE"
? deviceForm.replacementSerialNumber.trim()
: undefined,
condition: deviceForm.condition,
serviceOrigin: deviceForm.serviceOrigin,
customerId: deviceForm.customerId || undefined,
@@ -832,7 +856,7 @@ export default function InventoryPage() {
return (
<AppShell
title="Inventaris"
subtitle="Katalog produk & serial number, riwayat mutasi stok, serta catatan device service dan RMA"
subtitle="Katalog produk, SN, mutasi stok, dan service RMA"
>
{/* Ringkasan Cepat Inventaris */}
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4 mb-6">
@@ -1109,15 +1133,15 @@ export default function InventoryPage() {
<table className="w-full text-left border-collapse text-xs">
<thead>
<tr className="bg-slate-50 text-slate-500 font-semibold border-b border-slate-100">
<th className="py-3 px-6">SKU / Nama Produk</th>
<th className="py-3 px-4">Produk / SKU</th>
<th className="py-3 px-4">Kategori</th>
{canSeeHppAndMargin && <th className="py-3 px-4 text-right">Harga Beli (HPP)</th>}
{canSeeHppAndMargin && <th className="py-3 px-4 text-right">HPP</th>}
{canSeeSellingPrice && <th className="py-3 px-4 text-right">Harga Jual</th>}
{canSeeHppAndMargin && <th className="py-3 px-4 text-right">Margin Laba</th>}
<th className="py-3 px-4 text-center">Total Stok Fisik</th>
<th className="py-3 px-4">Lokasi Gudang</th>
{canSeeHppAndMargin && <th className="py-3 px-4 text-right">Margin</th>}
<th className="py-3 px-4 text-center">Stok</th>
<th className="py-3 px-4">Gudang</th>
{canManageInventory && (
<th className="py-3 px-6 text-center">Aksi</th>
<th className="py-3 px-4 text-right">Aksi</th>
)}
</tr>
</thead>
@@ -1138,7 +1162,7 @@ export default function InventoryPage() {
);
return (
<tr key={p.id} className="hover:bg-slate-50/60 transition-colors">
<td className="py-3.5 px-6">
<td className="py-3 px-4">
<div className="font-bold text-slate-900">{p.name}</div>
<div className="flex flex-wrap items-center gap-1.5 mt-0.5">
<span className="font-mono text-[11px] text-blue-600 font-medium">
@@ -1246,8 +1270,8 @@ export default function InventoryPage() {
)}
</td>
{canManageInventory && (
<td className="py-3.5 px-4 text-center">
<div className="flex items-center justify-center gap-1.5 flex-wrap">
<td className="py-3 px-4 text-right">
<div className="flex items-center justify-end gap-1.5 flex-wrap">
<button
onClick={() => handleOpenEditModal(p)}
className="inline-flex items-center gap-1 px-2.5 py-1.5 rounded-md bg-slate-100 hover:bg-amber-50 text-slate-700 hover:text-amber-800 border border-slate-200 transition-colors text-xs font-medium"
@@ -1600,6 +1624,13 @@ export default function InventoryPage() {
<div className="inline-block px-2 py-0.5 rounded bg-slate-900 text-amber-300 font-mono font-bold text-[11px]">
{d.serialNumber}
</div>
{d.replacementSerialNumber && (
<div className="mt-1">
<span className="inline-block px-2 py-0.5 rounded bg-emerald-50 text-emerald-800 border border-emerald-200 font-mono font-bold text-[10px]">
🔄 SN Pengganti: {d.replacementSerialNumber}
</span>
</div>
)}
<div className="text-[10px] font-mono text-slate-400 mt-1">
{d.recordNumber}
</div>
@@ -1752,107 +1783,93 @@ export default function InventoryPage() {
<Modal
isOpen={isAddModalOpen}
onClose={() => setIsAddModalOpen(false)}
title="Tambah Produk / Layanan Baru ke Katalog"
title="Tambah Produk / Layanan"
>
{formError && (
<div className="mb-4 p-3 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
<div className="mb-3 p-2.5 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
{formError}
</div>
)}
<form onSubmit={handleAddProduct} className="space-y-4 text-xs">
{/* Pilihan Jenis Item: Barang Fisik vs Layanan / Non-Fisik */}
<div>
<label className="block font-semibold text-slate-700 mb-1.5">
Jenis Item Katalog *
</label>
<div className="grid grid-cols-2 gap-2 p-1 bg-slate-100 rounded-lg">
<button
type="button"
onClick={() =>
setNewProduct({ ...newProduct, isService: false, unit: "PCS", minStock: 5 })
}
className={`py-2 px-3 rounded-md text-center text-xs transition-all ${
!newProduct.isService
? "bg-white text-blue-900 shadow-xs border border-blue-200 font-bold"
: "text-slate-600 hover:text-slate-900 font-medium"
}`}
>
📦 Barang Fisik (Stok Gudang)
</button>
<button
type="button"
onClick={() =>
setNewProduct({ ...newProduct, isService: true, unit: "MBPS", minStock: 0, initialQuantity: 0 })
}
className={`py-2 px-3 rounded-md text-center text-xs transition-all ${
newProduct.isService
? "bg-white text-purple-900 shadow-xs border border-purple-200 font-bold"
: "text-slate-600 hover:text-slate-900 font-medium"
}`}
>
🌐 Layanan / Non-Fisik (Internet/Jasa)
</button>
</div>
<form onSubmit={handleAddProduct} className="space-y-3 text-xs">
<div className="grid grid-cols-2 gap-2 p-1 bg-slate-100 rounded-lg">
<button
type="button"
onClick={() =>
setNewProduct({ ...newProduct, isService: false, unit: "PCS", minStock: 5 })
}
className={`py-2 px-3 rounded-md text-center text-xs transition-all ${
!newProduct.isService
? "bg-white text-blue-900 shadow-xs border border-blue-200 font-bold"
: "text-slate-600 hover:text-slate-900 font-medium"
}`}
>
📦 Barang Fisik
</button>
<button
type="button"
onClick={() =>
setNewProduct({ ...newProduct, isService: true, unit: "MBPS", minStock: 0, initialQuantity: 0 })
}
className={`py-2 px-3 rounded-md text-center text-xs transition-all ${
newProduct.isService
? "bg-white text-purple-900 shadow-xs border border-purple-200 font-bold"
: "text-slate-600 hover:text-slate-900 font-medium"
}`}
>
🌐 Layanan / Jasa
</button>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Kode SKU *
</label>
<label className="block font-semibold text-slate-700 mb-1">SKU *</label>
<input
type="text"
required
placeholder={newProduct.isService ? "misal: SRV-INET-100M" : "misal: PRD-ACC-01"}
placeholder={newProduct.isService ? "SRV-INET-100M" : "PRD-001"}
value={newProduct.sku}
onChange={(e) => setNewProduct({ ...newProduct, sku: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 uppercase font-mono"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 uppercase font-mono"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Satuan Ukuran *
</label>
<label className="block font-semibold text-slate-700 mb-1">Satuan *</label>
<input
type="text"
required
placeholder={newProduct.isService ? "MBPS, GBPS, PAKET, BULAN" : "PCS, BOX, ROLL, MTR"}
placeholder={newProduct.isService ? "MBPS / PAKET" : "PCS / UNIT"}
value={newProduct.unit}
onChange={(e) => setNewProduct({ ...newProduct, unit: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 uppercase"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 uppercase"
/>
</div>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
{newProduct.isService ? "Nama Layanan / Akses Internet *" : "Nama Produk *"}
{newProduct.isService ? "Nama Layanan *" : "Nama Produk *"}
</label>
<input
type="text"
required
placeholder={
newProduct.isService
? "misal: Dedicated Internet 100 Mbps / Link Metro-E"
: "misal: Cisco Catalyst 2960"
}
placeholder={newProduct.isService ? "Dedicated Internet 100 Mbps" : "Nama produk..."}
value={newProduct.name}
onChange={(e) => setNewProduct({ ...newProduct, name: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500"
/>
</div>
<div className={newProduct.isService ? "grid grid-cols-1 gap-3" : "grid grid-cols-1 sm:grid-cols-2 gap-3"}>
<div>
<div className="flex items-center justify-between mb-1">
<div className="h-5 flex items-center justify-between mb-1">
<label className="font-semibold text-slate-700">Kategori</label>
<button
type="button"
onClick={() => setAddingCat(!addingCat)}
className="text-[11px] font-semibold text-blue-600 hover:text-blue-700"
>
{addingCat ? "Pilih Dropdown" : "+ Kategori Baru"}
{addingCat ? "Pilih" : "+ Baru"}
</button>
</div>
{!addingCat ? (
@@ -1861,7 +1878,7 @@ export default function InventoryPage() {
onChange={(e) =>
setNewProduct({ ...newProduct, categoryId: e.target.value })
}
className="w-full px-3 py-2 border border-slate-300 rounded-lg bg-white"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white"
>
<option value="">-- Pilih Kategori --</option>
{categories.map((c) => (
@@ -1871,18 +1888,18 @@ export default function InventoryPage() {
))}
</select>
) : (
<div className="flex items-center gap-1">
<div className="flex items-center gap-1.5">
<input
type="text"
placeholder="Ketik kategori..."
placeholder="Kategori baru..."
value={newCatName}
onChange={(e) => setNewCatName(e.target.value)}
className="w-full px-2.5 py-2 border border-blue-400 rounded-lg"
className="w-full h-9 px-2.5 py-1.5 border border-blue-400 rounded-lg"
/>
<button
type="button"
onClick={handleQuickAddCategory}
className="px-2.5 py-2 bg-blue-600 text-white rounded-lg font-semibold shrink-0"
className="h-9 px-3 bg-blue-600 text-white rounded-lg font-semibold shrink-0"
>
Simpan
</button>
@@ -1891,8 +1908,8 @@ export default function InventoryPage() {
</div>
{!newProduct.isService && (
<div>
<label className="block font-semibold text-slate-700 mb-1">
Batas Minimum Stok
<label className="h-5 flex items-center font-semibold text-slate-700 mb-1">
Min. Stok
</label>
<input
type="number"
@@ -1902,18 +1919,12 @@ export default function InventoryPage() {
const v = e.target.value;
setNewProduct({ ...newProduct, minStock: v === "" ? "" : parseInt(v) || 0 });
}}
className="w-full px-3 py-2 border border-slate-300 rounded-lg"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg"
/>
</div>
)}
</div>
{/* Info Pendaftaran Master Produk */}
<div className="p-3 bg-blue-50/80 border border-blue-200 rounded-lg text-slate-700 text-[11px] leading-relaxed">
<span className="font-bold text-blue-900 block mb-0.5">ℹ️ Pendaftaran Master Produk</span>
Form ini hanya untuk mendaftarkan nama dan SKU barang ke katalog. HPP Modal dan Stok Fisik akan otomatis tercatat saat barang tiba dari PO Vendor. Harga Jual dapat disesuaikan kemudian melalui tombol Edit.
</div>
<div className="pt-2 flex items-center justify-end gap-2 border-t border-slate-200">
<button
type="button"
@@ -1927,7 +1938,7 @@ export default function InventoryPage() {
disabled={submitting}
className="px-5 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-semibold shadow-xs disabled:opacity-50"
>
{submitting ? "Menyimpan..." : "Simpan Produk"}
{submitting ? "Menyimpan..." : "Simpan"}
</button>
</div>
</form>
@@ -2440,68 +2451,84 @@ export default function InventoryPage() {
</div>
</Modal>
{/* Modal: Catat / Update Kondisi Device (Pernah Service, Rusak Total / Afkir, & Unit Kanibalan) */}
{/* Modal: Catat / Edit Device */}
<Modal
isOpen={isDeviceModalOpen}
onClose={() => !deviceSubmitting && setIsDeviceModalOpen(false)}
title={
editingDevice
? `Update Kondisi Device: ${editingDevice.serialNumber}`
: "Catat Device: Service, Rusak Total, atau Unit Kanibalan"
}
title={editingDevice ? `Edit Device — ${editingDevice.serialNumber}` : "Catat Device"}
maxWidth="max-w-2xl"
>
<form onSubmit={handleSubmitDeviceRecord} className="space-y-4 text-xs">
<form onSubmit={handleSubmitDeviceRecord} className="space-y-3 text-xs">
{deviceFormError && (
<div className="p-3 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 font-semibold">
<div className="p-2.5 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 font-semibold">
{deviceFormError}
</div>
)}
{editingDevice ? (
<div className="p-3 rounded-xl bg-slate-50 border border-slate-200 flex flex-wrap items-center justify-between gap-2">
<div className="px-3 py-2 rounded-lg bg-slate-50 border border-slate-200 flex flex-wrap items-center justify-between gap-2">
<div>
<div className="font-bold text-slate-800">{editingDevice.product?.name}</div>
<div className="text-[11px] text-slate-500">
No. Record: <span className="font-mono">{editingDevice.recordNumber}</span>
<span className="font-mono">{editingDevice.recordNumber}</span>
{editingDevice.salesOrderNumber && (
<span className="ml-2 text-blue-700 font-semibold">
Ref SO: {editingDevice.salesOrderNumber}
• {editingDevice.salesOrderNumber}
</span>
)}
</div>
</div>
<span className="px-2.5 py-1 rounded bg-slate-900 text-amber-300 font-mono font-bold">
<span className="px-2 py-0.5 rounded bg-slate-900 text-amber-300 font-mono font-bold">
SN: {editingDevice.serialNumber}
</span>
</div>
) : (
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Produk / Jenis Perangkat <span className="text-rose-500">*</span>
</label>
<div className="h-6 flex items-center mb-1">
<label className="font-semibold text-slate-700">
Produk <span className="text-rose-500">*</span>
</label>
</div>
<select
required
value={deviceForm.productId}
onChange={(e) => setDeviceForm({ ...deviceForm, productId: e.target.value })}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white text-xs font-medium"
>
<option value="">-- Pilih Produk Fisik --</option>
<option value="">-- Pilih Produk --</option>
{products
.filter((p) => !p.isService)
.map((p) => (
<option key={p.id} value={p.id}>
{p.name} ({p.sku}) — Stok: {getProductStockForPT(p)} {p.unit}
{p.name} ({p.sku}) — Stok: {getProductStockForPT(p)}
</option>
))}
</select>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Sumber / Kategori Unit
</label>
<div className="h-6 flex items-center justify-between mb-1">
<label className="font-semibold text-slate-700">Kategori</label>
{(() => {
const autoCut =
deviceForm.serviceOrigin === "WARRANTY_REPLACE" ||
(deviceForm.serviceOrigin === "WAREHOUSE_DEFECT" &&
(deviceForm.condition === "DAMAGED_UNUSABLE" ||
deviceForm.condition === "CANNIBALIZED"));
return (
<span
className={`text-[10px] leading-none font-semibold px-1.5 py-1 rounded ${
autoCut
? "bg-amber-50 text-amber-800 border border-amber-200"
: "bg-slate-100 text-slate-600 border border-slate-200"
}`}
>
{autoCut ? "Potong stok otomatis" : "Stok tetap"}
</span>
);
})()}
</div>
<select
value={deviceForm.serviceOrigin}
onChange={(e) => {
@@ -2515,53 +2542,45 @@ export default function InventoryPage() {
}}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white text-xs font-medium"
>
<option value="WAREHOUSE_DEFECT">🏢 Barang Gudang / Internal (DOA / Rusak Gudang)</option>
<option value="WARRANTY_FREE">🛡️ Service Gratis (Masa Garansi Aktif)</option>
<option value="WARRANTY_REPLACE">🔄 Ganti Unit (Tukar Unit Garansi)</option>
<option value="PAID_SERVICE">💰 Jasa Service Berbayar (Garansi Habis)</option>
<option value="WAREHOUSE_DEFECT">🏢 Internal Gudang</option>
<option value="WARRANTY_FREE">🛡️ Service Garansi</option>
<option value="WARRANTY_REPLACE">🔄 Ganti Unit Garansi</option>
<option value="PAID_SERVICE">💰 Service Berbayar</option>
</select>
</div>
</div>
)}
{/* Pilihan Kondisi Device */}
{/* Kondisi Unit */}
<div>
<label className="block font-semibold text-slate-700 mb-1.5">
Kondisi / Status Device <span className="text-rose-500">*</span>
{deviceForm.serviceOrigin === "WARRANTY_REPLACE" ? "Kondisi Unit Lama" : "Kondisi Unit"}{" "}
<span className="text-rose-500">*</span>
</label>
{deviceForm.serviceOrigin === "WARRANTY_REPLACE" && (
<div className="mb-2 p-2 rounded-lg bg-amber-50 border border-amber-200 text-[10.5px] text-amber-900 font-medium">
ℹ️ Khusus <strong>Ganti Unit (Tukar Unit Garansi)</strong>, kondisi unit lama hanya dicatat sebagai <strong>Rusak Total</strong> atau <strong>Unit Kanibalan</strong>.
</div>
)}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
<div className="grid grid-cols-2 gap-2">
{[
...(deviceForm.serviceOrigin !== "WARRANTY_REPLACE"
? [
{
id: "IN_SERVICE",
title: "⚙️ Sedang Diservis",
desc: "Dalam proses perbaikan teknisi",
activeCls: "bg-blue-50 border-blue-400 text-blue-900",
},
{
id: "SERVICED_OK",
title: "✅ Selesai Diservis (Normal)",
desc: "Perbaikan selesai & siap kirim balik ke user",
title: "✅ Selesai Diservis",
activeCls: "bg-emerald-50 border-emerald-400 text-emerald-900",
},
]
: []),
{
id: "CANNIBALIZED",
title: "🛠️ Unit Kanibalan / Sparepart",
desc: "Untuk diambil komponen/sparepartnya",
title: "🛠️ Unit Kanibalan",
activeCls: "bg-purple-50 border-purple-400 text-purple-900",
},
{
id: "DAMAGED_UNUSABLE",
title: "🚫 Rusak Total (Tidak Bisa Dipakai)",
desc: "Mati total / afkir / tidak layak pakai",
title: "🚫 Rusak Total",
activeCls: "bg-rose-50 border-rose-400 text-rose-900",
},
].map((opt) => (
@@ -2569,22 +2588,21 @@ export default function InventoryPage() {
key={opt.id}
type="button"
onClick={() => setDeviceForm({ ...deviceForm, condition: opt.id })}
className={`p-2.5 rounded-lg border text-left transition-all ${
className={`px-3 py-2 rounded-lg border text-left text-xs transition-all ${
deviceForm.condition === opt.id
? `${opt.activeCls} font-bold shadow-2xs`
: "bg-white border-slate-200 text-slate-600 hover:bg-slate-50"
: "bg-white border-slate-200 text-slate-600 hover:bg-slate-50 font-medium"
}`}
>
<div className="text-xs font-bold">{opt.title}</div>
<div className="text-[10px] opacity-80 font-normal mt-0.5">{opt.desc}</div>
{opt.title}
</button>
))}
</div>
</div>
{/* Input SN (Ketik Manual / Pilih Otomatis SN Produk / Upload Excel saat tambah baru) */}
{/* SN Unit (Lama) + Customer & Ref SO */}
{!editingDevice && (
<div className="p-3 rounded-xl bg-slate-50 border border-slate-200 space-y-3">
<div className="space-y-3">
{(() => {
const chosenProd = products.find((p) => p.id === deviceForm.productId);
const snPool: string[] =
@@ -2597,10 +2615,10 @@ export default function InventoryPage() {
.map((s) => s.trim())
.filter(Boolean);
return (
<div className="p-2.5 rounded-lg bg-amber-50/80 border border-amber-200 space-y-1.5">
<div className="flex items-center justify-between gap-2 flex-wrap">
<span className="text-[10.5px] font-bold text-amber-900">
SN Tercatat untuk Produk Ini ({snPool.length}) — Klik untuk pilih otomatis:
<div className="p-2 rounded-lg bg-slate-50 border border-slate-200 space-y-1.5">
<div className="flex items-center justify-between gap-2">
<span className="text-[10.5px] font-semibold text-slate-600">
Pilih SN ({snPool.length}):
</span>
<button
type="button"
@@ -2609,10 +2627,10 @@ export default function InventoryPage() {
}
className="px-2 py-0.5 rounded bg-amber-600 hover:bg-amber-700 text-white text-[10px] font-bold"
>
Pilih Semua ({snPool.length})
Pilih Semua
</button>
</div>
<div className="flex flex-wrap gap-1 max-h-24 overflow-y-auto">
<div className="flex flex-wrap gap-1 max-h-20 overflow-y-auto">
{snPool.slice(0, 40).map((sn) => {
const selected = currentTokens.includes(sn);
return (
@@ -2628,7 +2646,7 @@ export default function InventoryPage() {
className={`px-1.5 py-0.5 rounded font-mono text-[10px] border transition-colors ${
selected
? "bg-amber-600 text-white border-amber-700 font-bold"
: "bg-white text-slate-700 border-amber-200 hover:bg-amber-100"
: "bg-white text-slate-700 border-slate-200 hover:bg-slate-100"
}`}
>
{selected ? "✓ " : "+ "}
@@ -2642,25 +2660,26 @@ export default function InventoryPage() {
})()}
<SerialNumberInput
label="Daftar Serial Number (SN) Device *"
placeholder="Contoh: SN-DEV-001, SN-DEV-002 (bisa ketik manual atau upload Excel untuk banyak unit)"
label={
deviceForm.serviceOrigin === "WARRANTY_REPLACE"
? "SN Unit Lama (Rusak) *"
: "SN Unit *"
}
placeholder="misal: SN-001, SN-002"
templateName="Device_Service_Rusak_Kanibalan"
value={deviceForm.serialNumbers}
onChange={(val) => setDeviceForm({ ...deviceForm, serialNumbers: val })}
/>
{/* Opsi Customer & Ref SO */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Customer Terkait (Opsional)
</label>
<label className="block font-semibold text-slate-700 mb-1">Customer</label>
<select
value={deviceForm.customerId}
onChange={(e) => setDeviceForm({ ...deviceForm, customerId: e.target.value })}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white text-xs"
>
<option value="">-- Internal Gudang / Tanpa Customer --</option>
<option value="">-- Tanpa Customer --</option>
{deviceCustomers.map((c) => (
<option key={c.id} value={c.id}>
{c.name} {c.company ? `(${c.company})` : ""}
@@ -2669,9 +2688,7 @@ export default function InventoryPage() {
</select>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Ref. No. Sales Order / PO (Opsional)
</label>
<label className="block font-semibold text-slate-700 mb-1">No. SO / PO</label>
<input
type="text"
placeholder="misal: SO-20261125-0001"
@@ -2681,146 +2698,191 @@ export default function InventoryPage() {
/>
</div>
</div>
{/* Opsi Potong Stok Gudang Utama untuk Rusak Total / Kanibalan Internal */}
{canManageInventory &&
(deviceForm.condition === "DAMAGED_UNUSABLE" ||
deviceForm.condition === "CANNIBALIZED") && (
<label className="flex items-start gap-2.5 p-2.5 rounded-lg bg-rose-50 border border-rose-200 cursor-pointer">
<input
type="checkbox"
checked={deviceForm.deductWarehouseStock}
onChange={(e) =>
setDeviceForm({ ...deviceForm, deductWarehouseStock: e.target.checked })
}
className="mt-0.5 rounded border-rose-300 text-rose-600 focus:ring-rose-500"
/>
<span className="text-[11px] text-rose-900 leading-relaxed">
<strong>Potong Stok Fisik Gudang Utama</strong> sejumlah SN yang dicatat (centang jika barang ini diambil dari stok aktif gudang agar tidak terhitung sebagai stok siap jual).
</span>
</label>
)}
</div>
)}
{/* Biaya Jasa jika Service Berbayar & user boleh lihat uang */}
{/* SN Unit Pengganti (Khusus Ganti Unit Garansi) */}
{(deviceForm.serviceOrigin === "WARRANTY_REPLACE" ||
editingDevice?.serviceOrigin === "WARRANTY_REPLACE" ||
editingDevice?.condition === "REPLACED_WARRANTY") && (
<div className="space-y-2">
{(() => {
const targetProdId = editingDevice?.productId || deviceForm.productId;
const chosenProd = products.find((p) => p.id === targetProdId);
const availSns: string[] = chosenProd?.availableSerialNumbers || [];
if (availSns.length === 0) return null;
const currentReplTokens = deviceForm.replacementSerialNumber
.split(/[\n,;]+/)
.map((s) => s.trim())
.filter(Boolean);
return (
<div className="p-2 rounded-lg bg-slate-50 border border-slate-200 space-y-1">
<span className="text-[10.5px] font-semibold text-slate-600 block">
Pilih SN Pengganti ({availSns.length}):
</span>
<div className="flex flex-wrap gap-1 max-h-20 overflow-y-auto">
{availSns.slice(0, 30).map((sn) => {
const selected = currentReplTokens.includes(sn);
return (
<button
key={sn}
type="button"
onClick={() => {
if (editingDevice) {
setDeviceForm({ ...deviceForm, replacementSerialNumber: sn });
} else {
const next = selected
? currentReplTokens.filter((s) => s !== sn)
: [...currentReplTokens, sn];
setDeviceForm({
...deviceForm,
replacementSerialNumber: next.join(", "),
});
}
}}
className={`px-1.5 py-0.5 rounded font-mono text-[10px] border transition-colors ${
selected
? "bg-emerald-600 text-white border-emerald-700 font-bold"
: "bg-white text-slate-700 border-slate-200 hover:bg-emerald-50"
}`}
>
{selected ? "✓ " : "+ "}
{sn}
</button>
);
})}
</div>
</div>
);
})()}
{editingDevice ? (
<div>
<label className="block font-semibold text-slate-700 mb-1">
SN Unit Pengganti <span className="text-rose-500">*</span>
</label>
<input
type="text"
required
placeholder="misal: SN-BARU-099"
value={deviceForm.replacementSerialNumber}
onChange={(e) =>
setDeviceForm({ ...deviceForm, replacementSerialNumber: e.target.value })
}
className="w-full h-9 px-3 py-1.5 border border-emerald-400 bg-white rounded-lg font-mono font-bold text-xs"
/>
</div>
) : (
<SerialNumberInput
label="SN Unit Pengganti *"
placeholder="misal: SN-BARU-099, SN-BARU-100"
templateName="SN_Pengganti_Garansi"
value={deviceForm.replacementSerialNumber}
onChange={(val) =>
setDeviceForm({ ...deviceForm, replacementSerialNumber: val })
}
/>
)}
</div>
)}
{/* Biaya Jasa (Khusus Service Berbayar) */}
{canSeeSellingPrice && deviceForm.serviceOrigin === "PAID_SERVICE" && (
<div>
<label className="block font-semibold text-slate-700 mb-1">
Nominal Biaya Jasa Service Berbayar (Rp)
</label>
<label className="block font-semibold text-slate-700 mb-1">Biaya Service (Rp)</label>
<CurrencyInput
currency="IDR"
min={0}
placeholder="Contoh: 250000"
placeholder="0"
value={deviceForm.serviceFee === "" ? "" : deviceForm.serviceFee}
onChange={(val) => setDeviceForm({ ...deviceForm, serviceFee: val || 0 })}
/>
</div>
)}
{/* Pengiriman Balik ke User (Ditanggung Customer) — berlaku saat Service Selesai, Ganti Unit, atau Service Berbayar */}
{/* Pengiriman Balik */}
{(deviceForm.serviceOrigin !== "WAREHOUSE_DEFECT" || deviceForm.condition === "SERVICED_OK") && (
<div className="p-3 rounded-xl bg-sky-50/80 border border-sky-200 space-y-2.5">
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2.5">
<div>
<span className="font-bold text-sky-950 text-xs block">
🚚 Biaya Kirim Balik ke User / Customer (Ditanggung User)
</span>
<span className="text-[10.5px] text-sky-800">
Isi saat proses service selesai atau pengiriman ganti unit — ongkos kirim dibebankan ke user/customer.
</span>
<label className="block font-semibold text-slate-700 mb-1">Ongkir Balik (Rp)</label>
<CurrencyInput
currency="IDR"
min={0}
placeholder="0"
value={deviceForm.returnShippingCost === "" ? "" : deviceForm.returnShippingCost}
onChange={(val) => setDeviceForm({ ...deviceForm, returnShippingCost: val || 0 })}
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2.5">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Biaya Kirim (Rp)
</label>
<CurrencyInput
currency="IDR"
min={0}
placeholder="0"
value={deviceForm.returnShippingCost === "" ? "" : deviceForm.returnShippingCost}
onChange={(val) => setDeviceForm({ ...deviceForm, returnShippingCost: val || 0 })}
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Nama Kurir / Ekspedisi
</label>
<input
type="text"
placeholder="misal: JNE / J&T / Baraka"
value={deviceForm.returnCourierName}
onChange={(e) =>
setDeviceForm({ ...deviceForm, returnCourierName: e.target.value })
}
className="w-full h-9 px-2.5 py-1.5 border border-slate-300 rounded-lg bg-white text-xs"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
No. Resi
</label>
<input
type="text"
placeholder="misal: JNE-889911"
value={deviceForm.returnTrackingNumber}
onChange={(e) =>
setDeviceForm({ ...deviceForm, returnTrackingNumber: e.target.value })
}
className="w-full h-9 px-2.5 py-1.5 border border-sky-300 bg-white rounded-lg font-mono text-xs font-bold text-sky-900"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">Kurir</label>
<input
type="text"
placeholder="JNE / J&T"
value={deviceForm.returnCourierName}
onChange={(e) =>
setDeviceForm({ ...deviceForm, returnCourierName: e.target.value })
}
className="w-full h-9 px-2.5 py-1.5 border border-slate-300 rounded-lg bg-white text-xs"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">No. Resi</label>
<input
type="text"
placeholder="JNE-889911"
value={deviceForm.returnTrackingNumber}
onChange={(e) =>
setDeviceForm({ ...deviceForm, returnTrackingNumber: e.target.value })
}
className="w-full h-9 px-2.5 py-1.5 border border-slate-300 bg-white rounded-lg font-mono text-xs font-bold"
/>
</div>
</div>
)}
<div>
<label className="block font-semibold text-slate-700 mb-1">
Deskripsi Kerusakan / Gejala Teknis <span className="text-rose-500">*</span>
</label>
<textarea
required
rows={2}
placeholder="Contoh: Mainboard terbakar kena petir, port SFP 1-4 mati total, casing penyok..."
value={deviceForm.damageDescription}
onChange={(e) => setDeviceForm({ ...deviceForm, damageDescription: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-xs"
/>
{/* Kerusakan & Tindakan */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Kerusakan <span className="text-rose-500">*</span>
</label>
<textarea
required
rows={2}
placeholder="Deskripsikan kerusakan..."
value={deviceForm.damageDescription}
onChange={(e) => setDeviceForm({ ...deviceForm, damageDescription: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-xs"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">Tindakan / Catatan</label>
<textarea
rows={2}
placeholder="Opsional..."
value={deviceForm.actionTaken}
onChange={(e) => setDeviceForm({ ...deviceForm, actionTaken: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-xs"
/>
</div>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Tindakan Teknisi / Keputusan Akhir
</label>
<textarea
rows={2}
placeholder="Contoh: Sudah coba ganti IC power tetap mati -> diputuskan dijadikan unit kanibalan / afkir..."
value={deviceForm.actionTaken}
onChange={(e) => setDeviceForm({ ...deviceForm, actionTaken: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-xs"
/>
</div>
{/* Kolom Khusus Komponen Kanibalan */}
<div
className={`p-3 rounded-xl border ${
deviceForm.condition === "CANNIBALIZED"
? "bg-purple-50 border-purple-300"
: "bg-slate-50 border-slate-200"
}`}
>
<label className="block font-bold text-purple-950 mb-1">
🛠️ Catatan Komponen / Sparepart Kanibalan (Opsional)
</label>
<textarea
rows={2}
placeholder="Contoh: Power Supply & Fan masih normal (tersedia), Casing OK, IC LAN sudah diambil untuk service SO-004..."
value={deviceForm.salvagedParts}
onChange={(e) => setDeviceForm({ ...deviceForm, salvagedParts: e.target.value })}
className="w-full px-3 py-2 border border-purple-200 rounded-lg bg-white text-xs"
/>
</div>
{/* Sparepart Kanibalan — hanya muncul saat pilih Unit Kanibalan */}
{deviceForm.condition === "CANNIBALIZED" && (
<div>
<label className="block font-semibold text-slate-700 mb-1">
Sparepart Kanibalan (Opsional)
</label>
<input
type="text"
placeholder="misal: Power supply OK, casing mulus"
value={deviceForm.salvagedParts}
onChange={(e) => setDeviceForm({ ...deviceForm, salvagedParts: e.target.value })}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white text-xs"
/>
</div>
)}
<div className="flex justify-end gap-2 pt-2 border-t border-slate-200">
<button
@@ -2836,11 +2898,7 @@ export default function InventoryPage() {
disabled={deviceSubmitting}
className="px-5 py-2 bg-amber-600 hover:bg-amber-700 text-white rounded-lg font-semibold shadow-xs disabled:opacity-50"
>
{deviceSubmitting
? "Menyimpan..."
: editingDevice
? "Simpan Perubahan Kondisi"
: "Simpan Catatan Device"}
{deviceSubmitting ? "Menyimpan..." : "Simpan"}
</button>
</div>
</form>
+80 -96
View File
@@ -1067,7 +1067,7 @@ export default function PurchasesPage() {
return (
<AppShell
title="Pembelian"
subtitle="Purchase Order, pengajuan barang dari Sales, persetujuan Finance, dan penerimaan gudang"
subtitle="Purchase Order, pengajuan barang, approval Finance, dan penerimaan gudang"
>
{/* ===================================================================== */}
{/* 1. VISUAL WORKFLOW PIPELINE / HEADER CARD */}
@@ -2272,52 +2272,47 @@ export default function PurchasesPage() {
<Modal
isOpen={isReqModalOpen}
onClose={() => setIsReqModalOpen(false)}
title="Form Pengajuan Pembelian Barang ke Purchasing"
title="Pengajuan Pembelian"
maxWidth="max-w-2xl"
>
<form onSubmit={handleCreateRequisition} className="space-y-4 text-xs">
<form onSubmit={handleCreateRequisition} className="space-y-3 text-xs">
{formError && (
<div className="p-3 rounded-lg bg-rose-50 text-rose-700 border border-rose-200 flex items-center gap-2">
<div className="p-2.5 rounded-lg bg-rose-50 text-rose-700 border border-rose-200 flex items-center gap-2">
<AlertCircle className="h-4 w-4 shrink-0" />
<span>{formError}</span>
</div>
)}
{/* Bagian Entitas PT Pemohon (Internal Perusahaan Kita) */}
<div className="p-3 bg-indigo-50/60 border border-indigo-200 rounded-xl">
<label className="block font-bold text-indigo-950 text-xs mb-1">
Entitas PT Pemohon (Perusahaan Kita) <span className="text-rose-500">*</span>
</label>
<select
value={reqCompanyName}
onChange={(e) => setReqCompanyName(e.target.value)}
className="w-full px-3 py-2 border border-indigo-300 rounded-lg bg-white font-semibold text-slate-800 text-xs focus:ring-1 focus:ring-indigo-500"
>
{companies.map((c) => (
<option key={c} value={c}>{c}</option>
))}
</select>
<span className="text-[10px] text-indigo-600 mt-1 block">
Pengadaan ini akan dicatat dan dipertanggungjawabkan atas nama PT ini.
</span>
</div>
{/* Bagian Nama PT Customer (Dropdown dari DB) */}
<div className="p-3.5 bg-blue-50/60 border border-blue-200 rounded-xl space-y-3">
{/* PT Pemohon & Customer (Sejajar 2 Kolom) */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<div className="flex items-center justify-between mb-1">
<label className="font-bold text-blue-950">
Nama PT dari Customer (Tersimpan di Database) <span className="text-rose-500">*</span>
<label className="h-5 flex items-center font-semibold text-slate-700 mb-1">
Perusahaan (PT) <span className="text-rose-500 ml-0.5">*</span>
</label>
<select
value={reqCompanyName}
onChange={(e) => setReqCompanyName(e.target.value)}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800 text-xs"
>
{companies.map((c) => (
<option key={c} value={c}>{c}</option>
))}
</select>
</div>
<div>
<div className="h-5 flex items-center justify-between mb-1">
<label className="font-semibold text-slate-700">
Customer <span className="text-rose-500">*</span>
</label>
<button
type="button"
onClick={() => setIsNewCustModalOpen(true)}
className="text-[11px] font-bold text-blue-700 hover:text-blue-900 bg-white px-2.5 py-1 rounded-md border border-blue-300 shadow-2xs transition-colors"
className="text-[11px] font-semibold text-blue-600 hover:text-blue-700"
>
+ Tambah PT Customer Baru
+ Baru
</button>
</div>
<select
required
value={reqCustomerId}
@@ -2328,35 +2323,35 @@ export default function PurchasesPage() {
setReqCustomCompany(c ? (c.company || c.name) : "");
}
}}
className="w-full px-3 py-2 border border-slate-300 rounded-lg bg-white font-medium text-slate-800"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white font-medium text-slate-800 text-xs"
>
<option value="">-- Pilih PT Customer dari Dropdown --</option>
<option value="">-- Pilih Customer --</option>
{customers.map((c) => (
<option key={c.id} value={c.id}>
{c.company || c.name} {c.name && c.company && c.name !== c.company ? `— PIC: ${c.name}` : ""} ({c.code})
{c.company || c.name} {c.name && c.company && c.name !== c.company ? `— ${c.name}` : ""}
</option>
))}
<option value="MANUAL">+ Ketik Nama PT Baru Manual</option>
<option value="MANUAL">+ Ketik Manual</option>
</select>
</div>
{reqCustomerId === "MANUAL" && (
<div>
<label className="block font-semibold text-slate-700 mb-1">
Ketik Nama PT Customer Baru <span className="text-rose-500">*</span>
</label>
<input
type="text"
required
placeholder="Ketik nama lengkap PT / Perusahaan Customer pemesan..."
value={reqCustomCompany}
onChange={(e) => setReqCustomCompany(e.target.value)}
className="w-full px-3 py-2 border border-blue-400 rounded-lg bg-white font-bold text-blue-900"
/>
</div>
)}
</div>
{reqCustomerId === "MANUAL" && (
<div>
<label className="block font-semibold text-slate-700 mb-1">
Nama PT Customer Baru <span className="text-rose-500">*</span>
</label>
<input
type="text"
required
placeholder="Nama perusahaan customer..."
value={reqCustomCompany}
onChange={(e) => setReqCustomCompany(e.target.value)}
className="w-full h-9 px-3 py-1.5 border border-blue-400 rounded-lg bg-white font-semibold"
/>
</div>
)}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3.5">
<div>
<div className="flex items-center mb-1.5 h-5">
@@ -2597,69 +2592,54 @@ export default function PurchasesPage() {
setIsCreateModalOpen(false);
setSelectedReqId(null);
}}
title={selectedReqId ? "Proses Pengajuan Sales menjadi Purchase Order (PO)" : "Terbitkan Purchase Order Baru ke Vendor"}
title={selectedReqId ? "Buat Purchase Order (dari Pengajuan)" : "Buat Purchase Order Baru"}
maxWidth="max-w-3xl"
>
<form onSubmit={handleCreatePO} className="space-y-4 text-xs">
<form onSubmit={handleCreatePO} className="space-y-3 text-xs">
{formError && (
<div className="p-3 rounded-lg bg-rose-50 text-rose-700 border border-rose-200 flex items-center gap-2">
<div className="p-2.5 rounded-lg bg-rose-50 text-rose-700 border border-rose-200 flex items-center gap-2">
<AlertCircle className="h-4 w-4 shrink-0" />
<span>{formError}</span>
</div>
)}
{/* Entitas PT Pembeli (Internal Perusahaan Kita) */}
<div className="p-3 bg-indigo-50/60 border border-indigo-200 rounded-xl">
<label className="block font-bold text-indigo-950 text-xs mb-1">
Entitas PT Pembeli (Perusahaan Kita) <span className="text-rose-500">*</span>
</label>
<select
value={poCompanyName}
onChange={(e) => setPoCompanyName(e.target.value)}
className="w-full px-3 py-2 border border-indigo-300 rounded-lg bg-white font-semibold text-slate-800 text-xs focus:ring-1 focus:ring-indigo-500"
>
{companies.map((c) => (
<option key={c} value={c}>{c}</option>
))}
</select>
<span className="text-[10px] text-indigo-600 mt-1 block">
Jurnal utang usaha (2001) dan pengeluaran kas/bank (1002) saat pelunasan PO akan dibukukan pada PT ini.
</span>
</div>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3.5">
{/* Row 1: Perusahaan (PT), Vendor, No. PO — Simetris 3 Kolom */}
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
<div>
<div className="flex items-center justify-between mb-1.5 h-5">
<label className="font-semibold text-slate-700 text-xs">Nomor PO</label>
<span className="text-[10px] text-slate-400 font-normal px-1.5 py-0.5 rounded bg-slate-100">Opsional</span>
</div>
<input
type="text"
placeholder="Auto jika kosong"
value={customPoNumber}
onChange={(e) => setCustomPoNumber(e.target.value)}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg font-mono text-xs focus:ring-1 focus:ring-blue-500"
/>
<label className="h-5 flex items-center font-semibold text-slate-700 mb-1">
Perusahaan (PT) <span className="text-rose-500 ml-0.5">*</span>
</label>
<select
value={poCompanyName}
onChange={(e) => setPoCompanyName(e.target.value)}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800 text-xs"
>
{companies.map((c) => (
<option key={c} value={c}>{c}</option>
))}
</select>
</div>
<div>
<div className="flex items-center justify-between mb-1.5 h-5">
<label className="font-semibold text-slate-700 text-xs">Pemasok / Distributor <span className="text-rose-500">*</span></label>
<div className="h-5 flex items-center justify-between mb-1">
<label className="font-semibold text-slate-700 text-xs">
Vendor <span className="text-rose-500">*</span>
</label>
<button
type="button"
onClick={() => setIsSupModalOpen(true)}
className="text-[11px] font-semibold text-blue-600 hover:text-blue-700"
>
+ Tambah
+ Baru
</button>
</div>
<select
required
value={supplierId}
onChange={(e) => setSupplierId(e.target.value)}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white font-medium text-xs focus:ring-1 focus:ring-blue-500"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white font-medium text-xs"
>
<option value="">-- Pilih Pemasok --</option>
<option value="">-- Pilih Vendor --</option>
{suppliers.map((s) => (
<option key={s.id} value={s.id}>
{s.name} ({s.code})
@@ -2669,13 +2649,17 @@ export default function PurchasesPage() {
</div>
<div>
<div className="flex items-center mb-1.5 h-5">
<label className="font-semibold text-slate-700 text-xs">Gudang Tujuan Penerimaan</label>
</div>
<div className="w-full h-9 px-3 py-1.5 border border-slate-200 rounded-lg bg-slate-50 text-xs font-semibold text-slate-700 flex items-center justify-between">
<span>🏢 Gudang Utama</span>
<span className="text-[10px] text-slate-400 font-normal">Tunggal</span>
<div className="h-5 flex items-center justify-between mb-1">
<label className="font-semibold text-slate-700 text-xs">Nomor PO</label>
<span className="text-[10px] text-slate-400">Opsional</span>
</div>
<input
type="text"
placeholder="Auto jika kosong"
value={customPoNumber}
onChange={(e) => setCustomPoNumber(e.target.value)}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg font-mono text-xs"
/>
</div>
</div>
+7
View File
@@ -34,6 +34,7 @@ interface VerifiedDevice {
interface PublicTicket {
recordNumber: string;
serialNumber: string;
replacementSerialNumber?: string | null;
productName: string;
productSku: string;
companyName: string;
@@ -690,6 +691,12 @@ export default function PublicRmaPortalPage() {
<div className="text-[11px] text-slate-500">
SN: <strong className="font-mono text-slate-800">{t.serialNumber}</strong> • {getOriginDisplay(t.serviceOrigin)}
</div>
{t.replacementSerialNumber && (
<div className="mt-1 inline-block px-2 py-0.5 rounded bg-emerald-50 border border-emerald-200 text-[11px] text-emerald-800 font-semibold">
🔄 SN Unit Pengganti:{" "}
<strong className="font-mono">{t.replacementSerialNumber}</strong>
</div>
)}
</div>
<span className={`px-2.5 py-1 rounded-lg border font-bold text-[11px] ${badge.cls}`}>
{badge.label}
+124 -157
View File
@@ -980,6 +980,13 @@ export default function SalesPage() {
const handleSubmitRmaReplacement = async (e: React.FormEvent) => {
e.preventDefault();
if (!selectedRmaItemId) return;
if (!rmaReplacementSn.trim()) {
setRmaFeedbackMsg({
type: "error",
text: "Serial Number (SN) unit baru pengganti wajib dimasukkan sebelum memproses Ganti Unit Garansi.",
});
return;
}
setRmaSubmitting(true);
setRmaFeedbackMsg(null);
try {
@@ -1269,11 +1276,12 @@ export default function SalesPage() {
reader.onload = () => {
const img = new window.Image();
img.onload = () => {
const maxDim = 360;
const maxW = 720;
const maxH = 360;
let w = img.width;
let h = img.height;
if (w > maxDim || h > maxDim) {
const r = Math.min(maxDim / w, maxDim / h);
if (w > maxW || h > maxH) {
const r = Math.min(maxW / w, maxH / h);
w = Math.round(w * r);
h = Math.round(h * r);
}
@@ -1683,8 +1691,8 @@ export default function SalesPage() {
title={isInventoryOnly ? "Pengiriman" : "Penjualan"}
subtitle={
isInventoryOnly
? "Pengiriman pesanan pelanggan, Surat Jalan, input resi ekspedisi, dan ongkos kirim"
: "Pesanan pelanggan, Invoice, Surat Jalan, status garansi/RMA, dan pelunasan"
? "Pengiriman pesanan, serah terima barang, resi, dan ongkir"
: "Pesanan, invoice, serah terima barang, garansi/RMA, dan pelunasan"
}
>
{/* Ringkasan KPI (Untuk Gudang fokus ke Pengiriman & Resi; Untuk Sales/Finance/Admin tampilkan KPI Keuangan) */}
@@ -1876,35 +1884,30 @@ export default function SalesPage() {
className="inline-flex items-center gap-2 px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-white rounded-lg text-xs font-semibold shadow-xs transition-colors"
>
<Plus className="h-4 w-4" />
<span>Buat Sales Order (SO)</span>
<span>Buat Sales Order</span>
</button>
</>
) : (
<div className="flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-slate-100 text-slate-600 border border-slate-200 text-xs">
<Lock className="h-3.5 w-3.5 text-slate-400" />
<span>Pembuatan SO khusus Sales / Manager / Admin</span>
</div>
)}
) : null}
</div>
</div>
{/* Orders Table */}
<div className="bg-white rounded-xl border border-slate-200 shadow-xs overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full text-left border-collapse text-xs min-w-[1220px] table-fixed">
<table className="w-full text-left border-collapse text-xs min-w-[1180px] table-fixed">
<thead>
<tr className="bg-slate-50 text-slate-500 font-semibold border-b border-slate-200 whitespace-nowrap">
<th className="py-3.5 px-4 w-[16%]">No. SO & Tanggal</th>
<th className="py-3.5 px-3 w-[12%]">Pelanggan</th>
<th className="py-3.5 px-3 w-[16%]">Rincian Item</th>
<th className="py-3.5 px-3 w-[16%]">Garansi & Purna Jual</th>
<th className="py-3.5 px-3 w-[11%] text-right">
{canSeeSalesMoney ? "Total Nilai & Resi" : "Ongkir & Resi"}
<th className="py-3 px-4 w-[15%]">No. SO &amp; Tanggal</th>
<th className="py-3 px-3 w-[12%]">Pelanggan</th>
<th className="py-3 px-3 w-[15%]">Item</th>
<th className="py-3 px-3 w-[14%]">Garansi / RMA</th>
<th className="py-3 px-3 w-[12%] text-right">
{canSeeSalesMoney ? "Nilai & Resi" : "Ongkir & Resi"}
</th>
<th className="py-3.5 px-2 w-[7%] text-center">Status Kirim</th>
<th className="py-3.5 px-2 w-[7%] text-center">Pembayaran</th>
<th className="py-3.5 px-2 w-[11%] text-center">Dokumen Cetak</th>
<th className="py-3.5 px-3 w-[12%] text-right">Tindakan</th>
<th className="py-3 px-2 w-[7%] text-center">Kirim</th>
<th className="py-3 px-2 w-[7%] text-center">Bayar</th>
<th className="py-3 px-2 w-[9%] text-center">Dokumen</th>
<th className="py-3 px-3 w-[9%] text-right">Aksi</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-100">
@@ -2371,26 +2374,30 @@ export default function SalesPage() {
<Modal
isOpen={isModalOpen}
onClose={() => setIsModalOpen(false)}
title="Buat Pesanan Penjualan Baru (Sales Order)"
title="Buat Sales Order"
maxWidth="max-w-4xl"
>
{formError && (
<div className="mb-4 p-3 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
<div className="mb-3 p-2.5 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
{formError}
</div>
)}
<form onSubmit={handleCreateOrder} className="space-y-4 text-xs">
{/* Entitas PT Penjual & Skema Penjualan (Jual Putus vs Manage Service) */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3.5 p-3 bg-indigo-50/60 border border-indigo-200 rounded-xl">
<form onSubmit={handleCreateOrder} className="space-y-3 text-xs">
{/* Perusahaan (PT), Skema, & Garansi — Sejajar & Simetris */}
<div
className={`grid grid-cols-1 gap-3 ${
saleType === "JUAL_PUTUS" ? "sm:grid-cols-3" : "sm:grid-cols-2"
}`}
>
<div>
<label className="block font-bold text-indigo-950 text-xs mb-1">
Entitas PT Penjual (Perusahaan Kita) <span className="text-rose-500">*</span>
<label className="h-5 flex items-center font-semibold text-slate-700 mb-1">
Perusahaan (PT) <span className="text-rose-500 ml-0.5">*</span>
</label>
<select
value={soCompanyName}
onChange={(e) => setSoCompanyName(e.target.value)}
className="w-full h-9 px-3 py-1.5 border border-indigo-300 rounded-lg bg-white font-semibold text-slate-800 text-xs focus:ring-1 focus:ring-indigo-500"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800 text-xs"
>
{companies.map((c) => (
<option key={c} value={c}>{c}</option>
@@ -2399,10 +2406,10 @@ export default function SalesPage() {
</div>
<div>
<label className="block font-bold text-indigo-950 text-xs mb-1">
Skema Invoice / Barang Keluar <span className="text-rose-500">*</span>
<label className="h-5 flex items-center font-semibold text-slate-700 mb-1">
Skema Penjualan <span className="text-rose-500 ml-0.5">*</span>
</label>
<div className="grid grid-cols-2 gap-2 p-1 bg-indigo-100/70 rounded-lg h-9 items-center">
<div className="grid grid-cols-2 gap-1.5 p-1 bg-slate-100 rounded-lg h-9 items-center">
<button
type="button"
onClick={() => setSaleType("JUAL_PUTUS")}
@@ -2423,36 +2430,31 @@ export default function SalesPage() {
: "text-slate-600 hover:text-slate-900 font-medium"
}`}
>
Jual Manage Service
Manage Service
</button>
</div>
</div>
</div>
{/* Masa Garansi untuk Jual Putus */}
{saleType === "JUAL_PUTUS" && (
<div className="p-2.5 bg-sky-50 border border-sky-200 rounded-xl flex items-center justify-between text-xs">
<div className="flex items-center gap-2">
<ShieldCheck className="h-4 w-4 text-sky-600 shrink-0" />
<div>
<span className="font-bold text-sky-950">Masa Garansi Barang:</span>
<span className="text-slate-500 text-[11px] ml-1.5">(Berlaku untuk barang fisik non-layanan)</span>
</div>
{saleType === "JUAL_PUTUS" && (
<div>
<label className="h-5 flex items-center font-semibold text-slate-700 mb-1">
Masa Garansi
</label>
<select
value={warrantyMonths}
onChange={(e) => setWarrantyMonths(parseInt(e.target.value) || 12)}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white text-xs font-semibold text-slate-800"
>
<option value={1}>1 Bulan</option>
<option value={3}>3 Bulan</option>
<option value={6}>6 Bulan</option>
<option value={12}>12 Bulan (1 Tahun)</option>
<option value={24}>24 Bulan (2 Tahun)</option>
<option value={36}>36 Bulan (3 Tahun)</option>
</select>
</div>
<select
value={warrantyMonths}
onChange={(e) => setWarrantyMonths(parseInt(e.target.value) || 12)}
className="h-8 px-2.5 border border-sky-300 rounded-lg bg-white text-xs font-semibold text-sky-900"
>
<option value={1}>1 Bulan</option>
<option value={3}>3 Bulan</option>
<option value={6}>6 Bulan</option>
<option value={12}>12 Bulan (1 Tahun)</option>
<option value={24}>24 Bulan (2 Tahun)</option>
<option value={36}>36 Bulan (3 Tahun)</option>
</select>
</div>
)}
)}
</div>
{/* Baris 1: No SO, No PO Customer, No Faktur */}
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3.5">
@@ -4242,15 +4244,16 @@ export default function SalesPage() {
)}
</div>
) : (
<div className="p-2.5 bg-emerald-50 border border-emerald-200 rounded-lg text-[11px] text-emerald-900 font-medium">
✓ <strong>Tukar Unit Garansi (GRATIS / Rp 0):</strong> Karena masa garansi masih aktif s/d <strong>{expStr}</strong>, pelanggan dapat menukar unit rusak dengan unit baru dari stok Gudang Utama tanpa biaya jasa.
<div className="flex items-center justify-between px-3 py-2 rounded-lg bg-emerald-50 border border-emerald-200 text-[11px] text-emerald-900 font-semibold">
<span>✓ Garansi Aktif s/d {expStr} (Rp 0)</span>
<span className="text-[10px] font-medium text-emerald-700">Potong stok otomatis</span>
</div>
)}
<div className="space-y-3">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<SerialNumberInput
label="SN Unit Lama yang Rusak"
placeholder="misal: SN-LAMA-001, SN-LAMA-002"
label="SN Unit Lama (Rusak)"
placeholder="misal: SN-LAMA-001"
templateName="SN_Rusak_Garansi"
expectedQty={rmaReplaceQty}
value={rmaDamagedSn}
@@ -4258,8 +4261,8 @@ export default function SalesPage() {
/>
<SerialNumberInput
label="SN Unit Baru Pengganti"
placeholder="misal: SN-BARU-099, SN-BARU-100"
label="SN Unit Pengganti *"
placeholder="misal: SN-BARU-099"
templateName="SN_Pengganti_Garansi"
expectedQty={rmaReplaceQty}
value={rmaReplacementSn}
@@ -4270,7 +4273,7 @@ export default function SalesPage() {
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Jumlah Unit yang Diganti Baru:
Jumlah Diganti (Maks: {remainingReplaceable})
</label>
<input
type="number"
@@ -4284,142 +4287,109 @@ export default function SalesPage() {
}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg font-bold text-center text-xs"
/>
<span className="text-[10px] text-slate-500 mt-0.5 block">
Maksimal: {remainingReplaceable} unit (dari unit awal yang belum pernah diganti)
</span>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Ambil Stok Pengganti Dari PO Vendor:
Sumber Stok PO
</label>
<select
value={rmaReplaceBatchId}
onChange={(e) => setRmaReplaceBatchId(e.target.value)}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white text-xs font-medium"
>
<option value="">⚡ FIFO Otomatis dari Gudang Utama</option>
<option value="">⚡ FIFO Otomatis</option>
{productBatches.map((b) => (
<option key={b.id} value={b.id}>
🎯 {b.poNumber} ({b.purchaseOrder?.supplier?.name || "Vendor"}) — Sisa: {b.remainingQty} {b.product?.unit}
{b.poNumber} — Sisa: {b.remainingQty} {b.product?.unit}
</option>
))}
</select>
<span className="text-[10px] text-slate-500 mt-0.5 block">
Unit baru akan dipotong langsung dari stok fisik Gudang Utama
</span>
</div>
</div>
{/* Kondisi Unit Lama yang Rusak (KHUSUS Ganti Unit: HANYA Rusak Total atau Unit Kanibalan) */}
<div className="p-3 rounded-xl bg-amber-50/70 border border-amber-200 space-y-2">
<label className="block font-bold text-amber-950 text-xs">
Kondisi Unit Lama yang Dikembalikan Customer (Hanya Rusak Total / Kanibalan): <span className="text-rose-500">*</span>
{/* Kondisi Unit Lama */}
<div className="space-y-2">
<label className="block font-semibold text-slate-700">
Kondisi Unit Lama <span className="text-rose-500">*</span>
</label>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
<div className="grid grid-cols-2 gap-2">
<button
type="button"
onClick={() => setRmaReplaceDamagedCondition("DAMAGED_UNUSABLE")}
className={`p-2.5 rounded-lg border text-left transition-all ${
className={`px-3 py-2 rounded-lg border text-left text-xs transition-all ${
rmaReplaceDamagedCondition === "DAMAGED_UNUSABLE"
? "bg-rose-50 border-rose-400 text-rose-900 font-bold shadow-2xs"
: "bg-white border-slate-200 text-slate-600 hover:bg-slate-50"
: "bg-white border-slate-200 text-slate-600 hover:bg-slate-50 font-medium"
}`}
>
<div className="text-xs font-bold">🚫 Rusak Total (Tidak Bisa Dipakai)</div>
<div className="text-[10px] opacity-80 font-normal mt-0.5">
Unit mati total / afkir tidak layak pakai
</div>
🚫 Rusak Total
</button>
<button
type="button"
onClick={() => setRmaReplaceDamagedCondition("CANNIBALIZED")}
className={`p-2.5 rounded-lg border text-left transition-all ${
className={`px-3 py-2 rounded-lg border text-left text-xs transition-all ${
rmaReplaceDamagedCondition === "CANNIBALIZED"
? "bg-purple-50 border-purple-400 text-purple-900 font-bold shadow-2xs"
: "bg-white border-slate-200 text-slate-600 hover:bg-slate-50"
: "bg-white border-slate-200 text-slate-600 hover:bg-slate-50 font-medium"
}`}
>
<div className="text-xs font-bold">🛠️ Unit Kanibalan / Sparepart</div>
<div className="text-[10px] opacity-80 font-normal mt-0.5">
Disimpan untuk diambil komponen/sparepartnya
</div>
🛠️ Unit Kanibalan
</button>
</div>
{rmaReplaceDamagedCondition === "CANNIBALIZED" && (
<div>
<label className="block font-semibold text-purple-950 mb-1">
Catatan Komponen / Sparepart Kanibalan (Opsional):
</label>
<input
type="text"
placeholder="misal: Power supply OK, Fan OK, casing masih mulus..."
value={rmaReplaceSalvagedParts}
onChange={(e) => setRmaReplaceSalvagedParts(e.target.value)}
className="w-full h-9 px-2.5 py-1.5 border border-purple-200 rounded-lg bg-white text-xs"
/>
</div>
<input
type="text"
placeholder="Sparepart kanibalan (opsional)..."
value={rmaReplaceSalvagedParts}
onChange={(e) => setRmaReplaceSalvagedParts(e.target.value)}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white text-xs"
/>
)}
</div>
{/* Biaya Kirim Pengiriman Unit Pengganti (Ditanggung User) */}
<div className="p-3 rounded-xl bg-sky-50/80 border border-sky-200 space-y-2">
{/* Pengiriman Unit Pengganti */}
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2.5">
<div>
<span className="font-bold text-sky-950 text-xs block">
🚚 Pengiriman Unit Pengganti ke Customer (Biaya Kirim Ditanggung User)
</span>
<span className="text-[10.5px] text-sky-800">
Unit pengganti garansi gratis (Rp 0), namun biaya pengiriman tetap ditanggung oleh user/customer.
</span>
<label className="block font-semibold text-slate-700 mb-1">Ongkir Kirim (Rp)</label>
<CurrencyInput
currency="IDR"
min={0}
placeholder="0"
value={rmaReturnShippingCost === "" ? "" : rmaReturnShippingCost}
onChange={(val) => setRmaReturnShippingCost(val || 0)}
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2.5">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Biaya Kirim (Rp)
</label>
<CurrencyInput
currency="IDR"
min={0}
placeholder="0"
value={rmaReturnShippingCost === "" ? "" : rmaReturnShippingCost}
onChange={(val) => setRmaReturnShippingCost(val || 0)}
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Nama Kurir / Ekspedisi
</label>
<input
type="text"
placeholder="misal: JNE / J&T / Baraka"
value={rmaReturnCourierName}
onChange={(e) => setRmaReturnCourierName(e.target.value)}
className="w-full h-9 px-2.5 py-1.5 border border-slate-300 rounded-lg bg-white text-xs"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
No. Resi
</label>
<input
type="text"
placeholder="misal: JNE-991122"
value={rmaReturnTrackingNumber}
onChange={(e) => setRmaReturnTrackingNumber(e.target.value)}
className="w-full h-9 px-2.5 py-1.5 border border-sky-300 bg-white rounded-lg font-mono font-bold text-xs text-sky-900"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">Kurir</label>
<input
type="text"
placeholder="JNE / J&T"
value={rmaReturnCourierName}
onChange={(e) => setRmaReturnCourierName(e.target.value)}
className="w-full h-9 px-2.5 py-1.5 border border-slate-300 rounded-lg bg-white text-xs"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">No. Resi</label>
<input
type="text"
placeholder="JNE-991122"
value={rmaReturnTrackingNumber}
onChange={(e) => setRmaReturnTrackingNumber(e.target.value)}
className="w-full h-9 px-2.5 py-1.5 border border-slate-300 bg-white rounded-lg font-mono font-bold text-xs"
/>
</div>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Alasan Kerusakan & Catatan Ganti Unit Garansi: <span className="text-rose-500">*</span>
Alasan Penggantian <span className="text-rose-500">*</span>
</label>
<textarea
rows={2}
required
placeholder="Jelaskan alasan penggantian unit baru (misal: Unit terbakar / mati total / tidak dapat diperbaiki dalam masa garansi)..."
placeholder="Deskripsikan alasan ganti unit..."
value={rmaReplaceNotes}
onChange={(e) => setRmaReplaceNotes(e.target.value)}
className="w-full px-3 py-2 border border-slate-300 rounded-lg text-xs"
@@ -4427,17 +4397,14 @@ export default function SalesPage() {
</div>
{canCreateOrder && (
<div className="p-2.5 bg-amber-50/70 border border-amber-200 rounded-lg flex flex-col sm:flex-row sm:items-center justify-between gap-2">
<span className="text-[11px] text-amber-900 font-medium">
Penggantian ini akan memotong stok fisik <strong>Gudang Utama</strong> sebanyak {rmaReplaceQty} unit dan mencatat mutasi <strong>GANTI_UNIT_GARANSI</strong>.
</span>
<div className="flex justify-end pt-1">
<button
type="submit"
disabled={rmaSubmitting || (isExpired && !rmaForceReplace) || remainingReplaceable <= 0}
className="inline-flex items-center gap-1.5 px-4 py-2 bg-amber-600 hover:bg-amber-700 text-white font-bold rounded-lg text-xs shadow-2xs disabled:opacity-50 whitespace-nowrap"
>
<RotateCcw className="h-3.5 w-3.5" />
<span>{rmaSubmitting ? "Memproses..." : "Konfirmasi Tukar Unit Baru"}</span>
<span>{rmaSubmitting ? "Memproses..." : "Konfirmasi Ganti Unit"}</span>
</button>
</div>
)}
+108 -199
View File
@@ -13,7 +13,6 @@ import {
Radio,
History,
Lock,
ShieldCheck,
Download,
Database,
} from "lucide-react";
@@ -219,11 +218,11 @@ export default function SettingsPage() {
return (
<AppShell
title="Pengaturan"
subtitle="Konfigurasi email SMTP, notifikasi Telegram, dan aturan pengiriman laporan per divisi"
subtitle="Email SMTP, Bot Telegram, aturan notifikasi, dan backup database"
>
{statusMessage && (
<div
className={`mb-6 p-4 rounded-xl flex items-center gap-3 text-xs font-medium border ${
className={`mb-5 p-3 rounded-xl flex items-center gap-2.5 text-xs font-medium border ${
statusMessage.type === "success"
? "bg-emerald-50 text-emerald-800 border-emerald-200"
: "bg-rose-50 text-rose-800 border-rose-200"
@@ -238,24 +237,17 @@ export default function SettingsPage() {
</div>
)}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
<div className="lg:col-span-2 space-y-6">
<form onSubmit={handleSaveSettings} className="space-y-6">
{/* 1. Telegram Bot & Division Channels */}
<div className="bg-white rounded-xl border border-slate-200 shadow-xs p-6">
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
<div className="lg:col-span-2 space-y-5">
<form onSubmit={handleSaveSettings} className="space-y-5">
{/* 1. Telegram Bot */}
<div className="bg-white rounded-xl border border-slate-200 shadow-xs p-5">
<div className="flex items-center justify-between mb-4 border-b border-slate-100 pb-3">
<div className="flex items-center gap-2.5">
<div className="p-2 rounded-lg bg-sky-50 text-sky-600">
<Send className="h-5 w-5" />
</div>
<div>
<h3 className="text-sm font-bold text-slate-800">
Integrasi Bot Telegram & Routing Per Divisi
</h3>
<p className="text-[11px] text-slate-500">
Arahkan notifikasi otomatis ke grup Telegram masing-masing divisi terkait
</p>
<Send className="h-4 w-4" />
</div>
<h3 className="text-sm font-bold text-slate-800">Bot Telegram</h3>
</div>
<label className="flex items-center gap-2 cursor-pointer text-xs font-bold text-slate-700">
@@ -271,81 +263,73 @@ export default function SettingsPage() {
}
className="h-4 w-4 rounded text-blue-600 focus:ring-blue-500"
/>
<span>Aktifkan Telegram</span>
<span>Aktif</span>
</label>
</div>
<div className="space-y-4 text-xs">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Telegram Bot Token (dari @BotFather)
</label>
<input
type="text"
disabled={!isAdmin}
placeholder="misal: 123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ"
value={settings.TELEGRAM_BOT_TOKEN || ""}
onChange={(e) =>
setSettings({ ...settings, TELEGRAM_BOT_TOKEN: e.target.value })
}
className="w-full px-3 py-2 border border-slate-300 rounded-lg font-mono disabled:bg-slate-100"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Default Group / Channel Chat ID Utama Perusahaan
</label>
<div className="flex items-center gap-2">
<div className="space-y-3 text-xs">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">Bot Token</label>
<input
type="text"
disabled={!isAdmin}
placeholder="misal: -1001234567890"
value={settings.TELEGRAM_CHAT_ID || ""}
placeholder="123456789:ABCdef..."
value={settings.TELEGRAM_BOT_TOKEN || ""}
onChange={(e) =>
setSettings({ ...settings, TELEGRAM_CHAT_ID: e.target.value })
setSettings({ ...settings, TELEGRAM_BOT_TOKEN: e.target.value })
}
className="w-full px-3 py-2 border border-slate-300 rounded-lg font-mono disabled:bg-slate-100"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg font-mono disabled:bg-slate-100"
/>
</div>
{isAdmin && (
<button
type="button"
disabled={testing}
onClick={handleTestTelegram}
className="shrink-0 px-3 py-2 rounded-lg bg-sky-600 hover:bg-sky-700 text-white font-semibold flex items-center gap-1.5 shadow-xs transition-colors disabled:opacity-50"
>
<Radio className="h-3.5 w-3.5" />
<span>{testing ? "Menguji..." : "Tes Bot"}</span>
</button>
)}
<div>
<label className="block font-semibold text-slate-700 mb-1">Chat ID Utama</label>
<div className="flex items-center gap-2">
<input
type="text"
disabled={!isAdmin}
placeholder="-1001234567890"
value={settings.TELEGRAM_CHAT_ID || ""}
onChange={(e) =>
setSettings({ ...settings, TELEGRAM_CHAT_ID: e.target.value })
}
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg font-mono disabled:bg-slate-100"
/>
{isAdmin && (
<button
type="button"
disabled={testing}
onClick={handleTestTelegram}
className="shrink-0 h-9 px-3 rounded-lg bg-sky-600 hover:bg-sky-700 text-white font-semibold flex items-center gap-1.5 shadow-xs transition-colors disabled:opacity-50"
>
<Radio className="h-3.5 w-3.5" />
<span>{testing ? "..." : "Tes"}</span>
</button>
)}
</div>
</div>
</div>
{/* Per-Division Group Chat IDs */}
<div className="pt-3 border-t border-slate-100">
<p className="font-bold text-slate-800 mb-2">
Chat ID Grup Spesifik Per Divisi (Opsional):
</p>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<p className="font-semibold text-slate-700 mb-2">Chat ID Grup Divisi (Opsional)</p>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2.5">
{DIVISION_CHANNELS.map((ch) => (
<div
key={ch.key}
className="p-3 rounded-lg bg-slate-50 border border-slate-200"
>
<label className="block font-semibold text-slate-800 mb-0.5">
<div key={ch.key}>
<label className="block font-medium text-slate-700 mb-1 text-[11px]">
{ch.label}
</label>
<p className="text-[10px] text-slate-500 mb-1.5">{ch.desc}</p>
<input
type="text"
disabled={!isAdmin}
placeholder="Chat ID Grup Divisi (misal: -100987...)"
placeholder="-100..."
value={settings[ch.key] || ""}
onChange={(e) =>
setSettings({ ...settings, [ch.key]: e.target.value })
}
className="w-full px-2.5 py-1.5 border border-slate-300 rounded-md font-mono text-[11px] bg-white disabled:bg-slate-100"
className="w-full h-9 px-2.5 py-1.5 border border-slate-300 rounded-lg font-mono text-[11px] bg-white disabled:bg-slate-100"
/>
</div>
))}
@@ -354,21 +338,14 @@ export default function SettingsPage() {
</div>
</div>
{/* 2. Email Notification Section */}
<div className="bg-white rounded-xl border border-slate-200 shadow-xs p-6">
{/* 2. Email SMTP */}
<div className="bg-white rounded-xl border border-slate-200 shadow-xs p-5">
<div className="flex items-center justify-between mb-4 border-b border-slate-100 pb-3">
<div className="flex items-center gap-2.5">
<div className="p-2 rounded-lg bg-blue-50 text-blue-600">
<Mail className="h-5 w-5" />
</div>
<div>
<h3 className="text-sm font-bold text-slate-800">
Notifikasi Email (SMTP)
</h3>
<p className="text-[11px] text-slate-500">
Pengiriman surat pemberitahuan ke email terdaftar masing-masing user divisi
</p>
<Mail className="h-4 w-4" />
</div>
<h3 className="text-sm font-bold text-slate-800">Email SMTP</h3>
</div>
<label className="flex items-center gap-2 cursor-pointer text-xs font-bold text-slate-700">
@@ -384,31 +361,27 @@ export default function SettingsPage() {
}
className="h-4 w-4 rounded text-blue-600 focus:ring-blue-500"
/>
<span>Aktifkan Email</span>
<span>Aktif</span>
</label>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs">
<div>
<label className="block font-semibold text-slate-700 mb-1">
SMTP Host / Server
</label>
<label className="block font-semibold text-slate-700 mb-1">SMTP Host</label>
<input
type="text"
disabled={!isAdmin}
placeholder="misal: smtp.gmail.com / mail.perusahaan.id"
placeholder="smtp.gmail.com"
value={settings.SMTP_HOST || ""}
onChange={(e) =>
setSettings({ ...settings, SMTP_HOST: e.target.value })
}
className="w-full px-3 py-2 border border-slate-300 rounded-lg disabled:bg-slate-100"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg disabled:bg-slate-100"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
SMTP Port (587 TLS / 465 SSL)
</label>
<label className="block font-semibold text-slate-700 mb-1">SMTP Port</label>
<input
type="text"
disabled={!isAdmin}
@@ -417,14 +390,12 @@ export default function SettingsPage() {
onChange={(e) =>
setSettings({ ...settings, SMTP_PORT: e.target.value })
}
className="w-full px-3 py-2 border border-slate-300 rounded-lg font-mono disabled:bg-slate-100"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg font-mono disabled:bg-slate-100"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
SMTP Username / Email Login
</label>
<label className="block font-semibold text-slate-700 mb-1">SMTP Username</label>
<input
type="text"
disabled={!isAdmin}
@@ -433,40 +404,36 @@ export default function SettingsPage() {
onChange={(e) =>
setSettings({ ...settings, SMTP_USER: e.target.value })
}
className="w-full px-3 py-2 border border-slate-300 rounded-lg disabled:bg-slate-100"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg disabled:bg-slate-100"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
SMTP Password / App Password
</label>
<label className="block font-semibold text-slate-700 mb-1">SMTP Password</label>
<input
type="password"
disabled={!isAdmin}
placeholder="App Password SMTP"
placeholder="App Password"
value={settings.SMTP_PASS || ""}
onChange={(e) =>
setSettings({ ...settings, SMTP_PASS: e.target.value })
}
className="w-full px-3 py-2 border border-slate-300 rounded-lg disabled:bg-slate-100"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg disabled:bg-slate-100"
/>
</div>
<div className="sm:col-span-2 flex flex-col sm:flex-row sm:items-end gap-2">
<div className="flex-1">
<label className="block font-semibold text-slate-700 mb-1">
Alamat Pengirim (Sender From)
</label>
<label className="block font-semibold text-slate-700 mb-1">Sender From</label>
<input
type="text"
disabled={!isAdmin}
placeholder="erp-system@perusahaan.id"
placeholder="erp@perusahaan.id"
value={settings.SMTP_FROM || ""}
onChange={(e) =>
setSettings({ ...settings, SMTP_FROM: e.target.value })
}
className="w-full px-3 py-2 border border-slate-300 rounded-lg disabled:bg-slate-100"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg disabled:bg-slate-100"
/>
</div>
{isAdmin && (
@@ -477,34 +444,24 @@ export default function SettingsPage() {
className="shrink-0 h-9 px-3.5 rounded-lg bg-blue-600 hover:bg-blue-700 text-white font-semibold flex items-center justify-center gap-1.5 shadow-xs transition-colors disabled:opacity-50"
>
<Mail className="h-3.5 w-3.5" />
<span>{testing ? "Mengirim..." : "Tes Kirim Email"}</span>
<span>{testing ? "..." : "Tes Email"}</span>
</button>
)}
</div>
</div>
<p className="text-[10.5px] text-slate-500 mt-3 leading-relaxed">
ℹ️ Setiap staf menerima notifikasi otomatis ke alamat <strong>email terdaftar masing-masing</strong> sesuai <strong>kapasitas divisinya</strong> (Gudang tidak menerima nominal uang/keuangan, Finance fokus transaksi uang &amp; approval PO, Sales fokus order/RMA/pelunasan customer).
</p>
</div>
{/* 3. Event Trigger Toggles */}
<div className="bg-white rounded-xl border border-slate-200 shadow-xs p-6">
<div className="flex items-center gap-2.5 mb-4 border-b border-slate-100 pb-3">
{/* 3. Aturan Notifikasi */}
<div className="bg-white rounded-xl border border-slate-200 shadow-xs p-5">
<div className="flex items-center gap-2.5 mb-3.5 border-b border-slate-100 pb-3">
<div className="p-2 rounded-lg bg-emerald-50 text-emerald-600">
<Bell className="h-5 w-5" />
</div>
<div>
<h3 className="text-sm font-bold text-slate-800">
Pemicu Otomatis Notifikasi (Trigger Rules)
</h3>
<p className="text-[11px] text-slate-500">
Pilih kejadian operasional apa saja yang akan memicu pengiriman alert ke divisi terkait
</p>
<Bell className="h-4 w-4" />
</div>
<h3 className="text-sm font-bold text-slate-800">Aturan Notifikasi</h3>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4 text-xs">
<label className="p-3 rounded-lg border border-slate-200 bg-slate-50 flex items-start gap-3 cursor-pointer">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2.5 text-xs">
<label className="p-2.5 rounded-lg border border-slate-200 bg-slate-50 flex items-center gap-2.5 cursor-pointer">
<input
type="checkbox"
disabled={!isAdmin}
@@ -515,17 +472,12 @@ export default function SettingsPage() {
NOTIF_STOCK_IN_ENABLED: e.target.checked ? "true" : "false",
})
}
className="mt-0.5 h-4 w-4 rounded text-blue-600"
className="h-4 w-4 rounded text-blue-600"
/>
<div>
<div className="font-bold text-slate-900">📦 Barang Masuk</div>
<div className="text-[11px] text-slate-500 mt-0.5">
Rute: Divisi Gudang, Purchasing & Admin
</div>
</div>
<span className="font-semibold text-slate-900">📦 Barang Masuk</span>
</label>
<label className="p-3 rounded-lg border border-slate-200 bg-slate-50 flex items-start gap-3 cursor-pointer">
<label className="p-2.5 rounded-lg border border-slate-200 bg-slate-50 flex items-center gap-2.5 cursor-pointer">
<input
type="checkbox"
disabled={!isAdmin}
@@ -536,17 +488,12 @@ export default function SettingsPage() {
NOTIF_STOCK_OUT_ENABLED: e.target.checked ? "true" : "false",
})
}
className="mt-0.5 h-4 w-4 rounded text-blue-600"
className="h-4 w-4 rounded text-blue-600"
/>
<div>
<div className="font-bold text-slate-900">🚚 Barang Keluar</div>
<div className="text-[11px] text-slate-500 mt-0.5">
Rute: Divisi Gudang, Sales & Admin
</div>
</div>
<span className="font-semibold text-slate-900">🚚 Barang Keluar</span>
</label>
<label className="p-3 rounded-lg border border-slate-200 bg-slate-50 flex items-start gap-3 cursor-pointer">
<label className="p-2.5 rounded-lg border border-slate-200 bg-slate-50 flex items-center gap-2.5 cursor-pointer">
<input
type="checkbox"
disabled={!isAdmin}
@@ -557,17 +504,12 @@ export default function SettingsPage() {
NOTIF_MONEY_IN_ENABLED: e.target.checked ? "true" : "false",
})
}
className="mt-0.5 h-4 w-4 rounded text-blue-600"
className="h-4 w-4 rounded text-blue-600"
/>
<div>
<div className="font-bold text-slate-900">💵 Uang Masuk</div>
<div className="text-[11px] text-slate-500 mt-0.5">
Rute: Divisi Keuangan (Akuntan), Sales & Admin
</div>
</div>
<span className="font-semibold text-slate-900">💵 Uang Masuk</span>
</label>
<label className="p-3 rounded-lg border border-slate-200 bg-slate-50 flex items-start gap-3 cursor-pointer">
<label className="p-2.5 rounded-lg border border-slate-200 bg-slate-50 flex items-center gap-2.5 cursor-pointer">
<input
type="checkbox"
disabled={!isAdmin}
@@ -578,17 +520,12 @@ export default function SettingsPage() {
NOTIF_MONEY_OUT_ENABLED: e.target.checked ? "true" : "false",
})
}
className="mt-0.5 h-4 w-4 rounded text-blue-600"
className="h-4 w-4 rounded text-blue-600"
/>
<div>
<div className="font-bold text-slate-900">💳 Uang Keluar &amp; Approval PO</div>
<div className="text-[11px] text-slate-500 mt-0.5">
Rute: Finance (Akuntan), Purchasing, Manager &amp; Admin
</div>
</div>
<span className="font-semibold text-slate-900">💳 Uang Keluar &amp; Approval PO</span>
</label>
<label className="p-3 rounded-lg border border-slate-200 bg-slate-50 flex items-start gap-3 cursor-pointer sm:col-span-2">
<label className="p-2.5 rounded-lg border border-slate-200 bg-slate-50 flex items-center gap-2.5 cursor-pointer sm:col-span-2">
<input
type="checkbox"
disabled={!isAdmin}
@@ -599,58 +536,51 @@ export default function SettingsPage() {
NOTIF_RMA_ENABLED: e.target.checked ? "true" : "false",
})
}
className="mt-0.5 h-4 w-4 rounded text-blue-600"
className="h-4 w-4 rounded text-blue-600"
/>
<div>
<div className="font-bold text-slate-900">🔧 RMA, Service Garansi, Rusak &amp; Kanibalan</div>
<div className="text-[11px] text-slate-500 mt-0.5">
Rute: Divisi Sales, Gudang/Teknisi (Inventory), Manager &amp; Admin (termasuk tiket RMA customer tanpa login)
</div>
</div>
<span className="font-semibold text-slate-900">🔧 RMA, Service &amp; Garansi</span>
</label>
</div>
</div>
{isAdmin ? (
<div className="flex items-center justify-between">
<div className="flex items-center justify-between gap-3">
<button
type="button"
onClick={handleTestBroadcast}
className="px-4 py-2 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-700 text-xs font-semibold transition-colors"
className="h-9 px-4 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-700 text-xs font-semibold transition-colors"
>
Uji Siaran Notifikasi Sistem
Uji Siaran
</button>
<button
type="submit"
disabled={saving}
className="inline-flex items-center gap-2 px-6 py-2.5 rounded-lg bg-blue-600 hover:bg-blue-700 text-white text-xs font-bold shadow-xs transition-colors disabled:opacity-50"
className="inline-flex items-center gap-2 h-9 px-5 rounded-lg bg-blue-600 hover:bg-blue-700 text-white text-xs font-bold shadow-xs transition-colors disabled:opacity-50"
>
<Save className="h-4 w-4" />
<span>{saving ? "Menyimpan..." : "Simpan Konfigurasi"}</span>
<Save className="h-3.5 w-3.5" />
<span>{saving ? "Menyimpan..." : "Simpan Pengaturan"}</span>
</button>
</div>
) : (
<div className="p-3 rounded-lg bg-slate-100 text-slate-600 text-xs flex items-center gap-2">
<Lock className="h-4 w-4 text-slate-400" />
<span>Pengubahan pengaturan sistem dibatasi khusus peran Super Admin.</span>
<span>Hanya Super Admin yang dapat mengubah pengaturan.</span>
</div>
)}
</form>
{/* Kartu Keamanan Sistem & Backup Database */}
<div className="bg-white rounded-xl border border-slate-200 shadow-xs p-6 space-y-4">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3 border-b border-slate-100 pb-4">
{/* Backup Database */}
<div className="bg-white rounded-xl border border-slate-200 shadow-xs p-5">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div className="flex items-center gap-3">
<div className="h-10 w-10 rounded-xl bg-slate-100 text-slate-700 flex items-center justify-center border border-slate-200 shrink-0">
<ShieldCheck className="h-5 w-5" />
<div className="h-9 w-9 rounded-lg bg-slate-100 text-slate-700 flex items-center justify-center border border-slate-200 shrink-0">
<Database className="h-4 w-4" />
</div>
<div>
<h3 className="font-bold text-slate-900 text-sm">
Keamanan Sistem &amp; Backup Database
</h3>
<p className="text-xs text-slate-500">
Proteksi sesi aktif, enkripsi akun, dan unduh salinan snapshot database secara aman
<h3 className="font-bold text-slate-900 text-sm">Backup Database</h3>
<p className="text-[11px] text-slate-500">
Unduh snapshot SQLite secara aman tanpa mengganggu transaksi.
</p>
</div>
</div>
@@ -658,34 +588,13 @@ export default function SettingsPage() {
{isAdmin && (
<a
href="/api/settings/backup"
className="inline-flex items-center justify-center gap-2 px-4 py-2 rounded-lg bg-slate-900 hover:bg-slate-800 text-white text-xs font-semibold transition-colors shrink-0"
className="inline-flex items-center justify-center gap-2 h-9 px-4 rounded-lg bg-slate-900 hover:bg-slate-800 text-white text-xs font-semibold transition-colors shrink-0"
>
<Download className="h-3.5 w-3.5" />
<span>Unduh Backup (.db)</span>
<span>Unduh (.db)</span>
</a>
)}
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs">
<div className="p-3 rounded-lg bg-slate-50 border border-slate-200 space-y-1">
<div className="font-semibold text-slate-900 flex items-center gap-1.5">
<Database className="h-3.5 w-3.5 text-emerald-600" />
<span>Snapshot Online Atomik (SQLite)</span>
</div>
<p className="text-[11px] text-slate-600">
Backup otomatis mengambil snapshot database produksi tanpa mengganggu transaksi berjalan dan tercatat di Audit Log.
</p>
</div>
<div className="p-3 rounded-lg bg-slate-50 border border-slate-200 space-y-1">
<div className="font-semibold text-slate-900 flex items-center gap-1.5">
<ShieldCheck className="h-3.5 w-3.5 text-blue-600" />
<span>Kontrol Keamanan Aktif</span>
</div>
<p className="text-[11px] text-slate-600">
RBAC Middleware, Auto-Logout Idle 30 menit, Password min. 8 karakter (huruf &amp; angka), Rate-Limit Login/MFA/RMA, Masking Secret SMTP/Bot, &amp; Kunci Akun Aktif.
</p>
</div>
</div>
</div>
</div>
+171 -137
View File
@@ -227,13 +227,9 @@ export default function UsersPage() {
return (
<AppShell
title={isAdmin ? "Pengguna" : "Profil Saya"}
subtitle={
isAdmin
? "Kelola akun karyawan, hak akses role, keamanan MFA, dan preferensi notifikasi"
: "Kelola profil, password, keamanan MFA, dan preferensi notifikasi akun Anda"
}
subtitle={isAdmin ? "Kelola akun, role, MFA, dan audit trail" : "Kelola profil, password, dan keamanan MFA"}
>
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 mb-6">
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-5">
<div className="flex items-center p-1 bg-slate-200/80 rounded-lg text-xs font-semibold text-slate-600 w-fit">
<button
onClick={() => setActiveTab("users")}
@@ -244,7 +240,7 @@ export default function UsersPage() {
}`}
>
<Users className="h-3.5 w-3.5" />
<span>{isAdmin ? `Daftar Pengguna (${users.length})` : "Profil Pengguna Saya"}</span>
<span>{isAdmin ? `Pengguna (${users.length})` : "Profil Saya"}</span>
</button>
<button
onClick={() => setActiveTab("audit")}
@@ -255,11 +251,11 @@ export default function UsersPage() {
}`}
>
<FileCheck2 className="h-3.5 w-3.5" />
<span>Audit Trail Log ({auditLogs.length})</span>
<span>Audit Log ({auditLogs.length})</span>
</button>
</div>
{isAdmin ? (
{isAdmin && (
<button
onClick={() => {
setFormError(null);
@@ -269,13 +265,8 @@ export default function UsersPage() {
className="inline-flex items-center gap-2 px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-xs font-semibold shadow-xs transition-colors"
>
<Plus className="h-4 w-4" />
<span>Tambah Pengguna Baru</span>
<span>Tambah Pengguna</span>
</button>
) : (
<div className="flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-blue-50 text-blue-800 border border-blue-200 text-xs">
<Lock className="h-3.5 w-3.5 text-blue-600" />
<span>Anda dapat mengubah nama, email, password, MFA, dan notifikasi. Peran (role) hanya dapat diubah oleh Super Admin.</span>
</div>
)}
</div>
@@ -285,19 +276,19 @@ export default function UsersPage() {
<table className="w-full text-left border-collapse text-xs">
<thead>
<tr className="bg-slate-50 text-slate-500 font-semibold border-b border-slate-100">
<th className="py-3 px-6">Nama Pengguna</th>
<th className="py-3 px-4">Kontak Notifikasi</th>
<th className="py-3 px-4">Peran (Role)</th>
<th className="py-3 px-4">Keamanan MFA</th>
<th className="py-3 px-4">Saluran & Topik</th>
<th className="py-3 px-6">Deskripsi Kewenangan</th>
<th className="py-3 px-4 text-center">Aksi</th>
<th className="py-3 px-4">Nama</th>
<th className="py-3 px-4">Kontak</th>
<th className="py-3 px-4 text-center">Role</th>
<th className="py-3 px-4 text-center">MFA</th>
<th className="py-3 px-4">Notifikasi</th>
<th className="py-3 px-4">Kewenangan</th>
<th className="py-3 px-4 text-right">Aksi</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-100">
{users.map((u) => (
<tr key={u.id} className="hover:bg-slate-50/60 transition-colors">
<td className="py-3.5 px-6 font-bold text-slate-900">
<td className="py-3 px-4 font-bold text-slate-900 align-middle">
<div className="flex items-center gap-2.5">
<div className={`h-7 w-7 rounded-full text-white flex items-center justify-center text-[10px] font-bold ${u.isActive === false ? "bg-slate-400" : "bg-slate-800"}`}>
{u.name.slice(0, 2).toUpperCase()}
@@ -328,7 +319,7 @@ export default function UsersPage() {
</div>
)}
</td>
<td className="py-3.5 px-4">
<td className="py-3 px-4 text-center align-middle">
<span
className={`inline-block px-2.5 py-0.5 rounded-md text-[10px] font-bold border ${
u.role === "ADMIN"
@@ -345,19 +336,19 @@ export default function UsersPage() {
{u.role}
</span>
</td>
<td className="py-3.5 px-4">
<td className="py-3 px-4 text-center align-middle">
{u.mfaEnabled ? (
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-emerald-50 text-emerald-700 border border-emerald-200 text-[10px] font-bold">
<ShieldCheck className="h-3 w-3 text-emerald-600" />
<span>MFA Aktif ({u.mfaMethod || "TOTP"})</span>
<span>{u.mfaMethod || "TOTP"}</span>
</span>
) : (
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-slate-100 text-slate-500 border border-slate-200 text-[10px] font-medium">
<span>Nonaktif</span>
<span>Off</span>
</span>
)}
</td>
<td className="py-3.5 px-4">
<td className="py-3 px-4 align-middle">
<div className="flex items-center gap-1 flex-wrap">
{u.notifyEmail && (
<span className="px-1.5 py-0.5 rounded bg-blue-50 text-blue-700 border border-blue-200 text-[10px] font-bold">
@@ -396,17 +387,17 @@ export default function UsersPage() {
)}
</div>
</td>
<td className="py-3.5 px-6 text-slate-600">
<td className="py-3 px-4 text-slate-600 align-middle">
{roleDescriptions[u.role] || "Akses standar operasional"}
</td>
<td className="py-3.5 px-4 text-center">
<td className="py-3 px-4 text-right align-middle">
<button
onClick={() => openEditModal(u)}
title={isAdmin ? "Edit Akun, Role, Password & MFA" : "Edit Profil Saya"}
title={isAdmin ? "Edit Akun" : "Edit Profil"}
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-blue-50 hover:bg-blue-100 hover:text-blue-800 border border-blue-200 text-blue-700 text-[11px] font-semibold transition-colors"
>
<Pencil className="h-3 w-3" />
<span>{isAdmin ? "Edit Akun" : "Edit Profil Saya"}</span>
<span>{isAdmin ? "Edit" : "Edit Profil"}</span>
</button>
</td>
</tr>
@@ -458,65 +449,65 @@ export default function UsersPage() {
<Modal
isOpen={isCreateOpen}
onClose={() => setIsCreateOpen(false)}
title="Daftarkan Akun Pengguna Baru (Akses Admin)"
title="Tambah Pengguna"
>
{formError && (
<div className="mb-4 p-3 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
<div className="mb-3 p-2.5 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
{formError}
</div>
)}
<form onSubmit={handleCreateUser} className="space-y-4 text-xs">
<form onSubmit={handleCreateUser} className="space-y-3 text-xs">
<div>
<label className="block font-semibold text-slate-700 mb-1">Nama Lengkap Karyawan *</label>
<label className="block font-semibold text-slate-700 mb-1">Nama Lengkap *</label>
<input
type="text"
required
placeholder="misal: Hendra Saputra"
value={form.name}
onChange={(e) => setForm({ ...form, name: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg"
/>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">Alamat Email Kerja *</label>
<label className="block font-semibold text-slate-700 mb-1">Email *</label>
<input
type="email"
required
placeholder="hendra@erp.local"
value={form.email}
onChange={(e) => setForm({ ...form, email: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">ID Chat Telegram (Opsional)</label>
<label className="block font-semibold text-slate-700 mb-1">Chat ID Telegram</label>
<input
type="text"
placeholder="misal: 123456789"
placeholder="Opsional"
value={form.telegramChatId}
onChange={(e) => setForm({ ...form, telegramChatId: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg"
/>
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">Kata Sandi Awal *</label>
<label className="block font-semibold text-slate-700 mb-1">Password *</label>
<input
type="password"
required
placeholder="Minimal 6 karakter"
placeholder="Min. 8 karakter (huruf & angka)"
value={form.password}
onChange={(e) => setForm({ ...form, password: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">Peran & Hak Akses (Role) *</label>
<label className="block font-semibold text-slate-700 mb-1">Role *</label>
<select
value={form.role}
onChange={(e) => {
@@ -524,7 +515,7 @@ export default function UsersPage() {
const defs = getRoleDefaultNotifications(nextRole);
setForm({ ...form, role: nextRole, ...defs });
}}
className="w-full px-3 py-2 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
>
<option value="ADMIN">ADMIN</option>
<option value="MANAGER">MANAGER</option>
@@ -593,33 +584,25 @@ export default function UsersPage() {
Topik notifikasi otomatis disesuaikan dengan kapasitas peran <strong>{form.role}</strong>:
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
{NOTIF_TOPICS.map(({ key, type, label, desc }) => {
const allowed = isRoleAllowedNotifType(form.role, type);
return (
{NOTIF_TOPICS.filter(({ type }) => isRoleAllowedNotifType(form.role, type)).map(
({ key, label, desc }) => (
<label
key={key}
className={`flex items-start gap-2 p-2 rounded-lg border ${
allowed
? "cursor-pointer border-slate-200 bg-white hover:bg-slate-50"
: "cursor-not-allowed border-slate-100 bg-slate-100/70 opacity-60"
}`}
className="flex items-start gap-2 p-2 rounded-lg border cursor-pointer border-slate-200 bg-white hover:bg-slate-50"
>
<input
type="checkbox"
disabled={!allowed}
checked={allowed && (form[key as keyof typeof form] as boolean)}
checked={Boolean(form[key as keyof typeof form])}
onChange={(e) => setForm({ ...form, [key]: e.target.checked })}
className="mt-0.5 rounded text-blue-600"
/>
<div>
<div className="font-semibold text-slate-800 text-[11px]">{label}</div>
<div className="text-[10px] text-slate-400">
{allowed ? desc : `Di luar kapasitas role ${form.role}`}
</div>
<div className="text-[10px] text-slate-400">{desc}</div>
</div>
</label>
);
})}
)
)}
</div>
</div>
</div>
@@ -643,69 +626,67 @@ export default function UsersPage() {
</form>
</Modal>
{/* Modal: Edit Data Pengguna (Nama, Email, Password, Role, MFA & Notifikasi) */}
{/* Modal: Edit Data Pengguna */}
<Modal
isOpen={isEditOpen}
onClose={() => setIsEditOpen(false)}
title={`Edit Akun & Keamanan MFA — ${editUser?.name ?? ""}`}
title={`Edit Akun — ${editUser?.name ?? ""}`}
>
{editError && (
<div className="mb-4 p-3 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
<div className="mb-3 p-2.5 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs">
{editError}
</div>
)}
<form onSubmit={handleEditUser} className="space-y-4 text-xs">
<form onSubmit={handleEditUser} className="space-y-3 text-xs">
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1">
Nama Lengkap Karyawan *
<label className="h-5 flex items-center font-semibold text-slate-700 mb-1">
Nama Lengkap *
</label>
<input
type="text"
required
value={editForm.name}
onChange={(e) => setEditForm({ ...editForm, name: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1">
Alamat Email Login *
<label className="h-5 flex items-center font-semibold text-slate-700 mb-1">
Email Login *
</label>
<input
type="email"
required
value={editForm.email}
onChange={(e) => setEditForm({ ...editForm, email: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg font-mono"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg font-mono"
/>
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label className="block font-semibold text-slate-700 mb-1 flex items-center gap-1">
<label className="h-5 flex items-center gap-1 font-semibold text-slate-700 mb-1">
<KeyRound className="h-3.5 w-3.5 text-amber-600" />
<span>Ganti Password (Opsional)</span>
<span>Password Baru (Opsional)</span>
</label>
<input
type="password"
placeholder="Kosongkan jika tidak diubah"
value={editForm.password}
onChange={(e) => setEditForm({ ...editForm, password: e.target.value })}
className="w-full px-3 py-2 border border-slate-300 rounded-lg"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg"
/>
</div>
<div>
<label className="block font-semibold text-slate-700 mb-1 flex items-center justify-between">
<span>Peran / Role (RBAC) *</span>
<label className="h-5 flex items-center justify-between font-semibold text-slate-700 mb-1">
<span>Role *</span>
{!isAdmin && (
<span className="text-[10px] text-amber-700 font-semibold bg-amber-50 px-1.5 py-0.5 rounded border border-amber-200">
🔒 Khusus Super Admin
</span>
<span className="text-[10px] text-slate-500 font-medium">Khusus Admin</span>
)}
</label>
{isAdmin ? (
@@ -716,19 +697,19 @@ export default function UsersPage() {
const defs = getRoleDefaultNotifications(nextRole);
setEditForm({ ...editForm, role: nextRole, ...defs });
}}
className="w-full px-3 py-2 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
className="w-full h-9 px-3 py-1.5 border border-slate-300 rounded-lg bg-white font-semibold text-slate-800"
>
<option value="ADMIN">ADMIN - Super Admin</option>
<option value="MANAGER">MANAGER - Manajer</option>
<option value="INVENTORY">INVENTORY - Staf Gudang</option>
<option value="SALES">SALES - Staf Penjualan</option>
<option value="PURCHASING">PURCHASING - Staf Pengadaan</option>
<option value="ACCOUNTANT">ACCOUNTANT - Staf Akuntan</option>
<option value="ADMIN">ADMIN</option>
<option value="MANAGER">MANAGER</option>
<option value="INVENTORY">INVENTORY</option>
<option value="SALES">SALES</option>
<option value="PURCHASING">PURCHASING</option>
<option value="ACCOUNTANT">ACCOUNTANT</option>
</select>
) : (
<div className="w-full px-3 py-2 border border-slate-200 rounded-lg bg-slate-100 text-slate-700 font-semibold flex items-center justify-between">
<span>{editForm.role} — {roleDescriptions[editForm.role] || ""}</span>
<Lock className="h-3.5 w-3.5 text-slate-400" />
<div className="w-full h-9 px-3 py-1.5 border border-slate-200 rounded-lg bg-slate-100 text-slate-700 font-semibold flex items-center justify-between">
<span>{editForm.role}</span>
<Lock className="h-3.5 w-3.5 text-slate-400 shrink-0" />
</div>
)}
</div>
@@ -807,62 +788,115 @@ export default function UsersPage() {
<div className="p-3 bg-slate-50 rounded-lg border border-slate-200 space-y-2.5">
<span className="font-bold text-slate-800 flex items-center gap-1.5">
<Bell className="h-3.5 w-3.5 text-blue-600" />
<span>Saluran & Topik Notifikasi User:</span>
<span>Saluran &amp; Topik Notifikasi User:</span>
</span>
<div className="flex items-center gap-4">
<label className="flex items-center gap-2 cursor-pointer text-slate-700 font-medium">
<input
type="checkbox"
checked={editForm.notifyEmail}
onChange={(e) => setEditForm({ ...editForm, notifyEmail: e.target.checked })}
className="rounded text-blue-600 focus:ring-blue-500"
/>
<span>via Email</span>
</label>
<label className="flex items-center gap-2 cursor-pointer text-slate-700 font-medium">
<input
type="checkbox"
checked={editForm.notifyTelegram}
onChange={(e) => setEditForm({ ...editForm, notifyTelegram: e.target.checked })}
className="rounded text-blue-600 focus:ring-blue-500"
/>
<span>via Telegram</span>
</label>
</div>
{isAdmin ? (
<div className="flex items-center gap-4">
<label className="flex items-center gap-2 cursor-pointer text-slate-700 font-medium">
<input
type="checkbox"
checked={editForm.notifyEmail}
onChange={(e) => setEditForm({ ...editForm, notifyEmail: e.target.checked })}
className="rounded text-blue-600 focus:ring-blue-500"
/>
<span>via Email</span>
</label>
<label className="flex items-center gap-2 cursor-pointer text-slate-700 font-medium">
<input
type="checkbox"
checked={editForm.notifyTelegram}
onChange={(e) => setEditForm({ ...editForm, notifyTelegram: e.target.checked })}
className="rounded text-blue-600 focus:ring-blue-500"
/>
<span>via Telegram</span>
</label>
</div>
) : (
<div className="flex items-center gap-4 flex-wrap">
{editForm.notifyEmail && (
<label className="flex items-center gap-2 text-slate-700 font-medium">
<input
type="checkbox"
checked
readOnly
className="rounded text-blue-600 pointer-events-none"
/>
<span>via Email</span>
</label>
)}
{editForm.notifyTelegram && (
<label className="flex items-center gap-2 text-slate-700 font-medium">
<input
type="checkbox"
checked
readOnly
className="rounded text-blue-600 pointer-events-none"
/>
<span>via Telegram</span>
</label>
)}
{!editForm.notifyEmail && !editForm.notifyTelegram && (
<span className="text-[11px] text-slate-500 italic">
Tidak ada saluran notifikasi aktif
</span>
)}
</div>
)}
<div className="border-t border-slate-200 pt-2">
<div className="text-[10.5px] text-slate-500 mb-2">
Kapasitas notifikasi email/Telegram sesuai peran <strong>{editForm.role}</strong>:
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
{NOTIF_TOPICS.map(({ key, type, label, desc }) => {
{(() => {
const visibleTopics = NOTIF_TOPICS.filter(({ key, type }) => {
const allowed = isRoleAllowedNotifType(editForm.role, type);
if (!allowed) return false;
if (!isAdmin) {
return Boolean(editForm[key as keyof typeof editForm]);
}
return true;
});
if (visibleTopics.length === 0) {
return (
<label
key={key}
className={`flex items-start gap-2 p-2 rounded-lg border ${
allowed
? "cursor-pointer border-slate-200 bg-white hover:bg-slate-50"
: "cursor-not-allowed border-slate-100 bg-slate-100/70 opacity-60"
}`}
>
<input
type="checkbox"
disabled={!allowed}
checked={allowed && (editForm[key as keyof typeof editForm] as boolean)}
onChange={(e) => setEditForm({ ...editForm, [key]: e.target.checked })}
className="mt-0.5 rounded text-blue-600"
/>
<div>
<div className="font-semibold text-slate-800 text-[11px]">{label}</div>
<div className="text-[10px] text-slate-400">
{allowed ? desc : `Di luar kapasitas role ${editForm.role}`}
</div>
</div>
</label>
<div className="text-[11px] text-slate-500 italic py-1">
Belum ada topik notifikasi aktif untuk akun ini.
</div>
);
})}
</div>
}
return (
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
{visibleTopics.map(({ key, label, desc }) => (
<label
key={key}
className={`flex items-start gap-2 p-2 rounded-lg border border-slate-200 bg-white ${
isAdmin ? "cursor-pointer hover:bg-slate-50" : "cursor-default"
}`}
>
<input
type="checkbox"
checked={Boolean(editForm[key as keyof typeof editForm])}
readOnly={!isAdmin}
onChange={(e) => {
if (isAdmin) {
setEditForm({ ...editForm, [key]: e.target.checked });
}
}}
className={`mt-0.5 rounded text-blue-600 ${
!isAdmin ? "pointer-events-none" : ""
}`}
/>
<div>
<div className="font-semibold text-slate-800 text-[11px]">{label}</div>
<div className="text-[10px] text-slate-400">{desc}</div>
</div>
</label>
))}
</div>
);
})()}
</div>
</div>
+7 -14
View File
@@ -2,7 +2,7 @@
import React, { useRef, useState } from "react";
import * as XLSX from "xlsx";
import { Download, Upload, X, CheckCircle2, AlertCircle, FileSpreadsheet } from "lucide-react";
import { Download, Upload, X, CheckCircle2, AlertCircle } from "lucide-react";
interface SerialNumberInputProps {
value: string;
@@ -195,7 +195,7 @@ export function SerialNumberInput({
<div className={`space-y-1.5 ${className}`}>
<div className="flex flex-wrap items-center justify-between gap-1.5">
<div className="flex items-center gap-1.5 min-w-0">
<label className="text-[10.5px] font-bold text-slate-700 truncate">
<label className="text-xs font-semibold text-slate-700 truncate">
{label}
</label>
{snCount > 0 && (
@@ -220,20 +220,20 @@ export function SerialNumberInput({
type="button"
onClick={handleDownloadTemplate}
className="inline-flex items-center gap-1 px-2 py-1 rounded bg-white hover:bg-emerald-50 text-emerald-700 border border-emerald-300 text-[10px] font-bold transition-colors shadow-2xs"
title="Unduh Template Excel (.xlsx) untuk pengisian banyak Serial Number"
title="Unduh Template Excel (.xlsx)"
>
<Download className="h-3 w-3 shrink-0" />
<span>Template Excel</span>
<span>Template</span>
</button>
<button
type="button"
onClick={() => fileInputRef.current?.click()}
className="inline-flex items-center gap-1 px-2 py-1 rounded bg-emerald-600 hover:bg-emerald-700 text-white text-[10px] font-bold transition-colors shadow-2xs"
title="Upload file Excel (.xlsx, .xls, .csv) berisi daftar Serial Number"
title="Upload Excel (.xlsx, .xls, .csv)"
>
<Upload className="h-3 w-3 shrink-0" />
<span>Upload Excel</span>
<span>Excel</span>
</button>
{snCount > 0 && (
@@ -244,7 +244,7 @@ export function SerialNumberInput({
setUploadStatus(null);
}}
className="inline-flex items-center gap-0.5 px-1.5 py-1 rounded bg-white hover:bg-rose-50 text-rose-600 border border-rose-200 text-[10px] font-semibold transition-colors"
title="Kosongkan daftar SN"
title="Kosongkan SN"
>
<X className="h-3 w-3" />
</button>
@@ -294,13 +294,6 @@ export function SerialNumberInput({
<span>{uploadStatus.text}</span>
</div>
)}
{!uploadStatus && (
<div className="flex items-center gap-1 text-[9.5px] text-slate-500">
<FileSpreadsheet className="h-3 w-3 text-emerald-600 shrink-0" />
<span>Ketik dipisah koma, atau klik <strong>Template Excel</strong> &amp; <strong>Upload Excel</strong> untuk pengiriman banyak unit.</span>
</div>
)}
</div>
);
}
+43 -33
View File
@@ -285,47 +285,57 @@ export function Sidebar({
: "Enterprise ERP");
return (
<div className="h-15 flex items-center justify-between px-4 gap-2 border-b border-slate-200/80">
<div className="flex items-center gap-2.5 min-w-0">
{displayLogo ? (
<img
src={displayLogo}
alt={displayTitle}
className="h-9 w-9 shrink-0 rounded-lg object-contain bg-white p-0.5 border border-slate-200/80"
/>
) : (
<div className="h-8 w-8 shrink-0 rounded-lg bg-slate-900 dark:bg-white flex items-center justify-center text-white dark:text-slate-950">
<Building2 className="h-4 w-4" />
</div>
)}
<div className="min-w-0">
<span
className="font-semibold text-sm tracking-tight text-slate-900 dark:text-white block truncate"
title={displayTitle}
>
{displayTitle}
</span>
<span className="flex items-center gap-1.5 text-[10px] font-semibold text-slate-800 dark:text-slate-100 truncate">
<span
className={cn(
"h-1.5 w-1.5 rounded-full shrink-0",
companies.length > 0 ? "bg-emerald-500" : "bg-amber-400"
)}
/>
<span className="truncate">{displaySubtitle}</span>
</span>
</div>
</div>
<div className="relative px-3.5 pt-3.5 pb-3 border-b border-slate-200/80 flex flex-col gap-2">
{onCloseMobile && (
<button
type="button"
onClick={onCloseMobile}
aria-label="Tutup Menu"
className="lg:hidden p-1.5 rounded-lg text-slate-400 hover:text-slate-900 hover:bg-slate-100 transition-colors"
className="lg:hidden absolute top-2 right-2 z-10 p-1.5 rounded-lg bg-white/90 text-slate-500 hover:text-slate-900 hover:bg-slate-100 border border-slate-200/80 transition-colors"
>
<X className="h-4 w-4" />
<X className="h-3.5 w-3.5" />
</button>
)}
{/* Logo Full Width Landscape di Atas */}
{displayLogo ? (
<div
style={{ backgroundColor: "#ffffff" }}
className="w-full h-16 rounded-lg border border-slate-200/80 px-2.5 py-1.5 flex items-center justify-center overflow-hidden shadow-xs"
>
<img
src={displayLogo}
alt={displayTitle}
className="w-full h-full object-contain"
/>
</div>
) : (
<div className="w-full h-14 rounded-lg bg-slate-900 dark:bg-slate-800 border border-slate-200/80 flex items-center justify-center gap-2 text-white">
<Building2 className="h-5 w-5 shrink-0" />
<span className="text-xs font-semibold tracking-wide uppercase">
{companies.length > 0 ? "Belum Ada Logo" : "Enterprise ERP"}
</span>
</div>
)}
{/* Nama PT di Bawah Logo */}
<div className="w-full text-center min-w-0 px-0.5">
<span
className="font-bold text-[13px] leading-snug tracking-tight text-slate-900 dark:text-white block truncate"
title={displayTitle}
>
{displayTitle}
</span>
<span className="mt-0.5 flex items-center justify-center gap-1.5 text-[10px] font-semibold text-slate-800 dark:text-slate-100 truncate">
<span
className={cn(
"h-1.5 w-1.5 rounded-full shrink-0",
companies.length > 0 ? "bg-emerald-500" : "bg-amber-400"
)}
/>
<span className="truncate">{displaySubtitle}</span>
</span>
</div>
</div>
);
})()}
+5 -5
View File
@@ -66,7 +66,7 @@ export const ROLE_PERMISSIONS: Record<
MANAGER: {
allowedRoutes: ["/", "/inventory", "/sales", "/purchases", "/finance", "/users", "/settings"],
defaultRoute: "/",
accessSummary: "Dashboard eksekutif View-Only, approval anggaran, dan pantauan seluruh divisi (tidak bisa tambah user/ubah SMTP).",
accessSummary: "Dashboard eksekutif View-Only, approval anggaran, dan pantauan seluruh divisi.",
allowedNotifTypes: ["STOCK_IN", "STOCK_OUT", "MONEY_IN", "MONEY_OUT", "RMA_SERVICE", "SYSTEM"],
defaultNotifPrefs: {
notifStockIn: true,
@@ -93,7 +93,7 @@ export const ROLE_PERMISSIONS: Record<
INVENTORY: {
allowedRoutes: ["/", "/inventory", "/sales", "/purchases", "/users"],
defaultRoute: "/",
accessSummary: "Khusus operasional gudang & teknisi: stok, SN, terima barang PO, input resi/ongkir kirim, dan device service/rusak/kanibalan (tanpa akses harga jual/HPP/keuangan).",
accessSummary: "Khusus operasional gudang & teknisi: stok, SN, terima barang PO, input resi/ongkir kirim, dan device service/rusak/kanibalan.",
allowedNotifTypes: ["STOCK_IN", "STOCK_OUT", "RMA_SERVICE"],
defaultNotifPrefs: {
notifStockIn: true,
@@ -120,7 +120,7 @@ export const ROLE_PERMISSIONS: Record<
SALES: {
allowedRoutes: ["/", "/sales", "/purchases", "/inventory", "/users"],
defaultRoute: "/",
accessSummary: "Khusus penjualan, pengajuan pembelian, dan layanan RMA/service customer (tanpa akses keuangan, PPN, ongkir PO, atau pelunasan).",
accessSummary: "Khusus penjualan, pengajuan pembelian, dan layanan RMA/service customer.",
allowedNotifTypes: ["STOCK_OUT", "MONEY_IN", "RMA_SERVICE"],
defaultNotifPrefs: {
notifStockIn: false,
@@ -147,7 +147,7 @@ export const ROLE_PERMISSIONS: Record<
PURCHASING: {
allowedRoutes: ["/", "/purchases", "/inventory", "/users"],
defaultRoute: "/",
accessSummary: "Khusus pengadaan & PO ke vendor (tanpa akses penjualan, keuangan, biaya forwarder/pajak Finance, atau harga jual).",
accessSummary: "Khusus pengadaan & PO ke vendor.",
allowedNotifTypes: ["STOCK_IN", "MONEY_OUT"],
defaultNotifPrefs: {
notifStockIn: true,
@@ -174,7 +174,7 @@ export const ROLE_PERMISSIONS: Record<
ACCOUNTANT: {
allowedRoutes: ["/", "/finance", "/sales", "/purchases", "/users"],
defaultRoute: "/",
accessSummary: "Khusus keuangan & akuntansi: approve anggaran PO, biaya forwarder/pajak/PPN, pembayaran/DP vendor, pelunasan customer, payroll & jurnal (tanpa akses mutasi stok/pengaturan sistem).",
accessSummary: "Khusus keuangan & akuntansi: approve anggaran PO, biaya forwarder/pajak/PPN, pembayaran/DP vendor, pelunasan customer, payroll & jurnal.",
allowedNotifTypes: ["MONEY_IN", "MONEY_OUT"],
defaultNotifPrefs: {
notifStockIn: false,