101keyoperator commited on
Commit
ebd9a1b
·
verified ·
1 Parent(s): 19fe695

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +6 -4
  2. index.html +652 -19
  3. prompts.txt +1 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Vms
3
- emoji: 📈
4
- colorFrom: green
5
  colorTo: gray
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: vms
3
+ emoji: 🐳
4
+ colorFrom: yellow
5
  colorTo: gray
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,652 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Vending Machine Manager</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ .fade-in {
11
+ animation: fadeIn 0.3s ease-in-out;
12
+ }
13
+ @keyframes fadeIn {
14
+ from { opacity: 0; transform: translateY(10px); }
15
+ to { opacity: 1; transform: translateY(0); }
16
+ }
17
+ .profit-positive {
18
+ background-color: rgba(74, 222, 128, 0.2);
19
+ }
20
+ .profit-negative {
21
+ background-color: rgba(248, 113, 113, 0.2);
22
+ }
23
+ .scrollbar-hide::-webkit-scrollbar {
24
+ display: none;
25
+ }
26
+ .highlight-row {
27
+ animation: highlight 2s ease-out;
28
+ }
29
+ @keyframes highlight {
30
+ 0% { background-color: rgba(255, 255, 0, 0.3); }
31
+ 100% { background-color: transparent; }
32
+ }
33
+ </style>
34
+ </head>
35
+ <body class="bg-gray-100 min-h-screen">
36
+ <div class="container mx-auto px-4 py-8">
37
+ <!-- Header -->
38
+ <header class="mb-8">
39
+ <div class="flex justify-between items-center">
40
+ <h1 class="text-3xl font-bold text-indigo-700">
41
+ <i class="fas fa-cubes mr-2"></i> Vending Machine Manager
42
+ </h1>
43
+ <div class="flex space-x-4">
44
+ <button id="importBtn" class="bg-gray-200 hover:bg-gray-300 px-4 py-2 rounded-lg transition">
45
+ <i class="fas fa-file-import mr-2"></i> Import
46
+ </button>
47
+ <button id="exportBtn" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg transition">
48
+ <i class="fas fa-file-export mr-2"></i> Export
49
+ </button>
50
+ </div>
51
+ </div>
52
+ <p class="text-gray-600 mt-2">Manage inventory, pricing, and track weekly profits</p>
53
+ </header>
54
+
55
+ <!-- Main Content -->
56
+ <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
57
+ <!-- Inventory List -->
58
+ <div class="lg:col-span-2 bg-white rounded-xl shadow-md overflow-hidden">
59
+ <div class="p-6">
60
+ <div class="flex justify-between items-center mb-6">
61
+ <h2 class="text-xl font-semibold text-gray-800">
62
+ <i class="fas fa-boxes mr-2 text-indigo-500"></i> Inventory
63
+ </h2>
64
+ <div class="flex space-x-3">
65
+ <button id="endWeekBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition">
66
+ <i class="fas fa-calendar-week mr-2"></i> End Week
67
+ </button>
68
+ <button id="addItemBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg transition">
69
+ <i class="fas fa-plus mr-2"></i> Add Item
70
+ </button>
71
+ </div>
72
+ </div>
73
+
74
+ <div class="overflow-x-auto">
75
+ <table class="min-w-full divide-y divide-gray-200">
76
+ <thead class="bg-gray-50">
77
+ <tr>
78
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Item</th>
79
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Stock</th>
80
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Cost</th>
81
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Price</th>
82
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Profit</th>
83
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
84
+ </tr>
85
+ </thead>
86
+ <tbody id="inventoryTable" class="bg-white divide-y divide-gray-200">
87
+ <!-- Items will be added here dynamically -->
88
+ </tbody>
89
+ </table>
90
+ </div>
91
+ </div>
92
+ </div>
93
+
94
+ <!-- Stats and Profit Summary -->
95
+ <div class="space-y-6">
96
+ <!-- Profit Summary -->
97
+ <div class="bg-white rounded-xl shadow-md p-6">
98
+ <h2 class="text-xl font-semibold text-gray-800 mb-4">
99
+ <i class="fas fa-chart-line mr-2 text-indigo-500"></i> Profit Summary
100
+ </h2>
101
+ <div class="space-y-4">
102
+ <div class="flex justify-between items-center">
103
+ <span class="text-gray-600">Today's Profit:</span>
104
+ <span id="todayProfit" class="font-bold text-green-600">$0.00</span>
105
+ </div>
106
+ <div class="flex justify-between items-center">
107
+ <span class="text-gray-600">Weekly Profit:</span>
108
+ <span id="weeklyProfit" class="font-bold text-green-600">$0.00</span>
109
+ </div>
110
+ <div class="flex justify-between items-center">
111
+ <span class="text-gray-600">Monthly Profit:</span>
112
+ <span id="monthlyProfit" class="font-bold text-green-600">$0.00</span>
113
+ </div>
114
+ <div class="flex justify-between items-center">
115
+ <span class="text-gray-600">Total Profit:</span>
116
+ <span id="totalProfit" class="font-bold text-green-600">$0.00</span>
117
+ </div>
118
+ </div>
119
+ </div>
120
+
121
+ <!-- Weekly Sales -->
122
+ <div class="bg-white rounded-xl shadow-md p-6">
123
+ <h2 class="text-xl font-semibold text-gray-800 mb-4">
124
+ <i class="fas fa-calendar-week mr-2 text-indigo-500"></i> Weekly Sales
125
+ </h2>
126
+ <div id="weeklySalesList" class="space-y-3 max-h-60 overflow-y-auto scrollbar-hide">
127
+ <!-- Weekly sales will be added here dynamically -->
128
+ <div class="text-gray-500 italic">No weekly sales recorded</div>
129
+ </div>
130
+ </div>
131
+
132
+ <!-- Recent Transactions -->
133
+ <div class="bg-white rounded-xl shadow-md p-6">
134
+ <h2 class="text-xl font-semibold text-gray-800 mb-4">
135
+ <i class="fas fa-history mr-2 text-indigo-500"></i> Recent Transactions
136
+ </h2>
137
+ <div id="transactionsList" class="space-y-3 max-h-60 overflow-y-auto scrollbar-hide">
138
+ <!-- Transactions will be added here dynamically -->
139
+ <div class="text-gray-500 italic">No recent transactions</div>
140
+ </div>
141
+ </div>
142
+ </div>
143
+ </div>
144
+ </div>
145
+
146
+ <!-- Add/Edit Item Modal -->
147
+ <div id="itemModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
148
+ <div class="bg-white rounded-xl p-6 w-full max-w-md fade-in">
149
+ <div class="flex justify-between items-center mb-4">
150
+ <h3 class="text-xl font-semibold" id="modalTitle">Add New Item</h3>
151
+ <button id="closeModal" class="text-gray-500 hover:text-gray-700">
152
+ <i class="fas fa-times"></i>
153
+ </button>
154
+ </div>
155
+ <form id="itemForm" class="space-y-4">
156
+ <input type="hidden" id="itemId">
157
+ <div>
158
+ <label for="itemName" class="block text-sm font-medium text-gray-700">Item Name</label>
159
+ <input type="text" id="itemName" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
160
+ </div>
161
+ <div>
162
+ <label for="itemStock" class="block text-sm font-medium text-gray-700">Stock Quantity</label>
163
+ <input type="number" id="itemStock" min="0" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
164
+ </div>
165
+ <div>
166
+ <label for="itemCost" class="block text-sm font-medium text-gray-700">Cost Price ($)</label>
167
+ <input type="number" id="itemCost" min="0" step="0.01" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
168
+ </div>
169
+ <div>
170
+ <label for="itemPrice" class="block text-sm font-medium text-gray-700">Retail Price ($)</label>
171
+ <input type="number" id="itemPrice" min="0" step="0.01" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
172
+ </div>
173
+ <div class="flex justify-end space-x-3 pt-4">
174
+ <button type="button" id="cancelBtn" class="bg-gray-200 hover:bg-gray-300 px-4 py-2 rounded-lg transition">Cancel</button>
175
+ <button type="submit" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg transition">Save</button>
176
+ </div>
177
+ </form>
178
+ </div>
179
+ </div>
180
+
181
+ <!-- End Week Modal -->
182
+ <div id="endWeekModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
183
+ <div class="bg-white rounded-xl p-6 w-full max-w-2xl fade-in">
184
+ <div class="flex justify-between items-center mb-4">
185
+ <h3 class="text-xl font-semibold">End of Week Inventory</h3>
186
+ <button id="closeEndWeekModal" class="text-gray-500 hover:text-gray-700">
187
+ <i class="fas fa-times"></i>
188
+ </button>
189
+ </div>
190
+ <div class="mb-4">
191
+ <p class="text-gray-600">Enter remaining inventory quantities to calculate weekly sales and profit.</p>
192
+ </div>
193
+ <div class="overflow-x-auto">
194
+ <table class="min-w-full divide-y divide-gray-200">
195
+ <thead class="bg-gray-50">
196
+ <tr>
197
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Item</th>
198
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Starting Stock</th>
199
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Remaining Stock</th>
200
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Sold</th>
201
+ <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Profit</th>
202
+ </tr>
203
+ </thead>
204
+ <tbody id="endWeekTable" class="bg-white divide-y divide-gray-200">
205
+ <!-- Items will be added here dynamically -->
206
+ </tbody>
207
+ </table>
208
+ </div>
209
+ <div class="mt-4 flex justify-between items-center">
210
+ <div class="text-lg font-semibold">
211
+ Total Weekly Profit: <span id="weeklyTotalProfit" class="text-green-600">$0.00</span>
212
+ </div>
213
+ <div class="flex space-x-3">
214
+ <button id="cancelEndWeekBtn" class="bg-gray-200 hover:bg-gray-300 px-4 py-2 rounded-lg transition">Cancel</button>
215
+ <button id="confirmEndWeekBtn" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition">
216
+ <i class="fas fa-check mr-2"></i> Confirm
217
+ </button>
218
+ </div>
219
+ </div>
220
+ </div>
221
+ </div>
222
+
223
+ <!-- Import/Export Modal -->
224
+ <div id="dataModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden z-50">
225
+ <div class="bg-white rounded-xl p-6 w-full max-w-md fade-in">
226
+ <div class="flex justify-between items-center mb-4">
227
+ <h3 class="text-xl font-semibold" id="dataModalTitle">Export Data</h3>
228
+ <button id="closeDataModal" class="text-gray-500 hover:text-gray-700">
229
+ <i class="fas fa-times"></i>
230
+ </button>
231
+ </div>
232
+ <div id="exportContent" class="space-y-4">
233
+ <p class="text-gray-600">Copy the data below to save it:</p>
234
+ <textarea id="exportData" class="w-full h-40 border border-gray-300 rounded-md p-3 font-mono text-sm" readonly></textarea>
235
+ <button id="copyDataBtn" class="bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg transition w-full">
236
+ <i class="fas fa-copy mr-2"></i> Copy to Clipboard
237
+ </button>
238
+ </div>
239
+ <div id="importContent" class="space-y-4 hidden">
240
+ <p class="text-gray-600">Paste your saved data below:</p>
241
+ <textarea id="importData" class="w-full h-40 border border-gray-300 rounded-md p-3 font-mono text-sm"></textarea>
242
+ <button id="confirmImportBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg transition w-full">
243
+ <i class="fas fa-check mr-2"></i> Import Data
244
+ </button>
245
+ </div>
246
+ </div>
247
+ </div>
248
+
249
+ <script>
250
+ // Sample initial data
251
+ let inventory = [];
252
+ let transactions = [];
253
+ let weeklySales = [];
254
+ let editMode = false;
255
+ let currentEditId = null;
256
+ let currentWeekStart = new Date();
257
+ let startingInventory = [];
258
+
259
+ // DOM Elements
260
+ const inventoryTable = document.getElementById('inventoryTable');
261
+ const itemModal = document.getElementById('itemModal');
262
+ const dataModal = document.getElementById('dataModal');
263
+ const endWeekModal = document.getElementById('endWeekModal');
264
+ const addItemBtn = document.getElementById('addItemBtn');
265
+ const endWeekBtn = document.getElementById('endWeekBtn');
266
+ const closeModal = document.getElementById('closeModal');
267
+ const closeDataModal = document.getElementById('closeDataModal');
268
+ const closeEndWeekModal = document.getElementById('closeEndWeekModal');
269
+ const cancelBtn = document.getElementById('cancelBtn');
270
+ const cancelEndWeekBtn = document.getElementById('cancelEndWeekBtn');
271
+ const confirmEndWeekBtn = document.getElementById('confirmEndWeekBtn');
272
+ const itemForm = document.getElementById('itemForm');
273
+ const importBtn = document.getElementById('importBtn');
274
+ const exportBtn = document.getElementById('exportBtn');
275
+ const exportContent = document.getElementById('exportContent');
276
+ const importContent = document.getElementById('importContent');
277
+ const dataModalTitle = document.getElementById('dataModalTitle');
278
+ const exportData = document.getElementById('exportData');
279
+ const importData = document.getElementById('importData');
280
+ const copyDataBtn = document.getElementById('copyDataBtn');
281
+ const confirmImportBtn = document.getElementById('confirmImportBtn');
282
+ const transactionsList = document.getElementById('transactionsList');
283
+ const weeklySalesList = document.getElementById('weeklySalesList');
284
+ const todayProfit = document.getElementById('todayProfit');
285
+ const weeklyProfit = document.getElementById('weeklyProfit');
286
+ const monthlyProfit = document.getElementById('monthlyProfit');
287
+ const totalProfit = document.getElementById('totalProfit');
288
+ const endWeekTable = document.getElementById('endWeekTable');
289
+ const weeklyTotalProfit = document.getElementById('weeklyTotalProfit');
290
+
291
+ // Initialize the app
292
+ document.addEventListener('DOMContentLoaded', () => {
293
+ // Set current week start to Monday of this week
294
+ const today = new Date();
295
+ const day = today.getDay();
296
+ const diff = today.getDate() - day + (day === 0 ? -6 : 1); // adjust when day is Sunday
297
+ currentWeekStart = new Date(today.setDate(diff));
298
+ currentWeekStart.setHours(0, 0, 0, 0);
299
+
300
+ renderInventory();
301
+ updateProfitSummary();
302
+ renderWeeklySales();
303
+ });
304
+
305
+ // Render inventory table
306
+ function renderInventory() {
307
+ inventoryTable.innerHTML = '';
308
+
309
+ if (inventory.length === 0) {
310
+ inventoryTable.innerHTML = `
311
+ <tr>
312
+ <td colspan="6" class="px-6 py-4 text-center text-gray-500">No items in inventory. Add your first item!</td>
313
+ </tr>
314
+ `;
315
+ return;
316
+ }
317
+
318
+ inventory.forEach(item => {
319
+ const profit = (item.price - item.cost) * item.stock;
320
+ const profitClass = profit >= 0 ? 'text-green-600' : 'text-red-600';
321
+ const profitDisplay = profit >= 0 ? `+$${profit.toFixed(2)}` : `-$${Math.abs(profit).toFixed(2)}`;
322
+
323
+ const row = document.createElement('tr');
324
+ row.className = 'hover:bg-gray-50';
325
+ row.innerHTML = `
326
+ <td class="px-6 py-4 whitespace-nowrap">
327
+ <div class="font-medium text-gray-900">${item.name}</div>
328
+ </td>
329
+ <td class="px-6 py-4 whitespace-nowrap">
330
+ <div class="text-gray-900">${item.stock}</div>
331
+ </td>
332
+ <td class="px-6 py-4 whitespace-nowrap">
333
+ <div class="text-gray-900">$${item.cost.toFixed(2)}</div>
334
+ </td>
335
+ <td class="px-6 py-4 whitespace-nowrap">
336
+ <div class="text-gray-900">$${item.price.toFixed(2)}</div>
337
+ </td>
338
+ <td class="px-6 py-4 whitespace-nowrap">
339
+ <div class="${profitClass}">${profitDisplay}</div>
340
+ </td>
341
+ <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
342
+ <button class="text-indigo-600 hover:text-indigo-900 mr-3 edit-btn" data-id="${item.id}">
343
+ <i class="fas fa-edit"></i>
344
+ </button>
345
+ <button class="text-red-600 hover:text-red-900 delete-btn" data-id="${item.id}">
346
+ <i class="fas fa-trash"></i>
347
+ </button>
348
+ </td>
349
+ `;
350
+ inventoryTable.appendChild(row);
351
+ });
352
+
353
+ // Add event listeners to edit and delete buttons
354
+ document.querySelectorAll('.edit-btn').forEach(btn => {
355
+ btn.addEventListener('click', (e) => {
356
+ const id = parseInt(e.currentTarget.getAttribute('data-id'));
357
+ editItem(id);
358
+ });
359
+ });
360
+
361
+ document.querySelectorAll('.delete-btn').forEach(btn => {
362
+ btn.addEventListener('click', (e) => {
363
+ const id = parseInt(e.currentTarget.getAttribute('data-id'));
364
+ deleteItem(id);
365
+ });
366
+ });
367
+ }
368
+
369
+ // Add new item
370
+ addItemBtn.addEventListener('click', () => {
371
+ editMode = false;
372
+ currentEditId = null;
373
+ document.getElementById('modalTitle').textContent = 'Add New Item';
374
+ document.getElementById('itemForm').reset();
375
+ document.getElementById('itemId').value = '';
376
+ itemModal.classList.remove('hidden');
377
+ });
378
+
379
+ // Edit item
380
+ function editItem(id) {
381
+ const item = inventory.find(item => item.id === id);
382
+ if (!item) return;
383
+
384
+ editMode = true;
385
+ currentEditId = id;
386
+ document.getElementById('modalTitle').textContent = 'Edit Item';
387
+ document.getElementById('itemId').value = item.id;
388
+ document.getElementById('itemName').value = item.name;
389
+ document.getElementById('itemStock').value = item.stock;
390
+ document.getElementById('itemCost').value = item.cost;
391
+ document.getElementById('itemPrice').value = item.price;
392
+ itemModal.classList.remove('hidden');
393
+ }
394
+
395
+ // Delete item
396
+ function deleteItem(id) {
397
+ if (confirm('Are you sure you want to delete this item?')) {
398
+ inventory = inventory.filter(item => item.id !== id);
399
+ renderInventory();
400
+ updateProfitSummary();
401
+ }
402
+ }
403
+
404
+ // Close modal
405
+ closeModal.addEventListener('click', () => {
406
+ itemModal.classList.add('hidden');
407
+ });
408
+
409
+ cancelBtn.addEventListener('click', () => {
410
+ itemModal.classList.add('hidden');
411
+ });
412
+
413
+ // Save item (add or edit)
414
+ itemForm.addEventListener('submit', (e) => {
415
+ e.preventDefault();
416
+
417
+ const id = editMode ? currentEditId : Date.now();
418
+ const name = document.getElementById('itemName').value;
419
+ const stock = parseInt(document.getElementById('itemStock').value);
420
+ const cost = parseFloat(document.getElementById('itemCost').value);
421
+ const price = parseFloat(document.getElementById('itemPrice').value);
422
+
423
+ if (!name || isNaN(stock) || isNaN(cost) || isNaN(price)) {
424
+ alert('Please fill in all fields with valid values');
425
+ return;
426
+ }
427
+
428
+ if (editMode) {
429
+ // Update existing item
430
+ const index = inventory.findIndex(item => item.id === id);
431
+ if (index !== -1) {
432
+ const oldStock = inventory[index].stock;
433
+ inventory[index] = { id, name, stock, cost, price };
434
+
435
+ // Record transaction if stock changed
436
+ if (oldStock !== stock) {
437
+ const transaction = {
438
+ date: new Date(),
439
+ type: 'stock_update',
440
+ itemId: id,
441
+ itemName: name,
442
+ quantity: stock - oldStock,
443
+ cost: cost,
444
+ price: price
445
+ };
446
+ transactions.unshift(transaction);
447
+ renderTransactions();
448
+ }
449
+ }
450
+ } else {
451
+ // Add new item
452
+ inventory.push({ id, name, stock, cost, price });
453
+
454
+ // Record transaction for new item
455
+ const transaction = {
456
+ date: new Date(),
457
+ type: 'new_item',
458
+ itemId: id,
459
+ itemName: name,
460
+ quantity: stock,
461
+ cost: cost,
462
+ price: price
463
+ };
464
+ transactions.unshift(transaction);
465
+ renderTransactions();
466
+ }
467
+
468
+ renderInventory();
469
+ updateProfitSummary();
470
+ itemModal.classList.add('hidden');
471
+ });
472
+
473
+ // End Week functionality
474
+ endWeekBtn.addEventListener('click', () => {
475
+ if (inventory.length === 0) {
476
+ alert('No items in inventory to track weekly sales');
477
+ return;
478
+ }
479
+
480
+ // Save current inventory as starting point for the week
481
+ startingInventory = JSON.parse(JSON.stringify(inventory));
482
+
483
+ // Populate the end week modal
484
+ endWeekTable.innerHTML = '';
485
+ let totalProfit = 0;
486
+
487
+ inventory.forEach(item => {
488
+ const row = document.createElement('tr');
489
+ row.className = 'hover:bg-gray-50';
490
+ row.innerHTML = `
491
+ <td class="px-6 py-4 whitespace-nowrap">
492
+ <div class="font-medium text-gray-900">${item.name}</div>
493
+ </td>
494
+ <td class="px-6 py-4 whitespace-nowrap">
495
+ <div class="text-gray-900">${item.stock}</div>
496
+ </td>
497
+ <td class="px-6 py-4 whitespace-nowrap">
498
+ <input type="number" min="0" max="${item.stock}"
499
+ class="remaining-stock border border-gray-300 rounded px-2 py-1 w-20 text-center"
500
+ value="${item.stock}" data-id="${item.id}" data-start="${item.stock}">
501
+ </td>
502
+ <td class="px-6 py-4 whitespace-nowrap">
503
+ <div class="sold-quantity text-gray-900">0</div>
504
+ </td>
505
+ <td class="px-6 py-4 whitespace-nowrap">
506
+ <div class="item-profit text-green-600">$0.00</div>
507
+ </td>
508
+ `;
509
+ endWeekTable.appendChild(row);
510
+ });
511
+
512
+ // Add event listeners to remaining stock inputs
513
+ document.querySelectorAll('.remaining-stock').forEach(input => {
514
+ input.addEventListener('input', updateWeeklyProfitCalculation);
515
+ });
516
+
517
+ weeklyTotalProfit.textContent = '$0.00';
518
+ endWeekModal.classList.remove('hidden');
519
+ });
520
+
521
+ // Update weekly profit calculation when remaining stock changes
522
+ function updateWeeklyProfitCalculation() {
523
+ let totalProfit = 0;
524
+
525
+ document.querySelectorAll('.remaining-stock').forEach(input => {
526
+ const id = parseInt(input.getAttribute('data-id'));
527
+ const startStock = parseInt(input.getAttribute('data-start'));
528
+ const remainingStock = parseInt(input.value) || 0;
529
+ const sold = startStock - remainingStock;
530
+
531
+ const item = inventory.find(item => item.id === id);
532
+ if (item) {
533
+ const profit = sold * (item.price - item.cost);
534
+ totalProfit += profit;
535
+
536
+ // Update the row
537
+ const row = input.closest('tr');
538
+ row.querySelector('.sold-quantity').textContent = sold;
539
+ row.querySelector('.item-profit').textContent = formatCurrency(profit);
540
+ row.querySelector('.item-profit').className = `item-profit ${profit >= 0 ? 'text-green-600' : 'text-red-600'}`;
541
+ }
542
+ });
543
+
544
+ weeklyTotalProfit.textContent = formatCurrency(totalProfit);
545
+ weeklyTotalProfit.className = `text-lg font-semibold ${totalProfit >= 0 ? 'text-green-600' : 'text-red-600'}`;
546
+ }
547
+
548
+ // Close end week modal
549
+ closeEndWeekModal.addEventListener('click', () => {
550
+ endWeekModal.classList.add('hidden');
551
+ });
552
+
553
+ cancelEndWeekBtn.addEventListener('click', () => {
554
+ endWeekModal.classList.add('hidden');
555
+ });
556
+
557
+ // Confirm end week
558
+ confirmEndWeekBtn.addEventListener('click', () => {
559
+ const weekEndDate = new Date();
560
+ const weekStartDate = new Date(currentWeekStart);
561
+
562
+ let totalProfit = 0;
563
+ const weekItems = [];
564
+
565
+ document.querySelectorAll('.remaining-stock').forEach(input => {
566
+ const id = parseInt(input.getAttribute('data-id'));
567
+ const startStock = parseInt(input.getAttribute('data-start'));
568
+ const remainingStock = parseInt(input.value) || 0;
569
+ const sold = startStock - remainingStock;
570
+
571
+ const item = inventory.find(item => item.id === id);
572
+ if (item) {
573
+ const profit = sold * (item.price - item.cost);
574
+ totalProfit += profit;
575
+
576
+ // Update inventory
577
+ item.stock = remainingStock;
578
+
579
+ // Record transaction
580
+ if (sold > 0) {
581
+ const transaction = {
582
+ date: weekEndDate,
583
+ type: 'weekly_sale',
584
+ itemId: id,
585
+ itemName: item.name,
586
+ quantity: -sold, // negative because stock decreased
587
+ cost: item.cost,
588
+ price: item.price
589
+ };
590
+ transactions.unshift(transaction);
591
+ }
592
+
593
+ // Add to week items
594
+ weekItems.push({
595
+ itemId: id,
596
+ itemName: item.name,
597
+ startStock,
598
+ endStock: remainingStock,
599
+ sold,
600
+ profit
601
+ });
602
+ }
603
+ });
604
+
605
+ // Record weekly sale
606
+ weeklySales.unshift({
607
+ startDate: weekStartDate,
608
+ endDate: weekEndDate,
609
+ items: weekItems,
610
+ totalProfit
611
+ });
612
+
613
+ // Set new week start date (next Monday)
614
+ const nextMonday = new Date(weekEndDate);
615
+ nextMonday.setDate(nextMonday.getDate() + (7 - nextMonday.getDay() + 1) % 7);
616
+ currentWeekStart = nextMonday;
617
+
618
+ // Update UI
619
+ renderInventory();
620
+ renderTransactions();
621
+ renderWeeklySales();
622
+ updateProfitSummary();
623
+
624
+ endWeekModal.classList.add('hidden');
625
+
626
+ // Highlight inventory table to show changes
627
+ inventoryTable.querySelectorAll('tr').forEach(row => {
628
+ row.classList.add('highlight-row');
629
+ setTimeout(() => {
630
+ row.classList.remove('highlight-row');
631
+ }, 2000);
632
+ });
633
+ });
634
+
635
+ // Render weekly sales
636
+ function renderWeeklySales() {
637
+ weeklySalesList.innerHTML = '';
638
+
639
+ if (weeklySales.length === 0) {
640
+ weeklySalesList.innerHTML = '<div class="text-gray-500 italic">No weekly sales recorded</div>';
641
+ return;
642
+ }
643
+
644
+ // Show only the last 5 weekly sales
645
+ const recentWeeklySales = weeklySales.slice(0, 5);
646
+
647
+ recentWeeklySales.forEach(sale => {
648
+ const startDate = new Date(sale.startDate).toLocaleDateString();
649
+ const endDate = new Date(sale.endDate).toLocaleDateString();
650
+ const profitClass = sale.totalProfit >= 0 ? 'profit-positive' : 'profit-negative';
651
+ const profitDisplay = formatCurrency(s
652
+ </html>
prompts.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Modify this code to allow the user to input remaining inventory at the end of a sales week, then calculate how much profit was generated for the week.