New: update field "qty" with minimum qty for this supplier price

This commit is contained in:
Regis Houssin 2012-08-17 18:17:15 +02:00
parent 878f54b1e9
commit 577a853b9b
4 changed files with 29 additions and 6 deletions

View File

@ -1424,6 +1424,7 @@ class Form
$outkey=$objp->idprodfournprice; $outkey=$objp->idprodfournprice;
$outref=$objp->ref; $outref=$objp->ref;
$outval=''; $outval='';
$outqty=1;
$opt = '<option value="'.$objp->idprodfournprice.'"'; $opt = '<option value="'.$objp->idprodfournprice.'"';
if ($selected && $selected == $objp->idprodfournprice) $opt.= ' selected="selected"'; if ($selected && $selected == $objp->idprodfournprice) $opt.= ' selected="selected"';
@ -1451,6 +1452,7 @@ class Form
$opt.= price($objp->fprice).' '.$currencytext."/".$objp->quantity; $opt.= price($objp->fprice).' '.$currencytext."/".$objp->quantity;
$outval.= price($objp->fprice).' '.$currencytextnoent."/".$objp->quantity; $outval.= price($objp->fprice).' '.$currencytextnoent."/".$objp->quantity;
$outqty=$objp->quantity;
if ($objp->quantity == 1) if ($objp->quantity == 1)
{ {
$opt.= strtolower($langs->trans("Unit")); $opt.= strtolower($langs->trans("Unit"));
@ -1488,7 +1490,7 @@ class Form
// "key" value of json key array is used by jQuery automatically as selected value // "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box // "label" value of json key array is used by jQuery automatically as text for combo box
$outselect.=$opt; $outselect.=$opt;
array_push($outjson, array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'disabled'=>(empty($objp->idprodfournprice)?true:false))); array_push($outjson, array('key'=>$outkey, 'value'=>$outref, 'label'=>$outval, 'qty'=>$outqty, 'disabled'=>(empty($objp->idprodfournprice)?true:false)));
$i++; $i++;
} }

View File

@ -66,7 +66,13 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
$("#'.$htmlname.'").val(item.key).trigger("change"); $("#'.$htmlname.'").val(item.key).trigger("change");
} }
var label = item.label.toString(); var label = item.label.toString();
return { label: label, value: item.value, id: item.key, disabled: item.disabled } var update = {};
if (options.update) {
$.each(options.update, function(key, value) {
update[key] = item[value];
});
}
return { label: label, value: item.value, id: item.key, update: update, disabled: item.disabled }
})); }));
}, "json"); }, "json");
}, },
@ -74,6 +80,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
minLength: '.$minLength.', minLength: '.$minLength.',
select: function( event, ui ) { select: function( event, ui ) {
$("#'.$htmlname.'").val(ui.item.id).trigger("change"); $("#'.$htmlname.'").val(ui.item.id).trigger("change");
// Disable an element
if (options.disabled) { if (options.disabled) {
if (ui.item.disabled) { if (ui.item.disabled) {
$("#" + options.disabled).attr("disabled", "disabled"); $("#" + options.disabled).attr("disabled", "disabled");
@ -84,6 +91,12 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
$("#" + options.disabled).removeAttr("disabled"); $("#" + options.disabled).removeAttr("disabled");
} }
} }
// Update an element
if (ui.item.update) {
$.each(ui.item.update, function(key, value) {
$("#" + key).val(value);
});
}
} }
}).data( "autocomplete" )._renderItem = function( ul, item ) { }).data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" ) return $( "<li></li>" )

View File

@ -1530,7 +1530,11 @@ if ($id > 0 || ! empty($ref))
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td colspan="3">'; print '<td colspan="3">';
$ajaxoptions=array('disabled' => 'addPredefinedProductButton', 'error' => $langs->trans("NoPriceDefinedForThisSupplier")); $ajaxoptions=array(
'update' => array('pqty' => 'qty'),
'disabled' => 'addPredefinedProductButton',
'error' => $langs->trans("NoPriceDefinedForThisSupplier")
);
$form->select_produits_fournisseurs($object->fourn_id, '', 'idprodfournprice', '', '', $ajaxoptions); $form->select_produits_fournisseurs($object->fourn_id, '', 'idprodfournprice', '', '', $ajaxoptions);
if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>'; if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>';
@ -1547,7 +1551,7 @@ if ($id > 0 || ! empty($ref))
$doleditor->Create(); $doleditor->Create();
print '</td>'; print '</td>';
print '<td align="right"><input type="text" size="2" name="pqty" value="'.(GETPOST('pqty')?GETPOST('pqty'):'1').'"></td>'; print '<td align="right"><input type="text" size="2" id="pqty" name="pqty" value="'.(GETPOST('pqty')?GETPOST('pqty'):'1').'"></td>';
print '<td align="right" nowrap="nowrap"><input type="text" size="1" name="p_remise_percent" value="'.(GETPOST('p_remise_percent')?GETPOST('p_remise_percent'):$soc->remise_client).'">%</td>'; print '<td align="right" nowrap="nowrap"><input type="text" size="1" name="p_remise_percent" value="'.(GETPOST('p_remise_percent')?GETPOST('p_remise_percent'):$soc->remise_client).'">%</td>';
print '<td align="center" colspan="4"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans('Add').'"></td>'; print '<td align="center" colspan="4"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans('Add').'"></td>';
print '</tr>'; print '</tr>';

View File

@ -1806,7 +1806,11 @@ else
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td colspan="4">'; print '<td colspan="4">';
$ajaxoptions=array('disabled' => 'addPredefinedProductButton', 'error' => $langs->trans("NoPriceDefinedForThisSupplier")); $ajaxoptions=array(
'update' => array('pqty' => 'qty'),
'disabled' => 'addPredefinedProductButton',
'error' => $langs->trans("NoPriceDefinedForThisSupplier")
);
$form->select_produits_fournisseurs($object->socid, '', 'idprodfournprice', '', '', $ajaxoptions); $form->select_produits_fournisseurs($object->socid, '', 'idprodfournprice', '', '', $ajaxoptions);
if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>'; if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>';
@ -1823,7 +1827,7 @@ else
$doleditor->Create(); $doleditor->Create();
print '</td>'; print '</td>';
print '<td align="right"><input type="text" name="qty" value="1" size="1"></td>'; print '<td align="right"><input type="text" id="pqty" name="qty" value="1" size="1"></td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '<td align="center" valign="middle" colspan="2"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans("Add").'"></td>'; print '<td align="center" valign="middle" colspan="2"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans("Add").'"></td>';