-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·433 lines (398 loc) · 21.6 KB
/
Copy pathindex.html
File metadata and controls
executable file
·433 lines (398 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#00565f">
<title>TS INDUSTRIES · Invoice Generator</title>
<!-- Apply the saved theme BEFORE first paint to avoid a light/dark flash. -->
<script>
(function () {
try {
var t = localStorage.getItem("ts_theme");
if (t !== "dark" && t !== "light") t = "dark"; // default: dark (style C)
document.documentElement.setAttribute("data-theme", t);
} catch (e) { document.documentElement.setAttribute("data-theme", "dark"); }
// Toggle between the two chosen palettes: A = light, C = dark.
window.__toggleTheme = function () {
var cur = document.documentElement.getAttribute("data-theme") === "dark" ? "dark" : "light";
var next = cur === "dark" ? "light" : "dark";
document.documentElement.setAttribute("data-theme", next);
try { localStorage.setItem("ts_theme", next); } catch (e) {}
var b = document.getElementById("themeToggle");
if (b) b.textContent = next === "dark" ? "☀️" : "🌙";
};
})();
</script>
<!-- PDF engine: EXACT version the original used, for byte-identical output. -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js"
integrity="sha384-NaWTHo/8YCBYJ59830LTz/P4aQZK1sS0SneOgAvhsIl3zBu8r9RevNg5lHCHAuQ/"
crossorigin="anonymous"></script>
<!-- Firebase (compat SDKs — plain globals, no bundler needed). -->
<script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore-compat.js"></script>
<!-- App code (order matters).
Cache-busting: every local script has a ?v=APP_VERSION query string.
Mobile browsers (no visible "hard refresh" control) can otherwise keep
serving a stale cached copy of these files indefinitely after a
deploy, even across normal reloads. BUMP THE VERSION NUMBER BELOW on
every deploy that changes any local .js/.html file. -->
<script src="firebase-config.js?v=4"></script>
<script src="template-draw.js?v=4"></script>
<script src="invoice.js?v=4"></script>
<script src="db.js?v=4"></script>
<style>
/* ============================================================
THEME TOKENS — two palettes the user chose:
A = light (teal brand) · C = dark (charcoal / teal)
Everything below is driven by these variables, so a single
data-theme flip on <html> re-skins the whole app.
============================================================ */
[data-theme="light"] {
--bg:#eef1f2; --surface:#ffffff; --surface-2:#fafbfb;
--border:#e5eaeb; --border-input:#d3dadb;
--text:#112326; --muted:#5a6b6e;
--accent:#00838f; --accent-soft:rgba(0,131,143,.12);
--topbar-bg:#00565f; --topbar-text:#ffffff; --topbar-muted:#bfe6ee;
--tabbar-bg:#00565f; --tab-bg:#00424c; --tab-text:#bfe6ee;
--tab-active-bg:#eef1f2; --tab-active-text:#00565f; --tab-border:transparent;
--card-title:#00565f;
--btn-primary-bg:#0b6623; --btn-primary-text:#ffffff;
--btn-secondary-bg:#c7ea46; --btn-secondary-text:#20331a;
--btn-add-color:#00838f; --btn-add-border:#00838f; --btn-add-bg:#ffffff;
--linkbtn-bg:rgba(255,255,255,.14); --linkbtn-text:#ffffff;
--danger:#d33; --danger-bg:#fdecec;
--table-head-bg:#00565f; --table-head-text:#ffffff;
--table-stripe:#f4f6f6; --table-border:#dbe1e2;
--dot-on:#38d66b; --dot-off:#ff5252;
--shadow:0 2px 8px rgba(0,0,0,.07);
--actions-bg:rgba(255,255,255,.94);
}
[data-theme="dark"] {
--bg:#0f1419; --surface:#161b22; --surface-2:#0f1419;
--border:#232a33; --border-input:#2a323c;
--text:#e6edf3; --muted:#8b98a5;
--accent:#2dd4bf; --accent-soft:rgba(45,212,191,.15);
--topbar-bg:#161b22; --topbar-text:#ffffff; --topbar-muted:#8b98a5;
--tabbar-bg:#161b22; --tab-bg:#0f1419; --tab-text:#8b98a5;
--tab-active-bg:#2dd4bf; --tab-active-text:#04231f; --tab-border:#232a33;
--card-title:#2dd4bf;
--btn-primary-bg:#2dd4bf; --btn-primary-text:#04231f;
--btn-secondary-bg:#232a33; --btn-secondary-text:#e6edf3;
--btn-add-color:#2dd4bf; --btn-add-border:#2dd4bf; --btn-add-bg:transparent;
--linkbtn-bg:#232a33; --linkbtn-text:#e6edf3;
--danger:#ff6b6b; --danger-bg:#2a1416;
--table-head-bg:#232a33; --table-head-text:#e6edf3;
--table-stripe:#12171d; --table-border:#232a33;
--dot-on:#2dd4bf; --dot-off:#ff6b6b;
--shadow:0 2px 10px rgba(0,0,0,.4);
--actions-bg:rgba(15,20,25,.92);
}
* { box-sizing: border-box; }
body {
margin: 0; padding: 0 0 92px;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
background: var(--bg); color: var(--text);
-webkit-text-size-adjust: 100%;
}
button { cursor: pointer; border: 0; border-radius: 8px; font-family: inherit; }
/* ---- Inputs ---- */
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 5px; }
input, textarea, select {
width: 100%; font-size: 15px; font-family: inherit; color: var(--text);
background: var(--surface-2); border: 1.5px solid var(--border-input);
border-radius: 9px; padding: 11px 12px;
}
textarea { resize: vertical; }
input:focus, textarea:focus {
outline: none; border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface);
}
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); cursor: pointer; }
/* ---- Top bar ---- */
.topbar {
background: var(--topbar-bg); color: var(--topbar-text);
padding: 12px 16px; display: flex; align-items: center; justify-content: space-between;
gap: 10px; position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: .5px; font-weight: 800; white-space: nowrap; }
.status { font-size: 12px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #999; flex: none; }
.dot.on { background: var(--dot-on); }
.dot.off { background: var(--dot-off); }
#cloudLabel { color: var(--topbar-muted); overflow: hidden; text-overflow: ellipsis;
white-space: nowrap; max-width: 150px; }
.linkbtn { background: var(--linkbtn-bg); color: var(--linkbtn-text); border-radius: 7px;
padding: 7px 11px; font-size: 12px; font-weight: 600; }
.icon-toggle { background: var(--linkbtn-bg); border-radius: 8px; width: 36px; height: 34px;
font-size: 16px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
/* ---- Tabs ---- */
.tabs { display: flex; gap: 6px; background: var(--tabbar-bg); padding: 10px 12px;
position: sticky; top: 58px; z-index: 40; }
.tab {
flex: 1; text-align: center; background: var(--tab-bg); color: var(--tab-text);
border: 1px solid var(--tab-border); padding: 11px 6px; font-size: 13px; font-weight: 700;
border-radius: 10px; cursor: pointer; user-select: none;
}
.tab.active { background: var(--tab-active-bg); color: var(--tab-active-text); border-color: var(--tab-active-bg); }
.tabpanel { display: none; }
.tabpanel.active { display: block; }
/* ---- Layout ---- */
.wrap { max-width: 720px; margin: 0 auto; padding: 14px; }
.screen-title { font-size: 20px; font-weight: 800; margin: 6px 2px 14px; color: var(--card-title); }
/* ---- Cards ---- */
.card {
background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 15px; color: var(--card-title);
border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.checks { margin: 14px 0 4px; display: flex; flex-direction: column; gap: 12px; }
.chk { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600;
color: var(--text); margin: 0; }
.item-head { display: flex; align-items: center; justify-content: space-between; }
.item-head h3 { border: 0; margin: 0; padding: 0; }
/* ---- Custom product dropdown (replaces native <datalist>, which renders
as cramped autocomplete chips on iOS and can't show a full list) ---- */
.combo { position: relative; }
.combo-panel {
position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60;
background: var(--surface); border: 1.5px solid var(--accent); border-radius: 10px;
box-shadow: 0 8px 24px rgba(0,0,0,.35); max-height: 240px; overflow-y: auto;
-webkit-overflow-scrolling: touch; padding: 4px;
}
.combo-opt {
padding: 11px 12px; font-size: 15px; color: var(--text); border-radius: 7px;
cursor: pointer; white-space: normal; word-break: break-word;
}
.combo-opt:hover, .combo-opt.active { background: var(--accent-soft); color: var(--accent); }
.combo-empty { padding: 11px 12px; font-size: 14px; color: var(--muted); }
/* ---- Buttons ---- */
.btn-add { width: 100%; background: var(--btn-add-bg); color: var(--btn-add-color);
border: 2px dashed var(--btn-add-border); border-radius: 12px; padding: 14px;
font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.btn-remove { background: var(--danger-bg); color: var(--danger); border-radius: 8px;
padding: 7px 12px; font-size: 12px; font-weight: 700; }
.actions {
position: fixed; bottom: 0; left: 0; right: 0; display: flex; gap: 10px;
padding: 12px 14px; background: var(--actions-bg); border-top: 1px solid var(--border);
z-index: 45; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.actions > * { max-width: 720px; }
.btn-secondary { flex: 1; background: var(--btn-secondary-bg); color: var(--btn-secondary-text);
border-radius: 11px; padding: 14px; font-weight: 800; font-size: 15px; }
.btn-primary { flex: 1.4; background: var(--btn-primary-bg); color: var(--btn-primary-text);
border-radius: 11px; padding: 14px; font-weight: 800; font-size: 15px; }
/* ---- Login gate ---- */
.gate { max-width: 400px; margin: 48px auto; background: var(--surface); color: var(--text);
padding: 28px 24px; border-radius: 16px; text-align: center; box-shadow: var(--shadow);
border: 1px solid var(--border); }
.gate h2 { margin: 0 0 4px; color: var(--card-title); }
.gate .sub { font-size: 13px; color: var(--muted); margin: 0 0 16px; }
.gate input { text-align: center; }
.gate .err { color: var(--danger); font-size: 14px; min-height: 18px; margin: 8px 0; }
.gate button#loginBtn { width: 100%; margin-top: 4px; background: var(--btn-primary-bg);
color: var(--btn-primary-text); padding: 13px; font-size: 16px; font-weight: 800; border-radius: 11px; }
.gate .muted { color: var(--muted); font-size: 12px; margin-top: 14px; }
.gate .muted .linkbtn { background: var(--accent-soft); color: var(--accent); }
/* ---- Bill history ---- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1; min-width: 200px; }
.toolbar .btn-secondary { flex: 0 0 auto; padding: 11px 16px; }
.table-scroll { overflow-x: auto; border-radius: 12px; border: 1px solid var(--table-border); }
table.history { width: 100%; border-collapse: collapse; background: var(--surface); min-width: 640px; }
table.history th, table.history td { border-bottom: 1px solid var(--table-border);
padding: 10px 12px; text-align: left; font-size: 14px; vertical-align: middle; color: var(--text); }
table.history thead th { background: var(--table-head-bg); color: var(--table-head-text);
position: sticky; top: 0; font-size: 13px; }
table.history tbody tr:nth-child(even) { background: var(--table-stripe); }
.rowbtn { padding: 6px 10px; font-size: 12px; font-weight: 700; margin: 2px 4px 2px 0; border-radius: 7px; }
.rowbtn.dl { background: var(--btn-primary-bg); color: var(--btn-primary-text); }
.rowbtn.dup { background: var(--accent-soft); color: var(--accent); }
.rowbtn.del { background: var(--danger-bg); color: var(--danger); }
/* ---- Items (preset) manager ---- */
.muted-note { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.preset-scroll { overflow-x: visible; }
.presetgrid { min-width: 0; }
.presetrow { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr 70px 130px; gap: 8px;
align-items: center; background: var(--surface); padding: 8px; border: 1px solid var(--border);
margin-bottom: 6px; border-radius: 10px; }
.presetrow.head { background: var(--table-head-bg); color: var(--table-head-text); font-weight: 700; font-size: 13px; }
.presetrow > div { min-width: 0; } /* let inputs shrink instead of clipping */
.presetrow input { padding: 8px 9px; }
.presetrow > div[data-label]::before { content: none; }
.muted-msg { color: var(--muted); text-align: center; padding: 12px; }
/* On phones the 7-column grid can't fit — stack each item as its own card
with per-field labels so nothing is cropped. */
@media (max-width: 640px) {
.presetrow.head { display: none; }
.presetrow { grid-template-columns: 1fr 1fr; gap: 8px 10px; padding: 14px; margin-bottom: 12px; }
.presetrow > div[data-label="Product name"] { grid-column: 1 / -1; }
.presetrow > div:last-child { grid-column: 1 / -1; display: flex; gap: 8px; }
.presetrow > div:last-child .rowbtn { flex: 1; margin: 0; padding: 10px; }
.presetrow > div[data-label]::before {
content: attr(data-label); display: block; font-size: 11px; font-weight: 600;
color: var(--muted); margin-bottom: 4px;
}
.presetrow > div.center { text-align: left; }
.presetrow > div.center input[type="checkbox"] { display: block; }
}
/* ---- Misc ---- */
.center { text-align: center; }
.hide { display: none !important; }
.status-line { color: var(--muted); text-align: center; padding: 8px; font-size: 14px; }
.banner { margin: 12px auto 0; max-width: 720px; padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.banner.warn { background: #fff3cd; color: #664d03; border: 1px solid #ffe69c; }
[data-theme="dark"] .banner.warn { background: #2b2410; color: #f5d67b; border-color: #4a3d16; }
</style>
</head>
<body>
<div class="topbar">
<h1>TS INDUSTRIES</h1>
<div class="status">
<span id="cloudDot" class="dot"></span> <span id="cloudLabel">…</span>
<button id="themeToggle" class="icon-toggle" onclick="__toggleTheme()" title="Toggle light / dark" aria-label="Toggle theme">🌙</button>
<button id="showLoginBtn" class="linkbtn hide">Log in</button>
<button id="logoutBtn" class="linkbtn hide">Log out</button>
</div>
</div>
<!-- ============ LOGIN GATE ============ -->
<div id="gate" class="gate hide">
<h2>Enter password</h2>
<p class="sub">to unlock bill history & saved items</p>
<input id="pwInput" type="password" placeholder="Password" autocomplete="current-password">
<div id="pwErr" class="err"></div>
<button id="loginBtn">Unlock</button>
<div class="muted">You can still print invoices without unlocking — but history and saved items need it.</div>
<div class="muted"><button id="skipLogin" class="linkbtn">Skip & just print →</button></div>
</div>
<!-- ============ MAIN APP ============ -->
<div id="appRoot" class="hide">
<div class="tabs">
<div class="tab active" data-tab="new">New Invoice</div>
<div class="tab" data-tab="history">Bill History</div>
<div class="tab" data-tab="items">Items</div>
</div>
<div id="offlineBanner" class="banner warn hide">
⚠️ Cloud not connected — running in <b>print-only</b> mode. Invoices print
normally with identical output, but they won't be saved to history and
saved items are unavailable.
</div>
<!-- ---- TAB: NEW INVOICE ---- -->
<div id="tab-new" class="tabpanel active">
<div class="wrap">
<h2 class="screen-title">New Invoice</h2>
<form name="myForm" method="post" onsubmit="return false;">
<section class="card">
<h3>Invoice Details</h3>
<label>Invoice Number</label>
<input type="number" name="invn" inputmode="numeric">
<label>Invoice Date</label>
<input type="date" name="invd">
<label>Transport Details</label>
<input type="text" name="trans">
<label>Vehicle Number</label>
<input type="text" name="vehnum">
</section>
<section class="card">
<h3>Consignee Details</h3>
<label>Details of Consignee / Billed to</label>
<textarea name="billto" rows="4"></textarea>
</section>
<section class="card">
<h3>Additional Values</h3>
<label>Carriage Outward</label>
<input type="number" step="0.01" name="carrout" value="0" inputmode="decimal">
<label>Transport / packing / other charges</label>
<input type="number" step="0.01" name="otherchg" value="0" inputmode="decimal">
<div class="checks">
<label class="chk"><input type="checkbox" name="igstq"> Apply IGST (18%)</label>
<label class="chk"><input type="checkbox" name="sgstq"> Apply SGST (9%)</label>
<label class="chk"><input type="checkbox" name="cgstq"> Apply CGST (9%)</label>
</div>
<label>Less Advance</label>
<input type="number" step="1" name="lessadv" value="0" inputmode="decimal">
</section>
</form>
<form name="myForm2" method="post" onsubmit="return false;">
<div id="items"></div>
</form>
<!-- Shared datalist of product names, rebuilt from presets. -->
<datalist id="presetNames"></datalist>
<button type="button" class="btn-add" onclick="addItem()">+ Add New Item</button>
<!-- Legacy container kept for compatibility; no longer rendered. -->
<div id="itembuttons" class="hide"></div>
</div>
<div class="actions">
<button type="button" class="btn-secondary" onclick="validateFormUtil()">Check Amount</button>
<button type="button" class="btn-primary" onclick="validateForm(true)">Print Invoice</button>
</div>
</div>
<!-- ---- TAB: BILL HISTORY ---- -->
<div id="tab-history" class="tabpanel">
<div class="wrap">
<h2 class="screen-title">Bill History</h2>
<div class="toolbar">
<input id="histSearch" type="search" placeholder="Search by invoice number or consignee…">
<button class="btn-secondary" id="histRefresh">Refresh</button>
</div>
<div id="histStatus" class="status-line"></div>
<div class="table-scroll">
<table class="history">
<thead>
<tr>
<th>Invoice #</th><th>Date</th><th>Consignee</th>
<th>Items</th><th>Total (₹)</th><th>Saved</th><th>Actions</th>
</tr>
</thead>
<tbody id="histBody"></tbody>
</table>
</div>
</div>
</div>
<!-- ---- TAB: ITEMS (preset manager) ---- -->
<div id="tab-items" class="tabpanel">
<div class="wrap">
<h2 class="screen-title">Saved Items</h2>
<p class="muted-note">
These products appear as suggestions in the <b>Product Description</b> box on
the New Invoice tab. Picking one auto-fills its default GSM / HSN / Size /
Rate (you can still edit any value per invoice). Add as many as you like.
</p>
<div style="margin-bottom:12px">
<button class="btn-secondary" id="seedDefaults">+ Add the original 6 items</button>
</div>
<div class="preset-scroll">
<div class="presetgrid">
<div class="presetrow head">
<div>Product name</div><div>GSM</div><div>HSN</div>
<div>Size</div><div>Rate</div><div>Active</div><div>Action</div>
</div>
<div id="presetList"></div>
<div class="presetrow" id="newPresetRow">
<div data-label="Product name"><input id="np_name" type="text" placeholder="New product name"></div>
<div data-label="GSM"><input id="np_gsm" type="number" step="0.01" placeholder="GSM"></div>
<div data-label="HSN"><input id="np_hsn" type="number" step="1" placeholder="HSN"></div>
<div data-label="Size"><input id="np_size" type="text" placeholder="Size"></div>
<div data-label="Rate"><input id="np_rate" type="number" step="0.01" placeholder="Rate"></div>
<div class="center">—</div>
<div><button class="rowbtn dl" id="np_add">Add</button></div>
</div>
</div>
</div>
<div id="presetStatus" class="status-line"></div>
</div>
</div>
</div>
<script>
// Sync the toggle glyph to the theme applied pre-paint.
(function () {
var b = document.getElementById("themeToggle");
if (b) b.textContent = document.documentElement.getAttribute("data-theme") === "dark" ? "☀️" : "🌙";
})();
</script>
<script src="app.js?v=4"></script>
</body>
</html>