From b0aa502ed425aac4b091c8248b8c24d8a1efdd46 Mon Sep 17 00:00:00 2001
From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com>
Date: Wed, 29 Sep 2021 14:51:30 +0200
Subject: [PATCH] NEW: deposit payment terms: set deposit percentage in
proposals/orders + get from origin document or company
---
htdocs/comm/propal/card.php | 10 ++++++----
htdocs/commande/card.php | 20 +++++++++++++++-----
htdocs/core/class/commonobject.class.php | 2 +-
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php
index cff5c5d0e35..12b7138ce51 100644
--- a/htdocs/comm/propal/card.php
+++ b/htdocs/comm/propal/card.php
@@ -397,6 +397,7 @@ if (empty($reshook)) {
$object->warehouse_id = GETPOST('warehouse_id', 'int');
$object->duree_validite = $duration;
$object->cond_reglement_id = GETPOST('cond_reglement_id');
+ $object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'int');
$object->mode_reglement_id = GETPOST('mode_reglement_id');
$object->fk_account = GETPOST('fk_account', 'int');
$object->remise_percent = price2num(GETPOST('remise_percent'), '', 2);
@@ -429,6 +430,7 @@ if (empty($reshook)) {
$object->warehouse_id = GETPOST('warehouse_id', 'int');
$object->duree_validite = price2num(GETPOST('duree_validite', 'alpha'));
$object->cond_reglement_id = GETPOST('cond_reglement_id', 'int');
+ $object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'int');
$object->mode_reglement_id = GETPOST('mode_reglement_id', 'int');
$object->fk_account = GETPOST('fk_account', 'int');
$object->contact_id = GETPOST('contactid', 'int');
@@ -1358,7 +1360,7 @@ if (empty($reshook)) {
$result = $object->set_demand_reason($user, GETPOST('demand_reason_id', 'int'));
} elseif ($action == 'setconditions' && $usercancreate) {
// Terms of payment
- $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
+ $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'int'));
} elseif ($action == 'setremisepercent' && $usercancreate) {
$result = $object->set_remise_percent($user, price2num(GETPOST('remise_percent'), '', 2));
} elseif ($action == 'setremiseabsolue' && $usercancreate) {
@@ -1647,7 +1649,7 @@ if ($action == 'create') {
// Terms of payment
print '
| '.$langs->trans('PaymentConditionsShort').' | ';
print img_picto('', 'paiment');
- $form->select_conditions_paiements((GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $soc->cond_reglement_id), 'cond_reglement_id', -1, 1);
+ $form->select_conditions_paiements((GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $soc->cond_reglement_id), 'cond_reglement_id', -1, 1, 0, '', (GETPOSTISSET('cond_reglement_id_deposit_percent') ? GETPOST('cond_reglement_id_deposit_percent', 'int') : $soc->deposit_percent));
print ' |
';
// Mode of payment
@@ -2155,9 +2157,9 @@ if ($action == 'create') {
print '';
print '';
if ($object->statut == Propal::STATUS_DRAFT && $action == 'editconditions' && $usercancreate) {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id');
+ $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 0, $object->deposit_percent);
} else {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
+ $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 0, $object->deposit_percent);
}
print ' | ';
print '';
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index decabedc2e8..e933231822a 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -268,6 +268,7 @@ if (empty($reshook)) {
$object->ref_client = GETPOST('ref_client', 'alpha');
$object->model_pdf = GETPOST('model');
$object->cond_reglement_id = GETPOST('cond_reglement_id');
+ $object->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'int');
$object->mode_reglement_id = GETPOST('mode_reglement_id');
$object->fk_account = GETPOST('fk_account', 'int');
$object->availability_id = GETPOST('availability_id');
@@ -548,7 +549,7 @@ if (empty($reshook)) {
setEventMessages($object->error, $object->errors, 'errors');
}
} elseif ($action == 'setmode' && $usercancreate) {
- $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
+ $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'), GETPOST('mode_reglement_id_deposit_percent', 'int'));
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
}
@@ -569,7 +570,7 @@ if (empty($reshook)) {
setEventMessages($object->error, $object->errors, 'errors');
}
} elseif ($action == 'setconditions' && $usercancreate) {
- $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) {
dol_print_error($db, $object->error);
} else {
@@ -1437,6 +1438,10 @@ if ($action == 'create' && $usercancreate) {
$currency_code = $conf->currency;
+ $cond_reglement_id = GETPOST('cond_reglement_id', 'int');
+ $deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'int');
+ $mode_reglement_id = GETPOST('mode_reglement_id', 'int');
+
if (!empty($origin) && !empty($originid)) {
// Parse element/subelement (ex: project_task)
$element = $subelement = $origin;
@@ -1452,6 +1457,9 @@ if ($action == 'create' && $usercancreate) {
if (!$cond_reglement_id) {
$cond_reglement_id = $soc->cond_reglement_id;
}
+ if (!$deposit_percent) {
+ $deposit_percent = $soc->deposit_percent;
+ }
if (!$mode_reglement_id) {
$mode_reglement_id = $soc->mode_reglement_id;
}
@@ -1492,6 +1500,7 @@ if ($action == 'create' && $usercancreate) {
$soc = $objectsrc->thirdparty;
$cond_reglement_id = (!empty($objectsrc->cond_reglement_id) ? $objectsrc->cond_reglement_id : (!empty($soc->cond_reglement_id) ? $soc->cond_reglement_id : 0)); // TODO maybe add default value option
+ $deposit_percent = (!empty($objectsrc->deposit_percent) ? $objectsrc->deposit_percent : (!empty($soc->deposit_percent) ? $soc->deposit_percent : null));
$mode_reglement_id = (!empty($objectsrc->mode_reglement_id) ? $objectsrc->mode_reglement_id : (!empty($soc->mode_reglement_id) ? $soc->mode_reglement_id : 0));
$fk_account = (!empty($objectsrc->fk_account) ? $objectsrc->fk_account : (!empty($soc->fk_account) ? $soc->fk_account : 0));
$availability_id = (!empty($objectsrc->availability_id) ? $objectsrc->availability_id : (!empty($soc->availability_id) ? $soc->availability_id : 0));
@@ -1524,6 +1533,7 @@ if ($action == 'create' && $usercancreate) {
}
} else {
$cond_reglement_id = $soc->cond_reglement_id;
+ $deposit_percent = $soc->deposit_percent;
$mode_reglement_id = $soc->mode_reglement_id;
$fk_account = $soc->fk_account;
$availability_id = $soc->availability_id;
@@ -1649,7 +1659,7 @@ if ($action == 'create' && $usercancreate) {
// Terms of the settlement
print '| '.$langs->trans('PaymentConditionsShort').' | ';
print img_picto('', 'paiment');
- $form->select_conditions_paiements($cond_reglement_id, 'cond_reglement_id', - 1, 1);
+ $form->select_conditions_paiements($cond_reglement_id, 'cond_reglement_id', - 1, 1, 0, '', $deposit_percent);
print ' |
';
// Mode de reglement
@@ -2215,9 +2225,9 @@ if ($action == 'create' && $usercancreate) {
print $form->editfieldkey("PaymentConditionsShort", 'conditions', '', $object, $editenable);
print '';
if ($action == 'editconditions') {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
+ $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1, $object->deposit_percent);
} else {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1);
+ $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none', 1, $object->deposit_percent);
}
print ' | ';
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 01f42a73417..2a7c0c87353 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -2554,7 +2554,7 @@ abstract class CommonObject
*/
public function setPaymentTerms($id, $deposit_percent = null)
{
- dol_syslog(get_class($this).'::setPaymentTerms('.$id.')');
+ dol_syslog(get_class($this).'::setPaymentTerms('.$id.', '.var_export($deposit_percent, true).')');
if ($this->statut >= 0 || $this->element == 'societe') {
// TODO uniformize field name
$fieldname = 'fk_cond_reglement';