NEW: deposit payment terms: set deposit percentage in company card
This commit is contained in:
parent
4b3fc4d7f3
commit
4d6c1d892b
@ -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 '</tr></table>';
|
||||
print '</td><td>';
|
||||
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 "</td>";
|
||||
print '</tr>';
|
||||
|
||||
@ -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());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user