Subversion Repositories SmartDukaan

Rev

Rev 35776 | Rev 35838 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35776 Rev 35782
Line 369... Line 369...
369
											#end
369
											#end
370
										#end
370
										#end
371
									<tr class="out-of-stock-row" style="background-color: #f8d7da;">
371
									<tr class="out-of-stock-row" style="background-color: #f8d7da;">
372
										<td colspan="11">
372
										<td colspan="11">
373
											<a href="#" style="color: #c0392b; font-weight: bold;"
373
											<a href="#" style="color: #c0392b; font-weight: bold;"
374
											   onclick="toggleOutOfStock('$bnd', $warehouseId, this); return false;">
374
											   onclick="toggleOutOfStock('$bnd', $warehouseId, $fofoId, this); return false;">
375
												<span class="oos-toggle-icon">+</span> Out of Stock Items
375
												<span class="oos-toggle-icon">+</span> Out of Stock Items
376
												(HID/FastMoving/Running)
376
												(HID/FastMoving/Running)
377
											</a>
377
											</a>
378
											<div id="oos-content-$bnd" class="oos-content"
378
											<div id="oos-content-$bnd" class="oos-content"
379
												 style="display: none; margin-top: 10px;">
379
												 style="display: none; margin-top: 10px;">
Line 521... Line 521...
521
		} else {
521
		} else {
522
			row.style.display = 'none';
522
			row.style.display = 'none';
523
		}
523
		}
524
	}
524
	}
525
 
525
 
