FIX option PRODUIT_CUSTOMER_PRICES_BY_QTY
Fix setup of product
This commit is contained in:
parent
471f3e66e6
commit
7d7ef1e72a
@ -61,7 +61,7 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
|
||||
$script .= '<script>'."\n";
|
||||
$script .= '$(document).ready(function() {
|
||||
var autoselect = '.$autoselect.';
|
||||
var options = '.json_encode($ajaxoptions).';
|
||||
var options = '.json_encode($ajaxoptions).'; /* Option of actions to do after keyup, or after select */
|
||||
|
||||
/* Remove selected id as soon as we type or delete a char (it means old selection is wrong). Use keyup/down instead of change to avoid loosing the product id. This is needed only for select of predefined product */
|
||||
$("input#search_'.$htmlname.'").keydown(function(e) {
|
||||
@ -131,7 +131,9 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
|
||||
textarea[key] = item[value];
|
||||
});
|
||||
}
|
||||
return { label: label, value: item.value, id: item.key, update: update, textarea: textarea, disabled: item.disabled }
|
||||
return { label: label, value: item.value, id: item.key, disabled: item.disabled,
|
||||
update: update, textarea: textarea,
|
||||
pbq: item.pbq, type: item.type, qty: item.qty, discount: item.discount, pricebasetype: item.pricebasetype, price_ht: item.price_ht, price_ttc: item.price_ttc }
|
||||
}));
|
||||
}
|
||||
else console.error("Error: Ajax url '.$url.($urloption ? '?'.$urloption : '').' has returned an empty page. Should be an empty json array.");
|
||||
@ -142,6 +144,14 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLen
|
||||
select: function( event, ui ) { // Function ran once new value has been selected into javascript combo
|
||||
console.log("Call change on input '.$htmlname.' because of select definition of autocomplete select call on input#search_'.$htmlname.'");
|
||||
console.log("Selected id = "+ui.item.id+" - If this value is null, it means you select a record with key that is null so selection is not effective");
|
||||
|
||||
//console.log(ui.item);
|
||||
$("#'.$htmlname.'").attr("data-pbq", ui.item.pbq);
|
||||
$("#'.$htmlname.'").attr("data-pbqup", ui.item.price_ht);
|
||||
$("#'.$htmlname.'").attr("data-pbqbase", ui.item.pricebasetype);
|
||||
$("#'.$htmlname.'").attr("data-pbqqty", ui.item.qty);
|
||||
$("#'.$htmlname.'").attr("data-pbqpercent", ui.item.discount);
|
||||
|
||||
$("#'.$htmlname.'").val(ui.item.id).trigger("change"); // Select new value
|
||||
// Disable an element
|
||||
if (options.option_disabled) {
|
||||
|
||||
@ -631,13 +631,16 @@ if (!empty($usemargins) && $user->rights->margins->creer)
|
||||
if (empty($conf->global->MAIN_DISABLE_EDIT_PREDEF_PRICEHT) && empty($senderissupplier))
|
||||
{
|
||||
?>
|
||||
var pbq = parseInt($('option:selected', this).attr('data-pbq'));
|
||||
var pbq = parseInt($('option:selected', this).attr('data-pbq')); /* If product was selected with a HTML select */
|
||||
if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } /* If product was selected with a HTML input with autocomplete */
|
||||
//console.log(pbq);
|
||||
|
||||
if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
|
||||
{
|
||||
console.log("We are in a price per qty context, we do not call ajax/product");
|
||||
console.log("We are in a price per qty context, we do not call ajax/product, init of fields is done few lines later");
|
||||
} else {
|
||||
<?php if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { ?>
|
||||
if (isNaN(pbq)) { console.log("We use experimental option PRODUIT_CUSTOMER_PRICES_BY_QTY or PRODUIT_CUSTOMER_PRICES_BY_QTY but we are not yet able to get the id of pbq from product combo list, so load of price may be 0 if product has differet prices"); }
|
||||
if (isNaN(pbq)) { console.log("We use experimental option PRODUIT_CUSTOMER_PRICES_BY_QTY or PRODUIT_CUSTOMER_PRICES_BY_QTY but we could not get the id of pbq from product combo list, so load of price may be 0 if product has differet prices"); }
|
||||
<?php } ?>
|
||||
// Get the HT price for the product and display it
|
||||
console.log("Load unit price without tax and set it into #price_ht for product id="+$(this).val()+" socid=<?php print $object->socid; ?>");
|
||||
@ -760,11 +763,16 @@ if (!empty($usemargins) && $user->rights->margins->creer)
|
||||
?>
|
||||
|
||||
/* To process customer price per quantity (CUSTOMER_PRICE_PER_QTY works only if combo product is not an ajax after x key pressed) */
|
||||
var pbq = parseInt($('option:selected', this).attr('data-pbq'));
|
||||
var pbq = parseInt($('option:selected', this).attr('data-pbq')); // When select is done from HTML select
|
||||
if (isNaN(pbq)) { pbq = jQuery('#idprod').attr('data-pbq'); } // When select is done from HTML input with autocomplete
|
||||
var pbqup = parseFloat($('option:selected', this).attr('data-pbqup'));
|
||||
if (isNaN(pbqup)) { pbqup = jQuery('#idprod').attr('data-pbqup'); }
|
||||
var pbqbase = $('option:selected', this).attr('data-pbqbase');
|
||||
if (isNaN(pbqbase)) { pbqbase = jQuery('#idprod').attr('data-pbqbase'); }
|
||||
var pbqqty = parseFloat($('option:selected', this).attr('data-pbqqty'));
|
||||
if (isNaN(pbqqty)) { pbqqty = jQuery('#idprod').attr('data-pbqqty'); }
|
||||
var pbqpercent = parseFloat($('option:selected', this).attr('data-pbqpercent'));
|
||||
if (isNaN(pbqpercent)) { pbqpercent = jQuery('#idprod').attr('data-pbqpercent'); }
|
||||
|
||||
if ((jQuery('#idprod').val() > 0 || jQuery('#idprodfournprice').val()) && ! isNaN(pbq) && pbq > 0)
|
||||
{
|
||||
|
||||
@ -548,12 +548,13 @@ print load_fiche_titre($langs->trans("ProductOtherConf"), '', '');
|
||||
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="other">';
|
||||
print '<input type="hidden" name="page_y" value="">';
|
||||
|
||||
print '<table class="noborder centpercent">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("Parameters").'</td>'."\n";
|
||||
print '<td class="right" width="60">'.$langs->trans("Value").'</td>'."\n";
|
||||
print '<td width="80"> </td></tr>'."\n";
|
||||
print '</tr>'."\n";
|
||||
|
||||
|
||||
/*
|
||||
@ -583,8 +584,6 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) $current_rule = 'PROD
|
||||
if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) $current_rule = 'PRODUIT_CUSTOMER_PRICES';
|
||||
if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) $current_rule = 'PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES';
|
||||
print $form->selectarray("princingrule", $select_pricing_rules, $current_rule);
|
||||
print '</td><td rowspan="'.$rowspan.'" class="nohover right">';
|
||||
print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
@ -764,6 +763,10 @@ if (!empty($conf->global->PRODUCT_CANVAS_ABILITY))
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<div class="center">';
|
||||
print '<input type="submit" class="button reposition" value="'.$langs->trans("Modify").'">';
|
||||
print '</div>';
|
||||
|
||||
print '</form>';
|
||||
|
||||
// End of page
|
||||
|
||||
@ -453,7 +453,13 @@ if (empty($reshook))
|
||||
$sql .= $priceid.','.$price.','.$unitPrice.','.$quantity.','.$remise_percent.','.$remise.')';
|
||||
|
||||
$result = $db->query($sql);
|
||||
if (!$result) dol_print_error($db);
|
||||
if (!$result) {
|
||||
if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
|
||||
setEventMessages($langs->trans("DuplicateRecord"), null, 'errors');
|
||||
} else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -899,13 +905,14 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_
|
||||
{
|
||||
if ($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->rights->produit->creer || $user->rights->service->creer)) {
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="update_price_by_qty">';
|
||||
print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].'">';
|
||||
print '<input type="hidden" value="'.$prices['rowid'].'" name="rowid">';
|
||||
print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
|
||||
print '<td><input size="5" type="text" value="'.$prices['quantity'].'" name="quantity"></td>';
|
||||
print '<td class="right" colspan="2"><input size="10" type="text" value="'.price2num($prices['price'], 'MU').'" name="price"> '.$object->price_base_type.'</td>';
|
||||
print '<td class="right"><input size="5" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
|
||||
print '<td class="right nowraponall"><input size="5" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
|
||||
print '<td class="center"><input type="submit" value="'.$langs->trans("Modify").'" class="button"></td>';
|
||||
print '</tr>';
|
||||
print '</form>';
|
||||
@ -917,9 +924,9 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_
|
||||
print '<td class="right">'.price($prices['remise_percent']).' %</td>';
|
||||
print '<td class="center">';
|
||||
if (($user->rights->produit->creer || $user->rights->service->creer)) {
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit_price_by_qty&rowid='.$prices["rowid"].'">';
|
||||
print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit_price_by_qty&rowid='.$prices["rowid"].'">';
|
||||
print img_edit().'</a>';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_price_by_qty&rowid='.$prices["rowid"].'">';
|
||||
print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_price_by_qty&rowid='.$prices["rowid"].'">';
|
||||
print img_delete().'</a>';
|
||||
} else {
|
||||
print ' ';
|
||||
@ -930,6 +937,7 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_
|
||||
}
|
||||
if ($action != 'edit_price_by_qty' && ($user->rights->produit->creer || $user->rights->service->creer)) {
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="update_price_by_qty">';
|
||||
print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].'">'; // id in product_price
|
||||
print '<input type="hidden" value="0" name="rowid">'; // id in product_price
|
||||
@ -937,17 +945,17 @@ if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_
|
||||
print '<td><input size="5" type="text" value="1" name="quantity"></td>';
|
||||
print '<td class="right" class="nowrap"><input size="10" type="text" value="0" name="price"> '.$object->price_base_type.'</td>';
|
||||
print '<td class="right"> </td>';
|
||||
print '<td class="right" class="nowrap"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
|
||||
print '<td class="right" class="nowraponall"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
|
||||
print '<td class="center"><input type="submit" value="'.$langs->trans("Add").'" class="button"></td>';
|
||||
print '</tr>';
|
||||
print '</form>';
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable_price_by_qty&level='.$i.'">('.$langs->trans("DisablePriceByQty").')</a>';
|
||||
print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable_price_by_qty&level='.$i.'">('.$langs->trans("DisablePriceByQty").')</a>';
|
||||
} else {
|
||||
print $langs->trans("No");
|
||||
print ' <a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=activate_price_by_qty&level='.$i.'">('.$langs->trans("Activate").')</a>';
|
||||
print ' <a class="marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=activate_price_by_qty&level='.$i.'">('.$langs->trans("Activate").')</a>';
|
||||
}
|
||||
print '</td></tr>';
|
||||
}
|
||||
@ -1019,6 +1027,7 @@ else
|
||||
if ($action != 'edit_price_by_qty')
|
||||
{
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">'; // FIXME a form into a table is not allowed
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="update_price_by_qty">';
|
||||
print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].'">'; // id in product_price
|
||||
print '<input type="hidden" value="0" name="rowid">'; // id in product_price_by_qty
|
||||
@ -1030,7 +1039,7 @@ else
|
||||
//print $object->price_base_type;
|
||||
print '</td>';
|
||||
print '<td class="right"> </td>';
|
||||
print '<td class="right"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>';
|
||||
print '<td class="right nowraponall"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>';
|
||||
print '<td class="center"><input type="submit" value="'.$langs->trans("Add").'" class="button"></td>';
|
||||
print '</tr>';
|
||||
|
||||
@ -1041,6 +1050,7 @@ else
|
||||
if ($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->rights->produit->creer || $user->rights->service->creer))
|
||||
{
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="action" value="update_price_by_qty">';
|
||||
print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].'">'; // id in product_price
|
||||
print '<input type="hidden" value="'.$prices['rowid'].'" name="rowid">'; // id in product_price_by_qty
|
||||
@ -1052,7 +1062,7 @@ else
|
||||
print $prices['price_base_type'];
|
||||
print '</td>';
|
||||
print '<td class="right"> </td>';
|
||||
print '<td class="right"><input class="width50 right" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
|
||||
print '<td class="right nowraponall"><input class="width50 right" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
|
||||
print '<td class="center"><input type="submit" value="'.$langs->trans("Modify").'" class="button"></td>';
|
||||
print '</tr>';
|
||||
print '</form>';
|
||||
@ -1069,9 +1079,9 @@ else
|
||||
print '<td class="center">';
|
||||
if (($user->rights->produit->creer || $user->rights->service->creer))
|
||||
{
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit_price_by_qty&rowid='.$prices["rowid"].'">';
|
||||
print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit_price_by_qty&rowid='.$prices["rowid"].'">';
|
||||
print img_edit().'</a>';
|
||||
print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_price_by_qty&rowid='.$prices["rowid"].'">';
|
||||
print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_price_by_qty&rowid='.$prices["rowid"].'">';
|
||||
print img_delete().'</a>';
|
||||
} else {
|
||||
print ' ';
|
||||
@ -1862,6 +1872,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
||||
if (count($prodcustprice->lines) > 0)
|
||||
{
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||
|
||||
print '<table class="noborder centpercent">';
|
||||
@ -1983,6 +1994,7 @@ if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES))
|
||||
print_barre_liste($langs->trans('PriceByCustomer'), $page, $_SERVER ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png');
|
||||
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
|
||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||
print '<input type="hidden" name="id" value="'.$object->id.'">';
|
||||
|
||||
print '<table class="noborder centpercent">';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user