diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php
index c9f422d78c8..b511d932f52 100644
--- a/htdocs/comm/card.php
+++ b/htdocs/comm/card.php
@@ -169,7 +169,7 @@ if (empty($reshook)) {
// terms of the settlement
if ($action == 'setconditions' && $user->rights->societe->creer) {
$object->fetch($id);
- $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
+ $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'int'));
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
@@ -411,9 +411,9 @@ if ($object->id > 0) {
print '';
print '
';
if ($action == 'editconditions') {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
+ $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, $object->deposit_percent);
} else {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none');
+ $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none', 0, $object->deposit_percent);
}
print " | ";
print '';
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 7adf7a89079..01f42a73417 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2548,10 +2548,11 @@ abstract class CommonObject
/**
* Change the payments terms
*
- * @param int $id Id of new payment terms
- * @return int >0 if OK, <0 if KO
+ * @param int $id Id of new payment terms
+ * @param float $deposit_percent % of deposit if needed by payment terms
+ * @return int >0 if OK, <0 if KO
*/
- public function setPaymentTerms($id)
+ public function setPaymentTerms($id, $deposit_percent = null)
{
dol_syslog(get_class($this).'::setPaymentTerms('.$id.')');
if ($this->statut >= 0 || $this->element == 'societe') {
@@ -2564,8 +2565,17 @@ abstract class CommonObject
$fieldname = 'cond_reglement_supplier';
}
+ if (empty($deposit_percent) || $deposit_percent < 0) {
+ $deposit_percent = null;
+ }
+
+ if ($deposit_percent > 100) {
+ $deposit_percent = 100;
+ }
+
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
$sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL');
+ $sql .= " , deposit_percent = " . (! empty($deposit_percent) ? floatval($deposit_percent) : 'NULL');
$sql .= ' WHERE rowid='.((int) $this->id);
if ($this->db->query($sql)) {
@@ -2575,6 +2585,7 @@ abstract class CommonObject
$this->cond_reglement_supplier_id = $id;
}
$this->cond_reglement = $id; // for compatibility
+ $this->deposit_percent = $deposit_percent;
return 1;
} else {
dol_syslog(get_class($this).'::setPaymentTerms Error '.$sql.' - '.$this->db->error());