anuragshas commited on
Commit
f80fd9f
·
1 Parent(s): a4c293a

fix: double printing issue

Browse files
Files changed (3) hide show
  1. index.html +1 -1
  2. script.js +13 -1
  3. style.css +60 -18
index.html CHANGED
@@ -281,7 +281,7 @@
281
  </div>
282
  </form>
283
  </div>
284
- <div id="preview-container" class="w-full lg:w-1/2">
285
  <div
286
  id="quotation-preview"
287
  class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4"
 
281
  </div>
282
  </form>
283
  </div>
284
+ <div id="preview-container" class="w-full lg:w-1/2 hidden lg:block">
285
  <div
286
  id="quotation-preview"
287
  class="bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4"
script.js CHANGED
@@ -264,9 +264,18 @@ if (typeof document !== "undefined") {
264
  return html;
265
  }
266
 
 
 
 
 
 
 
 
 
 
267
  function updatePreview() {
268
  const form = document.getElementById("quotation-form");
269
- const html = generateQuotationHTML(form);
270
  previewContent.innerHTML = html;
271
  }
272
 
@@ -528,6 +537,9 @@ if (typeof document !== "undefined") {
528
  const html = generateQuotationHTML(form);
529
  quotationContent.innerHTML = html;
530
  output.classList.remove("hidden");
 
 
 
531
  });
532
 
533
  document
 
264
  return html;
265
  }
266
 
267
+ function generateQuotationHTMLForPreview(form) {
268
+ const html = generateQuotationHTML(form);
269
+ // Remove print button from preview
270
+ return html.replace(
271
+ /<button[^>]*onclick="window\.print\(\)"[^>]*>.*?<\/button>/s,
272
+ "",
273
+ );
274
+ }
275
+
276
  function updatePreview() {
277
  const form = document.getElementById("quotation-form");
278
+ const html = generateQuotationHTMLForPreview(form);
279
  previewContent.innerHTML = html;
280
  }
281
 
 
537
  const html = generateQuotationHTML(form);
538
  quotationContent.innerHTML = html;
539
  output.classList.remove("hidden");
540
+
541
+ // Add print-only class to modal for better print isolation
542
+ output.classList.add("print-modal");
543
  });
544
 
545
  document
style.css CHANGED
@@ -42,16 +42,19 @@
42
  max-width: 800px;
43
  margin: auto;
44
  border: 1px solid #000;
45
- padding: 20px;
 
 
46
  }
47
 
48
  .quotation-print h2 {
49
  text-align: center;
50
- margin-bottom: 20px;
 
51
  }
52
 
53
  .quotation-print .section {
54
- margin-bottom: 15px;
55
  }
56
 
