File size: 15,706 Bytes
fdf1eb5
3bdf605
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fdf1eb5
3bdf605
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7bff53
 
3bdf605
 
f7bff53
 
 
 
 
 
 
 
3bdf605
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24221de
3bdf605
 
 
 
 
 
 
7f90814
 
3bdf605
 
 
 
 
7f90814
 
 
3bdf605
 
 
 
24221de
7f90814
ae81d21
 
 
 
 
 
 
7f90814
 
 
3bdf605
ae81d21
 
7f90814
3bdf605
7f90814
ae81d21
3bdf605
4770540
 
ffca791
3bdf605
 
b9f7b60
ae81d21
 
 
 
3bdf605
 
 
 
7f90814
 
 
 
 
931a079
 
 
 
 
 
 
 
7f90814
931a079
7f90814
59f4fcd
9b79244
59f4fcd
 
 
 
9b79244
 
59f4fcd
9b79244
7f90814
 
931a079
7f90814
931a079
 
7f90814
59f4fcd
 
 
 
 
7f90814
 
931a079
7f90814
 
 
 
931a079
7f90814
 
931a079
7f90814
9b79244
7f90814
 
9b79244
 
7f90814
 
 
 
 
 
 
 
9b79244
7f90814
 
 
9b79244
7f90814
 
 
 
 
9b79244
931a079
9b79244
 
7f90814
931a079
7f90814
931a079
9b79244
 
7f90814
 
 
 
 
931a079
7f90814
9b79244
 
 
 
7f90814
931a079
9b79244
7f90814
9b79244
7f90814
931a079
7f90814
 
 
 
 
931a079
7f90814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24221de
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

