ShoaibAI commited on
Commit
f0bf16e
·
verified ·
1 Parent(s): 66ee011

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +277 -5
index.html CHANGED
@@ -62,6 +62,12 @@
62
  <span class="sidebar-text ml-3">Dashboard</span>
63
  </a>
64
  </li>
 
 
 
 
 
 
65
  <li>
66
  <a href="#" id="add-item-link" class="nav-item flex items-center py-2 px-3 rounded-lg hover:bg-blue-700 text-white mb-2">
67
  <i class="fas fa-plus-circle"></i>
@@ -220,6 +226,44 @@
220
  </div>
221
  </div>
222
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
  <!-- Add Item Content -->
224
  <div id="add-item-content" class="hidden fade-in">
225
  <div class="bg-white rounded-lg shadow p-6 mb-6">
@@ -633,7 +677,7 @@
633
  addItemContent.classList.add('hidden');
634
  viewItemsContent.classList.add('hidden');
635
 
636
- content.classList.remove('hidden');
637
  pageTitle.textContent = title;
638
 
639
  if (content === viewItemsContent) {
@@ -647,19 +691,19 @@
647
  dashboardLink.addEventListener('click', function(e) {
648
  e.preventDefault();
649
  setActiveNavItem(this);
650
- showContent(dashboardContent, 'Dashboard');
651
  });
652
 
653
  addItemLink.addEventListener('click', function(e) {
654
  e.preventDefault();
655
  setActiveNavItem(this);
656
- showContent(addItemContent, 'Add New Item');
657
  });
658
 
659
  viewItemsLink.addEventListener('click', function(e) {
660
  e.preventDefault();
661
  setActiveNavItem(this);
662
- showContent(viewItemsContent, 'Inventory Items');
663
  });
664
 
665
  // Toggle sidebar
@@ -766,7 +810,7 @@
766
  ${item.quantity} ${item.unit}
767
  </td>
768
  <td class="py-3 px-4 text-right">$${item.sellingPrice.toFixed(2)}</td>
769
- <td class="py-3 px-4 text-center">
770
  <button class="edit-btn px-2 py-1 bg-blue-100 text-blue-600 rounded mr-1" data-id="${item.id}">
771
  <i class="fas fa-edit"></i>
772
  </button>
@@ -1139,6 +1183,234 @@
1139
  // Initialize dashboard
1140
  setActiveNavItem(dashboardLink);
1141
  updateDashboardStats();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1142
  });
1143
  </script>
1144
  </body>
 
62
  <span class="sidebar-text ml-3">Dashboard</span>
63
  </a>
64
  </li>
65
+ <li>
66
+ <a href="#" id="counter-link" class="nav-item flex items-center py-2 px-3 rounded-lg hover:bg-blue-700 text-white mb-2">
67
+ <i class="fas fa-cash-register"></i>
68
+ <span class="sidebar-text ml-3">Counter</span>
69
+ </a>
70
+ </li>
71
  <li>
72
  <a href="#" id="add-item-link" class="nav-item flex items-center py-2 px-3 rounded-lg hover:bg-blue-700 text-white mb-2">
73
  <i class="fas fa-plus-circle"></i>
 
226
  </div>
227
  </div>
228
 
229
+ <!-- Counter Content -->
230
+ <div id="counter-content" class="hidden fade-in">
231
+ <div class="bg-white rounded-lg shadow p-6">
232
+ <h2 class="text-xl font-semibold mb-6">Counter Sales</h2>
233
+
234
+ <!-- Search Bar -->
235
+ <div class="mb-6">
236
+ <input type="text" id="medicine-search" placeholder="Search medicines..."
237
+ class="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
238
+ </div>
239
+
240
+ <!-- Available Medicines -->
241
+ <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-6" id="available-medicines">
242
+ <!-- Medicines will be populated here by JavaScript -->
243
+ </div>
244
+
245
+ <!-- Selected Items -->
246
+ <div class="mt-8">
247
+ <h3 class="text-lg font-semibold mb-4">Selected Items</h3>
248
+ <div class="bg-gray-50 rounded-lg p-4">
249
+ <div id="selected-items" class="mb-4">
250
+ <!-- Selected items will be added here -->
251
+ <p class="text-gray-500 text-center py-4">No items selected</p>
252
+ </div>
253
+ <div class="border-t pt-4">
254
+ <div class="flex justify-between items-center">
255
+ <span class="font-semibold">Total:</span>
256
+ <span id="sale-total" class="text-xl font-bold">$0.00</span>
257
+ </div>
258
+ <button id="complete-sale" class="w-full mt-4 bg-green-600 text-white py-2 px-4 rounded-lg hover:bg-green-700 transition-colors">
259
+ Complete Sale
260
+ </button>
261
+ </div>
262
+ </div>
263
+ </div>
264
+ </div>
265
+ </div>
266
+
267
  <!-- Add Item Content -->
