File size: 5,593 Bytes
42bc60d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ac4facb
42bc60d
 
 
 
 
ac4facb
 
 
42bc60d
 
 
 
 
 
 
ac4facb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42bc60d
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Production Plan</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/feather-icons"></script>
</head>
<body class="min-h-screen bg-gray-50">
    <!-- Fixed Top Panel -->
    <div class="fixed top-0 left-0 right-0 bg-white shadow-sm z-10 p-4 flex items-center">
        <a href="welders.html" class="mr-4 text-gray-600 hover:text-gray-800">
            <i data-feather="home"></i>
        </a>
        <h1 class="text-xl font-semibold">Production Plan</h1>
    </div>

    <!-- Input Section -->
    <div class="mt-16 p-4">
        <div class="bg-white rounded-lg shadow p-4">
            <div class="flex mb-2">
                <input type="text" placeholder="Article" class="flex-1 p-2 border rounded-l">
                <input type="number" placeholder="Qty" class="w-20 p-2 border-t border-b">
                <button class="bg-blue-500 text-white px-4 rounded-r flex items-center">
                    <i data-feather="plus" class="mr-2"></i>Add
                </button>
            </div>
        </div>
    </div>
    <!-- Plan List -->
    <div id="plan-list" class="p-4 space-y-4 mb-24"></div>

    <!-- Fixed Bottom Panel -->
    <div class="fixed bottom-0 left-0 right-0 bg-white shadow-md z-10 p-4">
        <div class="font-medium mb-2 text-gray-700">Norms</div>
        <div class="flex">
            <input id="norm-article" type="text" placeholder="Article" class="flex-1 p-2 border rounded-l">
            <input id="norm-time" type="number" placeholder="Time norm" step="0.1" class="w-24 p-2 border-t border-b">
            <button id="add-norm" class="bg-gray-600 text-white px-4 rounded-r flex items-center">
                <i data-feather="plus" class="mr-2"></i>Add
            </button>
        </div>
    </div>

    <script>
        feather.replace();

        // Load plans and norms
        async function loadData() {
            try {
                // Load plans
                const plansResponse = await fetch('http://localhost:8080/plans');
                const plans = await plansResponse.json();
                
                const planList = document.getElementById('plan-list');
                planList.innerHTML = '';
                
                plans.forEach(plan => {
                    const assignments = Object.entries(plan.assignments)
                        .map(([welderId, qty]) => `${welderId}: ${qty}`)
                        .join(', ');
                    
                    const planItem = document.createElement('div');
                    planItem.className = plan.completed_quantity === plan.total_quantity 
                        ? 'bg-white rounded-lg shadow overflow-hidden completed-plan'
                        : 'bg-white rounded-lg shadow overflow-hidden';
                    
                    planItem.innerHTML = `
                        <div class="p-4">
                            <div class="flex items-center">
                                <div class="flex-1">
                                    <div class="font-medium">${plan.article_code}</div>
                                </div>
                                <div class="${plan.completed_quantity === plan.total_quantity ? 'text-green-500' : 'text-gray-500'} font-medium">
                                    ${plan.completed_quantity}/${plan.total_quantity}
                                </div>
                            </div>
                            <div class="mt-2 text-sm text-gray-500">
                                <div>${assignments}</div>
                            </div>
                        </div>
                    `;
                    planList.appendChild(planItem);
                });

                // Load norms (could be used for display if needed)
                const normsResponse = await fetch('http://localhost:8080/norms');
                const norms = await normsResponse.json();
                console.log('Loaded norms:', norms);
            } catch (error) {
                console.error('Error loading data:', error);
            }
        }

        // Add new norm
        document.getElementById('add-norm').addEventListener('click', async () => {
            const article = document.getElementById('norm-article').value.trim();
            const timeNorm = parseFloat(document.getElementById('norm-time').value);
            
            if (article && !isNaN(timeNorm) && timeNorm > 0) {
                try {
                    const response = await fetch('http://localhost:8080/norms', {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json',
                        },
                        body: JSON.stringify({
                            article_code: article,
                            time_norm: timeNorm
                        }),
                    });
                    
                    if (response.ok) {
                        document.getElementById('norm-article').value = '';
                        document.getElementById('norm-time').value = '';
                        console.log('Norm added successfully');
                    }
                } catch (error) {
                    console.error('Error adding norm:', error);
                }
            }
        });

        // Load initial data
        loadData();
    </script>
</body>
</html>