document.addEventListener('DOMContentLoaded', function() {
    const questions = [
        {
            question: "What is the width of the deck (left to right)?",
            type: "number",
            key: "width"
        },
        {
            question: "What is the depth of the deck (distance from the house outward)?",
            type: "number",
            key: "depth"
        },
        {
            question: "Is the deck a simple rectangle, or does it have angles/irregularities?",
            type: "select",
            options: ["Simple rectangle", "Angles/irregularities"],
            key: "shape"
        },
        {
            question: "Is the deck tying into the house with a ledger?",
            type: "yesno",
            key: "hasLedger"
        },
        {
            question: "Will deck boards run parallel or perpendicular to the house?",
            type: "select",
            options: ["Parallel", "Perpendicular"],
            key: "boardOrientation"
        },
        {
            question: "Are we picture framing the deck?",
            type: "yesno",
            key: "hasPictureFrame",
            followups: [
                {
                    question: "What color is the picture frame?",
                    type: "select",
                    options: ["Black", "White", "Gray", "Brown", "Custom"],
                    key: "frameColor"
                },
                {
                    question: "What color is the field decking?",
                    type: "select",
                    options: ["Black", "White", "Gray", "Brown", "Custom"],
                    key: "fieldColor"
                }
            ]
        },
        {
            question: "Are there steps?",
            type: "yesno",
            key: "hasSteps",
            followups: [
                {
                    question: "How many sets of steps?",
                    type: "number",
                    key: "stepSets"
                },
                {
                    question: "What is the width of each step run?",
                    type: "number",
                    key: "stepWidth"
                },
                {
                    question: "What is the deck height off the ground?",
                    type: "number",
                    key: "deckHeight"
                },
                {
                    question: "Is there a landing?",
                    type: "yesno",
                    key: "hasLanding",
                    followups: [
                        {
                            question: "What size is the landing?",
                            type: "text",
                            key: "landingSize"
                        }
                    ]
                }
            ]
        },
        {
            question: "Are we installing railing on the deck?",
            type: "yesno",
            key: "hasRailing",
            followups: [
                {
                    question: "Which sides of the deck will have railing? (Select all that apply)",
                    type: "multiselect",
                    options: ["Front", "Left", "Right", "Back"],
                    key: "railingSides"
                }
            ]
        },
        {
            question: "Do we need ADA handrail?",
            type: "yesno",
            key: "hasAdaRail",
            followups: [
                {
                    question: "Choose ADA handrail length",
                    type: "select",
                    options: ["8'8\"", "16'"],
                    key: "adaRailLength"
                }
            ]
        },
        {
            question: "Will the deck be skirted?",
            type: "yesno",
            key: "hasSkirting"
        },
        {
            question: "Are we installing fascia?",
            type: "yesno",
            key: "hasFascia",
            followups: [
                {
                    question: "What color is the fascia?",
                    type: "select",
                    options: ["Black", "White", "Gray", "Brown", "Custom"],
                    key: "fasciaColor"
                }
            ]
        },
        {
            question: "Any customer preferences, township requirements, or special framing considerations?",
            type: "textarea",
            key: "notes"
        }
    ];

    let currentQuestion = 0;
    let answers = {};
    const questionContainer = document.getElementById('current-question');
    const answerInput = document.getElementById('answer-input');
    const nextBtn = document.getElementById('next-btn');

    function renderQuestion(index) {
        const q = questions[index];
        questionContainer.textContent = q.question;
        answerInput.innerHTML = '';

        switch(q.type) {
            case 'number':
                answerInput.innerHTML = `
                    <input type="number" class="w-full px-4 py-2 border border-gray-300 rounded-lg" 
                           id="answer" placeholder="Enter measurement in feet">
                `;
                break;
            case 'yesno':
                answerInput.innerHTML = `
                    <div class="flex space-x-4">
                        <button type="button" class="yesno-btn px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-100" data-value="yes">Yes</button>
                        <button type="button" class="yesno-btn px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-100" data-value="no">No</button>
                    </div>
                `;
                // Add click handlers for yes/no buttons
                document.querySelectorAll('.yesno-btn').forEach(btn => {
                    btn.addEventListener('click', function() {
                        document.querySelectorAll('.yesno-btn').forEach(b => b.classList.remove('bg-blue-500', 'text-white', 'border-blue-500'));
                        this.classList.add('bg-blue-500', 'text-white', 'border-blue-500');
                    });
                });
break;
            case 'select':
                answerInput.innerHTML = `
                    <select class="w-full px-4 py-2 border border-gray-300 rounded-lg" id="answer">
                        ${q.options.map(opt => `<option value="${opt}">${opt}</option>`).join('')}
                    </select>
                `;
                break;
            case 'multiselect':
                answerInput.innerHTML = `
                    <div class="space-y-2">
                        ${q.options.map(opt => `
                            <label class="flex items-center">
                                <input type="checkbox" class="mr-2" value="${opt}">
                                ${opt}
                            </label>
                        `).join('')}
                    </div>
                `;
                break;
            case 'textarea':
                answerInput.innerHTML = `
                    <textarea class="w-full px-4 py-2 border border-gray-300 rounded-lg" 
                              id="answer" rows="3"></textarea>
                `;
                break;
        }
    }
    function collectAnswer() {
        const q = questions[currentQuestion];
        let answer;

        switch(q.type) {
            case 'number':
                answer = parseFloat(document.getElementById('answer').value) || 0;
                break;
            case 'select':
            case 'textarea':
                answer = document.getElementById('answer').value;
                break;
            case 'yesno':
                const selectedBtn = document.querySelector('.yesno-btn.bg-blue-500');
                answer = selectedBtn ? selectedBtn.dataset.value : null;
                break;
            case 'multiselect':
                answer = Array.from(document.querySelectorAll('input[type="checkbox"]:checked'))
                    .map(cb => cb.value);
                break;
        }
        
        // Skip validation for notes question (it's optional)
        if (q.key === 'notes') {
            answers[q.key] = answer || '';
            return true;
        }

        // Validate other questions
        if (answer === null || answer === undefined || (Array.isArray(answer) && answer.length === 0)) {
            return false;
        }

        // Store answer
        answers[q.key] = answer;
        return true;
    }
nextBtn.addEventListener('click', function() {
        if (!collectAnswer()) {
            alert('Please provide an answer before continuing');
            return;
        }
currentQuestion++;
        if (currentQuestion < questions.length) {
            renderQuestion(currentQuestion);
        } else {
            // All questions answered - show material list section
            document.getElementById('question-container').classList.add('hidden');
            document.getElementById('results-section').classList.remove('hidden');
}
    });
    // Initialize first question
    renderQuestion(0);

    // Show stairs details if checkbox is checked on load
    if (document.getElementById('stairs').checked) {
        document.getElementById('stairs-details').classList.remove('hidden');
    }
// Toggle stairs details
    document.getElementById('stairs').addEventListener('change', function() {
        document.getElementById('stairs-details').classList.toggle('hidden', !this.checked);
    });

    // Toggle railing details
    document.getElementById('railing').addEventListener('change', function() {
        // Add any railing-specific toggle logic here
    });
    // Handle calculate button click
    document.getElementById('calculate-btn').addEventListener('click', function() {
        // First make sure all questions are answered
        while (currentQuestion < questions.length) {
            if (!collectAnswer()) {
                alert('Please answer all questions before calculating materials');
                document.getElementById('question-container').classList.remove('hidden');
                document.getElementById('results-section').classList.add('hidden');
                renderQuestion(currentQuestion);
                return;
            }
            currentQuestion++;
        }

        // Generate and show results
        generateMaterialList();
        document.getElementById('question-container').classList.add('hidden');
        document.getElementById('results-section').classList.remove('hidden');
        document.getElementById('results-section').scrollIntoView({ behavior: 'smooth' });
        
        // Reset for next calculation
        currentQuestion = 0;
        answers = {};
        renderQuestion(0);
        
        // Log answers for debugging
        console.log('User answers:', answers);
    });
function generateMaterialList() {
        // Get basic deck dimensions
        const width = answers.width || 10; // Default to 10ft if not provided
        const depth = answers.depth || 10; // Default to 10ft if not provided
        const deckArea = width * depth;
        
        // Get special features
        const boardType = document.getElementById('board-type').value;
        const hasStairs = document.getElementById('stairs').checked;
        const stepCount = parseInt(document.getElementById('step-count').value) || 0;
        const hasRailing = document.getElementById('railing').checked;
        const hasRoof = document.getElementById('roof').checked;

        // Calculate deck boards based on board type and dimensions
        const boardWidth = 5.5; // inches
        const boardSpacing = 0.25; // inches
        const effectiveWidth = boardWidth + boardSpacing;
        
        // Calculate number of boards needed along depth
        const boardsAlongDepth = Math.ceil((depth * 12) / effectiveWidth);
        
        // Calculate board lengths needed based on width
        let deckBoards;
        if (boardType === 'trex-grooved') {
            // Trex grooved comes in 12', 16', 20' lengths - optimize for least waste
            deckBoards = calculateOptimalBoards(width, boardsAlongDepth, [12, 16, 20]);
        } else if (boardType === 'trex-square') {
            // Trex square only in 20'
            deckBoards = calculateOptimalBoards(width, boardsAlongDepth, [20]);
        } else {
            // Wood/other composite - assume 12' boards
            deckBoards = calculateOptimalBoards(width, boardsAlongDepth, [12]);
        }

        // Calculate framing materials
        const joistSpacing = 16; // inches
        const joists = Math.ceil((width * 12) / joistSpacing) + 1; // +1 for rim joist
        const beams = Math.ceil(width / 8);
        const posts = Math.ceil(width / 6) * 2; // Posts on both sides
        const concrete = posts * 3; // 3 bags per post

        // Calculate fasteners
        const screwSpacing = 12; // inches along board length
        const screwsPerBoard = Math.ceil((depth * 12) / screwSpacing) * 2; // 2 screws per joist
        const totalScrews = screwsPerBoard * boardsAlongDepth;
        const fastenerBoxes = Math.ceil(totalScrews / 250); // 250 screws per box
        
        // Update results display
        document.getElementById('deck-boards').textContent = `${deckBoards.total} ${boardType.includes('trex') ? 'Trex' : boardType === 'wood' ? 'Wood' : 'Composite'} boards`;
        document.getElementById('joists').textContent = `${joists} (2×8 @ 16" OC)`;
        document.getElementById('beams').textContent = `${beams} (4×6)`;
        document.getElementById('posts').textContent = `${posts} (6×6)`;
        document.getElementById('concrete').textContent = `${concrete} bags`;
        document.getElementById('fasteners').textContent = `${fastenerBoxes} boxes`;

        // Add special features if checked
        if (hasStairs) {
            document.getElementById('deck-boards').textContent += ` + ${stepCount} stair treads`;
            document.getElementById('joists').textContent += ` + ${stepCount} stair stringers`;
        }
        if (hasRailing) {
            const railingLength = width * 2; // Assuming 2 sides
            const railingPosts = Math.ceil(railingLength / 6) * 2; // 6' max spacing, 2 per section
            document.getElementById('deck-boards').textContent += ` + ${Math.ceil(railingLength / 6)} railing sections`;
            document.getElementById('posts').textContent += ` + ${railingPosts} railing posts`;
        }
        if (hasRoof) {
            document.getElementById('joists').textContent += ` + ${Math.ceil(width / 2)} roof rafters`;
            document.getElementById('posts').textContent += ` + ${Math.ceil(width / 8) * 2} roof support posts`;
        }
    }

    function calculateOptimalBoards(width, count, availableLengths) {
        availableLengths.sort((a, b) => b - a); // Sort descending
        
        const result = {
            total: 0,
            lengths: {}
        };
        
        for (let i = 0; i < count; i++) {
            let remaining = width;
            let currentCut = {};
            
            while (remaining > 0) {
                for (const len of availableLengths) {
                    if (len <= remaining) {
                        currentCut[len] = (currentCut[len] || 0) + 1;
                        remaining -= len;
                        break;
                    }
                }
            }
            
            // Aggregate the lengths
            for (const [len, qty] of Object.entries(currentCut)) {
                result.lengths[len] = (result.lengths[len] || 0) + qty;
                result.total += qty;
            }
        }
        
        return result;
    }
});