Changed input type from select to input.

New function selectLot
This commit is contained in:
Stephan Steininger 2021-09-30 13:56:43 +02:00
parent 372aa6bf4c
commit 94cc75cb69
2 changed files with 65 additions and 7 deletions

View File

@ -973,8 +973,8 @@ 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 '<td>'.$formproduct->selectLotStock('', 'batch-'.$line->id.'-'.$i, '', 1, 0, $line->fk_product, '', '', '', '', '', '', 1).'</td>';
//print '<input type="text" class="width50" name="batch-'.$line->id.'-'.$i.'" value="'.$preselected.'">';
print '<input type="text" class="width50" name="batch-'.$line->id.'-'.$i.'" value="'.$preselected.'" list="batch-'.$line->id.'-'.$i.'">';
print $formproduct->selectLot('batch-'.$line->id.'-'.$i, 0, $line->fk_product, '', '');
}
print '</td>';
}

View File

@ -536,11 +536,10 @@ class FormProduct
* @param int $forcecombo 1=Force combo iso ajax select2
* @param array $events Events to add to select2
* @param string $morecss Add more css classes to HTML select
* @param int $use_baseval 1=uses batch as value within select
*
* @return string HTML select
*/
public function selectLotStock($selected = '', $htmlname = 'batch_id', $filterstatus = '', $empty = 0, $disabled = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array(), $empty_label = '', $forcecombo = 0, $events = array(), $morecss = 'minwidth200', $use_baseval = 0)
public function selectLotStock($selected = '', $htmlname = 'batch_id', $filterstatus = '', $empty = 0, $disabled = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array(), $empty_label = '', $forcecombo = 0, $events = array(), $morecss = 'minwidth200' )
{
global $conf, $langs;
@ -591,9 +590,7 @@ class FormProduct
$label .= ' <span class=\'opacitymedium\'>('.$langs->trans("Stock").' '.$arraytypes['qty'].')</span>';
}
if ( $use_baseval = 1 )
$out .= '<option value="'.$arraytypes['batch'].'"';
else $out .= '<option value="'.$id.'"';
$out .= '<option value="'.$id.'"';
if ($selected == $id || ($selected == 'ifone' && $nboflot == 1)) {
$out .= ' selected';
@ -613,6 +610,67 @@ class FormProduct
return $out;
}
/**
* Return list of lot numbers (stock from product_batch) with stock location and stock qty
*
* @param string $htmlname Name of html select html
* @param int $empty 1=Can be empty, 0 if not
* @param int $fk_product show lot numbers of product with id fk_product. All from objectLines if 0.
* @param int $fk_entrepot filter lot numbers for warehouse with id fk_entrepot. All if 0.
* @param array $objectLines Only cache lot numbers for products in lines of object. If no lines only for fk_product. If no fk_product, all.
* @param int $use_baseval 1=uses batch as value within select
*
* @return string HTML select
*/
public function selectLot( $htmlname = 'batch_id', $empty = 0, $fk_product = 0, $fk_entrepot = 0, $objectLines = array() )
{
global $conf, $langs;
dol_syslog(get_class($this)."::selectLot $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;
}
} else {
foreach ($objectLines as $line) {
if ($line->fk_product) {
$productIdArray[] = $line->fk_product;
}
}
}
$nboflot = $this->loadLotStock($productIdArray);
$out .= '<datalist id="'.$htmlname.'" >';
if (!empty($fk_product) && $fk_product > 0) {
$productIdArray = array((int) $fk_product); // only show lot stock for product
} else {
foreach ($this->cache_lot as $key => $value) {
$productIdArray[] = $key;
}
}
foreach ($productIdArray as $productId) {
foreach ($this->cache_lot[$productId] as $id => $arraytypes) {
if (empty($fk_entrepot) || $fk_entrepot == $arraytypes['entrepot_id']) {
$label = $arraytypes['entrepot_label'].' - ';
$label .= $arraytypes['batch'];
$out .= '<option>'.$arraytypes['batch'].'</option>';
}
}
}
$out .= '</datalist>';
return $out;
}
/**
* Load in cache array list of lot available in stock from a given list of products
*