Spaces:
Sleeping
Sleeping
Download src/domain.js from budijuarto/kriyatrack: direct link, hf CLI and curl.
- Browser
- Download file 3.02 kB
-
https://huggingface.co/spaces/budijuarto/kriyatrack/resolve/main/src/domain.js
- Command line
-
hf download hf://spaces/budijuarto/kriyatrack/src/domain.js
-
curl -L -o domain.js https://huggingface.co/spaces/budijuarto/kriyatrack/resolve/main/src/domain.js
3.02 kB
| export const STAGES = Object.freeze(['DP', 'Produksi', 'Pelunasan', 'Siap Kirim']); | |
| export const MAX_QUANTITY = 1000; | |
| export const MAX_UNIT_PRICE = 100_000_000; | |
| export const MAX_DEPOSIT = MAX_QUANTITY * MAX_UNIT_PRICE; | |
| const rupiah = new Intl.NumberFormat('id-ID', { maximumFractionDigits: 0 }); | |
| const timestamp = new Intl.DateTimeFormat('id-ID', { dateStyle: 'medium', timeStyle: 'short', timeZone: 'Asia/Jakarta' }); | |
| const limits = Object.freeze({ customer: 70, phone: 28, product: 85, spec: 350, address: 350 }); | |
| const labels = Object.freeze({ customer: 'nama pelanggan', phone: 'nomor kontak', product: 'nama produk', spec: 'spesifikasi custom', address: 'alamat pengiriman' }); | |
| export const money = value => Number.isFinite(value) ? `Rp ${rupiah.format(value)}` : '–'; | |
| export const stageName = stage => STAGES[stage] ?? '–'; | |
| export const dateLabel = value => typeof value === 'string' && value.includes('T') && Number.isFinite(Date.parse(value)) ? `${timestamp.format(new Date(value))} WIB` : value || '–'; | |
| export const total = order => order.quantity * order.price; | |
| export const received = order => order.settled ? total(order) : order.deposit; | |
| export const balance = order => total(order) - received(order); | |
| export function emptyDraft() { | |
| return { customer: '', phone: '', product: '', quantity: 1, price: null, deposit: 0, spec: '', address: '' }; | |
| } | |
| export function sampleDraft() { | |
| return { | |
| customer: 'Dara Rinjani', phone: '0800 0000 0031', product: 'Pouch nama custom', quantity: 2, price: 85_000, deposit: 75_000, | |
| spec: 'Kain hijau sage, bordir nama DARA, dan resleting krem.', address: 'Alamat demo · Bandung' | |
| }; | |
| } | |
| export function cleanDraft(draft) { | |
| return { | |
| ...Object.fromEntries(Object.keys(limits).map(field => [field, (draft[field] || '').trim()])), | |
| quantity: draft.quantity, price: draft.price, deposit: draft.deposit ?? 0 | |
| }; | |
| } | |
| export function validateDraft(draft) { | |
| const errors = []; | |
| for (const [field, limit] of Object.entries(limits)) { | |
| const value = typeof draft[field] === 'string' ? draft[field].trim() : ''; | |
| if (!value) errors.push(`Isi ${labels[field]}.`); | |
| else if (value.length > limit) errors.push(`${labels[field]} maksimal ${limit} karakter.`); | |
| } | |
| if (draft.phone?.trim() && (!/^\+?[\d ()-]+$/.test(draft.phone.trim()) || !/^\d{8,16}$/.test(draft.phone.replace(/\D/g, '')))) errors.push('Nomor kontak harus berisi 8–16 digit.'); | |
| if (!Number.isSafeInteger(draft.quantity) || draft.quantity < 1 || draft.quantity > MAX_QUANTITY) errors.push('Jumlah harus bilangan bulat 1–1.000 unit.'); | |
| if (!Number.isSafeInteger(draft.price) || draft.price < 1 || draft.price > MAX_UNIT_PRICE) errors.push('Harga satuan harus Rp1–Rp100.000.000 dalam rupiah bulat.'); | |
| if (!Number.isSafeInteger(draft.deposit) || draft.deposit < 0 || draft.deposit > MAX_DEPOSIT) errors.push('DP harus berupa rupiah bulat dan tidak boleh negatif.'); | |
| else if (draft.deposit > total(draft)) errors.push('DP melebihi total pesanan.'); | |
| return errors; | |
| } | |