feat: add bulk operations to vendor pages
Add selection and bulk actions to products, orders, and inventory: - Products: bulk activate/deactivate, feature/unfeature, delete - Orders: bulk status update, CSV export - Inventory: bulk stock adjustment, CSV export All pages include select-all checkbox, row selection highlighting, and action bars with operation buttons. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
142
static/vendor/js/inventory.js
vendored
142
static/vendor/js/inventory.js
vendored
@@ -65,6 +65,14 @@ function vendorInventory() {
|
||||
quantity: 0
|
||||
},
|
||||
|
||||
// Bulk operations
|
||||
selectedItems: [],
|
||||
showBulkAdjustModal: false,
|
||||
bulkAdjustForm: {
|
||||
quantity: 0,
|
||||
reason: ''
|
||||
},
|
||||
|
||||
// Debounce timer
|
||||
searchTimeout: null,
|
||||
|
||||
@@ -109,6 +117,16 @@ function vendorInventory() {
|
||||
return pages;
|
||||
},
|
||||
|
||||
// Computed: Check if all visible items are selected
|
||||
get allSelected() {
|
||||
return this.inventory.length > 0 && this.selectedItems.length === this.inventory.length;
|
||||
},
|
||||
|
||||
// Computed: Check if some but not all items are selected
|
||||
get someSelected() {
|
||||
return this.selectedItems.length > 0 && this.selectedItems.length < this.inventory.length;
|
||||
},
|
||||
|
||||
async init() {
|
||||
vendorInventoryLog.info('Inventory init() called');
|
||||
|
||||
@@ -360,6 +378,130 @@ function vendorInventory() {
|
||||
this.pagination.page = pageNum;
|
||||
this.loadInventory();
|
||||
}
|
||||
},
|
||||
|
||||
// ============================================================================
|
||||
// BULK OPERATIONS
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* Toggle select all items on current page
|
||||
*/
|
||||
toggleSelectAll() {
|
||||
if (this.allSelected) {
|
||||
this.selectedItems = [];
|
||||
} else {
|
||||
this.selectedItems = this.inventory.map(i => i.id);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Toggle selection of a single item
|
||||
*/
|
||||
toggleSelect(itemId) {
|
||||
const index = this.selectedItems.indexOf(itemId);
|
||||
if (index === -1) {
|
||||
this.selectedItems.push(itemId);
|
||||
} else {
|
||||
this.selectedItems.splice(index, 1);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if item is selected
|
||||
*/
|
||||
isSelected(itemId) {
|
||||
return this.selectedItems.includes(itemId);
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear all selections
|
||||
*/
|
||||
clearSelection() {
|
||||
this.selectedItems = [];
|
||||
},
|
||||
|
||||
/**
|
||||
* Open bulk adjust modal
|
||||
*/
|
||||
openBulkAdjustModal() {
|
||||
if (this.selectedItems.length === 0) return;
|
||||
this.bulkAdjustForm = {
|
||||
quantity: 0,
|
||||
reason: ''
|
||||
};
|
||||
this.showBulkAdjustModal = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute bulk stock adjustment
|
||||
*/
|
||||
async bulkAdjust() {
|
||||
if (this.selectedItems.length === 0 || this.bulkAdjustForm.quantity === 0) return;
|
||||
|
||||
this.saving = true;
|
||||
try {
|
||||
let successCount = 0;
|
||||
for (const itemId of this.selectedItems) {
|
||||
const item = this.inventory.find(i => i.id === itemId);
|
||||
if (item) {
|
||||
try {
|
||||
await apiClient.post(`/vendor/${this.vendorCode}/inventory/adjust`, {
|
||||
product_id: item.product_id,
|
||||
location: item.location,
|
||||
quantity: this.bulkAdjustForm.quantity,
|
||||
reason: this.bulkAdjustForm.reason || 'Bulk adjustment'
|
||||
});
|
||||
successCount++;
|
||||
} catch (error) {
|
||||
vendorInventoryLog.warn(`Failed to adjust item ${itemId}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
Utils.showToast(`${successCount} item(s) adjusted by ${this.bulkAdjustForm.quantity > 0 ? '+' : ''}${this.bulkAdjustForm.quantity}`, 'success');
|
||||
this.showBulkAdjustModal = false;
|
||||
this.clearSelection();
|
||||
await this.loadInventory();
|
||||
} catch (error) {
|
||||
vendorInventoryLog.error('Bulk adjust failed:', error);
|
||||
Utils.showToast(error.message || 'Failed to adjust inventory', 'error');
|
||||
} finally {
|
||||
this.saving = false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Export selected items as CSV
|
||||
*/
|
||||
exportSelectedItems() {
|
||||
if (this.selectedItems.length === 0) return;
|
||||
|
||||
const selectedData = this.inventory.filter(i => this.selectedItems.includes(i.id));
|
||||
|
||||
// Build CSV content
|
||||
const headers = ['Product', 'SKU', 'Location', 'Quantity', 'Low Stock Threshold', 'Status'];
|
||||
const rows = selectedData.map(i => [
|
||||
i.product_name || '-',
|
||||
i.sku || '-',
|
||||
i.location || 'Default',
|
||||
i.quantity || 0,
|
||||
i.low_stock_threshold || 5,
|
||||
this.getStockStatus(i)
|
||||
]);
|
||||
|
||||
const csvContent = [
|
||||
headers.join(','),
|
||||
...rows.map(row => row.map(cell => `"${cell}"`).join(','))
|
||||
].join('\n');
|
||||
|
||||
// Download
|
||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = `inventory_export_${new Date().toISOString().split('T')[0]}.csv`;
|
||||
link.click();
|
||||
|
||||
Utils.showToast(`Exported ${selectedData.length} item(s)`, 'success');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user