57
  .totals table {
@@ -68,11 +71,11 @@
68
 
69
  .disclaimer {
70
  color: #555;
71
- margin-top: 20px;
72
- font-size: 10px;
73
  text-align: justify;
74
  border-top: 1px solid #000;
75
- padding-top: 10px;
76
  }
77
 
78
  .quote-meta {
@@ -87,14 +90,14 @@
87
 
88
  .company-details h1 {
89
  margin: 0;
90
- font-size: 24px;
91
  color: #036;
92
  font-family: Arial, Helvetica, sans-serif;
93
  }
94
 
95
  .quotation-title h1 {
96
  margin: 0;
97
- font-size: 24px;
98
  color: #036;
99
  text-align: right;
100
  }
@@ -111,20 +114,22 @@
111
 
112
  .customer-info {
113
  border: 1px solid #000;
114
- padding: 10px;
115
- margin-bottom: 20px;
 
116
  }
117
 
118
  .items-table-print {
119
  width: 100%;
120
  border-collapse: collapse;
121
- margin-bottom: 20px;
 
122
  }
123
 
124
  .items-table-print th,
125
  .items-table-print td {
126
  border: 1px solid #000;
127
- padding: 8px;
128
  text-align: left;
129
  }
130
 
@@ -133,17 +138,19 @@
133
  }
134
 
135
  .footer {
136
- margin-top: 20px;
137
  }
138
 
139
  .notes-and-total {
140
  display: flex;
141
  justify-content: space-between;
 
142
  }
143
 
144
  .notes {
145
  width: 60%;
146
- font-size: 12px;
 
147
  }
148
 
149
  .totals {
@@ -156,8 +163,9 @@
156
 
157
  .thank-you {
158
  text-align: center;
159
- margin-top: 20px;
160
  font-weight: bold;
 
161
  }
162
 
163
  @media print {
@@ -170,18 +178,21 @@
170
 
171
  @page {
172
  size: a4;
173
- margin: 10mm;
174
  }
175
 
176
  body {
177
- font-size: 12pt;
 
178
  }
179
 
180
  .quotation-print {
181
  max-width: 100%;
182
- padding: 20px;
183
  margin: auto;
184
  border: 1px solid #000;
 
 
185
  }
186
 
187
  .items-table-print,
@@ -202,4 +213,35 @@
202
  button {
203
  display: none;
204
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  }
 
42
  max-width: 800px;
43
  margin: auto;
44
  border: 1px solid #000;
45
+ padding: 15px;
46
+ font-size: 12px;
47
+ line-height: 1.3;
48
  }
49
 
50
  .quotation-print h2 {
51
  text-align: center;
52
+ margin-bottom: 10px;
53
+ font-size: 18px;
54
  }
55
 
56
  .quotation-print .section {
57
+ margin-bottom: 8px;
58
  }
59
 
60
  .totals table {
 
71
 
72
  .disclaimer {
73
  color: #555;
74
+ margin-top: 10px;
75
+ font-size: 8px;
76
  text-align: justify;
77
  border-top: 1px solid #000;
78
+ padding-top: 5px;
79
  }
80
 
81
  .quote-meta {
 
90
 
91
  .company-details h1 {
92
  margin: 0;
93
+ font-size: 18px;
94
  color: #036;
95
  font-family: Arial, Helvetica, sans-serif;
96
  }
97
 
98
  .quotation-title h1 {
99
  margin: 0;
100
+ font-size: 18px;
101
  color: #036;
102
  text-align: right;
103
  }
 
114
 
115
  .customer-info {
116
  border: 1px solid #000;
117
+ padding: 8px;
118
+ margin-bottom: 10px;
119
+ font-size: 11px;
120
  }
121
 
122
  .items-table-print {
123
  width: 100%;
124
  border-collapse: collapse;
125
+ margin-bottom: 10px;
126
+ font-size: 10px;
127
  }
128
 
129
  .items-table-print th,
130
  .items-table-print td {
131
  border: 1px solid #000;
132
+ padding: 4px;
133
  text-align: left;
134
  }
135
 
 
138
  }
139
 
140
  .footer {
141
+ margin-top: 10px;
142
  }
143
 
144
  .notes-and-total {
145
  display: flex;
146
  justify-content: space-between;
147
+ margin-bottom: 5px;
148
  }
149
 
150
  .notes {
151
  width: 60%;
152
+ font-size: 10px;
153
+ line-height: 1.2;
154
  }
155
 
156
  .totals {
 
163
 
164
  .thank-you {
165
  text-align: center;
166
+ margin-top: 10px;
167
  font-weight: bold;
168
+ font-size: 12px;
169
  }
170
 
171
  @media print {
 
178
 
179
  @page {
180
  size: a4;
181
+ margin: 8mm;
182
  }
183
 
184
  body {
185
+ font-size: 10pt;
186
+ line-height: 1.2;
187
  }
188
 
189
  .quotation-print {
190
  max-width: 100%;
191
+ padding: 10px;
192
  margin: auto;
193
  border: 1px solid #000;
194
+ font-size: 10px;
195
+ line-height: 1.2;
196
  }
197
 
198
  .items-table-print,
 
213
  button {
214
  display: none;
215
  }
216
+
217
+ /* Hide all content except the print modal during printing */
218
+ body > *:not(.print-modal) {
219
+ display: none !important;
220
+ }
221
+
222
+ /* Show only the print modal content */
223
+ .print-modal {
224
+ display: block !important;
225
+ position: static !important;
226
+ z-index: auto !important;
227
+ background: white !important;
228
+ margin: 0 !important;
229
+ padding: 0 !important;
230
+ }
231
+
232
+ .print-modal > div {
233
+ max-width: 100% !important;
234
+ margin: 0 !important;
235
+ padding: 0 !important;
236
+ box-shadow: none !important;
237
+ background: white !important;
238
+ }
239
+
240
+ /* Ensure single page printing */
241
+ .print-modal .quotation-print {
242
+ page-break-after: avoid !important;
243
+ page-break-before: avoid !important;
244
+ margin: 0 !important;
245
+ padding: 8px !important;
246
+ }
247
  }