Skip to content

Commit

Permalink
New: update field "qty" with minimum qty for this supplier price
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Aug 17, 2012
1 parent 878f54b commit 577a853
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 3 additions & 1 deletion htdocs/core/class/html.form.class.php
Expand Up @@ -1424,6 +1424,7 @@ function select_produits_fournisseurs_do($socid,$selected='',$htmlname='producti
$outkey=$objp->idprodfournprice;
$outref=$objp->ref;
$outval='';
$outqty=1;

$opt = '<option value="'.$objp->idprodfournprice.'"';
if ($selected && $selected == $objp->idprodfournprice) $opt.= ' selected="selected"';
Expand Down Expand Up @@ -1451,6 +1452,7 @@ function select_produits_fournisseurs_do($socid,$selected='',$htmlname='producti

$opt.= price($objp->fprice).' '.$currencytext."/".$objp->quantity;
$outval.= price($objp->fprice).' '.$currencytextnoent."/".$objp->quantity;
$outqty=$objp->quantity;
if ($objp->quantity == 1)
{
$opt.= strtolower($langs->trans("Unit"));
Expand Down Expand Up @@ -1488,7 +1490,7 @@ function select_produits_fournisseurs_do($socid,$selected='',$htmlname='producti
// "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
$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++;
}
Expand Down
15 changes: 14 additions & 1 deletion htdocs/core/lib/ajax.lib.php
Expand Up @@ -66,14 +66,21 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
$("#'.$htmlname.'").val(item.key).trigger("change");
}
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");
},
dataType: "json",
minLength: '.$minLength.',
select: function( event, ui ) {
$("#'.$htmlname.'").val(ui.item.id).trigger("change");
// Disable an element
if (options.disabled) {
if (ui.item.disabled) {
$("#" + options.disabled).attr("disabled", "disabled");
Expand All @@ -84,6 +91,12 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt
$("#" + 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 ) {
return $( "<li></li>" )
Expand Down
8 changes: 6 additions & 2 deletions htdocs/fourn/commande/fiche.php
Expand Up @@ -1530,7 +1530,11 @@
print '<tr '.$bc[$var].'>';
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);

if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>';
Expand All @@ -1547,7 +1551,7 @@
$doleditor->Create();

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="center" colspan="4"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans('Add').'"></td>';
print '</tr>';
Expand Down
8 changes: 6 additions & 2 deletions htdocs/fourn/facture/fiche.php
Expand Up @@ -1806,7 +1806,11 @@
print '<tr '.$bc[$var].'>';
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);

if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '<br>';
Expand All @@ -1823,7 +1827,7 @@
$doleditor->Create();

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 align="center" valign="middle" colspan="2"><input type="submit" id="addPredefinedProductButton" class="button" value="'.$langs->trans("Add").'"></td>';
Expand Down

0 comments on commit 577a853

Please sign in to comment.