/* portal/commerce/public/order-detail.js — 주문 상세: 상태·금액·입금 안내·다음 단계·취소 가능 단계·남는 서비스. 처리 중이면 주기 갱신. */ (() => { const el = document.getElementById('order'); const esc = aw.esc; const money = (n, c) => Number(n).toLocaleString('ko-KR') + (c === 'KRW' ? '원' : ' ' + c); async function load() { try { const { order: o } = await aw.api('GET', `/api/commerce/orders/${el.dataset.id}`); const pi = o.payment_instructions || {}; const kind = o.status === 'approved' ? 'done' : ['rejected', 'expired', 'cancelled'].includes(o.status) ? 'failed' : 'waiting'; el.innerHTML = `
${kind === 'done' ? '✔' : kind === 'failed' ? '✘' : '◔'} ${esc(o.statusLabel)}마지막 갱신 ${aw.fmt(o.updated_at)}

${esc(o.nextStep)}

${o.remaining ? `

${esc(o.remaining)}

` : ''}
주문 번호
${esc(o.order_no)}
종류
${esc({ new: '신규', renewal: '갱신', downsize: '축소' }[o.kind] || o.kind)}
금액
${money(o.amount, o.currency)} + 세금 ${money(o.tax, o.currency)} = ${money(o.total, o.currency)}
결제 방식
계좌 이체(수동 결제 확인)
${o.due_at ? `
입금 기한
${aw.fmt(o.due_at)}
` : ''}${o.paid_at ? `
입금 확인
${aw.fmt(o.paid_at)}
` : ''}${o.approved_at ? `
승인
${aw.fmt(o.approved_at)}
` : ''}
취소 가능 단계
${esc(o.lastCancellableStep)}
${o.status === 'awaiting_payment' ? `

입금 안내

${esc(pi.bank || '')} ${esc(pi.account || '')} (예금주 ${esc(pi.holder || '')})

${esc(pi.note || '')}

` : ''} ${o.items.map((i) => ``).join('')}
항목수량적용 대상단가세금합계
${esc(i.name)}${i.qty}${i.target_type === 'site' ? '사이트 ' + esc(i.target_id || '') : '사용자 그룹'}${money(i.unit_price, o.currency)}${money(i.tax, o.currency)}${money(i.amount + i.tax, o.currency)}
${o.policyNotes ? `

입금 기한 ${o.policyNotes.paymentDeadlineDays}일 · 미납 ${o.policyNotes.restrictionAfterUnpaidDays}일 후 ${esc(o.policyNotes.restrictionEffect || '')}

` : ''}
${o.status === 'approved' ? '영수증' : '청구서'} 보기${o.canCancel ? '' : ''}${['rejected', 'expired'].includes(o.status) ? '다시 주문문의' : ''}
`; const c = el.querySelector('#cancel'); if (c) c.onclick = async () => { if (!(await aw.confirmDanger({ title: '주문 취소', target: o.order_no, impacts: ['권리 변화 없음', '입금한 경우 운영자에게 환불을 문의하세요'], confirmLabel: '취소' }))) return; try { await aw.api('POST', `/api/commerce/orders/${o.id}/cancel`); load(); } catch (e) { aw.toast(e.message); } }; return kind === 'waiting'; } catch (e) { aw.state(el, e.status === 404 ? 'empty' : 'failed', e.message, { retry: load }); return false; } } aw.poll(load, 10000); })();