NEW: deposit payment terms: futureproof evolutions by storing field as a string

This commit is contained in:
Marc de Lima Lucio 2021-10-28 16:53:28 +02:00
parent 03c24b2274
commit 7e059c0a22
14 changed files with 30 additions and 30 deletions

View File

@ -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');
}

View File

@ -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 '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
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 '</td></tr>';
// Mode of payment

View File

@ -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").",";

View File

@ -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)) {

View File

@ -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").",";

View File

@ -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)) {

View File

@ -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 ' <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 '<input id="'.$htmlname.'_deposit_percent" name="'.$htmlname.'_deposit_percent" class="maxwidth50" value="' . strval($deposit_percent) . '" />';
print '</span>';
print '
<script>
@ -5150,7 +5150,7 @@ class Form
* @param int $addempty Add empty entry
* @param string $type Type ('direct-debit' or 'bank-transfer')
* @param int $filtertype If > 0, include payment terms with deposit percentage (for objects other than invoices and invoice templates)
* @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

View File

@ -40,4 +40,4 @@ insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (10,'10DENDMONTH', 10,1, '10 days end of month','Due in 10 days, end of month',1,10,NULL);
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (11,'14D', 11,1, '14 days','Due in 14 days',0,14,NULL);
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (12,'14DENDMONTH', 12,1, '14 days end of month','Due in 14 days, end of month',1,14,NULL);
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (13,'DEP30PCTDEL', 13,0, '__DEPOSIT_PERCENT__% deposit','__DEPOSIT_PERCENT__% deposit, remainder on delivery',0,1,30);
insert into llx_c_payment_term(rowid, code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values (13,'DEP30PCTDEL', 13,0, '__DEPOSIT_PERCENT__% deposit','__DEPOSIT_PERCENT__% deposit, remainder on delivery',0,1,'30');

View File

@ -155,11 +155,11 @@ INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2011', '
INSERT INTO llx_c_forme_juridique (fk_pays, code, libelle) VALUES (20, '2012', 'Stiftelse');
-- Deposit generation helper with specific payment terms
ALTER TABLE llx_c_payment_term ADD COLUMN deposit_percent real DEFAULT NULL AFTER decalage;
ALTER TABLE llx_societe ADD COLUMN deposit_percent real DEFAULT NULL AFTER cond_reglement;
ALTER TABLE llx_propal ADD COLUMN deposit_percent real DEFAULT NULL AFTER fk_cond_reglement;
ALTER TABLE llx_commande ADD COLUMN deposit_percent real DEFAULT NULL AFTER fk_cond_reglement;
INSERT INTO llx_c_payment_term(code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values ('DEP30PCTDEL', 13, 0, '__DEPOSIT_PERCENT__% deposit', '__DEPOSIT_PERCENT__% deposit, remainder on delivery', 0, 1, 30);
ALTER TABLE llx_c_payment_term ADD COLUMN deposit_percent VARCHAR(63) DEFAULT NULL AFTER decalage;
ALTER TABLE llx_societe ADD COLUMN deposit_percent VARCHAR(63) DEFAULT NULL AFTER cond_reglement;
ALTER TABLE llx_propal ADD COLUMN deposit_percent VARCHAR(63) DEFAULT NULL AFTER fk_cond_reglement;
ALTER TABLE llx_commande ADD COLUMN deposit_percent VARCHAR(63) DEFAULT NULL AFTER fk_cond_reglement;
INSERT INTO llx_c_payment_term(code, sortorder, active, libelle, libelle_facture, type_cdr, nbjour, deposit_percent) values ('DEP30PCTDEL', 13, 0, '__DEPOSIT_PERCENT__% deposit', '__DEPOSIT_PERCENT__% deposit, remainder on delivery', 0, 1, '30');
-- START GRH/HRM MODULE

View File

@ -30,7 +30,7 @@ create table llx_c_payment_term
type_cdr tinyint, -- Type of change date reckoning. 1=Payment at end of current month, 2=the Nth of next month
nbjour smallint,
decalage smallint,
deposit_percent real DEFAULT NULL,
deposit_percent varchar(63) DEFAULT NULL,
module varchar(32) NULL,
position integer NOT NULL DEFAULT 0
)ENGINE=innodb;

View File

@ -63,7 +63,7 @@ create table llx_commande
fk_account integer, -- bank account
fk_currency varchar(3), -- currency code
fk_cond_reglement integer, -- condition de reglement
deposit_percent real DEFAULT NULL, -- default deposit % if payment term needs it
deposit_percent varchar(63) DEFAULT NULL, -- default deposit % if payment term needs it
fk_mode_reglement integer, -- mode de reglement
date_livraison datetime default NULL,

View File

@ -58,7 +58,7 @@ create table llx_propal
fk_account integer, -- bank account
fk_currency varchar(3), -- currency code
fk_cond_reglement integer, -- condition de reglement (30 jours, fin de mois ...)
deposit_percent real DEFAULT NULL, -- default deposit % if payment term needs it
deposit_percent varchar(63) DEFAULT NULL, -- default deposit % if payment term needs it
fk_mode_reglement integer, -- mode de reglement (Virement, Prelevement)
note_private text,

View File

@ -92,7 +92,7 @@ create table llx_societe
remise_supplier real DEFAULT 0, -- discount by default granted by this supplier
mode_reglement tinyint, -- payment mode customer
cond_reglement tinyint, -- payment term customer
deposit_percent real DEFAULT NULL, -- default deposit % if payment term needs it
deposit_percent varchar(63) DEFAULT NULL, -- default deposit % if payment term needs it
transport_mode tinyint, -- transport mode customer (Intracomm report)
mode_reglement_supplier tinyint, -- payment mode supplier
cond_reglement_supplier tinyint, -- payment term supplier

View File

@ -208,7 +208,7 @@ class Societe extends CommonObject
//'remise_supplier' =>array('type'=>'double', 'label'=>'SupplierDiscount', 'enabled'=>1, 'visible'=>-1, 'position'=>290, 'isameasure'=>1),
'mode_reglement' =>array('type'=>'tinyint(4)', 'label'=>'Mode reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>295),
'cond_reglement' =>array('type'=>'tinyint(4)', 'label'=>'Cond reglement', 'enabled'=>1, 'visible'=>-1, 'position'=>300),
'deposit_percent' =>array('type'=>'double', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>301),
'deposit_percent' =>array('type'=>'varchar(63)', 'label'=>'DepositPercent', 'enabled'=>1, 'visible'=>-1, 'position'=>301),
'mode_reglement_supplier' =>array('type'=>'integer', 'label'=>'Mode reglement supplier', 'enabled'=>1, 'visible'=>-1, 'position'=>305),
'outstanding_limit' =>array('type'=>'double(24,8)', 'label'=>'OutstandingBill', 'enabled'=>1, 'visible'=>-1, 'position'=>310, 'isameasure'=>1),
'order_min_amount' =>array('type'=>'double(24,8)', 'label'=>'Order min amount', 'enabled'=>'!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)', 'visible'=>-1, 'position'=>315, 'isameasure'=>1),
@ -1454,7 +1454,7 @@ class Societe extends CommonObject
$sql .= ",mode_reglement = ".(!empty($this->mode_reglement_id) ? "'".$this->db->escape($this->mode_reglement_id)."'" : "null");
$sql .= ",cond_reglement = ".(!empty($this->cond_reglement_id) ? "'".$this->db->escape($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 .= ",transport_mode = ".(!empty($this->transport_mode_id) ? "'".$this->db->escape($this->transport_mode_id)."'" : "null");
$sql .= ",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ? "'".$this->db->escape($this->mode_reglement_supplier_id)."'" : "null");
$sql .= ",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ? "'".$this->db->escape($this->cond_reglement_supplier_id)."'" : "null");