1289 lines
48 KiB
TypeScript
1289 lines
48 KiB
TypeScript
import { useEffect, useMemo, useRef, useState } from "react";
|
|
import PageMeta from "../../components/common/PageMeta";
|
|
import { apiGet, apiPost } from "../../lib/api";
|
|
import { useToastOnError } from "../../hooks/useToastOnError";
|
|
|
|
type Lokasi = { id: number; kode: string; nama: string };
|
|
type StokRow = {
|
|
id: number;
|
|
sku: string | null;
|
|
nama: string;
|
|
barcode: string;
|
|
harga_jual: number;
|
|
stok: number;
|
|
units: { id: number; name: string; multiplier: number; is_base: boolean }[];
|
|
};
|
|
|
|
type CartItem = {
|
|
produk_id: number;
|
|
nama: string;
|
|
barcode: string;
|
|
harga: number;
|
|
qty: number;
|
|
stok: number;
|
|
};
|
|
|
|
type RecentRow = {
|
|
id: number;
|
|
nomor_penjualan: string;
|
|
waktu: string;
|
|
total: number;
|
|
metode_pembayaran: string;
|
|
items_count: number;
|
|
};
|
|
|
|
type TransaksiDetail = {
|
|
id: number;
|
|
nomor_penjualan: string;
|
|
waktu: string;
|
|
subtotal: number;
|
|
diskon: number;
|
|
pajak: number;
|
|
total: number;
|
|
metode_pembayaran: string;
|
|
voucher_kode?: string | null;
|
|
voucher_amount?: number;
|
|
jumlah_bayar: number;
|
|
kembalian: number;
|
|
items: {
|
|
produk_id: number;
|
|
nama?: string | null;
|
|
barcode?: string | null;
|
|
jumlah: number;
|
|
harga: number;
|
|
total: number;
|
|
}[];
|
|
};
|
|
|
|
export default function Transaksi() {
|
|
const [loading, setLoading] = useState(true);
|
|
const [saving, setSaving] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [msg, setMsg] = useState<string | null>(null);
|
|
|
|
useToastOnError(error);
|
|
|
|
const [lokasiList, setLokasiList] = useState<Lokasi[]>([]);
|
|
const [lokasi, setLokasi] = useState<Lokasi | null>(null);
|
|
const [rows, setRows] = useState<StokRow[]>([]);
|
|
|
|
const [q, setQ] = useState("");
|
|
const [barcode, setBarcode] = useState("");
|
|
const barcodeRef = useRef<HTMLInputElement>(null);
|
|
const voucherRef = useRef<HTMLInputElement>(null);
|
|
const scanBufferRef = useRef("");
|
|
const scanTimeoutRef = useRef<number | null>(null);
|
|
const scanInputTimeoutRef = useRef<number | null>(null);
|
|
const displayChannelRef = useRef<BroadcastChannel | null>(null);
|
|
const [cart, setCart] = useState<CartItem[]>([]);
|
|
const [recent, setRecent] = useState<RecentRow[]>([]);
|
|
const [recentLoading, setRecentLoading] = useState(false);
|
|
const [detail, setDetail] = useState<TransaksiDetail | null>(null);
|
|
const [detailOpen, setDetailOpen] = useState(false);
|
|
const [detailLoading, setDetailLoading] = useState(false);
|
|
|
|
const [diskon, setDiskon] = useState("0");
|
|
const [pajak, setPajak] = useState("0");
|
|
const [metode, setMetode] = useState("CASH");
|
|
const [bayar, setBayar] = useState("0");
|
|
const [voucherInput, setVoucherInput] = useState("");
|
|
const [vouchers, setVouchers] = useState<
|
|
{ kode: string; saldo: number; amount: number }[]
|
|
>([]);
|
|
const [unitPiutang, setUnitPiutang] = useState("");
|
|
const [defaults, setDefaults] = useState({
|
|
diskon: 0,
|
|
pajak: 0,
|
|
metode: "CASH",
|
|
});
|
|
const [defaultsLoaded, setDefaultsLoaded] = useState(false);
|
|
|
|
const metodeLabel = (value: string) => {
|
|
if (value === "CASH") return "TUNAI";
|
|
if (value === "VOUCHER_CASH") return "VOUCHER + TUNAI";
|
|
return value;
|
|
};
|
|
|
|
const getAdminBase = () => {
|
|
const base =
|
|
document.querySelector('meta[name="app-base"]')?.getAttribute("content") ||
|
|
"";
|
|
return `${base}/admin`;
|
|
};
|
|
|
|
const loadLokasi = async () => {
|
|
const res = await apiGet<{ data: Lokasi[] }>("/admin-api/lokasi");
|
|
setLokasiList(res.data);
|
|
const def = res.data.find((l) => l.kode === "TOKO") || res.data[0] || null;
|
|
if (def) {
|
|
await loadStok(def.kode);
|
|
} else {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
const loadStok = async (kode: string) => {
|
|
setLoading(true);
|
|
setError(null);
|
|
const res = await apiGet<{ lokasi: Lokasi; data: StokRow[] }>(
|
|
`/admin-api/stok?kode=${encodeURIComponent(kode)}`
|
|
);
|
|
setLokasi(res.lokasi);
|
|
setRows(res.data);
|
|
setLoading(false);
|
|
};
|
|
|
|
const loadRecent = async () => {
|
|
setRecentLoading(true);
|
|
try {
|
|
const res = await apiGet<{ data: RecentRow[] }>(
|
|
"/admin-api/transaksi?limit=20"
|
|
);
|
|
setRecent(res.data);
|
|
} catch (e: any) {
|
|
setError(e?.message || "Gagal memuat transaksi");
|
|
} finally {
|
|
setRecentLoading(false);
|
|
}
|
|
};
|
|
|
|
const loadDefaults = async () => {
|
|
try {
|
|
const res = await apiGet<{ data: any }>("/admin-api/pengaturan");
|
|
const d = res.data?.transaksi || {};
|
|
const next = {
|
|
diskon: Number(d.diskon_default ?? 0),
|
|
pajak: Number(d.pajak_default ?? 0),
|
|
metode: d.metode_default || "CASH",
|
|
};
|
|
setDefaults(next);
|
|
setDiskon(String(next.diskon));
|
|
setPajak(String(next.pajak));
|
|
setMetode(next.metode);
|
|
setDefaultsLoaded(true);
|
|
} catch {
|
|
setDefaultsLoaded(true);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
let mounted = true;
|
|
setLoading(true);
|
|
setError(null);
|
|
loadLokasi().catch((e) => mounted && setError(e?.message || "Gagal memuat"));
|
|
loadRecent().catch(() => {});
|
|
loadDefaults().catch(() => {});
|
|
return () => {
|
|
mounted = false;
|
|
};
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
if (!detailOpen) {
|
|
requestAnimationFrame(() => barcodeRef.current?.focus());
|
|
}
|
|
}, [detailOpen]);
|
|
|
|
const filtered = useMemo(() => {
|
|
const s = q.trim().toLowerCase();
|
|
if (!s) return rows;
|
|
return rows.filter((r) =>
|
|
[r.nama, r.barcode, r.sku || ""].some((v) => v.toLowerCase().includes(s))
|
|
);
|
|
}, [rows, q]);
|
|
|
|
const subtotal = useMemo(() => {
|
|
return cart.reduce((sum, i) => sum + i.harga * i.qty, 0);
|
|
}, [cart]);
|
|
|
|
const pajakAmount = useMemo(() => {
|
|
const percent = Number(pajak) || 0;
|
|
return Math.max(0, Math.round(subtotal * (percent / 100)));
|
|
}, [subtotal, pajak]);
|
|
|
|
const total = useMemo(() => {
|
|
const d = Number(diskon) || 0;
|
|
return Math.max(0, subtotal - d + pajakAmount);
|
|
}, [subtotal, diskon, pajakAmount]);
|
|
|
|
const voucherAmountNum = useMemo(() => {
|
|
return vouchers.reduce((sum, v) => sum + (Number(v.amount) || 0), 0);
|
|
}, [vouchers]);
|
|
|
|
const kembalian = useMemo(() => {
|
|
const b = Number(bayar) || 0;
|
|
if (metode === "VOUCHER_CASH") {
|
|
const remaining = Math.max(0, total - voucherAmountNum);
|
|
return Math.max(0, b - remaining);
|
|
}
|
|
if (metode === "VOUCHER") return 0;
|
|
return Math.max(0, b - total);
|
|
}, [bayar, total, metode, voucherAmountNum]);
|
|
|
|
const sisaBayarVoucher = useMemo(() => {
|
|
if (metode === "VOUCHER" || metode === "VOUCHER_CASH") {
|
|
return Math.max(0, total - voucherAmountNum);
|
|
}
|
|
return 0;
|
|
}, [metode, total, voucherAmountNum]);
|
|
|
|
const sisaPiutang = useMemo(() => {
|
|
if (metode !== "PIUTANG") return 0;
|
|
const b = Number(bayar) || 0;
|
|
return Math.max(0, total - b);
|
|
}, [metode, bayar, total]);
|
|
|
|
const detailVoucherUsed = detail
|
|
? Number(detail.voucher_amount || (detail.voucher_kode ? detail.total : 0))
|
|
: 0;
|
|
const detailBayarLabel = detail
|
|
? detailVoucherUsed > 0
|
|
? "Bayar Tunai"
|
|
: `Bayar (${metodeLabel(detail.metode_pembayaran)})`
|
|
: "Bayar";
|
|
|
|
useEffect(() => {
|
|
if (metode !== "VOUCHER" && metode !== "VOUCHER_CASH") {
|
|
setVouchers([]);
|
|
setVoucherInput("");
|
|
}
|
|
}, [metode]);
|
|
|
|
useEffect(() => {
|
|
if (metode !== "PIUTANG") {
|
|
setUnitPiutang("");
|
|
}
|
|
}, [metode]);
|
|
|
|
useEffect(() => {
|
|
if (metode === "VOUCHER" || metode === "VOUCHER_CASH") {
|
|
requestAnimationFrame(() => {
|
|
voucherRef.current?.focus();
|
|
voucherRef.current?.select();
|
|
});
|
|
}
|
|
}, [metode]);
|
|
|
|
useEffect(() => {
|
|
if (
|
|
vouchers.length > 0 &&
|
|
(metode === "VOUCHER" || metode === "VOUCHER_CASH")
|
|
) {
|
|
recalcVoucherPayment(vouchers);
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [total]);
|
|
|
|
const addToCart = (p: StokRow, qtyAdd = 1) => {
|
|
setError(null);
|
|
setMsg(null);
|
|
setCart((prev) => {
|
|
const existing = prev.find((i) => i.produk_id === p.id);
|
|
const currentQty = existing?.qty ?? 0;
|
|
const nextQty = currentQty + qtyAdd;
|
|
if (nextQty > p.stok) {
|
|
setError(`Stok tidak cukup untuk ${p.nama}. Stok: ${p.stok}`);
|
|
return prev;
|
|
}
|
|
if (existing) {
|
|
return prev.map((i) =>
|
|
i.produk_id === p.id ? { ...i, qty: nextQty } : i
|
|
);
|
|
}
|
|
return [
|
|
...prev,
|
|
{
|
|
produk_id: p.id,
|
|
nama: p.nama,
|
|
barcode: p.barcode,
|
|
harga: p.harga_jual,
|
|
qty: qtyAdd,
|
|
stok: p.stok,
|
|
},
|
|
];
|
|
});
|
|
};
|
|
|
|
const updateQty = (produkId: number, qty: number) => {
|
|
setCart((prev) =>
|
|
prev.map((i) => {
|
|
if (i.produk_id !== produkId) return i;
|
|
const clamped = Math.max(1, Math.min(qty, i.stok));
|
|
return { ...i, qty: clamped };
|
|
})
|
|
);
|
|
};
|
|
|
|
const updateHarga = (produkId: number, harga: number) => {
|
|
setCart((prev) =>
|
|
prev.map((i) =>
|
|
i.produk_id === produkId ? { ...i, harga: Math.max(0, harga) } : i
|
|
)
|
|
);
|
|
};
|
|
|
|
const removeItem = (produkId: number) => {
|
|
setCart((prev) => prev.filter((i) => i.produk_id !== produkId));
|
|
};
|
|
|
|
const recalcVoucherPayment = (
|
|
nextVouchers: { kode: string; saldo: number; amount: number }[],
|
|
forceCash = true
|
|
) => {
|
|
const voucherTotal = nextVouchers.reduce(
|
|
(sum, v) => sum + (Number(v.amount) || 0),
|
|
0
|
|
);
|
|
const remaining = Math.max(0, total - voucherTotal);
|
|
if (voucherTotal >= total) {
|
|
setMetode("VOUCHER");
|
|
setBayar("0");
|
|
} else {
|
|
setMetode("VOUCHER_CASH");
|
|
if (forceCash) setBayar(String(remaining));
|
|
}
|
|
};
|
|
|
|
const addVoucher = async (code: string) => {
|
|
const kode = code.trim();
|
|
if (!kode) return;
|
|
if (vouchers.length >= 3) {
|
|
setError("Maksimal 3 voucher per transaksi.");
|
|
return;
|
|
}
|
|
if (vouchers.some((v) => v.kode === kode)) {
|
|
setError("Voucher sudah ditambahkan.");
|
|
return;
|
|
}
|
|
const remaining = Math.max(0, total - voucherAmountNum);
|
|
if (remaining <= 0) {
|
|
setError("Total sudah tertutup oleh voucher.");
|
|
return;
|
|
}
|
|
try {
|
|
const res = await apiGet<{ data: { saldo: number; aktif: boolean } }>(
|
|
`/admin-api/vouchers/lookup?kode=${encodeURIComponent(kode)}`
|
|
);
|
|
const saldo = Number(res?.data?.saldo || 0);
|
|
const aktif = Boolean(res?.data?.aktif);
|
|
if (!aktif) {
|
|
setError("Voucher tidak aktif.");
|
|
return;
|
|
}
|
|
if (saldo <= 0) {
|
|
setError("Saldo voucher tidak mencukupi.");
|
|
return;
|
|
}
|
|
const amount = Math.min(saldo, remaining);
|
|
const next = [...vouchers, { kode, saldo, amount }];
|
|
setVouchers(next);
|
|
setVoucherInput("");
|
|
setMsg("Voucher ditambahkan.");
|
|
recalcVoucherPayment(next, true);
|
|
} catch (e: any) {
|
|
setError(e?.message || "Voucher tidak ditemukan.");
|
|
}
|
|
};
|
|
|
|
const removeVoucher = (kode: string) => {
|
|
const next = vouchers.filter((v) => v.kode !== kode);
|
|
setVouchers(next);
|
|
recalcVoucherPayment(next, true);
|
|
};
|
|
|
|
const handleScan = (value: string) => {
|
|
const s = value.trim();
|
|
if (!s) return;
|
|
const hit =
|
|
rows.find((r) => r.barcode === s) ||
|
|
rows.find((r) => r.sku === s) ||
|
|
rows.find((r) => r.nama.toLowerCase() === s.toLowerCase());
|
|
if (!hit) {
|
|
setError(`Produk dengan barcode/SKU "${s}" tidak ditemukan.`);
|
|
return;
|
|
}
|
|
addToCart(hit, 1);
|
|
};
|
|
|
|
const submitBarcode = (value: string) => {
|
|
if (scanInputTimeoutRef.current) {
|
|
window.clearTimeout(scanInputTimeoutRef.current);
|
|
scanInputTimeoutRef.current = null;
|
|
}
|
|
handleScan(value);
|
|
setBarcode("");
|
|
requestAnimationFrame(() => barcodeRef.current?.focus());
|
|
};
|
|
|
|
const MIN_SCAN_LEN = 3;
|
|
const SCAN_IDLE_MS = 350;
|
|
|
|
useEffect(() => {
|
|
if ("BroadcastChannel" in window) {
|
|
displayChannelRef.current = new BroadcastChannel("pos-customer-display");
|
|
}
|
|
const handler = (event: KeyboardEvent) => {
|
|
const target = event.target as HTMLElement | null;
|
|
const tag = target?.tagName?.toLowerCase();
|
|
const isInput =
|
|
tag === "input" ||
|
|
tag === "textarea" ||
|
|
tag === "select" ||
|
|
target?.isContentEditable;
|
|
if (isInput) return;
|
|
|
|
if (event.key === "Enter") {
|
|
if (scanBufferRef.current) {
|
|
event.preventDefault();
|
|
submitBarcode(scanBufferRef.current);
|
|
scanBufferRef.current = "";
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (event.key.length !== 1) return;
|
|
scanBufferRef.current += event.key;
|
|
|
|
if (scanTimeoutRef.current) {
|
|
window.clearTimeout(scanTimeoutRef.current);
|
|
}
|
|
scanTimeoutRef.current = window.setTimeout(() => {
|
|
const value = scanBufferRef.current;
|
|
scanBufferRef.current = "";
|
|
scanTimeoutRef.current = null;
|
|
if (value.trim().length >= MIN_SCAN_LEN) {
|
|
submitBarcode(value);
|
|
}
|
|
}, SCAN_IDLE_MS);
|
|
};
|
|
|
|
window.addEventListener("keydown", handler);
|
|
return () => {
|
|
window.removeEventListener("keydown", handler);
|
|
if (scanTimeoutRef.current) {
|
|
window.clearTimeout(scanTimeoutRef.current);
|
|
}
|
|
if (scanInputTimeoutRef.current) {
|
|
window.clearTimeout(scanInputTimeoutRef.current);
|
|
}
|
|
displayChannelRef.current?.close();
|
|
};
|
|
}, [submitBarcode]);
|
|
|
|
useEffect(() => {
|
|
const empty = cart.length === 0;
|
|
const payload = {
|
|
waktu: new Date().toISOString(),
|
|
lokasi: lokasi?.nama || null,
|
|
items: cart.map((i) => ({
|
|
nama: i.nama,
|
|
qty: i.qty,
|
|
harga: i.harga,
|
|
total: i.harga * i.qty,
|
|
})),
|
|
subtotal: empty ? 0 : subtotal,
|
|
diskon: empty ? 0 : Number(diskon) || 0,
|
|
pajak: empty ? 0 : pajakAmount,
|
|
total: empty ? 0 : total,
|
|
bayar: empty ? 0 : Number(bayar) || 0,
|
|
kembalian: empty ? 0 : kembalian,
|
|
metode,
|
|
};
|
|
|
|
try {
|
|
localStorage.setItem("pos-display-state", JSON.stringify(payload));
|
|
} catch {}
|
|
displayChannelRef.current?.postMessage(payload);
|
|
}, [cart, subtotal, diskon, pajakAmount, total, bayar, kembalian, metode, lokasi]);
|
|
|
|
const submit = async () => {
|
|
if (!lokasi) return setError("Lokasi belum dipilih.");
|
|
if (cart.length === 0) return setError("Keranjang masih kosong.");
|
|
const voucherRequired = metode === "VOUCHER" || metode === "VOUCHER_CASH";
|
|
const voucherNum = voucherAmountNum;
|
|
const bayarNum = Number(bayar) || 0;
|
|
if (voucherRequired && vouchers.length === 0) {
|
|
return setError("Tambahkan minimal 1 voucher.");
|
|
}
|
|
if (vouchers.length > 3) {
|
|
return setError("Maksimal 3 voucher per transaksi.");
|
|
}
|
|
if (voucherRequired && voucherNum <= 0) {
|
|
return setError("Nominal voucher wajib diisi.");
|
|
}
|
|
if (voucherNum > total) {
|
|
return setError("Nominal voucher tidak boleh melebihi total.");
|
|
}
|
|
if (metode === "VOUCHER" && voucherNum < total) {
|
|
return setError("Saldo voucher tidak mencukupi untuk menutup total.");
|
|
}
|
|
if (metode === "VOUCHER_CASH") {
|
|
const remaining = Math.max(0, total - voucherNum);
|
|
if (bayarNum < remaining) {
|
|
return setError("Bayar tunai harus sama atau lebih besar dari sisa.");
|
|
}
|
|
}
|
|
if (metode === "PIUTANG" && !unitPiutang.trim()) {
|
|
return setError("Unit piutang wajib diisi.");
|
|
}
|
|
|
|
setSaving(true);
|
|
setError(null);
|
|
setMsg(null);
|
|
try {
|
|
const voucherAmountValue =
|
|
metode === "VOUCHER"
|
|
? total
|
|
: metode === "VOUCHER_CASH"
|
|
? voucherNum
|
|
: 0;
|
|
const bayarValue = metode === "VOUCHER" ? 0 : bayarNum;
|
|
const res = await apiPost<{ data?: { id?: number } }>(
|
|
"/admin-api/transaksi",
|
|
{
|
|
lokasi_id: lokasi.id,
|
|
items: cart.map((i) => ({
|
|
produk_id: i.produk_id,
|
|
qty: i.qty,
|
|
harga: i.harga,
|
|
})),
|
|
diskon: Number(diskon) || 0,
|
|
pajak: pajakAmount,
|
|
metode_pembayaran: metode,
|
|
jumlah_bayar: bayarValue,
|
|
voucher_kode: vouchers[0]?.kode || null,
|
|
voucher_amount: voucherAmountValue,
|
|
vouchers: vouchers.map((v) => ({ kode: v.kode, amount: v.amount })),
|
|
unit_piutang: unitPiutang || null,
|
|
}
|
|
);
|
|
|
|
setMsg("Transaksi berhasil disimpan.");
|
|
setCart([]);
|
|
setBayar("0");
|
|
setVoucherInput("");
|
|
setVouchers([]);
|
|
setUnitPiutang("");
|
|
if (defaultsLoaded) {
|
|
setDiskon(String(defaults.diskon));
|
|
setPajak(String(defaults.pajak));
|
|
setMetode(defaults.metode);
|
|
}
|
|
const savedId = res?.data?.id;
|
|
if (savedId) {
|
|
printTransaksi(savedId);
|
|
}
|
|
await loadStok(lokasi.kode);
|
|
await loadRecent();
|
|
} catch (e: any) {
|
|
setError(e?.message || "Gagal menyimpan transaksi");
|
|
} finally {
|
|
setSaving(false);
|
|
}
|
|
};
|
|
|
|
const printTransaksi = async (id: number) => {
|
|
try {
|
|
const [resTrx, resSet] = await Promise.all([
|
|
apiGet<{ data: TransaksiDetail }>(`/admin-api/transaksi/${id}`),
|
|
apiGet<{ data: any }>("/admin-api/pengaturan"),
|
|
]);
|
|
const d = resTrx.data;
|
|
const toko = resSet?.data?.toko || {};
|
|
const struk = resSet?.data?.struk || {};
|
|
const storeName = toko?.nama || "Toko";
|
|
const storeAddress = toko?.alamat || "";
|
|
const storePhone = toko?.telepon || "";
|
|
const storeLogo = toko?.logo || "";
|
|
const footer = struk?.footer || "Terima kasih telah berbelanja.";
|
|
const voucherUsed = Number(
|
|
d.voucher_amount || (d.voucher_kode ? d.total : 0)
|
|
);
|
|
const bayarLabel =
|
|
voucherUsed > 0
|
|
? "Bayar Tunai"
|
|
: `Bayar (${metodeLabel(d.metode_pembayaran)})`;
|
|
const win = window.open("", "_blank", "width=520,height=640");
|
|
if (!win) {
|
|
setError("Popup diblokir. Izinkan popup untuk mencetak.");
|
|
return;
|
|
}
|
|
const html = `
|
|
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>Struk ${d.nomor_penjualan}</title>
|
|
<style>
|
|
@page { margin: 6mm; }
|
|
body { font-family: "Courier New", monospace; padding: 0; color: #111; }
|
|
.receipt { width: 58mm; }
|
|
h1 { font-size: 13px; margin: 0 0 4px; text-align: center; }
|
|
.muted { color: #666; font-size: 10px; text-align: center; }
|
|
.center { text-align: center; }
|
|
.logo { display: block; margin: 0 auto 6px; max-height: 48px; max-width: 90px; object-fit: contain; }
|
|
.divider { border-top: 1px dashed #666; margin: 6px 0; }
|
|
.row { display: flex; justify-content: space-between; font-size: 11px; }
|
|
.item-name { font-size: 11px; margin: 4px 0 2px; }
|
|
.item-sub { display: flex; justify-content: space-between; font-size: 10px; color: #333; }
|
|
.total { font-weight: bold; }
|
|
.footer { font-size: 10px; text-align: center; margin-top: 6px; color: #666; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="receipt">
|
|
${storeLogo ? `<img src="${storeLogo}" class="logo" alt="Logo">` : ""}
|
|
<h1>${storeName}</h1>
|
|
${storeAddress ? `<div class="muted">${storeAddress}</div>` : ""}
|
|
${storePhone ? `<div class="muted">Telp: ${storePhone}</div>` : ""}
|
|
<div class="divider"></div>
|
|
<div class="center muted">No: ${d.nomor_penjualan}</div>
|
|
<div class="center muted">${new Date(d.waktu).toLocaleString("id-ID")}</div>
|
|
<div class="divider"></div>
|
|
|
|
${d.items
|
|
.map(
|
|
(i) => `
|
|
<div class="item-name">${i.nama || "-"}</div>
|
|
<div class="item-sub">
|
|
<div>${i.jumlah} x ${i.harga.toLocaleString("id-ID")}</div>
|
|
<div>Rp ${i.total.toLocaleString("id-ID")}</div>
|
|
</div>`
|
|
)
|
|
.join("")}
|
|
|
|
<div class="divider"></div>
|
|
<div class="row"><div>Subtotal</div><div>Rp ${d.subtotal.toLocaleString("id-ID")}</div></div>
|
|
<div class="row"><div>Diskon</div><div>Rp ${d.diskon.toLocaleString("id-ID")}</div></div>
|
|
<div class="row"><div>Pajak</div><div>Rp ${d.pajak.toLocaleString("id-ID")}</div></div>
|
|
${voucherUsed > 0 ? `<div class="row"><div>Voucher</div><div>Rp ${voucherUsed.toLocaleString("id-ID")}</div></div>` : ""}
|
|
<div class="row total"><div>Total</div><div>Rp ${d.total.toLocaleString("id-ID")}</div></div>
|
|
<div class="row"><div>${bayarLabel}</div><div>Rp ${d.jumlah_bayar.toLocaleString("id-ID")}</div></div>
|
|
<div class="row"><div>Kembalian</div><div>Rp ${d.kembalian.toLocaleString("id-ID")}</div></div>
|
|
<div class="divider"></div>
|
|
<div class="footer">${footer}</div>
|
|
</div>
|
|
<script>
|
|
window.print();
|
|
</script>
|
|
</body>
|
|
</html>`;
|
|
win.document.open();
|
|
win.document.write(html);
|
|
win.document.close();
|
|
} catch (e: any) {
|
|
setError(e?.message || "Gagal mencetak transaksi");
|
|
}
|
|
};
|
|
|
|
const openDetail = async (id: number) => {
|
|
setDetailLoading(true);
|
|
setDetailOpen(true);
|
|
try {
|
|
const res = await apiGet<{ data: TransaksiDetail }>(
|
|
`/admin-api/transaksi/${id}`
|
|
);
|
|
setDetail(res.data);
|
|
} catch (e: any) {
|
|
setError(e?.message || "Gagal memuat detail transaksi");
|
|
setDetailOpen(false);
|
|
} finally {
|
|
setDetailLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<PageMeta title="Transaksi" description="Transaksi penjualan" />
|
|
<div className="space-y-4">
|
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
<h1 className="text-2xl font-semibold text-gray-800 dark:text-white/90">
|
|
Transaksi
|
|
</h1>
|
|
<div className="flex w-full flex-col gap-2 sm:w-auto sm:flex-row">
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
const url = `${getAdminBase()}/customer-display`;
|
|
window.open(url, "_blank", "noopener,noreferrer");
|
|
}}
|
|
className="h-10 rounded-xl border border-gray-200 bg-white px-4 text-sm font-semibold hover:bg-gray-50 dark:border-gray-800 dark:bg-gray-900"
|
|
>
|
|
Buka Layar Pembeli
|
|
</button>
|
|
<select
|
|
value={lokasi?.id || ""}
|
|
onChange={(e) => {
|
|
const id = Number(e.target.value);
|
|
const pick = lokasiList.find((l) => l.id === id) || null;
|
|
if (pick) loadStok(pick.kode);
|
|
}}
|
|
className="h-10 rounded-xl border border-gray-200 bg-white px-3 text-sm dark:border-gray-800 dark:bg-gray-900"
|
|
>
|
|
{lokasiList.map((l) => (
|
|
<option key={l.id} value={l.id}>
|
|
{l.nama} ({l.kode})
|
|
</option>
|
|
))}
|
|
</select>
|
|
<input
|
|
value={q}
|
|
onChange={(e) => setQ(e.target.value)}
|
|
placeholder="Cari nama / barcode / SKU"
|
|
className="h-10 w-full sm:w-[280px] rounded-xl border border-gray-200 bg-white px-4 text-sm outline-none focus:ring-2 focus:ring-blue-500/30 dark:border-gray-800 dark:bg-gray-900"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{msg && (
|
|
<div className="rounded-xl bg-emerald-50 px-4 py-3 text-sm text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-300">
|
|
{msg}
|
|
</div>
|
|
)}
|
|
{error && (
|
|
<div className="rounded-xl bg-red-50 px-4 py-3 text-sm text-red-700 dark:bg-red-500/10 dark:text-red-300">
|
|
{error}
|
|
</div>
|
|
)}
|
|
|
|
<div className="grid gap-4 lg:grid-cols-2">
|
|
<div className="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
|
<div className="flex items-center justify-between gap-3">
|
|
<div className="text-sm font-semibold text-gray-800 dark:text-white/90">
|
|
Daftar Produk
|
|
</div>
|
|
<input
|
|
ref={barcodeRef}
|
|
autoFocus
|
|
value={barcode}
|
|
onChange={(e) => {
|
|
const next = e.target.value;
|
|
setBarcode(next);
|
|
if (scanInputTimeoutRef.current) {
|
|
window.clearTimeout(scanInputTimeoutRef.current);
|
|
}
|
|
if (next.trim().length < MIN_SCAN_LEN) return;
|
|
scanInputTimeoutRef.current = window.setTimeout(() => {
|
|
submitBarcode(next);
|
|
}, SCAN_IDLE_MS);
|
|
}}
|
|
onKeyDown={(e) => {
|
|
if (e.key === "Enter") {
|
|
e.preventDefault();
|
|
submitBarcode(barcode);
|
|
}
|
|
}}
|
|
placeholder="Scan barcode lalu Enter"
|
|
className="h-10 w-full sm:w-[220px] rounded-xl border border-gray-200 bg-white px-4 text-sm dark:border-gray-800 dark:bg-gray-950"
|
|
/>
|
|
</div>
|
|
|
|
{loading ? (
|
|
<div className="mt-4 text-sm text-gray-600 dark:text-gray-400">
|
|
Memuat
|
|
</div>
|
|
) : (
|
|
<div className="mt-4 max-h-[420px] overflow-auto">
|
|
<table className="min-w-full text-sm">
|
|
<thead>
|
|
<tr className="text-left text-gray-500 dark:text-gray-400">
|
|
<th className="py-2 pr-3">Nama</th>
|
|
<th className="py-2 pr-3">Barcode</th>
|
|
<th className="py-2 pr-3">Stok</th>
|
|
<th className="py-2 pr-3">Harga</th>
|
|
<th className="py-2 pr-3">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{filtered.map((r) => (
|
|
<tr
|
|
key={r.id}
|
|
className="border-t border-gray-100 dark:border-gray-800"
|
|
>
|
|
<td className="py-2 pr-3 text-gray-800 dark:text-white/90">
|
|
{r.nama}
|
|
</td>
|
|
<td className="py-2 pr-3 text-gray-500 dark:text-gray-400">
|
|
{r.barcode}
|
|
</td>
|
|
<td className="py-2 pr-3">
|
|
<span
|
|
className={`inline-flex rounded-full px-3 py-1 text-xs font-semibold ${
|
|
r.stok <= 0
|
|
? "bg-red-50 text-red-700 dark:bg-red-500/10 dark:text-red-300"
|
|
: "bg-emerald-50 text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-300"
|
|
}`}
|
|
>
|
|
{r.stok}
|
|
</span>
|
|
</td>
|
|
<td className="py-2 pr-3 text-gray-700 dark:text-gray-200">
|
|
Rp {Number(r.harga_jual || 0).toLocaleString("id-ID")}
|
|
</td>
|
|
<td className="py-2 pr-3">
|
|
<button
|
|
type="button"
|
|
onClick={() => addToCart(r, 1)}
|
|
className="h-8 rounded-lg border border-gray-200 bg-white px-3 text-xs font-semibold hover:bg-gray-50 dark:border-gray-800 dark:bg-gray-950"
|
|
>
|
|
Tambah
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
{filtered.length === 0 && (
|
|
<tr>
|
|
<td
|
|
colSpan={5}
|
|
className="py-6 text-center text-gray-500 dark:text-gray-400"
|
|
>
|
|
Tidak ada data.
|
|
</td>
|
|
</tr>
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
|
<div className="text-sm font-semibold text-gray-800 dark:text-white/90">
|
|
Keranjang
|
|
</div>
|
|
|
|
{cart.length === 0 ? (
|
|
<div className="mt-4 text-sm text-gray-500 dark:text-gray-400">
|
|
Keranjang masih kosong.
|
|
</div>
|
|
) : (
|
|
<div className="mt-4 space-y-3">
|
|
{cart.map((i) => (
|
|
<div
|
|
key={i.produk_id}
|
|
className="rounded-xl border border-gray-200 p-3 dark:border-gray-800"
|
|
>
|
|
<div className="flex items-start justify-between gap-2">
|
|
<div>
|
|
<div className="text-sm font-semibold text-gray-800 dark:text-white/90">
|
|
{i.nama}
|
|
</div>
|
|
<div className="text-xs text-gray-500 dark:text-gray-400">
|
|
{i.barcode}
|
|
</div>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={() => removeItem(i.produk_id)}
|
|
className="text-xs text-red-600 hover:underline"
|
|
>
|
|
Hapus
|
|
</button>
|
|
</div>
|
|
|
|
<div className="mt-3 grid grid-cols-3 gap-2">
|
|
<input
|
|
value={i.qty}
|
|
onChange={(e) =>
|
|
updateQty(i.produk_id, Number(e.target.value))
|
|
}
|
|
type="number"
|
|
min={1}
|
|
max={i.stok}
|
|
className="h-10 rounded-lg border border-gray-200 bg-white px-3 text-sm dark:border-gray-800 dark:bg-gray-950"
|
|
/>
|
|
<input
|
|
value={i.harga}
|
|
onChange={(e) =>
|
|
updateHarga(i.produk_id, Number(e.target.value))
|
|
}
|
|
type="number"
|
|
min={0}
|
|
className="h-10 rounded-lg border border-gray-200 bg-white px-3 text-sm dark:border-gray-800 dark:bg-gray-950"
|
|
/>
|
|
<div className="flex items-center justify-end text-sm font-semibold text-gray-800 dark:text-white/90">
|
|
Rp {(i.harga * i.qty).toLocaleString("id-ID")}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
<div className="mt-4 grid gap-2 sm:grid-cols-2">
|
|
<div className="rounded-xl border border-gray-200 p-3 text-sm dark:border-gray-800">
|
|
<div className="flex justify-between">
|
|
<span>Subtotal</span>
|
|
<span className="font-semibold">
|
|
Rp {subtotal.toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
<div className="mt-2 flex items-center justify-between gap-2">
|
|
<label className="text-xs text-gray-500">Diskon</label>
|
|
<input
|
|
value={diskon}
|
|
onChange={(e) => setDiskon(e.target.value)}
|
|
type="number"
|
|
min={0}
|
|
className="h-9 w-[140px] rounded-lg border border-gray-200 bg-white px-3 text-xs dark:border-gray-800 dark:bg-gray-950"
|
|
/>
|
|
</div>
|
|
<div className="mt-2 flex items-center justify-between gap-2">
|
|
<label className="text-xs text-gray-500">Pajak (%)</label>
|
|
<input
|
|
value={pajak}
|
|
onChange={(e) => setPajak(e.target.value)}
|
|
type="number"
|
|
min={0}
|
|
className="h-9 w-[140px] rounded-lg border border-gray-200 bg-white px-3 text-xs dark:border-gray-800 dark:bg-gray-950"
|
|
/>
|
|
</div>
|
|
<div className="mt-3 flex justify-between">
|
|
<span>Total</span>
|
|
<span className="font-semibold">
|
|
Rp {total.toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="rounded-xl border border-gray-200 p-3 text-sm dark:border-gray-800">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<label className="text-xs text-gray-500">Metode</label>
|
|
<select
|
|
value={metode}
|
|
onChange={(e) => setMetode(e.target.value)}
|
|
className="h-9 w-[140px] rounded-lg border border-gray-200 bg-white px-3 text-xs dark:border-gray-800 dark:bg-gray-950"
|
|
>
|
|
<option value="CASH">TUNAI</option>
|
|
<option value="QRIS">QRIS</option>
|
|
<option value="PIUTANG">PIUTANG</option>
|
|
<option value="VOUCHER">VOUCHER</option>
|
|
<option value="VOUCHER_CASH">VOUCHER + TUNAI</option>
|
|
</select>
|
|
</div>
|
|
<div className="mt-2 flex items-center justify-between gap-2">
|
|
<label className="text-xs text-gray-500">Bayar</label>
|
|
<input
|
|
value={bayar}
|
|
onChange={(e) => setBayar(e.target.value)}
|
|
type="number"
|
|
min={0}
|
|
disabled={metode === "VOUCHER"}
|
|
className="h-9 w-[140px] rounded-lg border border-gray-200 bg-white px-3 text-xs dark:border-gray-800 dark:bg-gray-950"
|
|
/>
|
|
</div>
|
|
{(metode === "VOUCHER" || metode === "VOUCHER_CASH") && (
|
|
<div className="mt-2 space-y-2">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<label className="text-xs text-gray-500">Voucher</label>
|
|
<div className="flex w-[140px] gap-1">
|
|
<input
|
|
ref={voucherRef}
|
|
value={voucherInput}
|
|
onChange={(e) => setVoucherInput(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === "Enter") {
|
|
e.preventDefault();
|
|
addVoucher(voucherInput);
|
|
}
|
|
}}
|
|
placeholder="Kode"
|
|
className="h-9 w-full rounded-lg border border-gray-200 bg-white px-2 text-xs dark:border-gray-800 dark:bg-gray-950"
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() => addVoucher(voucherInput)}
|
|
className="h-9 rounded-lg border border-gray-200 bg-white px-2 text-[10px] font-semibold hover:bg-gray-50 dark:border-gray-800 dark:bg-gray-950"
|
|
>
|
|
+
|
|
</button>
|
|
</div>
|
|
</div>
|
|
{vouchers.length > 0 && (
|
|
<div className="space-y-1">
|
|
{vouchers.map((v) => (
|
|
<div
|
|
key={v.kode}
|
|
className="flex items-center justify-between text-[11px] text-gray-500"
|
|
>
|
|
<span className="truncate">{v.kode}</span>
|
|
<div className="flex items-center gap-2">
|
|
<span>
|
|
Rp {Number(v.amount).toLocaleString("id-ID")}
|
|
</span>
|
|
<button
|
|
type="button"
|
|
onClick={() => removeVoucher(v.kode)}
|
|
className="text-red-600 hover:underline"
|
|
>
|
|
Hapus
|
|
</button>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
<div className="flex items-center justify-between text-[11px] text-gray-500">
|
|
<span>Total voucher</span>
|
|
<span>Rp {voucherAmountNum.toLocaleString("id-ID")}</span>
|
|
</div>
|
|
<div className="flex items-center justify-between text-[11px] text-gray-500">
|
|
<span>Sisa bayar</span>
|
|
<span>Rp {sisaBayarVoucher.toLocaleString("id-ID")}</span>
|
|
</div>
|
|
</div>
|
|
)}
|
|
{metode === "PIUTANG" && (
|
|
<div className="mt-2 flex items-center justify-between gap-2">
|
|
<label className="text-xs text-gray-500">Unit Piutang</label>
|
|
<input
|
|
value={unitPiutang}
|
|
onChange={(e) => setUnitPiutang(e.target.value)}
|
|
placeholder="Contoh: Farmasi"
|
|
className="h-9 w-[140px] rounded-lg border border-gray-200 bg-white px-3 text-xs dark:border-gray-800 dark:bg-gray-950"
|
|
/>
|
|
</div>
|
|
)}
|
|
<div className="mt-3 flex justify-between">
|
|
<span>{metode === "PIUTANG" ? "Sisa Piutang" : "Kembalian"}</span>
|
|
<span className="font-semibold">
|
|
Rp {(metode === "PIUTANG" ? sisaPiutang : kembalian).toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="mt-4 flex items-center justify-end gap-2">
|
|
<button
|
|
type="button"
|
|
onClick={() => setCart([])}
|
|
className="h-11 rounded-xl border border-gray-200 bg-white px-5 text-sm font-semibold hover:bg-gray-50 dark:border-gray-800 dark:bg-gray-950"
|
|
>
|
|
Kosongkan
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={submit}
|
|
disabled={saving || cart.length === 0}
|
|
className="h-11 rounded-xl bg-blue-600 px-5 text-sm font-semibold text-white hover:bg-blue-700 disabled:opacity-60"
|
|
>
|
|
{saving ? "Menyimpan…" : "Simpan Transaksi"}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="rounded-2xl border border-gray-200 bg-white p-5 shadow-sm dark:border-gray-800 dark:bg-gray-900">
|
|
<div className="flex items-center justify-between">
|
|
<div className="text-sm font-semibold text-gray-800 dark:text-white/90">
|
|
Transaksi Terakhir
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={loadRecent}
|
|
className="h-8 rounded-lg border border-gray-200 bg-white px-3 text-xs font-semibold hover:bg-gray-50 dark:border-gray-800 dark:bg-gray-950"
|
|
>
|
|
Refresh
|
|
</button>
|
|
</div>
|
|
|
|
{recentLoading ? (
|
|
<div className="mt-4 text-sm text-gray-600 dark:text-gray-400">
|
|
Memuat...
|
|
</div>
|
|
) : (
|
|
<div className="mt-4 overflow-x-auto">
|
|
<table className="min-w-full text-sm">
|
|
<thead>
|
|
<tr className="text-left text-gray-500 dark:text-gray-400">
|
|
<th className="py-2 pr-4">Waktu</th>
|
|
<th className="py-2 pr-4">No</th>
|
|
<th className="py-2 pr-4">Item</th>
|
|
<th className="py-2 pr-4">Total</th>
|
|
<th className="py-2 pr-4">Metode</th>
|
|
<th className="py-2 pr-4">Aksi</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{recent.map((r) => (
|
|
<tr
|
|
key={r.id}
|
|
className="border-t border-gray-100 dark:border-gray-800"
|
|
>
|
|
<td className="py-2 pr-4 text-gray-500 dark:text-gray-400">
|
|
{new Date(r.waktu).toLocaleString("id-ID")}
|
|
</td>
|
|
<td className="py-2 pr-4 font-medium text-gray-800 dark:text-white/90">
|
|
{r.nomor_penjualan}
|
|
</td>
|
|
<td className="py-2 pr-4 text-gray-600 dark:text-gray-300">
|
|
{r.items_count}
|
|
</td>
|
|
<td className="py-2 pr-4 text-gray-700 dark:text-gray-200">
|
|
Rp {Number(r.total || 0).toLocaleString("id-ID")}
|
|
</td>
|
|
<td className="py-2 pr-4 text-gray-600 dark:text-gray-300">
|
|
{metodeLabel(r.metode_pembayaran)}
|
|
</td>
|
|
<td className="py-2 pr-4">
|
|
<button
|
|
type="button"
|
|
onClick={() => openDetail(r.id)}
|
|
className="mr-2 h-8 rounded-lg border border-gray-200 bg-white px-3 text-xs font-semibold hover:bg-gray-50 dark:border-gray-800 dark:bg-gray-950"
|
|
>
|
|
Detail
|
|
</button>
|
|
<button
|
|
type="button"
|
|
onClick={() => printTransaksi(r.id)}
|
|
className="h-8 rounded-lg border border-gray-200 bg-white px-3 text-xs font-semibold hover:bg-gray-50 dark:border-gray-800 dark:bg-gray-950"
|
|
>
|
|
Print
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
{recent.length === 0 && (
|
|
<tr>
|
|
<td
|
|
colSpan={6}
|
|
className="py-6 text-center text-gray-500 dark:text-gray-400"
|
|
>
|
|
Belum ada transaksi.
|
|
</td>
|
|
</tr>
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{detailOpen && (
|
|
<div className="fixed inset-0 z-[9999] flex items-center justify-center bg-black/40 p-4">
|
|
<div className="w-full max-w-2xl rounded-2xl border border-gray-200 bg-white p-5 shadow-xl dark:border-gray-800 dark:bg-gray-900">
|
|
<div className="flex items-start justify-between gap-4">
|
|
<div>
|
|
<div className="text-sm font-semibold text-gray-800 dark:text-white/90">
|
|
Detail Transaksi
|
|
</div>
|
|
{detail && (
|
|
<div className="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
|
{detail.nomor_penjualan} - {" "}
|
|
{new Date(detail.waktu).toLocaleString("id-ID")}
|
|
</div>
|
|
)}
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={() => setDetailOpen(false)}
|
|
className="h-9 rounded-xl border border-gray-200 bg-white px-3 text-xs font-semibold hover:bg-gray-50 dark:border-gray-800 dark:bg-gray-950"
|
|
>
|
|
Tutup
|
|
</button>
|
|
</div>
|
|
|
|
{detailLoading ? (
|
|
<div className="mt-4 text-sm text-gray-600 dark:text-gray-400">
|
|
Memuat detail...
|
|
</div>
|
|
) : detail ? (
|
|
<>
|
|
<div className="mt-4 overflow-x-auto">
|
|
<table className="min-w-full text-sm">
|
|
<thead>
|
|
<tr className="text-left text-gray-500 dark:text-gray-400">
|
|
<th className="py-2 pr-4">Item</th>
|
|
<th className="py-2 pr-4">Barcode</th>
|
|
<th className="py-2 pr-4">Qty</th>
|
|
<th className="py-2 pr-4">Harga</th>
|
|
<th className="py-2 pr-4">Total</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{detail.items.map((i, idx) => (
|
|
<tr
|
|
key={`${i.produk_id}-${idx}`}
|
|
className="border-t border-gray-100 dark:border-gray-800"
|
|
>
|
|
<td className="py-2 pr-4 text-gray-800 dark:text-white/90">
|
|
{i.nama || "-"}
|
|
</td>
|
|
<td className="py-2 pr-4 text-gray-500 dark:text-gray-400">
|
|
{i.barcode || "-"}
|
|
</td>
|
|
<td className="py-2 pr-4 text-gray-700 dark:text-gray-200">
|
|
{i.jumlah}
|
|
</td>
|
|
<td className="py-2 pr-4 text-gray-700 dark:text-gray-200">
|
|
Rp {i.harga.toLocaleString("id-ID")}
|
|
</td>
|
|
<td className="py-2 pr-4 text-gray-800 dark:text-white/90">
|
|
Rp {i.total.toLocaleString("id-ID")}
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div className="mt-4 grid gap-2 sm:grid-cols-2">
|
|
<div className="rounded-xl border border-gray-200 p-3 text-sm dark:border-gray-800">
|
|
<div className="flex justify-between">
|
|
<span>Subtotal</span>
|
|
<span className="font-semibold">
|
|
Rp {detail.subtotal.toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
<div className="mt-1 flex justify-between">
|
|
<span>Diskon</span>
|
|
<span className="font-semibold">
|
|
Rp {detail.diskon.toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
<div className="mt-1 flex justify-between">
|
|
<span>Pajak</span>
|
|
<span className="font-semibold">
|
|
Rp {detail.pajak.toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
{detailVoucherUsed > 0 && (
|
|
<div className="mt-1 flex justify-between">
|
|
<span>Voucher</span>
|
|
<span className="font-semibold">
|
|
Rp {detailVoucherUsed.toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="rounded-xl border border-gray-200 p-3 text-sm dark:border-gray-800">
|
|
<div className="flex justify-between">
|
|
<span>Total</span>
|
|
<span className="font-semibold">
|
|
Rp {detail.total.toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
<div className="mt-1 flex justify-between">
|
|
<span>{detailBayarLabel}</span>
|
|
<span className="font-semibold">
|
|
Rp {detail.jumlah_bayar.toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
<div className="mt-1 flex justify-between">
|
|
<span>Kembalian</span>
|
|
<span className="font-semibold">
|
|
Rp {detail.kembalian.toLocaleString("id-ID")}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|