268
  <div id="add-item-content" class="hidden fade-in">
269
  <div class="bg-white rounded-lg shadow p-6 mb-6">
 
677
  addItemContent.classList.add('hidden');
678
  viewItemsContent.classList.add('hidden');
679
 
680
+ document.getElementById(content + '-content').classList.remove('hidden');
681
  pageTitle.textContent = title;
682
 
683
  if (content === viewItemsContent) {
 
691
  dashboardLink.addEventListener('click', function(e) {
692
  e.preventDefault();
693
  setActiveNavItem(this);
694
+ showContent('dashboard', 'Dashboard');
695
  });
696
 
697
  addItemLink.addEventListener('click', function(e) {
698
  e.preventDefault();
699
  setActiveNavItem(this);
700
+ showContent('add-item', 'Add New Item');
701
  });
702
 
703
  viewItemsLink.addEventListener('click', function(e) {
704
  e.preventDefault();
705
  setActiveNavItem(this);
706
+ showContent('view-items', 'Inventory Items');
707
  });
708
 
709
  // Toggle sidebar
 
810
  ${item.quantity} ${item.unit}
811
  </td>
812
  <td class="py-3 px-4 text-right">$${item.sellingPrice.toFixed(2)}</td>
813
+ <td class="text-center py-3 px-4">
814
  <button class="edit-btn px-2 py-1 bg-blue-100 text-blue-600 rounded mr-1" data-id="${item.id}">
815
  <i class="fas fa-edit"></i>
816
  </button>
 
1183
  // Initialize dashboard
1184
  setActiveNavItem(dashboardLink);
1185
  updateDashboardStats();
1186
+
1187
+ // Counter functionality
1188
+ const counterLink = document.getElementById('counter-link');
1189
+ const counterContent = document.getElementById('counter-content');
1190
+
1191
+ counterLink.addEventListener('click', function(e) {
1192
+ e.preventDefault();
1193
+ setActiveNavItem(this);
1194
+ showContent('counter', 'Counter');
1195
+ renderAvailableMedicines();
1196
+ });
1197
+
1198
+ function renderAvailableMedicines(searchTerm = '') {
1199
+ const container = document.getElementById('available-medicines');
1200
+ container.innerHTML = '';
1201
+
1202
+ const filteredItems = inventoryItems.filter(item => {
1203
+ const matchesSearch = item.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
1204
+ item.description.toLowerCase().includes(searchTerm.toLowerCase());
1205
+ return item.quantity > 0 && matchesSearch;
1206
+ });
1207
+
1208
+ if (filteredItems.length === 0) {
1209
+ container.innerHTML = '<p class="text-gray-500 col-span-3 text-center py-4">No available medicines found</p>';
1210
+ return;
1211
+ }
1212
+
1213
+ filteredItems.forEach(item => {
1214
+ const card = document.createElement('div');
1215
+ card.className = 'bg-white border rounded-lg p-4 hover:shadow-md transition-shadow';
1216
+ card.innerHTML = `
1217
+ <h4 class="font-semibold">${item.name}</h4>
1218
+ <p class="text-sm text-gray-600 mb-2">${item.description || 'No description'}</p>
1219
+ <div class="flex justify-between items-center">
1220
+ <span class="text-green-600 font-semibold">$${item.sellingPrice?.toFixed(2) || '0.00'}</span>
1221
+ <span class="text-sm ${item.quantity < 10 ? 'text-red-500' : 'text-gray-500'}">
1222
+ ${item.quantity} in stock
1223
+ </span>
1224
+ </div>
1225
+ <div class="mt-3 flex items-center">
1226
+ <input type="number"
1227
+ min="1"
1228
+ max="${item.quantity}"
1229
+ value="1"
1230
+ class="w-16 px-2 py-1 border rounded mr-2"
1231
+ data-medicine-id="${item.id}">
1232
+ <button class="bg-blue-600 text-white px-3 py-1 rounded text-sm hover:bg-blue-700 add-to-cart"
1233
+ data-medicine='${JSON.stringify(item)}'>
1234
+ Add
1235
+ </button>
1236
+ </div>
1237
+ `;
1238
+ container.appendChild(card);
1239
+ });
1240
+
1241
+ // Add event listeners to all add buttons
1242
+ document.querySelectorAll('.add-to-cart').forEach(button => {
1243
+ button.addEventListener('click', addToCart);
1244
+ });
1245
+ }
1246
+
1247
+ function addToCart(e) {
1248
+ const button = e.target;
1249
+ const medicine = JSON.parse(button.getAttribute('data-medicine'));
1250
+ const quantityInput = button.previousElementSibling;
1251
+ const quantity = parseInt(quantityInput.value) || 1;
1252
+
1253
+ if (quantity < 1 || quantity > medicine.quantity) {
1254
+ showToast('Invalid quantity', 'error');
1255
+ return;
1256
+ }
1257
+
1258
+ // Add to selected items
1259
+ const selectedItems = document.getElementById('selected-items');
1260
+
1261
+ // Check if item already in cart
1262
+ const existingItem = selectedItems.querySelector(`[data-medicine-id="${medicine.id}"]`);
1263
+
1264
+ if (existingItem) {
1265
+ // Update existing item quantity
1266
+ const qtyInput = existingItem.querySelector('input[type="number"]');
1267
+ const newQty = parseInt(qtyInput.value) + quantity;
1268
+ if (newQty > medicine.quantity) {
1269
+ showToast('Not enough stock available', 'error');
1270
+ return;
1271
+ }
1272
+ qtyInput.value = newQty;
1273
+ updateItemTotal(existingItem, medicine.sellingPrice, newQty);
1274
+ } else {
1275
+ // Add new item
1276
+ const itemElement = document.createElement('div');
1277
+ itemElement.className = 'flex justify-between items-center py-2 border-b';
1278
+ itemElement.setAttribute('data-medicine-id', medicine.id);
1279
+ itemElement.innerHTML = `
1280
+ <div class="flex-1">
1281
+ <div class="font-medium">${medicine.name}</div>
1282
+ <div class="text-sm text-gray-500">$${medicine.sellingPrice?.toFixed(2) || '0.00'} each</div>
1283
+ </div>
1284
+ <div class="flex items-center">
1285
+ <input type="number"
1286
+ min="1"
1287
+ max="${medicine.quantity}"
1288
+ value="${quantity}"
1289
+ class="w-16 px-2 py-1 border rounded mr-2 quantity-input"
1290
+ data-price="${medicine.sellingPrice || 0}">
1291
+ <span class="w-20 text-right item-total">$${(medicine.sellingPrice * quantity).toFixed(2)}</span>
1292
+ <button class="ml-2 text-red-500 remove-item">
1293
+ <i class="fas fa-times"></i>
1294
+ </button>
1295
+ </div>
1296
+ `;
1297
+
1298
+ // Add to the beginning of the selected items
1299
+ if (selectedItems.firstElementChild?.classList.contains('text-gray-500')) {
1300
+ selectedItems.innerHTML = '';
1301
+ }
1302
+ selectedItems.prepend(itemElement);
1303
+
1304
+ // Add event listeners
1305
+ const qtyInput = itemElement.querySelector('.quantity-input');
1306
+ qtyInput.addEventListener('change', updateCartItem);
1307
+ itemElement.querySelector('.remove-item').addEventListener('click', removeCartItem);
1308
+ }
1309
+
1310
+ updateCartTotal();
1311
+ showToast(`${quantity} ${medicine.name} added to cart`, 'success');
1312
+ }
1313
+
1314
+ function updateCartItem(e) {
1315
+ const input = e.target;
1316
+ const itemElement = input.closest('[data-medicine-id]');
1317
+ const price = parseFloat(input.getAttribute('data-price'));
1318
+ const quantity = parseInt(input.value) || 1;
1319
+
1320
+ // Get the original medicine to check max quantity
1321
+ const medicineId = parseInt(itemElement.getAttribute('data-medicine-id'));
1322
+ const medicine = inventoryItems.find(item => item.id === medicineId);
1323
+
1324
+ if (quantity < 1) {
1325
+ input.value = 1;
1326
+ } else if (medicine && quantity > medicine.quantity) {
1327
+ input.value = medicine.quantity;
1328
+ showToast(`Only ${medicine.quantity} available in stock`, 'error');
1329
+ }
1330
+
1331
+ updateItemTotal(itemElement, price, parseInt(input.value));
1332
+ updateCartTotal();
1333
+ }
1334
+
1335
+ function removeCartItem(e) {
1336
+ const itemElement = e.target.closest('[data-medicine-id]');
1337
+ itemElement.remove();
1338
+ updateCartTotal();
1339
+
1340
+ // Show empty message if no items left
1341
+ const selectedItems = document.getElementById('selected-items');
1342
+ if (selectedItems.children.length === 0) {
1343
+ selectedItems.innerHTML = '<p class="text-gray-500 text-center py-4">No items selected</p>';
1344
+ }
1345
+ }
1346
+
1347
+ function updateItemTotal(itemElement, price, quantity) {
1348
+ const totalElement = itemElement.querySelector('.item-total');
1349
+ const total = (price * quantity).toFixed(2);
1350
+ totalElement.textContent = `$${total}`;
1351
+ }
1352
+
1353
+ function updateCartTotal() {
1354
+ const total = Array.from(document.querySelectorAll('.item-total'))
1355
+ .reduce((sum, el) => sum + parseFloat(el.textContent.replace('$', '')), 0);
1356
+
1357
+ document.getElementById('sale-total').textContent = `$${total.toFixed(2)}`;
1358
+ }
1359
+
1360
+ // Complete sale
1361
+ document.getElementById('complete-sale').addEventListener('click', function() {
1362
+ const selectedItems = document.getElementById('selected-items');
1363
+ const items = [];
1364
+
1365
+ // Get all selected items
1366
+ selectedItems.querySelectorAll('[data-medicine-id]').forEach(itemElement => {
1367
+ const medicineId = parseInt(itemElement.getAttribute('data-medicine-id'));
1368
+ const quantity = parseInt(itemElement.querySelector('.quantity-input').value);
1369
+ const price = parseFloat(itemElement.querySelector('.quantity-input').getAttribute('data-price'));
1370
+
1371
+ items.push({
1372
+ id: medicineId,
1373
+ quantity: quantity,
1374
+ price: price,
1375
+ total: quantity * price
1376
+ });
1377
+
1378
+ // Update inventory
1379
+ const medicineIndex = inventoryItems.findIndex(item => item.id === medicineId);
1380
+ if (medicineIndex !== -1) {
1381
+ inventoryItems[medicineIndex].quantity -= quantity;
1382
+ // Update last sold date
1383
+ inventoryItems[medicineIndex].lastSold = new Date().toISOString().split('T')[0];
1384
+ }
1385
+ });
1386
+
1387
+ if (items.length === 0) {
1388
+ showToast('No items in cart', 'error');
1389
+ return;
1390
+ }
1391
+
1392
+ // Save updated inventory
1393
+ saveInventory();
1394
+
1395
+ // Clear cart
1396
+ selectedItems.innerHTML = '<p class="text-gray-500 text-center py-4">No items selected</p>';
1397
+ updateCartTotal();
1398
+
1399
+ // Show success message
1400
+ const total = items.reduce((sum, item) => sum + item.total, 0);
1401
+ showToast(`Sale completed! Total: $${total.toFixed(2)}`, 'success');
1402
+
1403
+ // Update dashboard stats
1404
+ updateDashboardStats();
1405
+
1406
+ // Refresh available medicines
1407
+ renderAvailableMedicines();
1408
+ });
1409
+
1410
+ // Search functionality
1411
+ document.getElementById('medicine-search').addEventListener('input', function(e) {
1412
+ renderAvailableMedicines(e.target.value);
1413
+ });
1414
  });
1415
  </script>
1416
  </body>