From 7e059c0a22135c24ff8296bb1b5947d157578ac8 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Thu, 28 Oct 2021 16:53:28 +0200 Subject: [PATCH] NEW: deposit payment terms: futureproof evolutions by storing field as a string --- htdocs/comm/card.php | 2 +- htdocs/comm/propal/card.php | 6 +++--- htdocs/comm/propal/class/propal.class.php | 6 +++--- htdocs/commande/card.php | 6 +++--- htdocs/commande/class/commande.class.php | 6 +++--- htdocs/core/class/commonobject.class.php | 4 ++-- htdocs/core/class/html.form.class.php | 6 +++--- htdocs/install/mysql/data/llx_c_payment_term.sql | 2 +- htdocs/install/mysql/migration/14.0.0-15.0.0.sql | 10 +++++----- htdocs/install/mysql/tables/llx_c_payment_term.sql | 2 +- htdocs/install/mysql/tables/llx_commande.sql | 2 +- htdocs/install/mysql/tables/llx_propal.sql | 2 +- htdocs/install/mysql/tables/llx_societe.sql | 2 +- htdocs/societe/class/societe.class.php | 4 ++-- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 38dd976f53c..ec02c3b56ae 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'), GETPOST('cond_reglement_id_deposit_percent', 'int')); + $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'alpha')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 891aa1698b4..113f4039b16 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -397,7 +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->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha'); $object->mode_reglement_id = GETPOST('mode_reglement_id'); $object->fk_account = GETPOST('fk_account', 'int'); $object->remise_percent = price2num(GETPOST('remise_percent'), '', 2); @@ -430,7 +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->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha'); $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int'); $object->fk_account = GETPOST('fk_account', 'int'); $object->contact_id = GETPOST('contactid', 'int'); @@ -1695,7 +1695,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, 0, '', (GETPOSTISSET('cond_reglement_id_deposit_percent') ? GETPOST('cond_reglement_id_deposit_percent', 'int') : $soc->deposit_percent)); + $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', 'alpha') : $soc->deposit_percent)); print ''; // Mode of payment diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index f062fa78b72..6e39507e55f 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -310,7 +310,7 @@ class Propal extends CommonObject 'fk_account' =>array('type'=>'integer', 'label'=>'BankAccount', 'enabled'=>1, 'visible'=>-1, 'position'=>150), 'fk_currency' =>array('type'=>'varchar(3)', 'label'=>'Currency', 'enabled'=>1, 'visible'=>-1, 'position'=>155), 'fk_cond_reglement' =>array('type'=>'integer', 'label'=>'PaymentTerm', 'enabled'=>1, 'visible'=>-1, 'position'=>160), - 'deposit_percent' =>array('type'=>'double', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>161), + 'deposit_percent' =>array('type'=>'varchar(63)', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>161), 'fk_mode_reglement' =>array('type'=>'integer', 'label'=>'PaymentMode', 'enabled'=>1, 'visible'=>-1, 'position'=>165), 'note_private' =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>170), 'note_public' =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>175), @@ -1116,7 +1116,7 @@ class Propal extends CommonObject $sql .= ", '".$this->db->escape($this->model_pdf)."'"; $sql .= ", ".($this->fin_validite != '' ? "'".$this->db->idate($this->fin_validite)."'" : "NULL"); $sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : 'NULL'); - $sql .= ", ".(! empty($this->deposit_percent) ? floatval($this->deposit_percent) : 'NULL'); + $sql .= ", ".(! empty($this->deposit_percent) ? "'".$this->db->escape($this->deposit_percent)."'" : 'NULL'); $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : 'NULL'); $sql .= ", ".($this->fk_account > 0 ? ((int) $this->fk_account) : 'NULL'); $sql .= ", '".$this->db->escape($this->ref_client)."'"; @@ -1661,7 +1661,7 @@ class Propal extends CommonObject $sql .= " fk_user_valid=".(isset($this->user_valid) ? $this->user_valid : "null").","; $sql .= " fk_projet=".(isset($this->fk_project) ? $this->fk_project : "null").","; $sql .= " fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id : "null").","; - $sql .= " deposit_percent=".(! empty($this->deposit_percent) ? floatval($this->deposit_percent) : "null").","; + $sql .= " deposit_percent=".(! empty($this->deposit_percent) ? "'".$this->db->escape($this->deposit_percent)."'" : "null").","; $sql .= " fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id : "null").","; $sql .= " fk_input_reason=".(isset($this->demand_reason_id) ? $this->demand_reason_id : "null").","; $sql .= " note_private=".(isset($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null").","; diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index d167d340dc9..1f507aeb4cc 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -268,7 +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->deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha'); $object->mode_reglement_id = GETPOST('mode_reglement_id'); $object->fk_account = GETPOST('fk_account', 'int'); $object->availability_id = GETPOST('availability_id'); @@ -570,7 +570,7 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'setconditions' && $usercancreate) { - $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'int')); + $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'), GETPOST('cond_reglement_id_deposit_percent', 'alpha')); if ($result < 0) { dol_print_error($db, $object->error); } else { @@ -1484,7 +1484,7 @@ 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'); + $deposit_percent = GETPOST('cond_reglement_id_deposit_percent', 'alpha'); $mode_reglement_id = GETPOST('mode_reglement_id', 'int'); if (!empty($origin) && !empty($originid)) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index e3cb73d205c..a860dd27a9e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -326,7 +326,7 @@ class Commande extends CommonOrder 'fk_account' =>array('type'=>'integer', 'label'=>'BankAccount', 'enabled'=>1, 'visible'=>-1, 'position'=>170), 'fk_currency' =>array('type'=>'varchar(3)', 'label'=>'MulticurrencyID', 'enabled'=>1, 'visible'=>-1, 'position'=>175), 'fk_cond_reglement' =>array('type'=>'integer', 'label'=>'PaymentTerm', 'enabled'=>1, 'visible'=>-1, 'position'=>180), - 'deposit_percent' =>array('type'=>'double', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>181), + 'deposit_percent' =>array('type'=>'varchar(63)', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>181), 'fk_mode_reglement' =>array('type'=>'integer', 'label'=>'PaymentMode', 'enabled'=>1, 'visible'=>-1, 'position'=>185), 'date_livraison' =>array('type'=>'date', 'label'=>'DateDeliveryPlanned', 'enabled'=>1, 'visible'=>-1, 'position'=>190), 'fk_shipping_method' =>array('type'=>'integer', 'label'=>'ShippingMethod', 'enabled'=>1, 'visible'=>-1, 'position'=>195), @@ -951,7 +951,7 @@ class Commande extends CommonOrder $sql .= ", ".($this->ref_int ? "'".$this->db->escape($this->ref_int)."'" : "null"); $sql .= ", '".$this->db->escape($this->model_pdf)."'"; $sql .= ", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) : "null"); - $sql .= ", ".(! empty($this->deposit_percent) ? floatval($this->deposit_percent) : "null"); + $sql .= ", ".(! empty($this->deposit_percent) ? "'".$this->db->escape($this->deposit_percent)."'" : "null"); $sql .= ", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) : "null"); $sql .= ", ".($this->fk_account > 0 ? ((int) $this->fk_account) : 'NULL'); $sql .= ", ".($this->availability_id > 0 ? ((int) $this->availability_id) : "null"); @@ -3319,7 +3319,7 @@ class Commande extends CommonOrder $sql .= " fk_user_valid=".(isset($this->user_valid) ? $this->user_valid : "null").","; $sql .= " fk_projet=".(isset($this->fk_project) ? $this->fk_project : "null").","; $sql .= " fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id : "null").","; - $sql .= " deposit_percent=".(! empty($this->deposit_percent) ? floatval($this->deposit_percent) : "null").","; + $sql .= " deposit_percent=".(! empty($this->deposit_percent) ? strval($this->deposit_percent) : "null").","; $sql .= " fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id : "null").","; $sql .= " date_livraison=".(strval($this->delivery_date) != '' ? "'".$this->db->idate($this->delivery_date)."'" : 'null').","; $sql .= " fk_shipping_method=".(isset($this->shipping_method_id) ? $this->shipping_method_id : "null").","; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 6460fd16e41..57e1157824e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2549,7 +2549,7 @@ abstract class CommonObject * Change the payments terms * * @param int $id Id of new payment terms - * @param float $deposit_percent % of deposit if needed by payment terms + * @param string $deposit_percent % of deposit if needed by payment terms * @return int >0 if OK, <0 if KO */ public function setPaymentTerms($id, $deposit_percent = null) @@ -2575,7 +2575,7 @@ abstract class CommonObject $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 .= " , deposit_percent = " . (! empty($deposit_percent) ? "'".$this->db->escape($deposit_percent)."'" : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); if ($this->db->query($sql)) { diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 2db440abe4c..81b0dee421b 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3888,7 +3888,7 @@ class Form * @param int $addempty Add an empty entry * @param int $noinfoadmin 0=Add admin info, 1=Disable admin info * @param string $morecss Add more CSS on select tag - * @param float $deposit_percent < 0 : deposit_percent input makes no sense (for example, in list filters) + * @param string $deposit_percent < 0 : deposit_percent input makes no sense (for example, in list filters) * 0 : use default deposit percentage from entry * > 0 : force deposit percentage (for example, from company object) * @return void @@ -3939,7 +3939,7 @@ class Form if ($deposit_percent >= 0) { print ' '; print '