-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInternalLogForm.html
More file actions
269 lines (235 loc) · 12.9 KB
/
InternalLogForm.html
File metadata and controls
269 lines (235 loc) · 12.9 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
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script src="https://cdn.jsdelivr.net/npm/qrcodejs@1.0.0/qrcode.min.js"></script>
<style>
/* --- Base Styles --- */
body { font-family: Arial, sans-serif; background-color: #f0f2f5; margin: 0; }
.header { background-color: #1C2790; padding: 20px; text-align: center; color: white; }
.header img { width: 300px; margin-bottom: 10px; }
.container { max-width: 700px; margin: 20px auto; background: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); border-top: 5px solid #1C2790; }
.form-group { margin-bottom: 20px; position: relative; } /* Relative for autocomplete */
.form-section-title { font-size: 1.2em; font-weight: bold; color: #1C2790; border-bottom: 2px solid #eee; padding-bottom: 10px; margin-bottom: 20px; margin-top: 30px; }
label { display: block; margin-bottom: 8px; font-weight: bold; color: #333; }
input[type="text"], select { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; }
button { padding: 12px; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; font-weight: bold; }
#submitButton { width: 100%; margin-top: 20px; background-color: #1C2790; color: white; }
#add-doc-btn { width: 100%; background-color: #28a745; color: white; margin-top: 10px; }
.document-entry { background-color: #f9f9f9; border: 1px solid #e0e0e0; border-radius: 6px; padding: 20px; margin-bottom: 15px; position: relative; }
.document-entry.prefilled { background-color: #eef3ff; border-left: 4px solid #1C2790; }
.ref-badge { display: inline-block; background-color: #1C2790; color: #fff; font-size: 11px; padding: 3px 8px; border-radius: 10px; margin-bottom: 8px; font-weight: bold; letter-spacing: 0.3px; }
.prefill-banner { background-color: #eef3ff; border: 1px solid #1C2790; color: #1C2790; padding: 12px 15px; border-radius: 6px; margin-bottom: 20px; font-size: 14px; }
.remove-btn { position: absolute; top: 10px; right: 10px; background-color: #dc3545; color: white; width: 30px; height: 30px; line-height: 30px; text-align: center; }
/* Autocomplete */
.autocomplete-items { position: absolute; border: 1px solid #d4d4d4; background: #fff; z-index: 99; width: 100%; left:0; right:0; max-height:200px; overflow-y:auto; }
.autocomplete-items div { padding: 10px; cursor: pointer; border-bottom: 1px solid #eee; }
.autocomplete-items div:hover { background-color: #e9e9e9; }
/* --- Print Slip Styles --- */
.slip-content { box-sizing: border-box; padding: 4mm; color: #000; text-align: left; border: 1px solid #000; font-size: 9pt; width: 105mm; }
.slip-header { border-bottom: 1px solid #ccc; padding-bottom: 2mm; margin-bottom: 2mm; text-align: center; }
.slip-body { display: flex; align-items: flex-start; gap: 2mm; }
.meta-table { width: 100%; font-size: 8pt; margin-bottom: 3mm; border-collapse: collapse; }
.docs-table { width: 100%; font-size: 7pt; border-collapse: collapse; margin-top: 2mm; border-top: 1px solid #000; }
.docs-table td, .docs-table th { padding: 2px; border-bottom: 1px solid #eee; text-align: left; }
@media print {
.header, #formContainer, .no-print { display: none !important; }
#successContainer { display: flex !important; justify-content: center; padding-top: 5mm; border: none; box-shadow: none; margin: 0; max-width: 100%; }
.slip-content { width: 100%; border: none; }
}
</style>
</head>
<body>
<div class="header">
<img src="https://i.imgur.com/jaEbfAR.png" alt="DAP Logo">
<h2>Internal Document Logger</h2>
</div>
<div class="container" id="formContainer">
<div id="prefillBanner" class="prefill-banner" style="display:none;">
Documents below were pre-loaded from the main workflow. The Transaction reference is included in each title. You can still edit, add, or remove rows before logging.
</div>
<form id="logForm">
<div class="form-group">
<label>Encoder Name (Optional)</label>
<input type="text" id="encoderName" placeholder="Enter your name...">
</div>
<div class="form-group">
<label>Received From (Optional - Sends Acknowledgment Email)</label>
<input type="text" id="receivedFrom" placeholder="Search name..." autocomplete="off">
<div class="autocomplete-items"></div>
</div>
<div class="form-section-title">Documents to Log</div>
<div id="documents-container"></div>
<button type="button" id="add-doc-btn">+ Add Another Document</button>
<button type="submit" id="submitButton">Log Documents & Print Slip</button>
</form>
</div>
<div class="container" id="successContainer" style="display: none;">
<div class="slip-content">
<div class="slip-header"><p style="font-weight:bold; margin:0;">Finance Dept - Internal Log</p></div>
<div class="slip-body">
<div style="flex-grow: 1;">
<table class="meta-table">
<tbody>
<tr><td style="width: 50px;">Log ID:</td><td style="font-size: 12pt; font-weight: bold;" id="slipLogId"></td></tr>
<tr><td>Date:</td><td id="slipTimestamp"></td></tr>
<tr><td>Status:</td><td><b>Finance Custody</b></td></tr>
</tbody>
</table>
<table class="docs-table">
<thead><tr><th>Type</th><th>Title</th></tr></thead>
<tbody id="slip-documents-list"></tbody>
</table>
</div>
<div style="flex-shrink: 0; text-align: center;">
<div id="qrcode"></div>
<div style="font-size:6pt;">Scan to Route</div>
</div>
</div>
</div>
<button class="no-print" onclick="location.reload()" style="margin-top:20px; background:#6c757d; color:white; width:100%;">Log Another Batch</button>
</div>
<script>
const docTypes = <?!= JSON.stringify(docTypes) ?>;
const PREFILL_RAW = <?!= JSON.stringify(prefillDocs || "") ?>;
let directory = [];
function escapeHtmlAttr(s) {
return String(s == null ? "" : s)
.replace(/&/g, "&").replace(/"/g, """)
.replace(/</g, "<").replace(/>/g, ">");
}
function createDocEntryHTML(prefill) {
const selectedType = prefill && prefill.type ? prefill.type : "";
const selectedTitle = prefill && prefill.title ? prefill.title : "";
const refBadge = prefill && prefill.ref
? `<div class="ref-badge">From Tx: ${escapeHtmlAttr(prefill.ref)}</div>`
: "";
let options = `<option value="" disabled ${selectedType ? "" : "selected"}>Select type...</option>`;
docTypes.forEach(t => {
const sel = (t === selectedType) ? "selected" : "";
options += `<option value="${escapeHtmlAttr(t)}" ${sel}>${escapeHtmlAttr(t)}</option>`;
});
return `
<button type="button" class="remove-btn" onclick="this.parentElement.remove()">X</button>
${refBadge}
<div class="form-group">
<label>Document Type</label>
<select class="doc-type-select" required>${options}</select>
</div>
<div class="form-group">
<label>Document Title</label>
<input type="text" class="doc-title-input" value="${escapeHtmlAttr(selectedTitle)}" required>
</div>
`;
}
function addDocumentEntry(prefill) {
const div = document.createElement('div');
div.className = 'document-entry' + (prefill ? ' prefilled' : '');
div.innerHTML = createDocEntryHTML(prefill);
document.getElementById('documents-container').appendChild(div);
}
function loadPrefilledDocs() {
if (!PREFILL_RAW) return false;
let parsed;
try {
// Inverse of: btoa(unescape(encodeURIComponent(json))) on the dashboard.
const json = decodeURIComponent(escape(atob(PREFILL_RAW)));
parsed = JSON.parse(json);
} catch (e) {
console.error("Could not parse prefill data: " + e);
return false;
}
if (!Array.isArray(parsed) || parsed.length === 0) return false;
parsed.forEach(d => {
const fullTitle = d.ref ? `[Ref: ${d.ref}] ${d.title}` : d.title;
addDocumentEntry({ ref: d.ref, type: d.type, title: fullTitle });
});
document.getElementById('prefillBanner').style.display = 'block';
return true;
}
function attachAutocomplete(inp) {
const list = inp.parentNode.querySelector('.autocomplete-items');
inp.addEventListener("input", function() {
const val = this.value; list.innerHTML = '';
if(!val) return;
directory.filter(d => d.name.toLowerCase().includes(val.toLowerCase())).slice(0,5).forEach(m => {
let div = document.createElement("div");
div.innerHTML = m.name;
div.onclick = function() { inp.value = m.name; list.innerHTML = ''; };
list.appendChild(div);
});
});
document.addEventListener("click", e => { if(e.target !== inp) list.innerHTML = ''; });
}
document.addEventListener('DOMContentLoaded', function() {
google.script.run.withSuccessHandler(data => { directory = data; }).getDirectory();
attachAutocomplete(document.getElementById('receivedFrom'));
const hadPrefill = loadPrefilledDocs();
if (!hadPrefill) addDocumentEntry();
document.getElementById('add-doc-btn').addEventListener('click', () => addDocumentEntry());
document.getElementById('logForm').addEventListener('submit', function(e) {
e.preventDefault();
const btn = document.getElementById('submitButton');
btn.disabled = true; btn.textContent = 'Processing...';
const docs = [];
document.querySelectorAll('.document-entry').forEach(entry => {
docs.push({
docType: entry.querySelector('.doc-type-select').value,
docTitle: entry.querySelector('.doc-title-input').value
});
});
const formData = {
encoder: document.getElementById('encoderName').value,
receivedFrom: document.getElementById('receivedFrom').value,
documents: docs
};
const submitNow = () => {
google.script.run.withSuccessHandler((res) => onSuccess(res, formData.receivedFrom))
.processInternalLog(formData);
};
// Run duplicate check first; only relevant for titles already containing a [Ref: ...] tag.
const titlesToCheck = docs.map(d => d.docTitle).filter(t => /\[Ref:\s*[^\]]+\]/i.test(t));
if (titlesToCheck.length === 0) { submitNow(); return; }
google.script.run.withSuccessHandler(dups => {
if (dups && dups.length > 0) {
const proceed = confirm(
"The following document(s) appear to have already been routed into the Internal Logbook:\n\n" +
dups.join("\n") +
"\n\nLog them again anyway?"
);
if (!proceed) {
btn.disabled = false; btn.textContent = 'Log Documents & Print Slip';
return;
}
}
submitNow();
}).withFailureHandler(() => submitNow())
.checkExternalRefDuplicates(titlesToCheck);
});
});
function onSuccess(res, receivedFrom) {
document.getElementById('slipLogId').textContent = res.logID;
document.getElementById('slipTimestamp').textContent = res.timestamp;
// --- NEW: Inject Received From Row if present ---
const metaTableBody = document.querySelector('.meta-table tbody');
if (receivedFrom && receivedFrom.trim() !== "") {
const row = document.createElement('tr');
row.innerHTML = `<td>Rec'd From:</td><td>${receivedFrom}</td>`;
metaTableBody.appendChild(row);
}
// ------------------------------------------------
const tbody = document.getElementById('slip-documents-list');
tbody.innerHTML = "";
res.documents.forEach(d => {
tbody.innerHTML += `<tr><td>${d.docType}</td><td>${d.docTitle}</td></tr>`;
});
const updateLink = `${res.appUrl}?page=internal-update&id=${res.logID}`;
document.getElementById('qrcode').innerHTML = "";
new QRCode(document.getElementById('qrcode'), { text: updateLink, width: 120, height: 120, correctLevel: QRCode.CorrectLevel.L });
document.getElementById('formContainer').style.display = 'none';
document.getElementById('successContainer').style.display = 'block';
setTimeout(() => window.print(), 500);
}
</script>
</body>
</html>