Actualiser assets/js/app.js
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
This commit is contained in:
@@ -7517,6 +7517,12 @@ function editInventoryItem(id) {
|
|||||||
package_unit: item.package_unit || '',
|
package_unit: item.package_unit || '',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const itemCatForEdit = mapToLocalCategory(item.category, item.name, item.brand);
|
||||||
|
const itemSubcatOptions = getSubcategoryOptionsHtml(itemCatForEdit, item.subcategory || '');
|
||||||
|
const itemSubcatList = SUBCATEGORIES_BY_CATEGORY[itemCatForEdit];
|
||||||
|
const itemSubcatVisible = (itemSubcatList && itemSubcatList.length > 0) ? 'block' : 'none';
|
||||||
|
const itemSubcatRequired = REQUIRED_SUBCATEGORY_CATEGORIES.includes(itemCatForEdit);
|
||||||
|
|
||||||
// Rebuild modal content for editing (don't close and reopen - just replace content)
|
// Rebuild modal content for editing (don't close and reopen - just replace content)
|
||||||
document.getElementById('modal-content').innerHTML = `
|
document.getElementById('modal-content').innerHTML = `
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@@ -7524,6 +7530,18 @@ function editInventoryItem(id) {
|
|||||||
<button class="modal-close" onclick="closeModal()">✕</button>
|
<button class="modal-close" onclick="closeModal()">✕</button>
|
||||||
</div>
|
</div>
|
||||||
<form class="form" onsubmit="submitEditInventory(event, ${id}, ${item.product_id})">
|
<form class="form" onsubmit="submitEditInventory(event, ${id}, ${item.product_id})">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>${t('product.category_label')}</label>
|
||||||
|
<select id="edit-inv-category" class="form-input" onchange="onEditInvCategoryChange()">
|
||||||
|
${Object.entries(CATEGORY_LABELS).map(([k, label]) => `<option value="${k}" ${itemCatForEdit === k ? 'selected' : ''}>${label}</option>`).join('')}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group" id="edit-inv-subcategory-group" style="display:${itemSubcatVisible}">
|
||||||
|
<label>📂 Sous-catégorie <span class="subcategory-required-mark" style="display:${itemSubcatRequired ? 'inline' : 'none'};color:#e74c3c">*</span></label>
|
||||||
|
<select id="edit-inv-subcategory" class="form-input">
|
||||||
|
${itemSubcatOptions}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>📦 ${t('inventory.label_quantity').replace('📦 ', '')}</label>
|
<label>📦 ${t('inventory.label_quantity').replace('📦 ', '')}</label>
|
||||||
<div class="qty-control-with-unit">
|
<div class="qty-control-with-unit">
|
||||||
@@ -7589,6 +7607,11 @@ function editInventoryItem(id) {
|
|||||||
setQtyInputUnitLabel('edit-qty', item.unit || 'pz');
|
setQtyInputUnitLabel('edit-qty', item.unit || 'pz');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onEditInvCategoryChange() {
|
||||||
|
const cat = document.getElementById('edit-inv-category')?.value || '';
|
||||||
|
updateSubcategoryField('edit-inv-subcategory', 'edit-inv-subcategory-group', cat);
|
||||||
|
}
|
||||||
|
|
||||||
function onEditUnitChange() {
|
function onEditUnitChange() {
|
||||||
const unit = document.getElementById('edit-unit').value;
|
const unit = document.getElementById('edit-unit').value;
|
||||||
setQtyInputUnitLabel('edit-qty', unit);
|
setQtyInputUnitLabel('edit-qty', unit);
|
||||||
@@ -7615,6 +7638,13 @@ function onEditUnitChange() {
|
|||||||
|
|
||||||
async function submitEditInventory(e, id, productId) {
|
async function submitEditInventory(e, id, productId) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
const category = document.getElementById('edit-inv-category')?.value || '';
|
||||||
|
const subcategory = document.getElementById('edit-inv-subcategory')?.value || '';
|
||||||
|
if (REQUIRED_SUBCATEGORY_CATEGORIES.includes(category) && !subcategory) {
|
||||||
|
showToast('Merci de préciser la sous-catégorie', 'error');
|
||||||
|
document.getElementById('edit-inv-subcategory')?.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const qty = parseFloat(document.getElementById('edit-qty').value);
|
const qty = parseFloat(document.getElementById('edit-qty').value);
|
||||||
const loc = document.getElementById('edit-loc').value;
|
const loc = document.getElementById('edit-loc').value;
|
||||||
const expiry = document.getElementById('edit-expiry').value || null;
|
const expiry = document.getElementById('edit-expiry').value || null;
|
||||||
@@ -7651,6 +7681,21 @@ async function submitEditInventory(e, id, productId) {
|
|||||||
payload.package_size = 0;
|
payload.package_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const editedItem = currentInventory.find(i => i.id === id) || {};
|
||||||
|
await api('product_save', {}, 'POST', {
|
||||||
|
id: productId,
|
||||||
|
barcode: editedItem.barcode || null,
|
||||||
|
name: editedItem.name,
|
||||||
|
brand: editedItem.brand || '',
|
||||||
|
category: category,
|
||||||
|
subcategory: subcategory || null,
|
||||||
|
image_url: editedItem.image_url || '',
|
||||||
|
unit: editedItem.unit || 'pz',
|
||||||
|
default_quantity: editedItem.default_quantity || 1,
|
||||||
|
package_unit: editedItem.package_unit || '',
|
||||||
|
notes: editedItem.notes || '',
|
||||||
|
});
|
||||||
|
|
||||||
await api('inventory_update', {}, 'POST', payload);
|
await api('inventory_update', {}, 'POST', payload);
|
||||||
closeModal();
|
closeModal();
|
||||||
showToast(t('toast.updated'), 'success');
|
showToast(t('toast.updated'), 'success');
|
||||||
|
|||||||
Reference in New Issue
Block a user