2
0
forked from Wavyzz/dolibarr
This commit is contained in:
atm-lena
2022-01-25 17:16:21 +01:00
parent a5ab9e059a
commit 2ea5da3e13
2 changed files with 17 additions and 50 deletions

View File

@@ -1026,7 +1026,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
print '<td>';
if ($tmpproduct->status_batch) {
$preselected = (GETPOSTISSET('batch-'.$line->id.'-'.$i) ? GETPOST('batch-'.$line->id.'-'.$i) : '');
// print '<input type="text" class="width50" name="batch-'.$line->id.'-'.$i.'" value="'.$preselected.'" list="batch-'.$line->id.'-'.$i.'">';
print '<input type="text" class="width50" name="batch-'.$line->id.'-'.$i.'" value="'.$preselected.'" list="batch-'.$line->id.'-'.$i.'">';
print $formproduct->selectLotDataList('batch-'.$line->id.'-'.$i, 1, $line->fk_product, '');
// print $formproduct->selectLotStock('', 'batch-'.$line->id.'-'.$i, '', 0, '', $line->fk_product);
}
@@ -1340,7 +1340,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
//select lots/series
var selectbatch_name = selectwarehouse.attr('name').replace('idwarehouse', 'batch');
var selectbatch = $("select[name*='" + selectbatch_name + "']");
var selectbatch = $("datalist[id*='" + selectbatch_name + "']");
var selectedbatch = selectbatch.val();
//produit de la ligne
@@ -1357,21 +1357,21 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}).done(function (data) {
selectbatch.empty();
$('input[name*='+selectbatch_name+']').val('');
var data = JSON.parse(data);
selectbatch.append($('<option>', {
value: -1,
text: ''
value: '',
}));
$.each(data, function (key, value) {
//si aucun entrepôt sélectionné, alors c'est le stock total du num lot/serie qui s'affiche
if(selectwarehouse.val() == -1) {
var label = key + " (<?php echo $langs->trans('Stock total') ?> : " + value + ")";
var label = " (<?php echo $langs->trans('Stock total') ?> : " + value + ")";
} else {
var label = key + " (<?php echo $langs->trans('Stock') ?> : " + value + ")";
var label = " (<?php echo $langs->trans('Stock') ?> : " + value + ")";
}
if(key === selectedbatch) {
@@ -1391,9 +1391,8 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
//Lorsqu'un numéro de lot/série est sélectionné et qu'il n'est disponible seulement dans un entrepôt, l'entrepôt est automatiquement sélectionné
function updateselectwarehousebybatch() {
var element = $("select[name*='batch']");
element.change(function () {
$(document).on('change', 'input', function(){
//select lot/série
var selectbatch = $(this);
@@ -1409,7 +1408,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
}
//produit de la ligne
var product_element_name = element.attr('name').replace('batch', 'product');
var product_element_name = selectbatch.attr('name').replace('batch', 'product');
$.ajax({
type: "POST",

View File

@@ -626,13 +626,13 @@ class FormProduct
{
global $conf, $langs;
dol_syslog(get_class($this) . "::selectLotDataList $htmlname, $empty, $fk_product, $fk_entrepot,$objectLines", LOG_DEBUG);
dol_syslog(get_class($this)."::selectLotDataList $htmlname, $empty, $fk_product, $fk_entrepot,$objectLines", LOG_DEBUG);
$out = '';
$productIdArray = array();
if (!is_array($objectLines) || !count($objectLines)) {
if (!empty($fk_product) && $fk_product > 0) {
$productIdArray[] = (int)$fk_product;
$productIdArray[] = (int) $fk_product;
}
} else {
foreach ($objectLines as $line) {
@@ -644,58 +644,26 @@ class FormProduct
$nboflot = $this->loadLotStock($productIdArray);
if ($conf->use_javascript_ajax && !$forcecombo) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$comboenhancement = ajax_combobox($htmlname, $events);
$out .= $comboenhancement;
}
$out .= '<select class="flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($disabled ? ' disabled' : '') . ' id="' . $htmlname . '" name="' . ($htmlname . ($disabled ? '_disabled' : '')) . '">';
if ($empty) {
$out .= '<option value="-1">'.($empty_label ? $empty_label : '&nbsp;').'</option>';
}
$out .= '<datalist id="'.$htmlname.'" >';
if (!empty($fk_product) && $fk_product > 0) {
$productIdArray = array((int)$fk_product); // only show lot stock for product
$productIdArray = array((int) $fk_product); // only show lot stock for product
} else {
foreach ($this->cache_lot as $key => $value) {
$productIdArray[] = $key;
}
}
$TBatchQuantity = array();
foreach ($productIdArray as $productId) {
foreach ($this->cache_lot[$productId] as $id => $arraytypes) {
$TBatchQuantity[$productId][$arraytypes['batch']][$arraytypes['entrepot_id']] = $arraytypes['qty'];
}
}
foreach($TBatchQuantity as $id_product => $TBatchs){
foreach ($TBatchs as $batch => $TQtyByWarehouse) {
$label = $batch;
//si pas d'entrepôt, on affiche le stock total du lot, tout entrepôt compris
if (empty($fk_entrepot)) $label .= " (" . $langs->trans('Stock total') . " : " . array_sum($TQtyByWarehouse) . ")";
//sinon on affiche seulement le stock de l'entrepôt en question
else $label .= " (" . $langs->trans('Stock') . " : " . $TQtyByWarehouse[$fk_entrepot] . ")";
$out .= '<option value="' . $batch . '"';
if ($selected == $batch) {
$out .= ' selected';
if (empty($fk_entrepot) || $fk_entrepot == $arraytypes['entrepot_id']) {
$label = $arraytypes['entrepot_label'].' - ';
$label .= $arraytypes['batch'];
$out .= '<option>'.$arraytypes['batch'].'</option>';
}
$out .= ' data-html="' . dol_escape_htmltag($label) . '"';
$out .= '>';
$out .= $label;
$out .= '</option>';
}
}
$out .= '</select>';
$out .= '</datalist>';
return $out;
}