index.php 19 KB

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