526
	function toggleOutOfStock(brand, warehouseId, linkElement) {
526
	function toggleOutOfStock(brand, warehouseId, fofoId, linkElement) {
527
		var contentDiv = document.getElementById('oos-content-' + brand);
527
		var contentDiv = document.getElementById('oos-content-' + brand);
528
		var icon = linkElement.querySelector('.oos-toggle-icon');
528
		var icon = linkElement.querySelector('.oos-toggle-icon');
529
 
529
 
530
		if (contentDiv.style.display === 'none') {
530
		if (contentDiv.style.display === 'none') {
531
			contentDiv.style.display = 'block';
531
			contentDiv.style.display = 'block';
Line 536... Line 536...
536
				contentDiv.innerHTML = '<p>Loading...</p>';
536
				contentDiv.innerHTML = '<p>Loading...</p>';
537
 
537
 
538
				$.ajax({
538
				$.ajax({
539
					url: '${rc.contextPath}/indent/getOutOfStockDetails',
539
					url: '${rc.contextPath}/indent/getOutOfStockDetails',
540
					type: 'GET',
540
					type: 'GET',
541
					data: {brand: brand, warehouseId: warehouseId},
541
					data: {brand: brand, warehouseId: warehouseId, fofoId: fofoId},
542
					success: function (response) {
542
					success: function (response) {
543
						console.log("RESPONSE:", response);
543
						console.log("RESPONSE:", response);
544
						oosDataLoaded[brand] = true;
544
						oosDataLoaded[brand] = true;
545
 
545
 
546
						var list = response.response;   // 🔥 correct
546
						var list = response.response;
547
 
547
 
548
						if (list && list.length > 0) {
548
						if (list && list.length > 0) {
-
 
549
							// Sort items alphabetically by model number (series-wise)
-
 
550
							list.sort(function (a, b) {
-
 
551
								return a.modelNumber.localeCompare(b.modelNumber, undefined, {sensitivity: 'base'});
-
 
552
							});
-
 
553
 
549
							var html = '<table class="table table-bordered table-sm" style="margin-bottom: 0;">';
554
							var html = '<table class="table table-bordered table-sm" style="margin-bottom: 0;">';
550
							html += '<thead><tr><th>Model Number</th><th>Status</th><th>Stock Qty</th></tr></thead><tbody>';
555
							html += '<thead><tr style="background-color: #f8d7da;"><th>Model Number</th><th>Status</th><th>DP</th><th>Our Stock</th><th>P-CurrentQty</th><th>Action</th></tr></thead><tbody>';
551
 
556
 
552
							for (var i = 0; i < list.length; i++) {
557
							for (var i = 0; i < list.length; i++) {
-
 
558
								var partnerQty = list[i].partnerCurrentQty || 0;
-
 
559
								var dpPrice = list[i].dp || 0;
-
 
560
								var partnerQtyStyle = partnerQty > 0 ? 'color: green; text-decoration: underline; cursor: pointer;' : 'color: #666;';
-
 
561
								var partnerQtyClick = partnerQty > 0 ? 'onclick="toggleOosPartnerStockRow(' + list[i].catalogId + ', ' + fofoId + ', \'' + list[i].modelNumber + '\')"' : '';
-
 
562
 
553
								html += '<tr style="background-color: #f8d7da;">';
563
								html += '<tr style="background-color: #f8d7da;">';
554
								html += '<td>' + list[i].modelNumber + '</td>';
564
								html += '<td>' + list[i].modelNumber + '</td>';
555
								html += '<td>' + list[i].status + '</td>';
565
								html += '<td>' + list[i].status + '</td>';
-
 
566
								html += '<td>' + dpPrice + '</td>';
556
								html += '<td>' + list[i].qty + '</td>';
567
								html += '<td>' + list[i].qty + '</td>';
-
 
568
								html += '<td style="' + partnerQtyStyle + '" ' + partnerQtyClick + '>' + partnerQty + '</td>';
-
 
569
								html += '<td>';
-
 
570
								html += '<button class="btn btn-sm btn-success add-to-cart-btn" data-toggle="modal" data-target="#poItemsDetail" ';
-
 
571
								html += 'data-catalogid="' + list[i].catalogId + '" data-warehouseid="' + warehouseId + '" ';
-
 
572
								html += 'data-model="' + list[i].modelNumber + '" data-price="' + dpPrice + '">Add to PO</button>';
-
 
573
								html += '</td>';
-
 
574
								html += '</tr>';
-
 
575
 
-
 
576
								// Add hidden row for partner stock details
-
 
577
								html += '<tr id="oos-partner-stock-row-' + list[i].catalogId + '" class="oos-partner-stock-detail-row" style="display: none; background-color: #d4edda;">';
-
 
578
								html += '<td colspan="6" style="padding: 10px 20px;"><div id="oos-partner-stock-content-' + list[i].catalogId + '"><p>Loading...</p></div></td>';
557
								html += '</tr>';
579
								html += '</tr>';
558
							}
580
							}
559
 
581
 
560
							html += '</tbody></table>';
582
							html += '</tbody></table>';
561
							contentDiv.innerHTML = html;
583
							contentDiv.innerHTML = html;
Line 571... Line 593...
571
		} else {
593
		} else {
572
			contentDiv.style.display = 'none';
594
			contentDiv.style.display = 'none';
573
			icon.textContent = '+';
595
			icon.textContent = '+';
574
		}
596
		}
575
	}
597
	}
-
 
598
 
-
 
599
	var oosPartnerStockDataLoaded = {};
-
 
600
 
-
 
601
	function toggleOosPartnerStockRow(catalogId, fofoId, modelNumber) {
-
 
602
		var row = document.getElementById('oos-partner-stock-row-' + catalogId);
-
 
603
		var contentDiv = document.getElementById('oos-partner-stock-content-' + catalogId);
-
 
604
 
-
 
605
		if (row.style.display === 'none') {
-
 
606
			row.style.display = 'table-row';
-
 
607
 
-
 
608
			// Load data only if not already loaded
-
 
609
			if (!oosPartnerStockDataLoaded[catalogId]) {
-
 
610
				contentDiv.innerHTML = '<p>Loading...</p>';
-
 
611
 
-
 
612
				$.ajax({
-
 
613
					url: '${rc.contextPath}/getItemsByCatalog',
-
 
614
					type: 'GET',
-
 
615
					data: {catalogId: catalogId, fofoId: fofoId},
-
 
616
					success: function (response) {
-
 
617
						oosPartnerStockDataLoaded[catalogId] = true;
-
 
618
 
-
 
619
						var list = response.response;
-
 
620
 
-
 
621
						if (list && list.length > 0) {
-
 
622
							var html = '<strong>Partner Stock: ' + modelNumber + '</strong>';
-
 
623
							html += '<table class="table table-bordered table-sm" style="margin-top:5px; background-color: #fff;">';
-
 
624
							html += '<thead><tr style="background-color: #d4edda;"><th>Item ID</th><th>Description</th><th>Qty</th><th>Status</th></tr></thead><tbody>';
-
 
625
 
-
 
626
							for (var i = 0; i < list.length; i++) {
-
 
627
								if (list[i].availability > 0) {
-
 
628
									var stockType = list[i].stockType || 'IN_STOCK';
-
 
629
									var rowStyle = stockType === 'GRN_PENDING' ? 'background-color: #fff3cd;' : '';
-
 
630
									var statusLabel = stockType === 'GRN_PENDING' ? '<span style="color: #856404; font-weight: bold;">GRN Pending</span>' : '<span style="color: #155724;">In Stock</span>';
-
 
631
									html += '<tr style="' + rowStyle + '">';
-
 
632
									html += '<td>' + list[i].itemId + '</td>';
-
 
633
									html += '<td>' + (list[i].itemDescription || '-') + '</td>';
-
 
634
									html += '<td>' + list[i].availability + '</td>';
-
 
635
									html += '<td>' + statusLabel + '</td>';
-
 
636
									html += '</tr>';
-
 
637
								}
-
 
638
							}
-
 
639
 
-
 
640
							html += '</tbody></table>';
-
 
641
							contentDiv.innerHTML = html;
-
 
642
						} else {
-
 
643
							contentDiv.innerHTML = '<p>No partner stock details available</p>';
-
 
644
						}
-
 
645
					},
-
 
646
					error: function () {
-
 
647
						contentDiv.innerHTML = '<p style="color: red; margin: 0;">Error loading partner stock details</p>';
-
 
648
					}
-
 
649
				});
-
 
650
			}
-
 
651
		} else {
-
 
652
			row.style.display = 'none';
-
 
653
		}
-
 
654
	}
576
</script>
655
</script>
577
 
656