index.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <?php
  2. require __DIR__ . '/auth.php';
  3. $dbPath = __DIR__ . '/_private/pl.db';
  4. $hasData = file_exists($dbPath) && filesize($dbPath) > 0;
  5. ?>
  6. <!DOCTYPE html>
  7. <html lang="en">
  8. <head>
  9. <meta charset="UTF-8">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <title>P&amp;L Viewer — ICG Magnetics</title>
  12. <style>
  13. *{box-sizing:border-box;margin:0;padding:0}
  14. html,body{height:100%;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;font-size:13px;background:#f1f5f9;color:#1e293b}
  15. /* ─── Layout ─── */
  16. #app{display:flex;height:100vh;overflow:hidden}
  17. #sidebar{width:220px;min-width:220px;background:#1e293b;color:#e2e8f0;display:flex;flex-direction:column;overflow:hidden;flex-shrink:0}
  18. #main{flex:1;display:flex;flex-direction:column;min-width:0;overflow:hidden}
  19. /* ─── Sidebar header ─── */
  20. #sb-head{padding:14px 14px 10px;border-bottom:1px solid #334155;flex-shrink:0}
  21. #sb-head h1{font-size:14px;font-weight:700;color:#f8fafc;letter-spacing:-.2px;line-height:1.3}
  22. #sb-head .sub{font-size:10px;color:#64748b;margin-top:2px;letter-spacing:.2px;text-transform:uppercase}
  23. .upload-link{display:flex;align-items:center;gap:6px;margin-top:10px;padding:7px 10px;background:#3b82f6;color:white;border-radius:5px;text-decoration:none;font-size:12px;font-weight:600;justify-content:center}
  24. .upload-link:hover{background:#2563eb}
  25. /* ─── Quick-select ─── */
  26. #qsel{padding:10px 12px 8px;border-bottom:1px solid #334155;flex-shrink:0}
  27. #qsel .qlabel{font-size:9px;text-transform:uppercase;letter-spacing:.6px;color:#64748b;margin-bottom:6px}
  28. .qrow{display:flex;gap:4px;flex-wrap:wrap}
  29. .qb{flex:1;min-width:calc(50% - 2px);padding:5px 2px;background:#334155;border:none;border-radius:4px;color:#cbd5e1;font-size:11px;cursor:pointer;text-align:center;line-height:1.2}
  30. .qb:hover{background:#475569;color:#f1f5f9}
  31. /* ─── Year/month scroll ─── */
  32. #yr-scroll{flex:1;overflow-y:auto;padding:6px 0}
  33. #yr-scroll::-webkit-scrollbar{width:3px}
  34. #yr-scroll::-webkit-scrollbar-thumb{background:#334155;border-radius:2px}
  35. .yr-item{}
  36. .yr-row{display:flex;align-items:center;padding:5px 12px;cursor:pointer;user-select:none;gap:0}
  37. .yr-row:hover{background:#27374d}
  38. .yr-cb{margin-right:7px;accent-color:#3b82f6;cursor:pointer;flex-shrink:0}
  39. .yr-lbl{flex:1;font-size:12px;font-weight:600;color:#cbd5e1}
  40. .yr-arrow{font-size:9px;color:#64748b;transition:transform .15s;display:inline-block}
  41. .yr-arrow.open{transform:rotate(90deg)}
  42. .mo-list{display:none;padding:1px 0 4px 32px}
  43. .mo-list.open{display:block}
  44. .mo-row{display:flex;align-items:center;padding:3px 6px;cursor:pointer;border-radius:3px}
  45. .mo-row:hover{background:#27374d}
  46. .mo-cb{margin-right:7px;accent-color:#3b82f6;cursor:pointer}
  47. .mo-lbl{font-size:11px;color:#94a3b8;cursor:pointer}
  48. .mo-lbl.partial{color:#f59e0b}
  49. /* ─── Top bar ─── */
  50. #top-bar{background:white;border-bottom:1px solid #e2e8f0;padding:10px 18px;display:flex;align-items:center;gap:12px;flex-shrink:0;min-height:46px}
  51. #top-bar h2{font-size:14px;font-weight:700;color:#0f172a;white-space:nowrap}
  52. #sel-info{font-size:12px;color:#64748b}
  53. #total-wrap{margin-left:auto;display:flex;align-items:center;gap:5px;font-size:12px;color:#475569;white-space:nowrap}
  54. #total-wrap input{accent-color:#3b82f6}
  55. /* ─── Table container ─── */
  56. #tbl-wrap{flex:1;overflow:auto;padding:12px 16px}
  57. #tbl-wrap.loading{opacity:.4;pointer-events:none;transition:opacity .1s}
  58. #empty-state{text-align:center;padding:60px 20px;color:#94a3b8}
  59. #empty-state h3{font-size:16px;color:#64748b;margin-bottom:8px}
  60. #empty-state a{color:#3b82f6}
  61. /* ─── P&L Table ─── */
  62. table.plt{border-collapse:collapse;white-space:nowrap;font-size:12px;table-layout:fixed}
  63. /* Sticky header */
  64. table.plt thead th{
  65. background:#1e293b;color:#e2e8f0;font-weight:600;
  66. text-align:right;position:sticky;top:0;z-index:3;
  67. padding:7px 10px;border-bottom:2px solid #0f172a;
  68. font-size:11px;letter-spacing:.2px;
  69. width:100px;overflow:hidden
  70. }
  71. table.plt thead th.col-name{
  72. text-align:left;position:sticky;left:0;z-index:4;
  73. width:220px
  74. }
  75. /* Year-total column header */
  76. table.plt thead th.col-ytotal{
  77. background:#0f172a;border-left:3px solid #3b82f6;color:#93c5fd;font-style:italic
  78. }
  79. /* Sticky name column */
  80. table.plt td.col-name{
  81. position:sticky;left:0;z-index:1;
  82. overflow:hidden;text-overflow:ellipsis;
  83. padding:5px 8px
  84. }
  85. /* Value cells */
  86. table.plt td.val{text-align:right;padding:5px 10px;font-variant-numeric:tabular-nums}
  87. table.plt td.val.neg{color:#ef4444}
  88. table.plt td.val.zero{color:#cbd5e1}
  89. /* Year-total value cells */
  90. table.plt td.col-ytotal{
  91. border-left:3px solid #3b82f6;font-weight:700;
  92. background:#eff6ff!important
  93. }
  94. tr.r-subtotal td.col-ytotal{background:#bfdbfe!important}
  95. tr.r-subtotal.L0 td.col-ytotal{background:#93c5fd!important}
  96. tr.r-total td.col-ytotal{background:#1e3a5f!important;color:#bfdbfe!important}
  97. /* indent */
  98. .i0{padding-left:8px!important}
  99. .i1{padding-left:18px!important}
  100. .i2{padding-left:30px!important}
  101. /* ── section header rows ── */
  102. tr.r-header td{
  103. background:#0f172a!important;color:#94a3b8;
  104. font-weight:700;font-size:10px;text-transform:uppercase;
  105. letter-spacing:.6px;padding:8px 8px 5px
  106. }
  107. tr.r-header.L0 td{background:#0f172a!important;color:#64748b;padding-top:12px}
  108. tr.r-header.L1 td{background:#1e293b!important;color:#94a3b8}
  109. /* ── item rows ── */
  110. tr.r-item td{background:#fff;border-bottom:1px solid #f1f5f9}
  111. tr.r-item:nth-child(even) td{background:#f8fafc}
  112. /* ── subtotal rows ── */
  113. tr.r-subtotal td{
  114. background:#dde3ed!important;font-weight:700;
  115. border-top:1px solid #c7d0e0;border-bottom:1px solid #c7d0e0
  116. }
  117. tr.r-subtotal.L0 td{background:#c7d0e0!important;font-size:13px}
  118. /* ── grand total row ── */
  119. tr.r-total td{
  120. background:#1e3a5f!important;color:#f0f9ff;
  121. font-weight:800;font-size:13px;
  122. border-top:3px solid #3b82f6
  123. }
  124. tr.r-total td.col-name{background:#1e3a5f!important;color:#f0f9ff}
  125. tr.r-total td.neg{color:#fca5a5!important}
  126. /* ─── Mobile hamburger toggle / backdrop (hidden on desktop) ─── */
  127. #sb-toggle{display:none}
  128. #sb-backdrop{display:none}
  129. /* ─── Mobile layout ─── */
  130. @media (max-width: 768px) {
  131. #sb-toggle{
  132. display:flex;align-items:center;justify-content:center;
  133. width:32px;height:32px;border:none;background:#1e293b;color:#f8fafc;
  134. border-radius:5px;font-size:16px;cursor:pointer;flex-shrink:0
  135. }
  136. #top-bar{padding:8px 10px;flex-wrap:wrap;gap:8px}
  137. #top-bar h2{font-size:13px}
  138. #sel-info{font-size:11px;flex-basis:100%;order:3;margin-left:40px}
  139. #total-wrap{margin-left:0;flex-wrap:wrap;font-size:11px;gap:4px}
  140. #app{position:relative}
  141. #sidebar{
  142. position:fixed;top:0;left:0;bottom:0;z-index:20;
  143. transform:translateX(-100%);transition:transform .2s ease;
  144. width:80vw;max-width:280px;box-shadow:2px 0 12px rgba(0,0,0,.3)
  145. }
  146. #sidebar.open{transform:translateX(0)}
  147. #sb-backdrop{
  148. display:none;position:fixed;inset:0;background:rgba(15,23,42,.5);z-index:19
  149. }
  150. #sb-backdrop.open{display:block}
  151. #main{width:100%}
  152. #tbl-wrap{padding:8px 10px;-webkit-overflow-scrolling:touch}
  153. table.plt{font-size:11px}
  154. table.plt thead th{width:74px;padding:6px 6px;font-size:10px}
  155. table.plt thead th.col-name{width:150px}
  156. table.plt td.val{padding:5px 6px}
  157. table.plt td.col-name{padding:5px 6px}
  158. }
  159. </style>
  160. </head>
  161. <body>
  162. <div id="app">
  163. <!-- ═══ SIDEBAR ═══ -->
  164. <div id="sidebar">
  165. <div id="sb-head">
  166. <a href="upload.php" class="upload-link">&#8593; Upload New CSV</a>
  167. </div>
  168. <div id="qsel">
  169. <div class="qlabel">Quick Select</div>
  170. <div class="qrow">
  171. <button class="qb" onclick="qs('thisYear')">This Year</button>
  172. <button class="qb" onclick="qs('lastYear')">Last Year</button>
  173. <button class="qb" onclick="qs('ytd')">YTD</button>
  174. <button class="qb" onclick="qs('last12')">Last 12 Mo</button>
  175. <button class="qb" onclick="qs('none')">Clear</button>
  176. <button class="qb" onclick="qs('all')">All</button>
  177. </div>
  178. </div>
  179. <div id="yr-scroll">
  180. <div id="yr-list">
  181. <?php if (!$hasData): ?>
  182. <div style="padding:20px 14px;color:#475569;font-size:12px;line-height:1.6">
  183. No data yet.<br>
  184. <a href="upload.php" style="color:#3b82f6">Upload a CSV</a> to get started.
  185. </div>
  186. <?php else: ?>
  187. <div style="padding:16px;color:#475569;font-size:12px">Loading…</div>
  188. <?php endif; ?>
  189. </div>
  190. </div>
  191. </div><!-- /sidebar -->
  192. <div id="sb-backdrop" onclick="toggleSidebar()"></div>
  193. <!-- ═══ MAIN ═══ -->
  194. <div id="main">
  195. <div id="top-bar">
  196. <button id="sb-toggle" onclick="toggleSidebar()" aria-label="Toggle menu">&#9776;</button>
  197. <h2>Profit &amp; Loss Statement</h2>
  198. <span id="sel-info"></span>
  199. <div id="total-wrap">
  200. <input type="checkbox" id="show-total" onchange="render()">
  201. <label for="show-total">Show Year Totals</label>
  202. <span style="color:#cbd5e1;margin:0 4px">|</span>
  203. <input type="checkbox" id="totals-only" onchange="onTotalsOnly()">
  204. <label for="totals-only">Totals Only</label>
  205. <span style="color:#cbd5e1;margin:0 8px">|</span>
  206. <a href="logout.php" style="font-size:12px;color:#94a3b8;text-decoration:none">Sign out</a>
  207. </div>
  208. </div>
  209. <div id="tbl-wrap">
  210. <?php if (!$hasData): ?>
  211. <div id="empty-state">
  212. <h3>No Data Available</h3>
  213. <p>Please <a href="upload.php">upload a QuickBooks P&amp;L CSV export</a> to get started.</p>
  214. </div>
  215. <?php endif; ?>
  216. </div>
  217. </div>
  218. </div><!-- /app -->
  219. <script>
  220. 'use strict';
  221. // ── State ──
  222. let allMonths = []; // flat array from API
  223. let yearMap = {}; // year -> [{id, label, month_num, is_partial}, ...]
  224. let selected = new Set(); // selected month IDs
  225. let plData = null; // last API /data response
  226. let debounce = null;
  227. const MO = ['','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  228. // ── Boot ──
  229. <?php if ($hasData): ?>
  230. (async () => {
  231. try {
  232. const res = await fetch('api.php?action=months');
  233. if (!res.ok) throw new Error(res.status);
  234. allMonths = await res.json();
  235. if (allMonths.error) throw new Error(allMonths.error);
  236. buildSidebar();
  237. qs('thisYear');
  238. } catch(e) {
  239. document.getElementById('yr-list').innerHTML =
  240. '<div style="padding:14px;color:#f87171;font-size:12px">Error: '+esc(String(e.message))+'</div>';
  241. }
  242. })();
  243. <?php endif; ?>
  244. // ── Build sidebar ──
  245. function buildSidebar() {
  246. yearMap = {};
  247. allMonths.forEach(m => {
  248. if (m.is_total) return;
  249. (yearMap[m.year] = yearMap[m.year] || []).push(m);
  250. });
  251. const years = Object.keys(yearMap).map(Number).sort((a,b)=>b-a);
  252. const curY = new Date().getFullYear();
  253. let html = '';
  254. years.forEach(y => {
  255. const mos = yearMap[y];
  256. const open = y >= curY - 1;
  257. html += `<div class="yr-item" id="yi-${y}">
  258. <div class="yr-row" onclick="toggleYear(${y})">
  259. <input class="yr-cb" type="checkbox" id="yc-${y}"
  260. onclick="event.stopPropagation();toggleYearCb(${y})">
  261. <span class="yr-lbl">${y}</span>
  262. <span class="yr-arrow${open?' open':''}" id="ya-${y}">&#9654;</span>
  263. </div>
  264. <div class="mo-list${open?' open':''}" id="ml-${y}">
  265. ${mos.map(m=>`
  266. <div class="mo-row">
  267. <input class="mo-cb" type="checkbox" id="mc-${m.id}" value="${m.id}" onchange="onMoCb()">
  268. <label class="mo-lbl${m.is_partial?' partial':''}" for="mc-${m.id}">${MO[m.month_num]}${m.is_partial?' <em>(partial)</em>':''}</label>
  269. </div>`).join('')}
  270. </div>
  271. </div>`;
  272. });
  273. document.getElementById('yr-list').innerHTML = html;
  274. }
  275. // ── Mobile sidebar toggle ──
  276. function toggleSidebar() {
  277. document.getElementById('sidebar').classList.toggle('open');
  278. document.getElementById('sb-backdrop').classList.toggle('open');
  279. }
  280. function closeMobileSidebar() {
  281. if (window.innerWidth <= 768) {
  282. document.getElementById('sidebar').classList.remove('open');
  283. document.getElementById('sb-backdrop').classList.remove('open');
  284. }
  285. }
  286. // ── Sidebar interactions ──
  287. function toggleYear(y) {
  288. document.getElementById('ml-'+y).classList.toggle('open');
  289. document.getElementById('ya-'+y).classList.toggle('open');
  290. }
  291. function toggleYearCb(y) {
  292. const cb = document.getElementById('yc-'+y);
  293. (yearMap[y]||[]).forEach(m => {
  294. const mcb = document.getElementById('mc-'+m.id);
  295. if (!mcb) return;
  296. mcb.checked = cb.checked;
  297. cb.checked ? selected.add(m.id) : selected.delete(m.id);
  298. });
  299. syncYearCb(y);
  300. schedule();
  301. }
  302. function onMoCb() {
  303. selected.clear();
  304. allMonths.forEach(m => {
  305. const cb = document.getElementById('mc-'+m.id);
  306. if (cb && cb.checked) selected.add(m.id);
  307. });
  308. Object.keys(yearMap).forEach(y => syncYearCb(+y));
  309. schedule();
  310. }
  311. function syncYearCb(y) {
  312. const cb = document.getElementById('yc-'+y);
  313. if (!cb) return;
  314. const mos = yearMap[y] || [];
  315. const n = mos.filter(m => selected.has(m.id)).length;
  316. cb.indeterminate = n > 0 && n < mos.length;
  317. cb.checked = n === mos.length && mos.length > 0;
  318. }
  319. // ── Quick selects ──
  320. function qs(mode) {
  321. const now = new Date();
  322. const curY = now.getFullYear();
  323. const curM = now.getMonth() + 1;
  324. allMonths.forEach(m => {
  325. if (m.is_total) return;
  326. let pick = false;
  327. if (mode==='all') pick = true;
  328. else if (mode==='thisYear') pick = m.year === curY;
  329. else if (mode==='lastYear') pick = m.year === curY - 1;
  330. else if (mode==='ytd') pick = m.year === curY && m.month_num <= curM;
  331. else if (mode==='last12') {
  332. const md = m.year*12 + m.month_num;
  333. const nd = curY*12 + curM;
  334. pick = md > nd-12 && md <= nd;
  335. }
  336. const cb = document.getElementById('mc-'+m.id);
  337. if (cb) cb.checked = pick;
  338. pick ? selected.add(m.id) : selected.delete(m.id);
  339. });
  340. Object.keys(yearMap).forEach(y => syncYearCb(+y));
  341. schedule();
  342. closeMobileSidebar();
  343. }
  344. // ── Data loading ──
  345. function schedule() {
  346. clearTimeout(debounce);
  347. debounce = setTimeout(load, 120);
  348. }
  349. async function load() {
  350. if (selected.size === 0) {
  351. document.getElementById('sel-info').textContent = '';
  352. document.getElementById('tbl-wrap').innerHTML =
  353. '<div style="padding:40px;text-align:center;color:#94a3b8;font-size:13px">Select months from the sidebar to view data.</div>';
  354. return;
  355. }
  356. const wrap = document.getElementById('tbl-wrap');
  357. wrap.classList.add('loading');
  358. // Year totals are computed client-side — only request selected months
  359. let ids = [...selected];
  360. try {
  361. const res = await fetch('api.php?action=data&ids='+encodeURIComponent(ids.join(',')));
  362. plData = await res.json();
  363. render();
  364. } catch(e) {
  365. wrap.innerHTML = '<div style="padding:40px;text-align:center;color:#ef4444">Error loading data: '+esc(e.message)+'</div>';
  366. } finally {
  367. wrap.classList.remove('loading');
  368. }
  369. }
  370. // ── Totals-only toggle: force show-total on when totals-only is enabled ──
  371. function onTotalsOnly() {
  372. const totalsOnly = document.getElementById('totals-only').checked;
  373. const showTotal = document.getElementById('show-total');
  374. if (totalsOnly) { showTotal.checked = true; showTotal.disabled = true; }
  375. else { showTotal.disabled = false; }
  376. render();
  377. }
  378. // ── Render table ──
  379. function render() {
  380. if (!plData || !plData.rows) return;
  381. const showTotal = document.getElementById('show-total').checked;
  382. const totalsOnly = document.getElementById('totals-only').checked;
  383. // Only real month columns (no DB TOTAL)
  384. const monthCols = (plData.columns || []).filter(c => !c.is_total);
  385. // Group month columns by year, preserving order
  386. const yearGroups = [];
  387. monthCols.forEach(c => {
  388. const last = yearGroups[yearGroups.length - 1];
  389. if (last && last.year === c.year) { last.cols.push(c); }
  390. else { yearGroups.push({ year: c.year, cols: [c] }); }
  391. });
  392. // Build flat display-column list.
  393. // In totals-only mode: one year-total sentinel per year, no individual months.
  394. // Otherwise: months interleaved with optional year-total sentinels.
  395. const dispCols = [];
  396. yearGroups.forEach(yg => {
  397. if (!totalsOnly) yg.cols.forEach(c => dispCols.push(c));
  398. if (totalsOnly || showTotal) dispCols.push({ isYTotal: true, year: yg.year, cols: yg.cols });
  399. });
  400. const selCount = selected.size;
  401. document.getElementById('sel-info').textContent =
  402. selCount + ' month' + (selCount !== 1 ? 's' : '') + ' selected';
  403. // Helper: sum row values across a set of columns
  404. function rowSum(row, cols) {
  405. return cols.reduce((s, c) => {
  406. const v = row.values[String(c.id)];
  407. return s + (v !== undefined && v !== null ? parseFloat(v) || 0 : 0);
  408. }, 0);
  409. }
  410. // Build header row
  411. let h = '<table class="plt"><thead><tr><th class="col-name">Account</th>';
  412. dispCols.forEach(dc => {
  413. if (dc.isYTotal) {
  414. h += `<th class="col-ytotal">${dc.year}</th>`;
  415. } else {
  416. h += `<th>${esc(dc.label)}</th>`;
  417. }
  418. });
  419. h += '</tr></thead><tbody>';
  420. // Render data rows — skip item rows with no data in any displayed month
  421. plData.rows.forEach(row => {
  422. if (row.type === 'item') {
  423. const hasData = monthCols.some(c => {
  424. const v = row.values[String(c.id)];
  425. return v !== undefined && v !== null && parseFloat(v) !== 0;
  426. });
  427. if (!hasData) return;
  428. }
  429. const L = row.indent;
  430. const rCls = 'r-' + row.type + (row.type === 'header' || row.type === 'subtotal' ? ' L' + L : '');
  431. const iCls = 'i' + L;
  432. if (row.type === 'header') {
  433. h += `<tr class="${rCls}"><td colspan="${dispCols.length + 1}" class="col-name ${iCls}">${esc(row.name)}</td></tr>`;
  434. return;
  435. }
  436. h += `<tr class="${rCls}"><td class="col-name ${iCls}">${esc(row.name)}</td>`;
  437. dispCols.forEach(dc => {
  438. if (dc.isYTotal) {
  439. const sum = rowSum(row, dc.cols);
  440. const vcls = 'val col-ytotal' + (sum < 0 ? ' neg' : sum === 0 ? ' zero' : '');
  441. h += `<td class="${vcls}">${fmt(sum)}</td>`;
  442. } else {
  443. const v = row.values[String(dc.id)];
  444. const num = (v === undefined || v === null) ? 0 : parseFloat(v);
  445. const vcls = 'val' + (num < 0 ? ' neg' : num === 0 ? ' zero' : '');
  446. h += `<td class="${vcls}">${fmt(num)}</td>`;
  447. }
  448. });
  449. h += '</tr>';
  450. });
  451. h += '</tbody></table>';
  452. document.getElementById('tbl-wrap').innerHTML = h;
  453. }
  454. // ── Helpers ──
  455. function fmt(n) {
  456. if (n === 0) return '—';
  457. const abs = Math.abs(n);
  458. const s = abs.toLocaleString('en-US', {minimumFractionDigits:2, maximumFractionDigits:2});
  459. return (n < 0 ? '-' : '') + '$' + s;
  460. }
  461. function esc(s) {
  462. return String(s||'')
  463. .replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')
  464. .replace(/"/g,'&quot;');
  465. }
  466. </script>
  467. </body>
  468. </html>