NEW: deposit payment terms: add input in payment conditions form
This commit is contained in:
parent
004b52f590
commit
4b3fc4d7f3
@ -3609,7 +3609,7 @@ class Form
|
|||||||
|
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
|
|
||||||
$sql = "SELECT rowid, code, libelle as label";
|
$sql = "SELECT rowid, code, libelle as label, deposit_percent";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX.'c_payment_term';
|
$sql .= " FROM ".MAIN_DB_PREFIX.'c_payment_term';
|
||||||
$sql .= " WHERE entity IN (".getEntity('c_payment_term').")";
|
$sql .= " WHERE entity IN (".getEntity('c_payment_term').")";
|
||||||
$sql .= " AND active > 0";
|
$sql .= " AND active > 0";
|
||||||
@ -3621,11 +3621,11 @@ class Form
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
while ($i < $num) {
|
while ($i < $num) {
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
|
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
|
||||||
$label = ($langs->trans("PaymentConditionShort".$obj->code) != ("PaymentConditionShort".$obj->code) ? $langs->trans("PaymentConditionShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
|
$label = ($langs->trans("PaymentConditionShort".$obj->code) != ("PaymentConditionShort".$obj->code) ? $langs->trans("PaymentConditionShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
|
||||||
$this->cache_conditions_paiements[$obj->rowid]['code'] = $obj->code;
|
$this->cache_conditions_paiements[$obj->rowid]['code'] = $obj->code;
|
||||||
$this->cache_conditions_paiements[$obj->rowid]['label'] = $label;
|
$this->cache_conditions_paiements[$obj->rowid]['label'] = $label;
|
||||||
|
$this->cache_conditions_paiements[$obj->rowid]['deposit_percent'] = $obj->deposit_percent;
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3881,9 +3881,10 @@ class Form
|
|||||||
* @param int $addempty Add an empty entry
|
* @param int $addempty Add an empty entry
|
||||||
* @param int $noinfoadmin 0=Add admin info, 1=Disable admin info
|
* @param int $noinfoadmin 0=Add admin info, 1=Disable admin info
|
||||||
* @param string $morecss Add more CSS on select tag
|
* @param string $morecss Add more CSS on select tag
|
||||||
|
* @param float $deposit_percent % of deposit if needed by payment conditions
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function select_conditions_paiements($selected = 0, $htmlname = 'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss = '')
|
public function select_conditions_paiements($selected = 0, $htmlname = 'condid', $filtertype = -1, $addempty = 0, $noinfoadmin = 0, $morecss = '', $deposit_percent = null)
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
global $langs, $user, $conf;
|
global $langs, $user, $conf;
|
||||||
@ -3901,13 +3902,24 @@ class Form
|
|||||||
if ($addempty) {
|
if ($addempty) {
|
||||||
print '<option value="0"> </option>';
|
print '<option value="0"> </option>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$selectedDepositPercent = null;
|
||||||
foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
|
foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
|
||||||
if ($selected == $id) {
|
if ($selected == $id) {
|
||||||
print '<option value="'.$id.'" selected>';
|
$selectedDepositPercent = ! empty($deposit_percent) ? $deposit_percent : $arrayconditions['deposit_percent'];
|
||||||
|
print '<option value="'.$id.'" data-deposit_percent="' . $arrayconditions['deposit_percent'] . '" selected>';
|
||||||
} else {
|
} else {
|
||||||
print '<option value="'.$id.'">';
|
print '<option value="'.$id.'" data-deposit_percent="' . $arrayconditions['deposit_percent'] . '">';
|
||||||
}
|
}
|
||||||
print $arrayconditions['label'];
|
|
||||||
|
$label = $arrayconditions['label'];
|
||||||
|
|
||||||
|
if (! empty($arrayconditions['deposit_percent'])) {
|
||||||
|
$label = sprintf($label, ! empty($deposit_percent) ? $deposit_percent : $arrayconditions['deposit_percent']);
|
||||||
|
}
|
||||||
|
|
||||||
|
print $label;
|
||||||
|
|
||||||
print '</option>';
|
print '</option>';
|
||||||
}
|
}
|
||||||
print '</select>';
|
print '</select>';
|
||||||
@ -3915,6 +3927,28 @@ class Form
|
|||||||
print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
||||||
}
|
}
|
||||||
print ajax_combobox($htmlname);
|
print ajax_combobox($htmlname);
|
||||||
|
print ' <span id="'.$htmlname.'_deposit_percent_container"' . (empty($selectedDepositPercent) ? ' style="display: none"' : '') . '>';
|
||||||
|
print $langs->trans('DepositPercent') . ' : ';
|
||||||
|
print '<input id="'.$htmlname.'_deposit_percent" name="'.$htmlname.'_deposit_percent" class="maxwidth50" value="' . floatval($deposit_percent) . '" />';
|
||||||
|
print '</span>';
|
||||||
|
print '
|
||||||
|
<script>
|
||||||
|
// let defaultDepositPercent = ' . (! empty($depositPercent) ? $depositPercent : null) . ';
|
||||||
|
$(document).ready(function () {
|
||||||
|
$("#' . $htmlname . '").change(function () {
|
||||||
|
let $selected = $(this).find("option:selected");
|
||||||
|
let depositPercent = $selected.attr("data-deposit_percent");
|
||||||
|
|
||||||
|
if (depositPercent.length > 0) {
|
||||||
|
$("#'.$htmlname.'_deposit_percent_container").show().find("#'.$htmlname.'_deposit_percent").val(depositPercent);
|
||||||
|
} else {
|
||||||
|
$("#'.$htmlname.'_deposit_percent_container").hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -5103,9 +5137,10 @@ class Form
|
|||||||
* @param string $selected Id condition pre-selectionne
|
* @param string $selected Id condition pre-selectionne
|
||||||
* @param string $htmlname Name of select html field
|
* @param string $htmlname Name of select html field
|
||||||
* @param int $addempty Add empty entry
|
* @param int $addempty Add empty entry
|
||||||
|
* @param float $deposit_percent % of deposit if needed by payment conditions
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function form_conditions_reglement($page, $selected = '', $htmlname = 'cond_reglement_id', $addempty = 0)
|
public function form_conditions_reglement($page, $selected = '', $htmlname = 'cond_reglement_id', $addempty = 0, $deposit_percent = null)
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
global $langs;
|
global $langs;
|
||||||
@ -5113,14 +5148,20 @@ class Form
|
|||||||
print '<form method="post" action="'.$page.'">';
|
print '<form method="post" action="'.$page.'">';
|
||||||
print '<input type="hidden" name="action" value="setconditions">';
|
print '<input type="hidden" name="action" value="setconditions">';
|
||||||
print '<input type="hidden" name="token" value="'.newToken().'">';
|
print '<input type="hidden" name="token" value="'.newToken().'">';
|
||||||
$this->select_conditions_paiements($selected, $htmlname, -1, $addempty);
|
$this->select_conditions_paiements($selected, $htmlname, -1, $addempty, 0, '', $deposit_percent);
|
||||||
print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
|
print '<input type="submit" class="button valignmiddle smallpaddingimp" value="'.$langs->trans("Modify").'">';
|
||||||
print '</form>';
|
print '</form>';
|
||||||
} else {
|
} else {
|
||||||
if ($selected) {
|
if ($selected) {
|
||||||
$this->load_cache_conditions_paiements();
|
$this->load_cache_conditions_paiements();
|
||||||
if (isset($this->cache_conditions_paiements[$selected])) {
|
if (isset($this->cache_conditions_paiements[$selected])) {
|
||||||
print $this->cache_conditions_paiements[$selected]['label'];
|
$label = $this->cache_conditions_paiements[$selected]['label'];
|
||||||
|
|
||||||
|
if (! empty($this->cache_conditions_paiements[$selected]['deposit_percent'])) {
|
||||||
|
$label = sprintf($label, ! empty($deposit_percent) ? $deposit_percent : $this->cache_conditions_paiements[$selected]['deposit_percent']);
|
||||||
|
}
|
||||||
|
|
||||||
|
print $label;
|
||||||
} else {
|
} else {
|
||||||
$langs->load('errors');
|
$langs->load('errors');
|
||||||
print $langs->trans('ErrorNotInDictionaryPaymentConditions');
|
print $langs->trans('ErrorNotInDictionaryPaymentConditions');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user