From c860c0dc4a72c35b38dfc5aee34ba968a1e1a13b Mon Sep 17 00:00:00 2001 From: BENKE Charlene <1179011+defrance@users.noreply.github.com> Date: Thu, 26 Nov 2020 11:47:45 +0100 Subject: [PATCH 001/628] Add default BOM --- htdocs/install/mysql/tables/llx_product.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index 2431c884c62..a1ccf065ffa 100644 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -100,5 +100,6 @@ create table llx_product desiredstock float DEFAULT 0, fk_unit integer DEFAULT NULL, price_autogen tinyint DEFAULT 0, + fk_default_bom integer DEFAULT NULL, fk_project integer DEFAULT NULL -- Used when product was generated by a project or is specifif to a project )ENGINE=innodb; From c2bd30a7e92445e10b6ffd0cc90b3121178d8816 Mon Sep 17 00:00:00 2001 From: BENKE Charlene <1179011+defrance@users.noreply.github.com> Date: Thu, 26 Nov 2020 11:59:00 +0100 Subject: [PATCH 002/628] working progress --- htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 1 + htdocs/product/class/product.class.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index c83755009ae..95d6d208145 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -29,6 +29,7 @@ -- Missing in v12 or lower +ALTER TABLE llx_product ADD COLUMN fk_default_bom integer DEFAULT NULL; ALTER TABLE llx_payment_salary MODIFY COLUMN ref varchar(30) NULL; ALTER TABLE llx_payment_various MODIFY COLUMN ref varchar(30) NULL; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 03d81d4fd64..40d63c4643f 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -248,6 +248,13 @@ class Product extends CommonObject */ public $finished; + /** + * fk_default_bom indicates the default bom + * + * @var int + */ + public $fk_default_bom; + /** * We must manage lot/batch number, sell-by date and so on : '1':yes '0':no * @@ -996,6 +1003,7 @@ class Product extends CommonObject $sql .= ", tobuy = ".(int) $this->status_buy; $sql .= ", tobatch = ".((empty($this->status_batch) || $this->status_batch < 0) ? '0' : (int) $this->status_batch); $sql .= ", finished = ".((!isset($this->finished) || $this->finished < 0 || $this->finished == '') ? "null" : (int) $this->finished); + $sql .= ", fk_default_bom = ".((!isset($this->fk_default_bom) || $this->fk_default_bom < 0 || $this->fk_default_bom == '') ? "null" : (int) $this->fk_default_bom); $sql .= ", net_measure = ".($this->net_measure != '' ? "'".$this->db->escape($this->net_measure)."'" : 'null'); $sql .= ", net_measure_units = ".($this->net_measure_units != '' ? "'".$this->db->escape($this->net_measure_units)."'" : 'null'); $sql .= ", weight = ".($this->weight != '' ? "'".$this->db->escape($this->weight)."'" : 'null'); @@ -2046,7 +2054,7 @@ class Product extends CommonObject $sql .= " price_min, price_min_ttc, price_base_type, cost_price, default_vat_code, tva_tx, recuperableonly as tva_npr, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, tosell,"; $sql .= " tobuy, fk_product_type, duration, fk_default_warehouse, seuil_stock_alerte, canvas, net_measure, net_measure_units, weight, weight_units,"; $sql .= " length, length_units, width, width_units, height, height_units,"; - $sql .= " surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,"; + $sql .= " surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,fk_default_bom,"; $sql .= " accountancy_code_buy, accountancy_code_buy_intra, accountancy_code_buy_export,"; $sql .= " accountancy_code_sell, accountancy_code_sell_intra, accountancy_code_sell_export, stock, pmp,"; $sql .= " datec, tms, import_key, entity, desiredstock, tobatch, fk_unit,"; @@ -2107,8 +2115,10 @@ class Product extends CommonObject $this->localtax2_tx = $obj->localtax2_tx; $this->localtax1_type = $obj->localtax1_type; $this->localtax2_type = $obj->localtax2_type; - + $this->finished = $obj->finished; + $this->fk_default_bom = $obj->fk_default_bom; + $this->duration = $obj->duration; $this->duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1); $this->duration_unit = substr($obj->duration, -1); From 5b40950f500f5a2de2e3a7bc58c8f12b42bd70af Mon Sep 17 00:00:00 2001 From: BENKE Charlene <1179011+defrance@users.noreply.github.com> Date: Thu, 26 Nov 2020 12:45:06 +0100 Subject: [PATCH 003/628] Update card.php add on card --- htdocs/product/card.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 6fdfb82e354..5fed4bc4ca1 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -17,7 +17,7 @@ * Copyright (C) 2016 Meziane Sof * Copyright (C) 2017 Josep Lluís Amador * Copyright (C) 2019 Frédéric France - * Copyright (C) 2019-2020 Thibault FOUCART + * Copyright (C) 2019-2020 Thibault FOUCART * Copyright (C) 2020 Pierre Ardoin * * This program is free software; you can redistribute it and/or modify @@ -59,6 +59,7 @@ if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/command if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; +if (!empty($conf->bom->enabled)) require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php'; // Load translation files required by the page $langs->loadLangs(array('products', 'other')); @@ -454,6 +455,13 @@ if (empty($reshook)) $object->finished = null; } + $fk_default_bom = GETPOST('fk_default_bom', 'int'); + if ($fk_default_bom >= 0) { + $object->fk_default_bom = $fk_default_bom; + } else { + $object->fk_default_bom = null; + } + $units = GETPOST('units', 'int'); if ($units > 0) { $object->fk_unit = $units; @@ -1567,6 +1575,13 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print $formproduct->selectProductNature('finished', $object->finished); print ''; + if ($conf->bom->enabled) { + print ''.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc")).''; + $bomkey = "Bom:bom/class/bom.class.php:0:t.status=1 AND t.fk_product=".$object->id; + print $form->selectForForms($bomkey, 'fk_default_bom', $object->fk_default_bom, 1); + print ''; + } + // Brut Weight print ''.$langs->trans("Weight").''; print ' '; @@ -2059,6 +2074,16 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) print $object->getLibFinished(); print ''; + if ($conf->bom->enabled) { + print ''.$form->textwithpicto($langs->trans("DefaultBOM"), $langs->trans("DefaultBOMDesc")).''; + if ($object->fk_default_bom) { + $bom_static = new BOM($db); + $bom_static->fetch($object->fk_default_bom); + print $bom_static->getNomUrl(1); + } + print ''; + } + // Brut Weight print ''.$langs->trans("Weight").''; if ($object->weight != '') From 5329a1792e37bec9098f73b072860a629bd40cf5 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 2 Apr 2021 13:48:27 +0200 Subject: [PATCH 004/628] NEW add action trigger for member excluded --- htdocs/install/mysql/migration/13.0.0-14.0.0.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index af32340170e..60005979239 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -359,3 +359,6 @@ ALTER TABLE llx_propal ADD CONSTRAINT fk_propal_fk_user_signature FOREIGN KEY (f UPDATE llx_propal SET fk_user_signature = fk_user_cloture WHERE fk_user_signature IS NULL AND fk_user_cloture IS NOT NULL; UPDATE llx_propal SET date_signature = date_cloture WHERE date_signature IS NULL AND date_cloture IS NOT NULL; + +INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_EXCLUDE','Member excluded','Executed when a member is excluted','member',26); + From cacc785305cbc3824c2dbfd7526fe04c7c89f5cb Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 2 Apr 2021 13:48:51 +0200 Subject: [PATCH 005/628] Update 13.0.0-14.0.0.sql --- htdocs/install/mysql/migration/13.0.0-14.0.0.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index 60005979239..34a2ffa74fb 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -360,5 +360,5 @@ ALTER TABLE llx_propal ADD CONSTRAINT fk_propal_fk_user_signature FOREIGN KEY (f UPDATE llx_propal SET fk_user_signature = fk_user_cloture WHERE fk_user_signature IS NULL AND fk_user_cloture IS NOT NULL; UPDATE llx_propal SET date_signature = date_cloture WHERE date_signature IS NULL AND date_cloture IS NOT NULL; -INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_EXCLUDE','Member excluded','Executed when a member is excluted','member',26); +INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_EXCLUDE','Member excluded','Executed when a member is excluded','member',26); From 8675484d9065a43b4438bd3b74305647cd27eca3 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sat, 3 Apr 2021 10:25:29 +0200 Subject: [PATCH 006/628] Update llx_c_action_trigger.sql --- htdocs/install/mysql/data/llx_c_action_trigger.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/install/mysql/data/llx_c_action_trigger.sql b/htdocs/install/mysql/data/llx_c_action_trigger.sql index 34cef4c94d4..a0391f5d841 100644 --- a/htdocs/install/mysql/data/llx_c_action_trigger.sql +++ b/htdocs/install/mysql/data/llx_c_action_trigger.sql @@ -90,6 +90,7 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_SUBSCRIPTION_DELETE','Member subscribtion deleted','Executed when a member subscribtion is deleted','member',24); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_RESILIATE','Member resiliated','Executed when a member is resiliated','member',25); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_DELETE','Member deleted','Executed when a member is deleted','member',26); +insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_EXCLUDE','Member excluded','Executed when a member is excluded','member',27); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_VALIDATE','Intervention validated','Executed when a intervention is validated','ficheinter',30); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_CLASSIFY_BILLED','Intervention set billed','Executed when a intervention is set to billed (when option FICHINTER_CLASSIFY_BILLED is set)','ficheinter',32); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_CLASSIFY_UNBILLED','Intervention set unbilled','Executed when a intervention is set to unbilled (when option FICHINTER_CLASSIFY_BILLED is set)','ficheinter',33); From 52bad238ff8c8fd95202bb5b1259a0792c664eb4 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sat, 3 Apr 2021 10:25:44 +0200 Subject: [PATCH 007/628] Update 13.0.0-14.0.0.sql --- htdocs/install/mysql/migration/13.0.0-14.0.0.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index 34a2ffa74fb..5886e3cf33d 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -360,5 +360,5 @@ ALTER TABLE llx_propal ADD CONSTRAINT fk_propal_fk_user_signature FOREIGN KEY (f UPDATE llx_propal SET fk_user_signature = fk_user_cloture WHERE fk_user_signature IS NULL AND fk_user_cloture IS NOT NULL; UPDATE llx_propal SET date_signature = date_cloture WHERE date_signature IS NULL AND date_cloture IS NOT NULL; -INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_EXCLUDE','Member excluded','Executed when a member is excluded','member',26); +INSERT INTO llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_EXCLUDE','Member excluded','Executed when a member is excluded','member',27); From 1a385052f6e66436784a40d286dc609a7febfa30 Mon Sep 17 00:00:00 2001 From: kastoras Date: Fri, 7 May 2021 23:39:14 +0300 Subject: [PATCH 008/628] New Create share link on file upload Create MAIN_CREATE_SHARE_ON_FILE_UPLOAD, when this set to 1 and a file is uploaded a shared link will be created --- htdocs/core/lib/files.lib.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index ce5e7129bcf..1a52102d61d 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1766,7 +1766,7 @@ function dol_remove_file_process($filenb, $donotupdatesession = 0, $donotdeletef */ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uploaded', $setsharekey = 0, $object = null) { - global $db, $user; + global $db, $user, $conf; $result = 0; @@ -1792,6 +1792,9 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo $ecmfile->src_object_type = $object->table_element; } + if(!empty($conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD) && $conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD=='1'){ + $setsharekey = 1; + } if ($setsharekey) { require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; $ecmfile->share = getRandomPassword(true); From fc26e5eecfd6faff7dcf9509db1dd1b9597222f2 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Fri, 7 May 2021 20:42:53 +0000 Subject: [PATCH 009/628] Fixing style errors. --- htdocs/core/lib/files.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 1a52102d61d..9bf520d56b5 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1792,7 +1792,7 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo $ecmfile->src_object_type = $object->table_element; } - if(!empty($conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD) && $conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD=='1'){ + if (!empty($conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD) && $conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD=='1') { $setsharekey = 1; } if ($setsharekey) { From 76c10f053abeeab7baf8203048cc05e016a87b17 Mon Sep 17 00:00:00 2001 From: kastoras Date: Tue, 11 May 2021 22:29:07 +0300 Subject: [PATCH 010/628] Change parameter name to MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE --- htdocs/core/lib/files.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 1a52102d61d..4232eb78b40 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1792,7 +1792,7 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo $ecmfile->src_object_type = $object->table_element; } - if(!empty($conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD) && $conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD=='1'){ + if(!empty($conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE) && $conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE=='1'){ $setsharekey = 1; } if ($setsharekey) { From cd9ea9566b5d27bff62a515efec1329447c0a55c Mon Sep 17 00:00:00 2001 From: kastoras Date: Tue, 11 May 2021 22:31:38 +0300 Subject: [PATCH 011/628] Change parameter name to MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE --- htdocs/core/lib/files.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 9bf520d56b5..4232eb78b40 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1792,7 +1792,7 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo $ecmfile->src_object_type = $object->table_element; } - if (!empty($conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD) && $conf->global->MAIN_CREATE_SHARE_ON_FILE_UPLOAD=='1') { + if(!empty($conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE) && $conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE=='1'){ $setsharekey = 1; } if ($setsharekey) { From b8a3485c4cd73f113c5b011e7faa4b6d37078329 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 11 May 2021 19:33:23 +0000 Subject: [PATCH 012/628] Fixing style errors. --- htdocs/core/lib/files.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 4232eb78b40..7ee3dbee46f 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1792,7 +1792,7 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo $ecmfile->src_object_type = $object->table_element; } - if(!empty($conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE) && $conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE=='1'){ + if (!empty($conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE) && $conf->global->MAIN_FORCE_SHARING_ON_ANY_UPLOADED_FILE=='1') { $setsharekey = 1; } if ($setsharekey) { From 09ab9308065677ff55d55093d3bb8e187c77e942 Mon Sep 17 00:00:00 2001 From: Anthony Berton <34568357+bb2a@users.noreply.github.com> Date: Mon, 17 May 2021 18:31:19 +0200 Subject: [PATCH 013/628] sale_representative_order_invoice_list --- htdocs/commande/list.php | 55 ++++++++++++++++++++++++++++++++++ htdocs/compta/facture/list.php | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 3747b2107b2..af6fa6e5bf5 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -187,6 +187,7 @@ $arrayfields = array( 'c.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>105), 'c.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>110), 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>115), + 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>1), 'c.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>120), 'c.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>125), 'c.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>130), @@ -1172,6 +1173,9 @@ if ($resql) { print ''; print ''; } + if (!empty($arrayfields['sale_representative']['checked'])) { + print ''; + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; // Fields from hook @@ -1329,6 +1333,9 @@ if ($resql) { if (!empty($arrayfields['u.login']['checked'])) { print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder); } + if (!empty($arrayfields['sale_representative']['checked'])) { + print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder); + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; @@ -1685,6 +1692,54 @@ if ($resql) { } } + if (!empty($arrayfields['sale_representative']['checked'])) { + // Sales representatives + print ''; + if ($obj->socid > 0) { + $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user); + if ($listsalesrepresentatives < 0) { + dol_print_error($db); + } + $nbofsalesrepresentative = count($listsalesrepresentatives); + if ($nbofsalesrepresentative > 6) { + // We print only number + print $nbofsalesrepresentative; + } elseif ($nbofsalesrepresentative > 0) { + $userstatic = new User($db); + $j = 0; + foreach ($listsalesrepresentatives as $val) { + $userstatic->id = $val['id']; + $userstatic->lastname = $val['lastname']; + $userstatic->firstname = $val['firstname']; + $userstatic->email = $val['email']; + $userstatic->statut = $val['statut']; + $userstatic->entity = $val['entity']; + $userstatic->photo = $val['photo']; + $userstatic->login = $val['login']; + $userstatic->office_phone = $val['office_phone']; + $userstatic->office_fax = $val['office_fax']; + $userstatic->user_mobile = $val['user_mobile']; + $userstatic->job = $val['job']; + $userstatic->gender = $val['gender']; + //print '
': + print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2); + $j++; + if ($j < $nbofsalesrepresentative) { + print ' '; + } + //print '
'; + } + } + //else print $langs->trans("NoSalesRepresentativeAffected"); + } else { + print ' '; + } + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; // Fields from hook diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 14b0383fa8d..ad8ead936be 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -228,6 +228,7 @@ $arrayfields = array( 'dynamount_payed'=>array('label'=>"Received", 'checked'=>0, 'position'=>140), 'rtp'=>array('label'=>"Rest", 'checked'=>0, 'position'=>150), // Not enabled by default because slow 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>165), + 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>1), 'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>170), 'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>171), 'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>180), @@ -1234,6 +1235,9 @@ if ($resql) { print ''; print ''; } + if (!empty($arrayfields['sale_representative']['checked'])) { + print ''; + } if (!empty($arrayfields['f.retained_warranty']['checked'])) { print ''; print ''; @@ -1426,6 +1430,9 @@ if ($resql) { if (!empty($arrayfields['u.login']['checked'])) { print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder); } + if (!empty($arrayfields['sale_representative']['checked'])) { + print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder); + } if (!empty($arrayfields['f.retained_warranty']['checked'])) { print_liste_field_titre($arrayfields['f.retained_warranty']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'align="right"', $sortfield, $sortorder); } @@ -1894,6 +1901,54 @@ if ($resql) { } } + if (!empty($arrayfields['sale_representative']['checked'])) { + // Sales representatives + print ''; + if ($obj->socid > 0) { + $listsalesrepresentatives = $thirdpartystatic->getSalesRepresentatives($user); + if ($listsalesrepresentatives < 0) { + dol_print_error($db); + } + $nbofsalesrepresentative = count($listsalesrepresentatives); + if ($nbofsalesrepresentative > 6) { + // We print only number + print $nbofsalesrepresentative; + } elseif ($nbofsalesrepresentative > 0) { + $userstatic = new User($db); + $j = 0; + foreach ($listsalesrepresentatives as $val) { + $userstatic->id = $val['id']; + $userstatic->lastname = $val['lastname']; + $userstatic->firstname = $val['firstname']; + $userstatic->email = $val['email']; + $userstatic->statut = $val['statut']; + $userstatic->entity = $val['entity']; + $userstatic->photo = $val['photo']; + $userstatic->login = $val['login']; + $userstatic->office_phone = $val['office_phone']; + $userstatic->office_fax = $val['office_fax']; + $userstatic->user_mobile = $val['user_mobile']; + $userstatic->job = $val['job']; + $userstatic->gender = $val['gender']; + //print '
': + print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2); + $j++; + if ($j < $nbofsalesrepresentative) { + print ' '; + } + //print '
'; + } + } + //else print $langs->trans("NoSalesRepresentativeAffected"); + } else { + print ' '; + } + print ''; + if (!$i) { + $totalarray['nbfield']++; + } + } + if (!empty($arrayfields['f.retained_warranty']['checked'])) { print ''.(!empty($obj->retained_warranty) ?price($obj->retained_warranty).'%' : ' ').''; } From 70a062e2c1da3ed83f59e249ac74554eee95ff6a Mon Sep 17 00:00:00 2001 From: Anthony Berton <34568357+bb2a@users.noreply.github.com> Date: Mon, 17 May 2021 23:59:42 +0200 Subject: [PATCH 014/628] change position --- htdocs/commande/list.php | 2 +- htdocs/compta/facture/list.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 4f68c1d9014..72f5528ec31 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -187,7 +187,7 @@ $arrayfields = array( 'c.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>105), 'c.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>110), 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>115), - 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>1), + 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'position'=>116), 'c.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>120), 'c.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>125), 'c.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>130), diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 6cb2d05a157..c8175300b16 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -228,7 +228,7 @@ $arrayfields = array( 'dynamount_payed'=>array('label'=>"Received", 'checked'=>0, 'position'=>140), 'rtp'=>array('label'=>"Rest", 'checked'=>0, 'position'=>150), // Not enabled by default because slow 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>165), - 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>1), + 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'position'=>166), 'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>170), 'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>171), 'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>180), From c02e3eed6b227123f883ecd607e935dce5d8fcd1 Mon Sep 17 00:00:00 2001 From: Anthony Berton <34568357+bb2a@users.noreply.github.com> Date: Tue, 18 May 2021 18:45:07 +0200 Subject: [PATCH 015/628] checked --- htdocs/commande/list.php | 2 +- htdocs/compta/facture/list.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 72f5528ec31..153250534fd 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -187,7 +187,7 @@ $arrayfields = array( 'c.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>105), 'c.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>110), 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>115), - 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'position'=>116), + 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>0, 'position'=>116), 'c.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>120), 'c.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>125), 'c.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>130), diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index c8175300b16..9eab570f31b 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -228,7 +228,7 @@ $arrayfields = array( 'dynamount_payed'=>array('label'=>"Received", 'checked'=>0, 'position'=>140), 'rtp'=>array('label'=>"Rest", 'checked'=>0, 'position'=>150), // Not enabled by default because slow 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>165), - 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'position'=>166), + 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>0, 'position'=>166), 'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>170), 'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>171), 'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>180), From 8eb8889b176dbdaa43fd5ae24d3eaed55eeb14da Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Wed, 19 May 2021 11:12:34 +0200 Subject: [PATCH 016/628] NEW: autocomplete account group when editing an account card --- htdocs/accountancy/admin/card.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index b629e45cf0d..ae1ba5a3ad3 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -257,7 +257,16 @@ if ($action == 'create') { print $form->textwithpicto($langs->trans("Pcgtype"), $langs->transnoentitiesnoconv("PcgtypeDesc")); print ''; print ''; - print ''; + print ''; + print ''; + $sql = 'SELECT a.rowid as rowid, a.code as code, a.label FROM '.MAIN_DB_PREFIX.'c_accounting_category as a WHERE a.active=1'; + $resql = $db->query($sql); + if ($resql) { + while ($obj = $db->fetch_object($resql)) { + print ''; print ''; // Category From 62bc6e9e1f383db48d7dc7351f1a90fc227c8cc2 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 20 May 2021 13:15:32 +0200 Subject: [PATCH 017/628] on going --- htdocs/compta/facture/list.php | 23 +++++++++++++--- htdocs/core/class/html.form.class.php | 39 ++++++++++++++++----------- htdocs/langs/en_US/bills.lang | 3 ++- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 282aad95d89..6bf02d5d580 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -363,7 +363,7 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } -if ($massaction == 'makepayment') { +if ($massaction == 'makepayment_confirm') { $arrayofselected = is_array($toselect) ? $toselect : array(); $loc = dol_buildpath('/compta/paiement.php', 2).'?action=create&facids='.implode(',', $arrayofselected); @@ -948,8 +948,10 @@ if ($resql) { 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), - //'makepayment'=>$langs->trans("InvoicePaymentsLimits"), TODO Blank page when using this ); + if ($user->rights->facture->paiement) { + $arrayofmassactions['makepayment'] = $langs->trans("RegisterPaymentAndClasiffiedPayed"); + } if ($conf->prelevement->enabled && !empty($user->rights->prelevement->bons->creer)) { $langs->load("withdrawals"); $arrayofmassactions['withdrawrequest'] = $langs->trans("MakeWithdrawRequest"); @@ -961,7 +963,7 @@ if ($resql) { $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); } } - if (in_array($massaction, array('presend', 'predelete'))) { + if (in_array($massaction, array('presend', 'predelete' ,'makepayment'))) { $arrayofmassactions = array(); } $massactionbutton = $form->selectMassAction('', $arrayofmassactions); @@ -997,6 +999,21 @@ if ($resql) { $trackid = 'inv'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; + if ($massaction=='makepayment') { + $formconfirm = ''; + $formquestion = array( + // 'text' => $langs->trans("ConfirmClone"), + // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), + // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), + array('type' => 'date', 'name' => 'datepaiment', 'label' => $langs->trans("Date")), + array('type' => 'other', 'name' => 'paiementid', 'label' => $langs->trans("PaymentMode"), 'value' => $form->select_types_paiements(GETPOST('search_paymentmode'), 'paiementid', '', 2, 0, 1, 0, 1, '', 1)), + array('type' => 'other', 'name' => 'bankid', 'label' => $langs->trans("Date"), 'value'=>$form->select_comptes('', 'bankid', 0, '', 0, '', 0, '', 1)), + //array('type' => 'other', 'name' => 'invoicesid', 'label' => '', 'value'=>''), + ); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('RegisterPaymentAndClasiffiedPayed'), $langs->trans('RegisterPaymentAndClasiffiedPayed', $object->ref), 'makepayment_confirm', $formquestion, 1, 0, 200, 500, 1); + print $formconfirm; + } + if ($sall) { foreach ($fieldstosearchall as $key => $val) { $fieldstosearchall[$key] = $langs->trans($val); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 57bbbe3a029..763a3da6c57 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3914,13 +3914,16 @@ class Form * @param int $maxlength Max length of label * @param int $active Active or not, -1 = all * @param string $morecss Add more CSS on select tag + * @param int $nooutput 1=Return string, do not send to output * @return void */ - public function select_types_paiements($selected = '', $htmlname = 'paiementtype', $filtertype = '', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss = '') + public function select_types_paiements($selected = '', $htmlname = 'paiementtype', $filtertype = '', $format = 0, $empty = 1, $noadmininfo = 0, $maxlength = 0, $active = 1, $morecss = '', $nooutput = 0) { // phpcs:enable global $langs, $user, $conf; + $out = ''; + dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG); $filterarray = array(); @@ -3939,9 +3942,9 @@ class Form $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TYPE_ID; } - print ''; if ($empty) { - print ''; + $out .= ''; } foreach ($this->cache_types_paiements as $id => $arraytypes) { // If not good status @@ -3960,25 +3963,25 @@ class Form } if ($format == 0) { - print ''; + $out .= $value ? $value : ' '; + $out .= ''; } - print ''; + $out .= ''; if ($user->admin && !$noadmininfo) { - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } + $out .= ajax_combobox('select'.$htmlname); + + if (empty($nooutput)) { + print $out; + } else { + return $out; } - print ajax_combobox('select'.$htmlname); } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 940da4e35b4..1ccdd162719 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -589,4 +589,5 @@ FacParentLine=Invoice Line Parent SituationTotalRayToRest=Remainder to pay without taxe PDFSituationTitle=Situation n° %d SituationTotalProgress=Total progress %d %% -SearchUnpaidInvoicesWithDueDate=Search unpaid invoices with a due date = %s \ No newline at end of file +SearchUnpaidInvoicesWithDueDate=Search unpaid invoices with a due date = %s +RegisterPaymentAndClasiffiedPayed=Enter payment and Classify 'Paid' From 7c6ac86d3209d5822672ae7efd58e6cdcc137ef2 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 20 May 2021 13:41:23 +0200 Subject: [PATCH 018/628] ongoing --- htdocs/compta/facture/list.php | 54 ++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 6bf02d5d580..067a7cb959a 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -363,13 +363,53 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } -if ($massaction == 'makepayment_confirm') { +if ($action == 'makepayment_confirm') { + /*require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; $arrayofselected = is_array($toselect) ? $toselect : array(); + if (!empty($invoices_id)) { + $bankid=GETPOST('bankid','int'); + $paiementid=GETPOST('paiementid','int'); + $paiementdate=dol_mktime(12,0,0,GETPOST('datepaimentmonth','int'),GETPOST('datepaimentday','int'),GETPOST('datepaimentyear','year')); + foreach ($arrayofselected as $toselectid) { + $facture = new Facture($db); + $result = $facture->fetch($invoice_id); + if ($result < 0) { + setEventMessage($facture->error, 'errors'); + } else { + if (empty($facture->paye)) { - $loc = dol_buildpath('/compta/paiement.php', 2).'?action=create&facids='.implode(',', $arrayofselected); - - header('Location: '.$loc); - exit; + $paiementAmount = $facture->getSommePaiement(); + $totalcreditnotes = $facture->getSumCreditNotesUsed(); + $totaldeposits = $facture->getSumDepositsUsed(); + $totalpay = $paiementAmount + $totalcreditnotes + $totaldeposits; + $remaintopay = price2num($facture->total_ttc - $totalpay); + if ($remaintopay!=0) { + $resultBank = $facture->setBankAccount($bankid); + if ($resultBank < 0) { + setEventMessage($facture->error, 'errors'); + } else { + $paiement = new Paiement($this->db); + $paiement->datepaye = $paiementdate; + $paiement->amounts[$facture->id] = $remaintopay; // Array with all payments dispatching with invoice id + $paiement->multicurrency_amounts[$facture->id] = $remaintopay; + $paiement->paiementid = $paiementid; + $paiement_id = $paiement->create($user, 1, $facture->thirdparty); + if ($paiement_id < 0) { + setEventMessage($facture->ref . ' ' . $paiement->error, 'errors'); + } else { + $result = $paiement->addPaymentToBank($user, 'payment', '', $bankid, '', ''); + if ($result < 0) { + setEventMessages($facture->ref . ' ' . $paiement->error, $paiement->errors, 'errors'); + } + } + } + } + } else { + setEventMessage($facture->ref.' Total 0 € Pas de réglement enregistré', 'errors'); + } + } + } + }*/ } elseif ($massaction == 'withdrawrequest') { $langs->load("withdrawals"); @@ -985,7 +1025,9 @@ if ($resql) { } print ''; print ''; - print ''; + if (!in_array($massaction, array('presend', 'predelete' ,'makepayment'))) { + print ''; + } print ''; print ''; print ''; From 4d7b09ff2ae7bde4a4caa3a6935b5552663523fb Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 20 May 2021 14:00:43 +0200 Subject: [PATCH 019/628] done --- htdocs/compta/facture/list.php | 37 ++++++++++++++++++++++------------ htdocs/langs/en_US/bills.lang | 4 +++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 067a7cb959a..677d92e8765 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -363,21 +363,22 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } -if ($action == 'makepayment_confirm') { - /*require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; +if ($action == 'makepayment_confirm' && $user->rights->facture->paiement) { + require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; $arrayofselected = is_array($toselect) ? $toselect : array(); - if (!empty($invoices_id)) { - $bankid=GETPOST('bankid','int'); - $paiementid=GETPOST('paiementid','int'); - $paiementdate=dol_mktime(12,0,0,GETPOST('datepaimentmonth','int'),GETPOST('datepaimentday','int'),GETPOST('datepaimentyear','year')); + if (!empty($arrayofselected)) { + $bankid=GETPOST('bankid', 'int'); + $paiementid=GETPOST('paiementid', 'int'); + $paiementdate=dol_mktime(12, 0, 0, GETPOST('datepaimentmonth', 'int'), GETPOST('datepaimentday', 'int'), GETPOST('datepaimentyear', 'year')); foreach ($arrayofselected as $toselectid) { + $errorpayment=0; $facture = new Facture($db); - $result = $facture->fetch($invoice_id); + $result = $facture->fetch($toselectid); if ($result < 0) { setEventMessage($facture->error, 'errors'); + $errorpayment++; } else { - if (empty($facture->paye)) { - + if ($facture->type != Facture::TYPE_CREDIT_NOTE && $facture->statut == 1 && $facture->paye == 0) { $paiementAmount = $facture->getSommePaiement(); $totalcreditnotes = $facture->getSumCreditNotesUsed(); $totaldeposits = $facture->getSumDepositsUsed(); @@ -387,8 +388,9 @@ if ($action == 'makepayment_confirm') { $resultBank = $facture->setBankAccount($bankid); if ($resultBank < 0) { setEventMessage($facture->error, 'errors'); + $errorpayment++; } else { - $paiement = new Paiement($this->db); + $paiement = new Paiement($db); $paiement->datepaye = $paiementdate; $paiement->amounts[$facture->id] = $remaintopay; // Array with all payments dispatching with invoice id $paiement->multicurrency_amounts[$facture->id] = $remaintopay; @@ -396,20 +398,29 @@ if ($action == 'makepayment_confirm') { $paiement_id = $paiement->create($user, 1, $facture->thirdparty); if ($paiement_id < 0) { setEventMessage($facture->ref . ' ' . $paiement->error, 'errors'); + $errorpayment++; } else { $result = $paiement->addPaymentToBank($user, 'payment', '', $bankid, '', ''); if ($result < 0) { setEventMessages($facture->ref . ' ' . $paiement->error, $paiement->errors, 'errors'); + $errorpayment++; } } } + } else { + setEventMessage($langs->trans('NoPaymentAvailable', $facture->ref), 'warnings'); + $errorpayment++; } } else { - setEventMessage($facture->ref.' Total 0 € Pas de réglement enregistré', 'errors'); + setEventMessage($langs->trans('NoPaymentAvailable', $facture->ref), 'warnings'); + $errorpayment++; } } + if (empty($errorpayment)) { + setEventMessage($langs->trans('RegisterPaymentAndClasiffiedPayedDone', $facture->ref)); + } } - }*/ + } } elseif ($massaction == 'withdrawrequest') { $langs->load("withdrawals"); @@ -1048,7 +1059,7 @@ if ($resql) { // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), array('type' => 'date', 'name' => 'datepaiment', 'label' => $langs->trans("Date")), - array('type' => 'other', 'name' => 'paiementid', 'label' => $langs->trans("PaymentMode"), 'value' => $form->select_types_paiements(GETPOST('search_paymentmode'), 'paiementid', '', 2, 0, 1, 0, 1, '', 1)), + array('type' => 'other', 'name' => 'paiementid', 'label' => $langs->trans("PaymentMode"), 'value' => $form->select_types_paiements(GETPOST('search_paymentmode'), 'paiementid', '', 0, 0, 1, 0, 1, '', 1)), array('type' => 'other', 'name' => 'bankid', 'label' => $langs->trans("Date"), 'value'=>$form->select_comptes('', 'bankid', 0, '', 0, '', 0, '', 1)), //array('type' => 'other', 'name' => 'invoicesid', 'label' => '', 'value'=>''), ); diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 1ccdd162719..a43d56217b4 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -590,4 +590,6 @@ SituationTotalRayToRest=Remainder to pay without taxe PDFSituationTitle=Situation n° %d SituationTotalProgress=Total progress %d %% SearchUnpaidInvoicesWithDueDate=Search unpaid invoices with a due date = %s -RegisterPaymentAndClasiffiedPayed=Enter payment and Classify 'Paid' +RegisterPaymentAndClasiffiedPayed=Enter payment and classify 'Paid' +NoPaymentAvailable=No payment available for %s +RegisterPaymentAndClasiffiedPayedDone=Payment registered and classify 'Paid' done for invoice %s From d70bbe29b54e7055043f51f72a47bfc84af90b78 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 20 May 2021 14:03:18 +0200 Subject: [PATCH 020/628] fix --- htdocs/compta/facture/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index e17e56e4378..850c012a5e7 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -1036,7 +1036,7 @@ if ($resql) { } print ''; print ''; - if (!in_array($massaction, array('presend', 'predelete' ,'makepayment'))) { + if (!in_array($massaction, array('makepayment'))) { print ''; } print ''; From e6deab5c859eb9a4a3bbfebb5f5702183c4dde8a Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Fri, 28 May 2021 08:42:38 +0200 Subject: [PATCH 021/628] FIX proposed new feature: autocomplete for accounting account groups --- htdocs/accountancy/admin/card.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index ae1ba5a3ad3..1d62fe1d414 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -258,13 +258,13 @@ if ($action == 'create') { print ''; print ''; print ''; + // autosuggest from existing account types if found print ''; - $sql = 'SELECT a.rowid as rowid, a.code as code, a.label FROM '.MAIN_DB_PREFIX.'c_accounting_category as a WHERE a.active=1'; - $resql = $db->query($sql); - if ($resql) { - while ($obj = $db->fetch_object($resql)) { - print ''; print ''; From b5904e49a023354f435858c7060a1d02cf9d3a07 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 1 Jun 2021 22:43:43 +0200 Subject: [PATCH 022/628] NEW Add field date from/to in customer payment list --- htdocs/compta/paiement/list.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index 1e99cf8676f..eb6d50712c5 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -56,11 +56,10 @@ $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'p $facid = GETPOST('facid', 'int'); $socid = GETPOST('socid', 'int'); $userid = GETPOST('userid', 'int'); -$day = GETPOST('day', 'int'); -$month = GETPOST('month', 'int'); -$year = GETPOST('year', 'int'); $search_ref = GETPOST("search_ref", "alpha"); +$search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int')); +$search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int')); $search_company = GETPOST("search_company", 'alpha'); $search_paymenttype = GETPOST("search_paymenttype"); $search_account = GETPOST("search_account", "int"); @@ -130,14 +129,13 @@ if (empty($reshook)) { // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $search_ref = ''; + $search_date_start = ''; + $search_date_end = ''; $search_account = ''; $search_amount = ''; $search_paymenttype = ''; $search_payment_num = ''; $search_company = ''; - $day = ''; - $year = ''; - $month = ''; $option = ''; $toselect = ''; $search_array_options = array(); @@ -211,10 +209,15 @@ if (GETPOST("orphelins", "alpha")) { } // Search criteria - $sql .= dolSqlDateFilter("p.datep", $day, $month, $year); if ($search_ref) { $sql .= natural_search('p.ref', $search_ref); } + if ($search_date_start) { + $sql .= " AND p.datep >= '" . $db->idate($search_date_start) . "'"; + } + if ($search_date_end) { + $sql .= " AND p.datep <= '" . $db->idate($search_date_end) . "'"; + } if ($search_account > 0) { $sql .= " AND b.fk_account=".((int) $search_account); } @@ -275,6 +278,8 @@ if ($limit > 0 && $limit != $conf->liste_limit) { } $param .= (GETPOST("orphelins") ? "&orphelins=1" : ''); $param .= ($search_ref ? "&search_ref=".urlencode($search_ref) : ''); +$param .= ($search_date_start ? "&search_date_start=".urlencode($search_date_start) : ''); +$param .= ($search_date_end ? "&search_date_end=".urlencode($search_date_end) : ''); $param .= ($search_company ? "&search_company=".urlencode($search_company) : ''); $param .= ($search_amount ? "&search_amount=".urlencode($search_amount) : ''); $param .= ($search_payment_num ? "&search_payment_num=".urlencode($search_payment_num) : ''); @@ -331,11 +336,14 @@ if (!empty($arrayfields['p.ref']['checked'])) { // Filter: Date if (!empty($arrayfields['p.datep']['checked'])) { print ''; - if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { - print ''; - } - print ''; - $formother->select_year($year ? $year : -1, 'year', 1, 20, 5); + print '
'; + print $langs->trans('From') . ' '; + print $form->selectDate($search_date_start?$search_date_start:-1, 'search_date_start', 0, 0, 1); + print '
'; + print '
'; + print $langs->trans('to') . ' '; + print $form->selectDate($search_date_end?$search_date_end:-1, 'search_date_end', 0, 0, 1); + print '
'; print ''; } From 3744ccdd286b8e33968031248884f331cbefd133 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 1 Jun 2021 22:50:55 +0200 Subject: [PATCH 023/628] Look & feel v14 --- htdocs/compta/paiement/list.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index eb6d50712c5..c06f8ee9cb5 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -337,12 +337,10 @@ if (!empty($arrayfields['p.ref']['checked'])) { if (!empty($arrayfields['p.datep']['checked'])) { print ''; print '
'; - print $langs->trans('From') . ' '; - print $form->selectDate($search_date_start?$search_date_start:-1, 'search_date_start', 0, 0, 1); + print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); print '
'; print '
'; - print $langs->trans('to') . ' '; - print $form->selectDate($search_date_end?$search_date_end:-1, 'search_date_end', 0, 0, 1); + print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); print '
'; print ''; } From c35124f036d75ab99dbf9a2d76abfbe4f24f2d74 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Tue, 1 Jun 2021 23:23:00 +0200 Subject: [PATCH 024/628] NEW Add field date from/to in supplier payment list --- htdocs/fourn/paiement/list.php | 41 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/htdocs/fourn/paiement/list.php b/htdocs/fourn/paiement/list.php index 6a38ae2033d..6b932ae2019 100644 --- a/htdocs/fourn/paiement/list.php +++ b/htdocs/fourn/paiement/list.php @@ -36,6 +36,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; // Load translation files required by the page $langs->loadLangs(array('companies', 'bills', 'banks', 'compta')); @@ -48,9 +49,8 @@ $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 've $socid = GETPOST('socid', 'int'); $search_ref = GETPOST('search_ref', 'alpha'); -$search_day = GETPOST('search_day', 'int'); -$search_month = GETPOST('search_month', 'int'); -$search_year = GETPOST('search_year', 'int'); +$search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int')); +$search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int')); $search_company = GETPOST('search_company', 'alpha'); $search_payment_type = GETPOST('search_payment_type'); $search_cheque_num = GETPOST('search_cheque_num', 'alpha'); @@ -135,9 +135,8 @@ if (empty($reshook)) { if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $search_ref = ''; - $search_day = ''; - $search_month = ''; - $search_year = ''; + $search_date_start = ''; + $search_date_end = ''; $search_company = ''; $search_payment_type = ''; $search_cheque_num = ''; @@ -187,7 +186,13 @@ if ($socid > 0) { if ($search_ref) { $sql .= natural_search('p.ref', $search_ref); } -$sql .= dolSqlDateFilter('p.datep', $search_day, $search_month, $search_year); +if ($search_date_start) { + $sql .= " AND p.datep >= '" . $db->idate($search_date_start) . "'"; +} +if ($search_date_end) { + $sql .=" AND p.datep <= '" . $db->idate($search_date_end) . "'"; +} + if ($search_company) { $sql .= natural_search('s.nom', $search_company); } @@ -254,14 +259,11 @@ if ($optioncss != '') { if ($search_ref) { $param .= '&search_ref='.urlencode($search_ref); } -if ($saerch_day) { - $param .= '&search_day='.urlencode($search_day); +if ($search_date_start) { + $param.= '&search_date_start='.urlencode($search_date_start); } -if ($saerch_month) { - $param .= '&search_month='.urlencode($search_month); -} -if ($search_year) { - $param .= '&search_year='.urlencode($search_year); +if ($search_date_end) { + $param.= '&search_date_end='.urlencode($search_date_end); } if ($search_company) { $param .= '&search_company='.urlencode($search_company); @@ -336,11 +338,12 @@ if (!empty($arrayfields['p.ref']['checked'])) { // Filter: Date if (!empty($arrayfields['p.datep']['checked'])) { print ''; - if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { - print ''; - } - print ''; - $formother->select_year($search_year ? $search_year : -1, 'search_year', 1, 20, 5); + print '
'; + print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From')); + print '
'; + print '
'; + print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to')); + print '
'; print ''; } From e46faacac1d99c8a82eee26a0bcee616e3347936 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 2 Jun 2021 18:11:47 +0200 Subject: [PATCH 025/628] FIX : Add process payment with online link order --- htdocs/public/payment/paymentok.php | 101 ++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index f4b9f0feb5b..5f8f90ba72b 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -721,6 +721,107 @@ if ($ispaymentok) $postactionmessages[] = 'Invoice paid '.$tmptag['INV'].' was not found'; $ispostactionok = -1; } + } elseif (array_key_exists('ORD', $tmptag) && $tmptag['ORD'] > 0) { + // Record payment + include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; + $object = new Commande($db); + $result = $object->fetch($tmptag['ORD']); + if ($result) { + $FinalPaymentAmt = $_SESSION["FinalPaymentAmt"]; + + $paymentTypeId = 0; + if ($paymentmethod == 'paybox') $paymentTypeId = $conf->global->PAYBOX_PAYMENT_MODE_FOR_PAYMENTS; + if ($paymentmethod == 'paypal') $paymentTypeId = $conf->global->PAYPAL_PAYMENT_MODE_FOR_PAYMENTS; + if ($paymentmethod == 'stripe') $paymentTypeId = $conf->global->STRIPE_PAYMENT_MODE_FOR_PAYMENTS; + if (empty($paymentTypeId)) { + $paymentType = $_SESSION["paymentType"]; + if (empty($paymentType)) $paymentType = 'CB'; + $paymentTypeId = dol_getIdFromCode($db, $paymentType, 'c_paiement', 'code', 'id', 1); + } + + $currencyCodeType = $_SESSION['currencyCodeType']; + + // Do action only if $FinalPaymentAmt is set (session variable is cleaned after this page to avoid duplicate actions when page is POST a second time) + if (!empty($FinalPaymentAmt) && $paymentTypeId > 0) { + include_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; + $invoice = new Facture($db); + $result = $invoice->createFromOrder($object, $user); + if ($result > 0) { + $object->classifyBilled($user); + $invoice->validate($user); + // Creation of payment line + include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; + $paiement = new Paiement($db); + $paiement->datepaye = $now; + if ($currencyCodeType == $conf->currency) { + $paiement->amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching with invoice id + } else { + $paiement->multicurrency_amounts = array($invoice->id => $FinalPaymentAmt); // Array with all payments dispatching + + $postactionmessages[] = 'Payment was done in a different currency that currency expected of company'; + $ispostactionok = -1; + $error++; // Not yet supported + } + $paiement->paiementid = $paymentTypeId; + $paiement->num_payment = ''; + $paiement->note_public = 'Online payment ' . dol_print_date($now, 'standard') . ' from ' . $ipaddress; + $paiement->ext_payment_id = $TRANSACTIONID; + $paiement->ext_payment_site = $service; + + if (!$error) { + $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents + if ($paiement_id < 0) { + $postactionmessages[] = $paiement->error . ' ' . join("
\n", $paiement->errors); + $ispostactionok = -1; + $error++; + } else { + $postactionmessages[] = 'Payment created'; + $ispostactionok = 1; + } + } + + if (!$error && !empty($conf->banque->enabled)) { + $bankaccountid = 0; + if ($paymentmethod == 'paybox') $bankaccountid = $conf->global->PAYBOX_BANK_ACCOUNT_FOR_PAYMENTS; + elseif ($paymentmethod == 'paypal') $bankaccountid = $conf->global->PAYPAL_BANK_ACCOUNT_FOR_PAYMENTS; + elseif ($paymentmethod == 'stripe') $bankaccountid = $conf->global->STRIPE_BANK_ACCOUNT_FOR_PAYMENTS; + + if ($bankaccountid > 0) { + $label = '(CustomerInvoicePayment)'; + if ($object->type == Facture::TYPE_CREDIT_NOTE) $label = '(CustomerInvoicePaymentBack)'; // Refund of a credit note + $result = $paiement->addPaymentToBank($user, 'payment', $label, $bankaccountid, '', ''); + if ($result < 0) { + $postactionmessages[] = $paiement->error . ' ' . join("
\n", $paiement->errors); + $ispostactionok = -1; + $error++; + } else { + $postactionmessages[] = 'Bank transaction of payment created'; + $ispostactionok = 1; + } + } else { + $postactionmessages[] = 'Setup of bank account to use in module ' . $paymentmethod . ' was not set. No way to record the payment.'; + $ispostactionok = -1; + $error++; + } + } + + if (!$error) { + $db->commit(); + } else { + $db->rollback(); + } + } else { + $postactionmessages[] = 'Failed to create invoice form order ' . $tmptag['ORD'] . '.'; + $ispostactionok = -1; + } + } else { + $postactionmessages[] = 'Failed to get a valid value for "amount paid" (' . $FinalPaymentAmt . ') or "payment type" (' . $paymentType . ') to record the payment of order ' . $tmptag['ORD'] . '. May be payment was already recorded.'; + $ispostactionok = -1; + } + } else { + $postactionmessages[] = 'Order paid ' . $tmptag['ORD'] . ' was not found'; + $ispostactionok = -1; + } } else { // Nothing done } From a7300d01b050f8cfb68ec08c2cd1040b71460614 Mon Sep 17 00:00:00 2001 From: ATM john Date: Thu, 3 Jun 2021 09:49:07 +0200 Subject: [PATCH 026/628] WIP - create validation method for common object --- htdocs/core/class/commonobject.class.php | 189 ++++++++++++++++++++++ htdocs/core/class/validate.class.php | 194 +++++++++++++++++++++++ htdocs/langs/en_US/validate.lang | 12 ++ 3 files changed, 395 insertions(+) create mode 100644 htdocs/core/class/validate.class.php create mode 100644 htdocs/langs/en_US/validate.lang diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 3f4b2dd9ee6..12f88fc0a58 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7285,6 +7285,195 @@ abstract class CommonObject return $out; } + /** + * Return validation test for a field + * + * @param array $val Array of properties of field to show + * @param string $key Key of attribute + * @return int >0 if OK, <0 if KO , 0 no test available. + */ + public function validateField($val, $fieldKey, $fieldValue) + { + global $langs; + + if(!class_exists('Validate')){ require_once DOL_DOCUMENT_ROOT . '/core/class/validate.class.php'; } + + // TODO : ask @eldy to know if need to use another error field to separate error msg + $this->error = ''; // error will be use for form error display so must be clear before + + if(!isset($val[$fieldKey])){ + return false; + } + + $param = array(); + $param['options'] = array(); + $type = $val[$fieldKey]['type']; + + $required = false; + if(isset($val[$fieldKey]['notnull']) && $val[$fieldKey]['notnull'] === 1){ + // 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). + $required = true; + } + + $maxSize = 0; + + + // + // PREPARE Elements + // + + // Convert var to be able to share same code than showOutputField of extrafields + if (preg_match('/varchar\((\d+)\)/', $type, $reg)) { + $type = 'varchar'; // convert varchar(xx) int varchar + $maxSize = $reg[1]; + } elseif (preg_match('/varchar/', $type)) { + $type = 'varchar'; // convert varchar(xx) int varchar + } + + if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { + $type = 'select'; + } + + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) { + $type = 'link'; + } + + if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) { + $param['options'] = $val['arrayofkeyval']; + } + + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) { + $type = 'link'; + $param['options'] = array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); + } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) { + $param['options'] = array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4] => 'N'); + $type = 'sellist'; + } elseif (preg_match('/^sellist:(.*):(.*):(.*)/i', $val['type'], $reg)) { + $param['options'] = array($reg[1].':'.$reg[2].':'.$reg[3] => 'N'); + $type = 'sellist'; + } elseif (preg_match('/^sellist:(.*):(.*)/i', $val['type'], $reg)) { + $param['options'] = array($reg[1].':'.$reg[2] => 'N'); + $type = 'sellist'; + } + + // + // TEST Value + // + + // Use Validate class to allow external Modules to use data validation part instead of concentrate all test here (factoring) + $validate = new Validate($this->db, $langs); + + + if($required && !$validate->isNotEmptyString($fieldValue)){ + $this->error = $validate->error; + return -1; + } + + + if(!empty($maxSize) && !$validate->isMaxLength($fieldValue, $maxSize)){ + $this->error = $validate->error; + return -1; + } + + + + if (in_array($type, array('date', 'datetime', 'timestamp'))) { + if(!$validate->isTimestamp($fieldValue)){ + $this->error = $validate->error; + return -1; + } + } elseif ($type == 'duration') { + // int + } elseif (in_array($type, array('double', 'real', 'price'))) { + // is numeric + } elseif ($type == 'boolean') { + // is bool + } elseif ($type == 'mail') { + if(!$validate->isEmail($fieldValue)){ + $this->error = $validate->error; + return -1; + } + } elseif ($type == 'url') { + if(!$validate->isUrl($fieldValue)){ + $this->error = $validate->error; + return -1; + } + } elseif ($type == 'phone') { + + } elseif ($type == 'select' || $type == 'radio') { + // isset in list + if(!isset($param['options'][$fieldValue])){ + + } + } elseif ($type == 'sellist' || $type == 'chkbxlst') { + $param_list = array_keys($param['options']); + $InfoFieldList = explode(":", $param_list[0]); + $value_arr = explode(',', $fieldValue); + $value_arr = array_map(array($this->db, 'escape'), $value_arr); + + $selectkey = "rowid"; + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { + $selectkey = $InfoFieldList[2]; + } + + // TODO tester toute les valeur du tableau séparement + + $sql = 'SELECT '.$selectkey; + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + if ($selectkey == 'rowid' && empty($value)) { + $sql .= " WHERE ".$selectkey."=0"; + } else { + $sql .= " WHERE ".$selectkey." IN ('".implode(',',$value_arr)."')"; + } + + dol_syslog(get_class($this).':validateField:$type=sellist', LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + if (empty($num)) { + // error value not found + $this->error = 'error msg'; + return false; + } else { + return true; + } + + } else { + dol_syslog(get_class($this).'::validateField error '.$this->db->lasterror(), LOG_WARNING); + return false; + } + } elseif ($type == 'link') { + + // only if something to display (perf) + if (!empty($fieldValue)) { + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' + $InfoFieldList = explode(":", $param_list[0]); + $classname = $InfoFieldList[0]; + $classpath = $InfoFieldList[1]; + if (!empty($classpath)) { + dol_include_once($InfoFieldList[1]); + if ($classname && class_exists($classname)) { + $object = new $classname($this->db); + if($object->fetch($fieldValue)>0){ + return true; + } + $this->error = 'class not found for validation'; + } else { + $this->error = 'Error bad setup of extrafield'; + } + return false; + } else { + $this->error = 'Error bad setup of extrafield'; + return false; + } + } + else { + // TODO vérifier si requis + } + } + + return 0; + } /** * Function to show lines of extrafields with output datas. diff --git a/htdocs/core/class/validate.class.php b/htdocs/core/class/validate.class.php new file mode 100644 index 00000000000..fa02018118b --- /dev/null +++ b/htdocs/core/class/validate.class.php @@ -0,0 +1,194 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/class/validate.class.php + * \ingroup core + * \brief File for Utils class + */ + + +/** + * Class toolbox to validate values + */ +class Validate +{ + + /** + * @var DoliDb Database handler (result of a new DoliDB) + */ + public $db; + + /** + * @var Translate $outputLang + */ + public $outputLang; + + /** + * @var string Error string + * @see $errors + */ + public $error; + + + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param Translate $outputLang + */ + public function __construct($db,$outputLang = false) + { + global $langs; + + if ($outputLang) { + $this->outputLang = $langs; + } else { + $this->outputLang = $outputLang; + } + + $outputLang->load('validate'); + + $this->db = $db; + } + + /** + * Use to clear errors msg or other ghost vars + */ + protected function clear() + { + $this->error = ''; + } + + /** + * Use to clear errors msg or other ghost vars + */ + protected function setError($errMsg) + { + $this->error = ''; + } + + /** + * Check for e-mail validity + * + * @param string $email e-mail address to validate + * @param int $maxLength + * @return boolean Validity is ok or not + */ + public function isEmail($email, $maxLength = false) + { + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + $this->error = $this->outputLang->trans('RequireValidEmail'); + return false; + } + return true; + } + + /** + * Check for price validity + * + * @param string $price Price to validate + * @return boolean Validity is ok or not + */ + public function isPrice($price) + { + if (!preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/ui', $price)) { + $this->error = $this->outputLang->trans('RequireValidValue'); + return false; + } + return true; + } + + /** + * Check for timestamp validity + * + * @param string|int $stamp timestamp to validate + * @return boolean Validity is ok or not + */ + public function isTimestamp($stamp) + { + if (!is_numeric($stamp) && (int)$stamp == $stamp) { + $this->error = $this->outputLang->trans('RequireValideDate'); + return false; + } + return true; + } + + /** + * Check for string max length validity + * + * @param string $string to validate + * @param int $length max length + * @return boolean Validity is ok or not + */ + public function isMaxLength($string, $length) + { + if (strlen($string) > $length) { + $this->error = $this->outputLang->trans('RequireMaxLength', $length); + return false; + } + return true; + } + + /** + * Check for string not empty + * + * @param string $string to validate + * @param int $length max length + * @return boolean Validity is ok or not + */ + public function isNotEmptyString($string) + { + if (!strlen($string)) { + $this->error = $this->outputLang->trans('RequireANotEmptyValue'); + return false; + } + return true; + } + + /** + * Check for string min length validity + * + * @param string $string to validate + * @param int $length max length + * @return boolean Validity is ok or not + */ + public function isMinLength($string, $length) + { + if (!strlen($string) < $length) { + $this->error = $this->outputLang->trans('RequireMinLength', $length); + return false; + } + return true; + } + + /** + * Check url validity + * + * @param string $url to validate + * @return boolean Validity is ok or not + */ + public function isUrl($url) + { + if (!filter_var($url, FILTER_VALIDATE_URL)) { + $this->error = $this->outputLang->trans('RequireValidUrl'); + return false; + } + return true; + } + +} diff --git a/htdocs/langs/en_US/validate.lang b/htdocs/langs/en_US/validate.lang new file mode 100644 index 00000000000..1464805b853 --- /dev/null +++ b/htdocs/langs/en_US/validate.lang @@ -0,0 +1,12 @@ +# Dolibarr language file - Source file is en_US - users +RequireValidValue = Value not valid +RequireAtLeastXString = Requires at least % character(s) +RequireXStringMax = Requires % character(s) max +RequireAtLeastXDigits = Requires at least % digit(s) +RequireXDigitsMax = Requires % digit(s) max +RequireValidEmail = Email address is not valid +RequireMaxLength = Length must be less than %s chars +RequireMinLength = Length must be more than %s char(s) +RequireValidUrl = Require valid URL +RequireValideDate = Require a valid date +RequireANotEmptyValue = Is required From 466bc2625663f7b775dc8302e37cf21129b873d9 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 5 Jun 2021 07:16:43 +0200 Subject: [PATCH 027/628] Fix with search_date_startxxx --- htdocs/fourn/paiement/list.php | 42 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/htdocs/fourn/paiement/list.php b/htdocs/fourn/paiement/list.php index 6b932ae2019..39ad7131b24 100644 --- a/htdocs/fourn/paiement/list.php +++ b/htdocs/fourn/paiement/list.php @@ -49,13 +49,19 @@ $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 've $socid = GETPOST('socid', 'int'); $search_ref = GETPOST('search_ref', 'alpha'); -$search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int')); -$search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int')); -$search_company = GETPOST('search_company', 'alpha'); +$search_date_startday = GETPOST('search_date_startday', 'int'); +$search_date_startmonth = GETPOST('search_date_startmonth', 'int'); +$search_date_startyear = GETPOST('search_date_startyear', 'int'); +$search_date_endday = GETPOST('search_date_endday', 'int'); +$search_date_endmonth = GETPOST('search_date_endmonth', 'int'); +$search_date_endyear = GETPOST('search_date_endyear', 'int'); +$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver +$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear); +$search_company = GETPOST('search_company', 'alpha'); $search_payment_type = GETPOST('search_payment_type'); -$search_cheque_num = GETPOST('search_cheque_num', 'alpha'); +$search_cheque_num = GETPOST('search_cheque_num', 'alpha'); $search_bank_account = GETPOST('search_bank_account', 'int'); -$search_amount = GETPOST('search_amount', 'alpha'); // alpha because we must be able to search on '< x' +$search_amount = GETPOST('search_amount', 'alpha'); // alpha because we must be able to search on '< x' $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'alpha'); @@ -135,6 +141,12 @@ if (empty($reshook)) { if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $search_ref = ''; + $search_date_startday = ''; + $search_date_startmonth = ''; + $search_date_startyear = ''; + $search_date_endday = ''; + $search_date_endmonth = ''; + $search_date_endyear = ''; $search_date_start = ''; $search_date_end = ''; $search_company = ''; @@ -259,11 +271,23 @@ if ($optioncss != '') { if ($search_ref) { $param .= '&search_ref='.urlencode($search_ref); } -if ($search_date_start) { - $param.= '&search_date_start='.urlencode($search_date_start); +if ($search_date_startday) { + $param .= '&search_date_startday='.urlencode($search_date_startday); } -if ($search_date_end) { - $param.= '&search_date_end='.urlencode($search_date_end); +if ($search_date_startmonth) { + $param .= '&search_date_startmonth='.urlencode($search_date_startmonth); +} +if ($search_date_startyear) { + $param .= '&search_date_startyear='.urlencode($search_date_startyear); +} +if ($search_date_endday) { + $param .= '&search_date_endday='.urlencode($search_date_endday); +} +if ($search_date_endmonth) { + $param .= '&search_date_endmonth='.urlencode($search_date_endmonth); +} +if ($search_date_endyear) { + $param .= '&search_date_endyear='.urlencode($search_date_endyear); } if ($search_company) { $param .= '&search_company='.urlencode($search_company); From a92bd31ce14d46b5786ad5fc303d5452a5af3b5e Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sat, 5 Jun 2021 07:39:15 +0200 Subject: [PATCH 028/628] Fix search_datexxx --- htdocs/compta/paiement/list.php | 68 +++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index c06f8ee9cb5..b6835765c00 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -5,7 +5,7 @@ * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015 Juanjo Menent - * Copyright (C) 2017 Alexandre Spangaro + * Copyright (C) 2017-2021 Alexandre Spangaro * Copyright (C) 2018 Ferran Marcet * Copyright (C) 2018 Charlene Benke * Copyright (C) 2020 Tobias Sekan @@ -58,12 +58,18 @@ $socid = GETPOST('socid', 'int'); $userid = GETPOST('userid', 'int'); $search_ref = GETPOST("search_ref", "alpha"); -$search_date_start = dol_mktime(0, 0, 0, GETPOST('search_date_startmonth', 'int'), GETPOST('search_date_startday', 'int'), GETPOST('search_date_startyear', 'int')); -$search_date_end = dol_mktime(23, 59, 59, GETPOST('search_date_endmonth', 'int'), GETPOST('search_date_endday', 'int'), GETPOST('search_date_endyear', 'int')); -$search_company = GETPOST("search_company", 'alpha'); -$search_paymenttype = GETPOST("search_paymenttype"); -$search_account = GETPOST("search_account", "int"); -$search_payment_num = GETPOST('search_payment_num', 'alpha'); +$search_date_startday = GETPOST('search_date_startday', 'int'); +$search_date_startmonth = GETPOST('search_date_startmonth', 'int'); +$search_date_startyear = GETPOST('search_date_startyear', 'int'); +$search_date_endday = GETPOST('search_date_endday', 'int'); +$search_date_endmonth = GETPOST('search_date_endmonth', 'int'); +$search_date_endyear = GETPOST('search_date_endyear', 'int'); +$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver +$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear); +$search_company = GETPOST("search_company", 'alpha'); +$search_paymenttype = GETPOST("search_paymenttype"); +$search_account = GETPOST("search_account", "int"); +$search_payment_num = GETPOST('search_payment_num', 'alpha'); $search_amount = GETPOST("search_amount", 'alpha'); // alpha because we must be able to search on "< x" $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; @@ -129,8 +135,13 @@ if (empty($reshook)) { // All tests are required to be compatible with all browsers if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $search_ref = ''; + $search_date_startday = ''; + $search_date_startmonth = ''; + $search_date_startyear = ''; + $search_date_endday = ''; + $search_date_endmonth = ''; + $search_date_endyear = ''; $search_date_start = ''; - $search_date_end = ''; $search_account = ''; $search_amount = ''; $search_paymenttype = ''; @@ -276,13 +287,40 @@ if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { if ($limit > 0 && $limit != $conf->liste_limit) { $param .= '&limit='.urlencode($limit); } -$param .= (GETPOST("orphelins") ? "&orphelins=1" : ''); -$param .= ($search_ref ? "&search_ref=".urlencode($search_ref) : ''); -$param .= ($search_date_start ? "&search_date_start=".urlencode($search_date_start) : ''); -$param .= ($search_date_end ? "&search_date_end=".urlencode($search_date_end) : ''); -$param .= ($search_company ? "&search_company=".urlencode($search_company) : ''); -$param .= ($search_amount ? "&search_amount=".urlencode($search_amount) : ''); -$param .= ($search_payment_num ? "&search_payment_num=".urlencode($search_payment_num) : ''); + +if (GETPOST("orphelins")) { + $param .= '&orphelins=1'; +} +if ($search_ref) { + $param .= '&search_ref='.urlencode($search_ref); +} +if ($search_date_startday) { + $param .= '&search_date_startday='.urlencode($search_date_startday); +} +if ($search_date_startmonth) { + $param .= '&search_date_startmonth='.urlencode($search_date_startmonth); +} +if ($search_date_startyear) { + $param .= '&search_date_startyear='.urlencode($search_date_startyear); +} +if ($search_date_endday) { + $param .= '&search_date_endday='.urlencode($search_date_endday); +} +if ($search_date_endmonth) { + $param .= '&search_date_endmonth='.urlencode($search_date_endmonth); +} +if ($search_date_endyear) { + $param .= '&search_date_endyear='.urlencode($search_date_endyear); +} +if ($search_company) { + $param .= '&search_company='.urlencode($search_company); +} +if ($search_amount != '') { + $param .= '&search_amount='.urlencode($search_amount); +} +if ($search_payment_num) { + $param .= '&search_payment_num='.urlencode($search_payment_num); +} if ($optioncss != '') { $param .= '&optioncss='.urlencode($optioncss); } From c1757bdbd8b0476274ba452e774857fb51a8c754 Mon Sep 17 00:00:00 2001 From: Alexandre SPANGARO Date: Sun, 6 Jun 2021 06:28:38 +0200 Subject: [PATCH 029/628] Remove warning --- htdocs/compta/paiement/list.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index b6835765c00..ee847603954 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -71,6 +71,7 @@ $search_paymenttype = GETPOST("search_paymenttype"); $search_account = GETPOST("search_account", "int"); $search_payment_num = GETPOST('search_payment_num', 'alpha'); $search_amount = GETPOST("search_amount", 'alpha'); // alpha because we must be able to search on "< x" +$search_status = GETPOST('search_status', 'intcomma'); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); @@ -142,11 +143,13 @@ if (empty($reshook)) { $search_date_endmonth = ''; $search_date_endyear = ''; $search_date_start = ''; + $search_date_end = ''; $search_account = ''; $search_amount = ''; $search_paymenttype = ''; $search_payment_num = ''; $search_company = ''; + $search_status = ''; $option = ''; $toselect = ''; $search_array_options = array(); @@ -348,10 +351,12 @@ if ($search_all) { $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields +$massactionbutton = ''; if ($massactionbutton) { $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); } +$moreforfilter = ''; print '
'; print ''; From aa94d40ad0ef4325c44b39df8bbb5e6b1dfd73e8 Mon Sep 17 00:00:00 2001 From: ATM john Date: Sun, 6 Jun 2021 21:12:03 +0200 Subject: [PATCH 030/628] WIP - create validation method for common object --- htdocs/core/class/commonobject.class.php | 179 ++++++++++++----------- htdocs/core/class/validate.class.php | 114 ++++++++++++++- htdocs/langs/en_US/validate.lang | 9 +- 3 files changed, 215 insertions(+), 87 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 12f88fc0a58..ae5f0d33216 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7286,11 +7286,12 @@ abstract class CommonObject } /** - * Return validation test for a field + * Return validation test result for a field * - * @param array $val Array of properties of field to show - * @param string $key Key of attribute - * @return int >0 if OK, <0 if KO , 0 no test available. + * @param array $val Array of properties of field to show + * @param string $fieldKey Key of attribute + * @param string $fieldValue value of attribute + * @return bool return false if fail true on success, see $this->error for error message */ public function validateField($val, $fieldKey, $fieldValue) { @@ -7301,7 +7302,7 @@ abstract class CommonObject // TODO : ask @eldy to know if need to use another error field to separate error msg $this->error = ''; // error will be use for form error display so must be clear before - if(!isset($val[$fieldKey])){ + if (!isset($val[$fieldKey])) { return false; } @@ -7310,13 +7311,13 @@ abstract class CommonObject $type = $val[$fieldKey]['type']; $required = false; - if(isset($val[$fieldKey]['notnull']) && $val[$fieldKey]['notnull'] === 1){ + if (isset($val[$fieldKey]['notnull']) && $val[$fieldKey]['notnull'] === 1) { // 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). $required = true; } $maxSize = 0; - + $minSize = 0; // // PREPARE Elements @@ -7360,52 +7361,98 @@ abstract class CommonObject // TEST Value // - // Use Validate class to allow external Modules to use data validation part instead of concentrate all test here (factoring) + // Use Validate class to allow external Modules to use data validation part instead of concentrate all test here (factoring) or just for reuse $validate = new Validate($this->db, $langs); + // little trick : to perform tests with good performances sort tests by quick to low + + // + // COMMON TESTS + // + + // Required test and empty value if($required && !$validate->isNotEmptyString($fieldValue)){ $this->error = $validate->error; - return -1; + return false; + } + elseif (!$required && !$validate->isNotEmptyString($fieldValue)) { + // if no value sent and the field is not mandatory, no need to perform tests + return true; } - + // MAX Size test if(!empty($maxSize) && !$validate->isMaxLength($fieldValue, $maxSize)){ $this->error = $validate->error; - return -1; + return false; } + // MIN Size test + if(!empty($minSize) && !$validate->isMinLength($fieldValue, $minSize)){ + $this->error = $validate->error; + return false; + } + // + // TESTS for TYPE + // if (in_array($type, array('date', 'datetime', 'timestamp'))) { - if(!$validate->isTimestamp($fieldValue)){ + if (!$validate->isTimestamp($fieldValue)) { $this->error = $validate->error; - return -1; - } + return false; + } else { return true; } } elseif ($type == 'duration') { - // int - } elseif (in_array($type, array('double', 'real', 'price'))) { + if(!$validate->isDuration($fieldValue)){ + $this->error = $validate->error; + return false; + } else { return true; } + } + elseif (in_array($type, array('double', 'real', 'price'))) + { // is numeric - } elseif ($type == 'boolean') { - // is bool - } elseif ($type == 'mail') { + if(!$validate->isDuration($fieldValue)){ + $this->error = $validate->error; + return false; + } else { return true; } + } + elseif ($type == 'boolean') + { + if(!$validate->isBool($fieldValue)){ + $this->error = $validate->error; + return false; + } else { return true; } + } + elseif ($type == 'mail') + { if(!$validate->isEmail($fieldValue)){ $this->error = $validate->error; - return -1; + return false; } - } elseif ($type == 'url') { + } + elseif ($type == 'url') + { if(!$validate->isUrl($fieldValue)){ $this->error = $validate->error; - return -1; - } - } elseif ($type == 'phone') { - - } elseif ($type == 'select' || $type == 'radio') { - // isset in list - if(!isset($param['options'][$fieldValue])){ - - } - } elseif ($type == 'sellist' || $type == 'chkbxlst') { + return false; + } else { return true; } + } + elseif ($type == 'phone') + { + if (!$validate->isPhone($fieldValue)) { + $this->error = $validate->error; + return false; + } else { return true; } + } + elseif ($type == 'select' || $type == 'radio') + { + if (!isset($param['options'][$fieldValue])) { + $this->error = $langs->trans('RequireValidValue'); + return false; + } else { return true; } + } + elseif ($type == 'sellist' || $type == 'chkbxlst') + { $param_list = array_keys($param['options']); $InfoFieldList = explode(":", $param_list[0]); $value_arr = explode(',', $fieldValue); @@ -7416,63 +7463,25 @@ abstract class CommonObject $selectkey = $InfoFieldList[2]; } - // TODO tester toute les valeur du tableau séparement - - $sql = 'SELECT '.$selectkey; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; - if ($selectkey == 'rowid' && empty($value)) { - $sql .= " WHERE ".$selectkey."=0"; - } else { - $sql .= " WHERE ".$selectkey." IN ('".implode(',',$value_arr)."')"; - } - - dol_syslog(get_class($this).':validateField:$type=sellist', LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - if (empty($num)) { - // error value not found - $this->error = 'error msg'; - return false; - } else { - return true; - } - - } else { - dol_syslog(get_class($this).'::validateField error '.$this->db->lasterror(), LOG_WARNING); + if(!isInDb($value_arr, $InfoFieldList[0], $selectkey)){ + $this->error = $validate->error; return false; - } - } elseif ($type == 'link') { - - // only if something to display (perf) - if (!empty($fieldValue)) { - $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' - $InfoFieldList = explode(":", $param_list[0]); - $classname = $InfoFieldList[0]; - $classpath = $InfoFieldList[1]; - if (!empty($classpath)) { - dol_include_once($InfoFieldList[1]); - if ($classname && class_exists($classname)) { - $object = new $classname($this->db); - if($object->fetch($fieldValue)>0){ - return true; - } - $this->error = 'class not found for validation'; - } else { - $this->error = 'Error bad setup of extrafield'; - } - return false; - } else { - $this->error = 'Error bad setup of extrafield'; - return false; - } - } - else { - // TODO vérifier si requis - } + } else { return true; } + } + elseif ($type == 'link') + { + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' + $InfoFieldList = explode(":", $param_list[0]); + $classname = $InfoFieldList[0]; + $classpath = $InfoFieldList[1]; + if(!$validate->isFetchable($fieldValue, $classname, $classpath)){ + $this->error = $validate->error; + return false; + } else { return true; } } - return 0; + // if no test failled all is ok + return true; } /** diff --git a/htdocs/core/class/validate.class.php b/htdocs/core/class/validate.class.php index fa02018118b..ac01ce76531 100644 --- a/htdocs/core/class/validate.class.php +++ b/htdocs/core/class/validate.class.php @@ -122,7 +122,22 @@ class Validate public function isTimestamp($stamp) { if (!is_numeric($stamp) && (int)$stamp == $stamp) { - $this->error = $this->outputLang->trans('RequireValideDate'); + $this->error = $this->outputLang->trans('RequireValidDate'); + return false; + } + return true; + } + + /** + * Check for phone validity + * + * @param string $phone Phone string to validate + * @return boolean Validity is ok or not + */ + public function isPhone($phone) + { + if (!preg_match('/^[+0-9. ()-]*$/ui', $phone)) { + $this->error = $this->outputLang->trans('RequireValidPhone'); return false; } return true; @@ -191,4 +206,101 @@ class Validate return true; } + /** + * Check Duration validity + * + * @param string $duration to validate + * @return boolean Validity is ok or not + */ + public function isDuration($duration) + { + if (!is_int($duration) && $duration >= 0) { + $this->error = $this->outputLang->trans('RequireValidDuration'); + return false; + } + return true; + } + + /** + * Check for boolean validity + * + * @param boolean $bool Boolean to validate + * @return boolean Validity is ok or not + */ + public function isBool($bool) + { + if(!(is_null($bool) || is_bool($bool) || preg_match('/^[0|1]{1}$/ui', $bool))){ + $this->error = $this->outputLang->trans('RequireValidBool'); + return false; + } + return true; + } + + /** + * Check for all values in db + * + * @param array $values Boolean to validate + * @param string $table the db table name without MAIN_DB_PREFIX + * @param string $col the target col + * @return boolean Validity is ok or not + * @throws Exception + */ + public function isInDb($values, $table, $col) + { + if (!is_array($values)) { + $value_arr = array($values); + } else { + $value_arr = $values; + } + + if (!count($value_arr)) { + $this->error = $this->outputLang->trans('RequireValue'); + return false; + } + + foreach ($value_arr as $val){ + $val = $this->db->escape($val); + $sql = 'SELECT ' . $col . ' FROM ' . MAIN_DB_PREFIX . $table . " WHERE " . $col ." = '" . $val . "'"; // nore quick than count(*) to check existing of a row + $resql = $this->db->getRow($sql); + if ($resql) { + continue; + } else { + $this->error = $this->outputLang->trans('RequireValidExistingElement'); + return false; + } + } + + return true; + } + + /** + * Check for all values in db + * + * @param array $values Boolean to validate + * @param string $classname the class name + * @param string $classpath the class path + * @return boolean Validity is ok or not + * @throws Exception + */ + public function isFetchable($values, $classname, $classpath) + { + if (!empty($classpath)) { + if (dol_include_once($classpath)) { + if ($classname && class_exists($classname)) { + /** @var CommonObject $object */ + $object = new $classname($this->db); + + if (!is_callable(array($object, 'fetch')) || !is_callable(array($object, 'isExistingObject'))) { + $this->error = $this->outputLang->trans('BadSetupOfFieldFetchNotCallable'); + return false; + } + + if (!empty($object->table_element) && $object->isExistingObject($object->table_element, $values)) { + return true; + } else { $this->error = $this->outputLang->trans('RequireValidExistingElement'); } + } else { $this->error = $this->outputLang->trans('BadSetupOfFieldClassNotFoundForValidation'); } + } else { $this->error = $this->outputLang->trans('BadSetupOfFieldFileNotFound'); } + } else { $this->error = $this->outputLang->trans('BadSetupOfField'); } + return false; + } } diff --git a/htdocs/langs/en_US/validate.lang b/htdocs/langs/en_US/validate.lang index 1464805b853..bd25b6c0c74 100644 --- a/htdocs/langs/en_US/validate.lang +++ b/htdocs/langs/en_US/validate.lang @@ -8,5 +8,12 @@ RequireValidEmail = Email address is not valid RequireMaxLength = Length must be less than %s chars RequireMinLength = Length must be more than %s char(s) RequireValidUrl = Require valid URL -RequireValideDate = Require a valid date +RequireValidDate = Require a valid date RequireANotEmptyValue = Is required +RequireValidDuration = Require a valid duration +RequireValidExistingElement = Require an existing value +RequireValidBool = Require a valid boolean +BadSetupOfField = Error bad setup of field +BadSetupOfFieldClassNotFoundForValidation = Error bad setup of field : Class not found for validation +BadSetupOfFieldFileNotFound = Error bad setup of field : File not found for inclusion +BadSetupOfFieldFetchNotCallable = Error bad setup of field : Fetch not callable on class From f1b1dcd1b145af430a62141e013990dbeb28d795 Mon Sep 17 00:00:00 2001 From: ATM john Date: Sun, 6 Jun 2021 21:53:17 +0200 Subject: [PATCH 031/628] WIP - create validation method for common object --- htdocs/core/class/commonobject.class.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index ae5f0d33216..f3426608c55 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6376,9 +6376,10 @@ abstract class CommonObject * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. * @param int $nonewbutton Force to not show the new button on field that are links to object + * @param bool $displayValidationResult Display validation results messages for fields, set it to true after form sended to display user mistakes * @return string */ - public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0) + public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0, $displayValidationResult = false) { global $conf, $langs, $form; @@ -6391,6 +6392,25 @@ abstract class CommonObject $val = $this->fields[$key]; } + // This is en experimental validation output TODO : remove this deactivation line + if ($conf->global->MAIN_FEATURES_LEVEL < 2 && empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) { $displayValidationResult = false; } + + // Validation tests and output + $fieldValidation = 0; // 0 not tested, -1 error, 1 success + $fieldValidationErrorMesg = ''; + $validationClass = ''; + if ($displayValidationResult) { + if (!$this->validateField($val, $key, $value)) { + $validationClass = ' --error'; // the -- is use as class state in css : .--error can't be be defined alone it must be define with another class like .my-class.--error or input.--error + $fieldValidation = -1; + $fieldValidationErrorMesg = $this->error; + } else { + $validationClass = ' --success'; // the -- is use as class state in css : .--success can't be be defined alone it must be define with another class like .my-class.--success or input.--success + $fieldValidation = 1; + } + } + + $out = ''; $type = ''; $isDependList=0; From 801f6cab2d3bb86554a610fba27b92a649420ebb Mon Sep 17 00:00:00 2001 From: ATM john Date: Sun, 6 Jun 2021 21:58:59 +0200 Subject: [PATCH 032/628] WIP - create validation method for common object --- htdocs/core/class/validate.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/core/class/validate.class.php b/htdocs/core/class/validate.class.php index ac01ce76531..3f94da5dbe0 100644 --- a/htdocs/core/class/validate.class.php +++ b/htdocs/core/class/validate.class.php @@ -259,8 +259,7 @@ class Validate } foreach ($value_arr as $val){ - $val = $this->db->escape($val); - $sql = 'SELECT ' . $col . ' FROM ' . MAIN_DB_PREFIX . $table . " WHERE " . $col ." = '" . $val . "'"; // nore quick than count(*) to check existing of a row + $sql = 'SELECT ' . $col . ' FROM ' . MAIN_DB_PREFIX . $table . " WHERE " . $col ." = '" . $this->db->escape($val) . "'"; // nore quick than count(*) to check existing of a row $resql = $this->db->getRow($sql); if ($resql) { continue; From a63d3364b4bdd72b40c0fbe5739747d4b18d2cc9 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sun, 6 Jun 2021 22:51:27 +0200 Subject: [PATCH 033/628] Fix links in box last MO --- htdocs/core/boxes/box_mos.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/htdocs/core/boxes/box_mos.php b/htdocs/core/boxes/box_mos.php index 43d1cd411e4..d7f7a8f72ae 100644 --- a/htdocs/core/boxes/box_mos.php +++ b/htdocs/core/boxes/box_mos.php @@ -86,12 +86,15 @@ class box_mos extends ModeleBoxes if ($user->rights->mrp->read) { $sql = "SELECT p.ref as product_ref"; + $sql .= ", p.rowid as productid"; + $sql .= ", p.tosell"; + $sql .= ", p.tobuy"; + $sql .= ", p.tobatch"; $sql .= ", c.rowid"; $sql .= ", c.date_creation"; $sql .= ", c.tms"; $sql .= ", c.ref"; $sql .= ", c.status"; - //$sql.= ", c.fk_user_valid"; $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; $sql .= ", ".MAIN_DB_PREFIX."mrp_mo as c"; $sql .= " WHERE c.fk_product = p.rowid"; @@ -110,9 +113,12 @@ class box_mos extends ModeleBoxes $datem = $this->db->jdate($objp->tms); $mostatic->id = $objp->rowid; $mostatic->ref = $objp->ref; - $mostatic->id = $objp->socid; $mostatic->status = $objp->status; + $productstatic->id = $objp->productid; $productstatic->ref = $objp->product_ref; + $productstatic->status = $objp->tosell; + $productstatic->status_buy = $objp->tobuy; + $productstatic->status_batch = $objp->tobatch; $this->info_box_contents[$line][] = array( 'td' => 'class="nowraponall"', @@ -126,17 +132,6 @@ class box_mos extends ModeleBoxes 'asis' => 1, ); - if (!empty($conf->global->MRP_BOX_LAST_MOS_SHOW_VALIDATE_USER)) { - if ($objp->fk_user_valid > 0) { - $userstatic->fetch($objp->fk_user_valid); - } - $this->info_box_contents[$line][] = array( - 'td' => 'class="right"', - 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''), - 'asis' => 1, - ); - } - $this->info_box_contents[$line][] = array( 'td' => 'class="center nowraponall"', 'text' => dol_print_date($datem, 'day', 'tzuserrel'), From 6733d278d8775cab97e49afb47348c595e00510b Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Tue, 8 Jun 2021 18:13:18 +0200 Subject: [PATCH 034/628] NEW: project time spent: conf to prevent recording time after X months --- htdocs/core/lib/project.lib.php | 50 ++++++++++++++++++++++++++---- htdocs/langs/en_US/admin.lang | 1 + htdocs/langs/en_US/projects.lang | 1 + htdocs/projet/admin/project.php | 15 +++++++++ htdocs/projet/class/task.class.php | 12 +++++++ 5 files changed, 73 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index aaa1e144202..d48d37a9539 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -1076,6 +1076,13 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 to start break , -1 no break } + $restrictBefore = null; + + if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); + } + //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0)); for ($i = 0; $i < $numlines; $i++) { @@ -1307,6 +1314,10 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr $disabledtask = 1; } + if ($restrictBefore && $preselectedday < $restrictBefore) { + $disabledtask = 1; + } + // Form to add new time print ''; +print ''; + +print ''; +print ''; + +print ''; +print ''; print '
'; $tableCell = $form->selectDate($preselectedday, $lines[$i]->id, 1, 1, 2, "addtime", 0, 0, $disabledtask); @@ -1451,6 +1462,13 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 = start break, -1 = never break } + $restrictBefore = null; + + if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); + } + for ($i = 0; $i < $numlines; $i++) { if ($parent == 0) $level = 0; @@ -1708,6 +1726,12 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ $cssweekend = 'weekend'; } + $disabledtaskday = $disabledtask; + + if (! $disabledtask && $restrictBefore && $tmpday < $restrictBefore) { + $disabledtaskday = 1; + } + $tableCell = ''; //$tableCell .= 'idw='.$idw.' '.$conf->global->MAIN_START_WEEK.' '.$numstartworkingday.'-'.$numendworkingday; $placeholder = ''; @@ -1717,7 +1741,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ //$placeholder=' placeholder="00:00"'; //$tableCell.='+'; } - $tableCell .= ''; @@ -1812,6 +1836,13 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 = start break, -1 = never break } + $restrictBefore = null; + + if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); + } + for ($i = 0; $i < $numlines; $i++) { if ($parent == 0) $level = 0; @@ -1954,10 +1985,11 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & $tableCell = ''; $modeinput = 'hours'; $TFirstDay = getFirstDayOfEachWeek($TWeek, date('Y', $firstdaytoshow)); $TFirstDay[reset($TWeek)] = 1; - foreach ($TFirstDay as &$fday) { - $fday--; - } - foreach ($TWeek as $weekNb) + + $firstdaytoshowarray = dol_getdate($firstdaytoshow); + $year = $firstdaytoshowarray['year']; + $month = $firstdaytoshowarray['mon']; + foreach ($TWeek as $weekIndex => $weekNb) { $weekWorkLoad = $projectstatic->monthWorkLoadPerTask[$weekNb][$lines[$i]->id]; $totalforeachweek[$weekNb] += $weekWorkLoad; @@ -1966,6 +1998,12 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & if ($weekWorkLoad > 0) $alreadyspent = convertSecondToTime($weekWorkLoad, 'allhourmin'); $alttitle = $langs->trans("AddHereTimeSpentForWeek", $weekNb); + $disabledtaskweek = $disabledtask; + $firstdayofweek = dol_mktime(0, 0, 0, $month, $TFirstDay[$weekIndex], $year); + + if (! $disabledtask && $restrictBefore && $firstdayofweek < $restrictBefore) { + $disabledtaskweek = 1; + } $tableCell = ''; $placeholder = ''; @@ -1976,7 +2014,7 @@ function projectLinesPerMonth(&$inc, $firstdaytoshow, $fuser, $parent, $lines, & //$tableCell.='+'; } - $tableCell .= ''; diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index f5770bad737..446f01a5446 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -81,6 +81,7 @@ NumberOfBytes=Number of Bytes SearchString=Search string NotAvailableWhenAjaxDisabled=Not available when Ajax disabled AllowToSelectProjectFromOtherCompany=On document of a third party, can choose a project linked to another third party +TimesheetPreventAfterFollowingMonths=Prevent recording time spent after the following number of months JavascriptDisabled=JavaScript disabled UsePreviewTabs=Use preview tabs ShowPreview=Show preview diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 2aedbd53377..9fea85e7d1e 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -139,6 +139,7 @@ NoTasks=No tasks for this project LinkedToAnotherCompany=Linked to other third party TaskIsNotAssignedToUser=Task not assigned to user. Use button '%s' to assign task now. ErrorTimeSpentIsEmpty=Time spent is empty +TimeRecordingRestrictedToNMonthsBack=Time recording is restricted to %s months back ThisWillAlsoRemoveTasks=This action will also delete all tasks of project (%s tasks at the moment) and all inputs of time spent. IfNeedToUseOtherObjectKeepEmpty=If some objects (invoice, order, ...), belonging to another third party, must be linked to the project to create, keep this empty to have the project being multi third parties. CloneTasks=Clone tasks diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index f36aae34c4f..143f75b72ab 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -242,6 +242,11 @@ elseif ($action == 'setdoc') $projectToSelect = GETPOST('projectToSelect', 'alpha'); dolibarr_set_const($db, 'PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY', $projectToSelect, 'chaine', 0, '', $conf->entity); //Allow to disable this configuration if empty value } + if (GETPOST('PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS')) + { + $timesheetFreezeDuration = GETPOST('timesheetFreezeDuration', 'alpha'); + dolibarr_set_const($db, 'PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS', intval($timesheetFreezeDuration), 'chaine', 0, '', $conf->entity); //Allow to disable this configuration if empty value + } } @@ -839,6 +844,16 @@ print ''; print '
'.$langs->trans("TimesheetPreventAfterFollowingMonths").''; +print ' '; +print ''; +print '
'; diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index b4733de05ae..1b64f0d9a66 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1095,6 +1095,18 @@ class Task extends CommonObject if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note); if (empty($this->timespent_datehour)) $this->timespent_datehour = $this->timespent_date; + if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); + + if ($this->timespent_date < $restrictBefore) { + $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); + $this->errors[] = $this->error; + return -1; + } + } + + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."projet_task_time ("; From 7317aad41f76c944b21618df2caf3346788520e8 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Wed, 9 Jun 2021 11:08:38 +0200 Subject: [PATCH 035/628] FIX: projet time spent: also restrict to X months back for update and delete --- htdocs/projet/class/task.class.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 1b64f0d9a66..e974532f545 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1465,6 +1465,17 @@ class Task extends CommonObject if (empty($this->timespent_datehour)) $this->timespent_datehour = $this->timespent_date; if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note); + if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); + + if ($this->timespent_date < $restrictBefore) { + $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); + $this->errors[] = $this->error; + return -1; + } + } + $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET"; @@ -1530,6 +1541,17 @@ class Task extends CommonObject $error = 0; + if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); + + if ($this->timespent_date < $restrictBefore) { + $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); + $this->errors[] = $this->error; + return -1; + } + } + $this->db->begin(); $sql = "DELETE FROM ".MAIN_DB_PREFIX."projet_task_time"; From c62c668c68e9456cd36864de6ecbf3c5d95af2e0 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 9 Jun 2021 09:29:22 +0000 Subject: [PATCH 036/628] Fixing style errors. --- htdocs/projet/class/task.class.php | 54 +++++++++++++++--------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index f46869382a5..05ce98b8896 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1158,16 +1158,16 @@ class Task extends CommonObject $this->timespent_datehour = $this->timespent_date; } - if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); + if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); - if ($this->timespent_date < $restrictBefore) { - $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); - $this->errors[] = $this->error; - return -1; - } - } + if ($this->timespent_date < $restrictBefore) { + $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); + $this->errors[] = $this->error; + return -1; + } + } $this->db->begin(); @@ -1531,16 +1531,16 @@ class Task extends CommonObject $this->timespent_note = trim($this->timespent_note); } - if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); + if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); - if ($this->timespent_date < $restrictBefore) { - $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); - $this->errors[] = $this->error; - return -1; - } - } + if ($this->timespent_date < $restrictBefore) { + $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); + $this->errors[] = $this->error; + return -1; + } + } $this->db->begin(); @@ -1608,16 +1608,16 @@ class Task extends CommonObject $error = 0; - if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { - require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); + if (! empty($conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS)) { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $restrictBefore = dol_time_plus_duree(dol_now(), - $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS, 'm'); - if ($this->timespent_date < $restrictBefore) { - $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); - $this->errors[] = $this->error; - return -1; - } - } + if ($this->timespent_date < $restrictBefore) { + $this->error = $langs->trans('TimeRecordingRestrictedToNMonthsBack', $conf->global->PROJECT_TIMESHEET_PREVENT_AFTER_MONTHS); + $this->errors[] = $this->error; + return -1; + } + } $this->db->begin(); From 4e1fe23b7e1a83d34b45c51348968d415626085c Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 9 Jun 2021 15:48:31 +0200 Subject: [PATCH 037/628] FIX: add check display payment link if invoice module is enabled --- htdocs/commande/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 1ef37552f1f..4913731efb5 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2633,7 +2633,7 @@ if ($action == 'create' && $usercancreate) $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem, $compatibleImportElementsList); // Show online payment link - $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled)); + $useonlinepayment = ((!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled)) && !empty($conf->facture->enabled)); if (!empty($conf->global->ORDER_HIDE_ONLINE_PAYMENT_ON_ORDER)) $useonlinepayment = 0; if ($object->statut != Commande::STATUS_DRAFT && $useonlinepayment) { From 1e7df0ba9fe9f8b247e77ac8b0f75b98a969bb01 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Thu, 10 Jun 2021 21:53:06 +0200 Subject: [PATCH 038/628] NEW: holiday: handle monthly updates with cronjob --- htdocs/core/modules/modHoliday.class.php | 22 ++++++++++++++++++++++ htdocs/holiday/class/holiday.class.php | 2 +- htdocs/holiday/define_holiday.php | 4 ---- htdocs/holiday/list.php | 3 --- htdocs/hrm/index.php | 10 ---------- htdocs/langs/en_US/holiday.lang | 1 + test/phpunit/HolidayTest.php | 2 +- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/htdocs/core/modules/modHoliday.class.php b/htdocs/core/modules/modHoliday.class.php index 23cbf7eddf8..76700b59b31 100644 --- a/htdocs/core/modules/modHoliday.class.php +++ b/htdocs/core/modules/modHoliday.class.php @@ -135,6 +135,28 @@ class modHoliday extends DolibarrModules //$r++; + // Cronjobs + $arraydate = dol_getdate(dol_now()); + $datestart = dol_mktime(4, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']); + $this->cronjobs = array( + 0 => array( + 'label' => 'HolidayBalanceMonthlyUpdate', + 'jobtype' => 'method', + 'class' => 'holiday/class/holiday.class.php', + 'objectname' => 'Holiday', + 'method' => 'updateBalance', + 'parameters' => '', + 'comment' => 'Update holiday balance every month', + 'frequency' => 1, + 'unitfrequency' => 3600 * 24, + 'priority' => 50, + 'status' => 1, + 'test' => '$conf->holiday->enabled', + 'datestart' => $datestart + ) + ); + + // Permissions $this->rights = array(); // Permission array used by this module $r = 0; diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index 55dd1c4bafb..b885202f3a9 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -227,7 +227,7 @@ class Holiday extends CommonObject if ($result >= 0) { $this->db->commit(); - return 1; + return 0; // for cronjob use (0 is OK, any other value is an error code) } else { $this->db->rollback(); return -1; diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index b3d2c25adda..fcb8b73d486 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -193,10 +193,6 @@ llxHeader('', $langs->trans('CPTitreMenu')); $typeleaves = $holiday->getTypes(1, 1); -$result = $holiday->updateBalance(); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user. -if ($result < 0) { - setEventMessages($holiday->error, $holiday->errors, 'errors'); -} print '
'; diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index c62185d5f2a..9d569f4344e 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -231,9 +231,6 @@ $formfile = new FormFile($db); $fuser = new User($db); $holidaystatic = new Holiday($db); -// Update sold -$result = $object->updateBalance(); - $title = $langs->trans('CPTitreMenu'); llxHeader('', $title); diff --git a/htdocs/hrm/index.php b/htdocs/hrm/index.php index 50fd4c3f521..6cc4dc3b5bd 100644 --- a/htdocs/hrm/index.php +++ b/htdocs/hrm/index.php @@ -68,16 +68,6 @@ if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INF $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT; -/* - * Actions - */ - -// Update sold -if (!empty($conf->holiday->enabled) && !empty($setupcompanynotcomplete)) { - $holidaystatic = new Holiday($db); - $result = $holidaystatic->updateBalance(); -} - /* * View diff --git a/htdocs/langs/en_US/holiday.lang b/htdocs/langs/en_US/holiday.lang index 2393a02ee50..0e6b1d69b36 100644 --- a/htdocs/langs/en_US/holiday.lang +++ b/htdocs/langs/en_US/holiday.lang @@ -132,3 +132,4 @@ FreeLegalTextOnHolidays=Free text on PDF WatermarkOnDraftHolidayCards=Watermarks on draft leave requests HolidaysToApprove=Holidays to approve NobodyHasPermissionToValidateHolidays=Nobody has permission to validate holidays +HolidayBalanceMonthlyUpdate=Monthly update of holiday balance diff --git a/test/phpunit/HolidayTest.php b/test/phpunit/HolidayTest.php index bba5d68c41e..415d45da674 100644 --- a/test/phpunit/HolidayTest.php +++ b/test/phpunit/HolidayTest.php @@ -366,6 +366,6 @@ class HolidayTest extends PHPUnit\Framework\TestCase $localobjecta->updateConfCP('lastUpdate', '20100101120000'); $result = $localobjecta->updateBalance(); - $this->assertEquals($result, 1); + $this->assertEquals($result, 0); } } From 82feb57fcfbfdd971a1a4c7581878fbc1c1349fc Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 10 Jun 2021 19:56:03 +0000 Subject: [PATCH 039/628] Fixing style errors. --- htdocs/core/modules/modHoliday.class.php | 28 ++++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/htdocs/core/modules/modHoliday.class.php b/htdocs/core/modules/modHoliday.class.php index 76700b59b31..71ab96e65bd 100644 --- a/htdocs/core/modules/modHoliday.class.php +++ b/htdocs/core/modules/modHoliday.class.php @@ -140,20 +140,20 @@ class modHoliday extends DolibarrModules $datestart = dol_mktime(4, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']); $this->cronjobs = array( 0 => array( - 'label' => 'HolidayBalanceMonthlyUpdate', - 'jobtype' => 'method', - 'class' => 'holiday/class/holiday.class.php', - 'objectname' => 'Holiday', - 'method' => 'updateBalance', - 'parameters' => '', - 'comment' => 'Update holiday balance every month', - 'frequency' => 1, - 'unitfrequency' => 3600 * 24, - 'priority' => 50, - 'status' => 1, - 'test' => '$conf->holiday->enabled', - 'datestart' => $datestart - ) + 'label' => 'HolidayBalanceMonthlyUpdate', + 'jobtype' => 'method', + 'class' => 'holiday/class/holiday.class.php', + 'objectname' => 'Holiday', + 'method' => 'updateBalance', + 'parameters' => '', + 'comment' => 'Update holiday balance every month', + 'frequency' => 1, + 'unitfrequency' => 3600 * 24, + 'priority' => 50, + 'status' => 1, + 'test' => '$conf->holiday->enabled', + 'datestart' => $datestart + ) ); From 578dc9adde74c913962083eb4e129ffec0ed0fc9 Mon Sep 17 00:00:00 2001 From: ATM john Date: Sat, 12 Jun 2021 12:58:20 +0200 Subject: [PATCH 040/628] WIP - create validation method for common object --- htdocs/core/actions_addupdatedelete.inc.php | 9 +++ htdocs/core/class/commonobject.class.php | 65 +++++++++++++++---- .../template/class/myobject.class.php | 2 +- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index f871ed73de8..6c03839a996 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -105,6 +105,15 @@ if ($action == 'add' && !empty($permissiontoadd)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors'); } + + // Validation of fields values + if ($conf->global->MAIN_FEATURE_LEVEL >= 2 || !empty($conf->global->MAIN_USE_COMMON_VALIDATION)) { + if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) { + if (!$object->validateField($object->fields, $key, $value)) { + $error++; + } + } + } } // Fill array 'array_options' with data from add form diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index f3426608c55..39eeae90fc2 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -123,6 +123,10 @@ abstract class CommonObject */ protected $table_ref_field = ''; + /** + * @var array $validateFieldsErrors to store error results of ->validateField() + */ + public $validateFieldsErrors = array(); // Following vars are used by some objects only. We keep this property here in CommonObject to be able to provide common method using them. @@ -7305,6 +7309,40 @@ abstract class CommonObject return $out; } + /** + * clear validation message result for a field + * + * @param string $fieldKey Key of attribute to clear + */ + public function clearFieldError($fieldKey) + { + $this->error = ''; + unset($this->validateFieldsErrors[$fieldKey]); + } + + /** + * set validation error message a field + * + * @param string $fieldKey Key of attribute + */ + public function setFieldError($fieldKey, $msg = '') + { + $this->error = $this->validateFieldsErrors[$fieldKey] = $msg; + } + + /** + * get field error message + * + * @param string $fieldKey Key of attribute + */ + public function getFieldError($fieldKey) + { + if (!empty($this->validateFieldsErrors[$fieldKey])) { + return $this->validateFieldsErrors[$fieldKey]; + } + return ''; + } + /** * Return validation test result for a field * @@ -7319,8 +7357,7 @@ abstract class CommonObject if(!class_exists('Validate')){ require_once DOL_DOCUMENT_ROOT . '/core/class/validate.class.php'; } - // TODO : ask @eldy to know if need to use another error field to separate error msg - $this->error = ''; // error will be use for form error display so must be clear before + $this->clearFieldError($fieldKey); if (!isset($val[$fieldKey])) { return false; @@ -7393,7 +7430,7 @@ abstract class CommonObject // Required test and empty value if($required && !$validate->isNotEmptyString($fieldValue)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } elseif (!$required && !$validate->isNotEmptyString($fieldValue)) { @@ -7403,13 +7440,13 @@ abstract class CommonObject // MAX Size test if(!empty($maxSize) && !$validate->isMaxLength($fieldValue, $maxSize)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } // MIN Size test if(!empty($minSize) && !$validate->isMinLength($fieldValue, $minSize)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } @@ -7419,12 +7456,12 @@ abstract class CommonObject if (in_array($type, array('date', 'datetime', 'timestamp'))) { if (!$validate->isTimestamp($fieldValue)) { - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } } elseif ($type == 'duration') { if(!$validate->isDuration($fieldValue)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } } @@ -7432,35 +7469,35 @@ abstract class CommonObject { // is numeric if(!$validate->isDuration($fieldValue)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } } elseif ($type == 'boolean') { if(!$validate->isBool($fieldValue)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } } elseif ($type == 'mail') { if(!$validate->isEmail($fieldValue)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } } elseif ($type == 'url') { if(!$validate->isUrl($fieldValue)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } } elseif ($type == 'phone') { if (!$validate->isPhone($fieldValue)) { - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } } @@ -7484,7 +7521,7 @@ abstract class CommonObject } if(!isInDb($value_arr, $InfoFieldList[0], $selectkey)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } } @@ -7495,7 +7532,7 @@ abstract class CommonObject $classname = $InfoFieldList[0]; $classpath = $InfoFieldList[1]; if(!$validate->isFetchable($fieldValue, $classname, $classpath)){ - $this->error = $validate->error; + $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } } diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index e69c5bc333d..be8736f9d49 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -91,7 +91,7 @@ class MyObject extends CommonObject * 'arrayofkeyval' to set a list of values if type is a list of predefined values. For example: array("0"=>"Draft","1"=>"Active","-1"=>"Cancel"). Note that type can be 'integer' or 'varchar' * 'autofocusoncreate' to have field having the focus on a create form. Only 1 field should have this property set to 1. * 'comment' is not used. You can store here any text of your choice. It is not used by application. - * + * 'validate' is 1 if need to validate with $this->validateField() * Note: To have value dynamic, you can set value to 0 in definition and edit the value on the fly into the constructor. */ From 43ecba2e6304496caa6b499c596bbc74634d509a Mon Sep 17 00:00:00 2001 From: ATM john Date: Sat, 12 Jun 2021 14:16:40 +0200 Subject: [PATCH 041/628] WIP - create validation method for common object --- htdocs/core/actions_addupdatedelete.inc.php | 11 ++++++++- htdocs/core/class/commonobject.class.php | 25 ++++++++++++++------- htdocs/core/lib/functions.lib.php | 17 ++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 6c03839a996..d2d22d74e3c 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -107,7 +107,7 @@ if ($action == 'add' && !empty($permissiontoadd)) { } // Validation of fields values - if ($conf->global->MAIN_FEATURE_LEVEL >= 2 || !empty($conf->global->MAIN_USE_COMMON_VALIDATION)) { + if ($conf->global->MAIN_FEATURE_LEVEL >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) { if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) { if (!$object->validateField($object->fields, $key, $value)) { $error++; @@ -213,6 +213,15 @@ if ($action == 'update' && !empty($permissiontoadd)) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv($val['label'])), null, 'errors'); } + + // Validation of fields values + if ($conf->global->MAIN_FEATURE_LEVEL >= 2 || !empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) { + if (!$error && !empty($val['validate']) && is_callable(array($object, 'validateField'))) { + if (!$object->validateField($object->fields, $key, $value)) { + $error++; + } + } + } } // Fill array 'array_options' with data from add form diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 39eeae90fc2..cfba42e0adf 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6381,9 +6381,10 @@ abstract class CommonObject * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. * @param int $nonewbutton Force to not show the new button on field that are links to object * @param bool $displayValidationResult Display validation results messages for fields, set it to true after form sended to display user mistakes + * @param string $mode 1=Used for search filters * @return string */ - public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0, $displayValidationResult = false) + public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0, $mode = 0) { global $conf, $langs, $form; @@ -6400,17 +6401,14 @@ abstract class CommonObject if ($conf->global->MAIN_FEATURES_LEVEL < 2 && empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) { $displayValidationResult = false; } // Validation tests and output - $fieldValidation = 0; // 0 not tested, -1 error, 1 success - $fieldValidationErrorMesg = ''; + $fieldValidationErrorMsg = ''; $validationClass = ''; - if ($displayValidationResult) { - if (!$this->validateField($val, $key, $value)) { + if($mode == 0){ + $fieldValidationErrorMsg = $this->getFieldError($key); + if (!empty($fieldValidationErrorMsg)) { $validationClass = ' --error'; // the -- is use as class state in css : .--error can't be be defined alone it must be define with another class like .my-class.--error or input.--error - $fieldValidation = -1; - $fieldValidationErrorMesg = $this->error; } else { $validationClass = ' --success'; // the -- is use as class state in css : .--success can't be be defined alone it must be define with another class like .my-class.--success or input.--success - $fieldValidation = 1; } } @@ -6506,6 +6504,11 @@ abstract class CommonObject } } + // Add validation state class + if (!empty($validationClass)) { + $morecss.= ' '.$validationClass; + } + if (in_array($type, array('date'))) { $tmp = explode(',', $size); $newsize = $tmp[0]; @@ -6971,6 +6974,12 @@ abstract class CommonObject if ($type == 'date') $out.=' (YYYY-MM-DD)'; elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; */ + + // Display error message for field + if ($mode == 0 && !empty($fieldValidationErrorMsg) && function_exists('getFieldErrorIcon')) { + $out .= ' '.getFieldErrorIcon($fieldValidationErrorMsg); + } + return $out; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 61a3869fe1a..5dd500a26a0 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9753,6 +9753,23 @@ function dolGetButtonTitleSeparator($moreClass = "") return ''; } +/** + * get field error icon + * + * @param string $fieldValidationErrorMsg + */ +function getFieldErrorIcon($fieldValidationErrorMsg) +{ + $out = ''; + if (!empty($fieldValidationErrorMesg)) { + $out.= ''; // role alert is used for accessibility + $out.= ''; // For accessibility icon is separated and aria-hidden + $out.= ''; + } + + return $out; +} + /** * Function dolGetButtonTitle : this kind of buttons are used in title in list * From 23765bf459474e30fb213c4086099fb6178cef41 Mon Sep 17 00:00:00 2001 From: ATM john Date: Mon, 14 Jun 2021 20:59:46 +0200 Subject: [PATCH 042/628] WIP - create validation method for common object --- htdocs/core/class/commonobject.class.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index cfba42e0adf..9e9333b8962 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6380,8 +6380,7 @@ abstract class CommonObject * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. * @param int $nonewbutton Force to not show the new button on field that are links to object - * @param bool $displayValidationResult Display validation results messages for fields, set it to true after form sended to display user mistakes - * @param string $mode 1=Used for search filters + * @param int $mode 1=Used for search filters * @return string */ public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0, $mode = 0) @@ -6397,9 +6396,6 @@ abstract class CommonObject $val = $this->fields[$key]; } - // This is en experimental validation output TODO : remove this deactivation line - if ($conf->global->MAIN_FEATURES_LEVEL < 2 && empty($conf->global->MAIN_ACTIVATE_VALIDATION_RESULT)) { $displayValidationResult = false; } - // Validation tests and output $fieldValidationErrorMsg = ''; $validationClass = ''; From be367c589f971f81e6010d5f527c605db3d5f8a0 Mon Sep 17 00:00:00 2001 From: ATM john Date: Mon, 14 Jun 2021 21:12:48 +0200 Subject: [PATCH 043/628] WIP - create validation method for common object --- htdocs/core/class/commonobject.class.php | 65 ++++++++++-------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 9e9333b8962..2b83e324ab3 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6399,7 +6399,7 @@ abstract class CommonObject // Validation tests and output $fieldValidationErrorMsg = ''; $validationClass = ''; - if($mode == 0){ + if ($mode == 0) { $fieldValidationErrorMsg = $this->getFieldError($key); if (!empty($fieldValidationErrorMsg)) { $validationClass = ' --error'; // the -- is use as class state in css : .--error can't be be defined alone it must be define with another class like .my-class.--error or input.--error @@ -7318,6 +7318,7 @@ abstract class CommonObject * clear validation message result for a field * * @param string $fieldKey Key of attribute to clear + * @return null */ public function clearFieldError($fieldKey) { @@ -7328,7 +7329,9 @@ abstract class CommonObject /** * set validation error message a field * - * @param string $fieldKey Key of attribute + * @param string $fieldKey Key of attribute + * @param string $msg the field error message + * @return null */ public function setFieldError($fieldKey, $msg = '') { @@ -7339,6 +7342,7 @@ abstract class CommonObject * get field error message * * @param string $fieldKey Key of attribute + * @return string */ public function getFieldError($fieldKey) { @@ -7360,7 +7364,7 @@ abstract class CommonObject { global $langs; - if(!class_exists('Validate')){ require_once DOL_DOCUMENT_ROOT . '/core/class/validate.class.php'; } + if (!class_exists('Validate')) { require_once DOL_DOCUMENT_ROOT . '/core/class/validate.class.php'; } $this->clearFieldError($fieldKey); @@ -7434,23 +7438,22 @@ abstract class CommonObject // // Required test and empty value - if($required && !$validate->isNotEmptyString($fieldValue)){ + if ($required && !$validate->isNotEmptyString($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; - } - elseif (!$required && !$validate->isNotEmptyString($fieldValue)) { + } elseif (!$required && !$validate->isNotEmptyString($fieldValue)) { // if no value sent and the field is not mandatory, no need to perform tests return true; } // MAX Size test - if(!empty($maxSize) && !$validate->isMaxLength($fieldValue, $maxSize)){ + if (!empty($maxSize) && !$validate->isMaxLength($fieldValue, $maxSize)) { $this->setFieldError($fieldKey, $validate->error); return false; } // MIN Size test - if(!empty($minSize) && !$validate->isMinLength($fieldValue, $minSize)){ + if (!empty($minSize) && !$validate->isMinLength($fieldValue, $minSize)) { $this->setFieldError($fieldKey, $validate->error); return false; } @@ -7465,56 +7468,42 @@ abstract class CommonObject return false; } else { return true; } } elseif ($type == 'duration') { - if(!$validate->isDuration($fieldValue)){ + if (!$validate->isDuration($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } - } - elseif (in_array($type, array('double', 'real', 'price'))) - { + } elseif (in_array($type, array('double', 'real', 'price'))) { // is numeric - if(!$validate->isDuration($fieldValue)){ + if (!$validate->isDuration($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } - } - elseif ($type == 'boolean') - { - if(!$validate->isBool($fieldValue)){ + } elseif ($type == 'boolean') { + if (!$validate->isBool($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } - } - elseif ($type == 'mail') - { - if(!$validate->isEmail($fieldValue)){ + } elseif ($type == 'mail') { + if (!$validate->isEmail($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; } - } - elseif ($type == 'url') - { - if(!$validate->isUrl($fieldValue)){ + } elseif ($type == 'url') { + if (!$validate->isUrl($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } - } - elseif ($type == 'phone') - { + } elseif ($type == 'phone') { if (!$validate->isPhone($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } - } - elseif ($type == 'select' || $type == 'radio') - { + } elseif ($type == 'select' || $type == 'radio') { if (!isset($param['options'][$fieldValue])) { $this->error = $langs->trans('RequireValidValue'); return false; } else { return true; } - } - elseif ($type == 'sellist' || $type == 'chkbxlst') - { + } elseif ($type == 'sellist' || $type == 'chkbxlst') { $param_list = array_keys($param['options']); $InfoFieldList = explode(":", $param_list[0]); $value_arr = explode(',', $fieldValue); @@ -7525,18 +7514,16 @@ abstract class CommonObject $selectkey = $InfoFieldList[2]; } - if(!isInDb($value_arr, $InfoFieldList[0], $selectkey)){ + if (!isInDb($value_arr, $InfoFieldList[0], $selectkey)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } - } - elseif ($type == 'link') - { + } elseif ($type == 'link') { $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' $InfoFieldList = explode(":", $param_list[0]); $classname = $InfoFieldList[0]; $classpath = $InfoFieldList[1]; - if(!$validate->isFetchable($fieldValue, $classname, $classpath)){ + if (!$validate->isFetchable($fieldValue, $classname, $classpath)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } From 82f195dc3057f6eef8fce4b4659f9a3b8c9a0f8d Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 14 Jun 2021 19:15:53 +0000 Subject: [PATCH 044/628] Fixing style errors. --- htdocs/core/class/validate.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/validate.class.php b/htdocs/core/class/validate.class.php index 3f94da5dbe0..2b9d98ae5e0 100644 --- a/htdocs/core/class/validate.class.php +++ b/htdocs/core/class/validate.class.php @@ -51,7 +51,7 @@ class Validate * @param DoliDB $db Database handler * @param Translate $outputLang */ - public function __construct($db,$outputLang = false) + public function __construct($db, $outputLang = false) { global $langs; @@ -121,7 +121,7 @@ class Validate */ public function isTimestamp($stamp) { - if (!is_numeric($stamp) && (int)$stamp == $stamp) { + if (!is_numeric($stamp) && (int) $stamp == $stamp) { $this->error = $this->outputLang->trans('RequireValidDate'); return false; } @@ -229,7 +229,7 @@ class Validate */ public function isBool($bool) { - if(!(is_null($bool) || is_bool($bool) || preg_match('/^[0|1]{1}$/ui', $bool))){ + if (!(is_null($bool) || is_bool($bool) || preg_match('/^[0|1]{1}$/ui', $bool))) { $this->error = $this->outputLang->trans('RequireValidBool'); return false; } @@ -258,7 +258,7 @@ class Validate return false; } - foreach ($value_arr as $val){ + foreach ($value_arr as $val) { $sql = 'SELECT ' . $col . ' FROM ' . MAIN_DB_PREFIX . $table . " WHERE " . $col ." = '" . $this->db->escape($val) . "'"; // nore quick than count(*) to check existing of a row $resql = $this->db->getRow($sql); if ($resql) { From 4d043b713cf7c44c34890037592b380f659dd99d Mon Sep 17 00:00:00 2001 From: ATM john Date: Mon, 21 Jun 2021 21:54:03 +0200 Subject: [PATCH 045/628] WIP - create validation method for common object --- htdocs/core/class/commonobject.class.php | 22 +++++++++---------- htdocs/core/lib/functions.lib.php | 7 +++--- .../template/class/myobject.class.php | 20 ++++++++--------- htdocs/theme/eldy/global.inc.php | 8 ++++--- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 2b83e324ab3..b9cc03893fd 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6380,10 +6380,9 @@ abstract class CommonObject * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. * @param int $nonewbutton Force to not show the new button on field that are links to object - * @param int $mode 1=Used for search filters * @return string */ - public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0, $mode = 0) + public function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0, $nonewbutton = 0) { global $conf, $langs, $form; @@ -6399,16 +6398,13 @@ abstract class CommonObject // Validation tests and output $fieldValidationErrorMsg = ''; $validationClass = ''; - if ($mode == 0) { - $fieldValidationErrorMsg = $this->getFieldError($key); - if (!empty($fieldValidationErrorMsg)) { - $validationClass = ' --error'; // the -- is use as class state in css : .--error can't be be defined alone it must be define with another class like .my-class.--error or input.--error - } else { - $validationClass = ' --success'; // the -- is use as class state in css : .--success can't be be defined alone it must be define with another class like .my-class.--success or input.--success - } + $fieldValidationErrorMsg = $this->getFieldError($key); + if (!empty($fieldValidationErrorMsg)) { + $validationClass = ' --error'; // the -- is use as class state in css : .--error can't be be defined alone it must be define with another class like .my-class.--error or input.--error + } else { + $validationClass = ' --success'; // the -- is use as class state in css : .--success can't be be defined alone it must be define with another class like .my-class.--success or input.--success } - $out = ''; $type = ''; $isDependList=0; @@ -6972,7 +6968,7 @@ abstract class CommonObject */ // Display error message for field - if ($mode == 0 && !empty($fieldValidationErrorMsg) && function_exists('getFieldErrorIcon')) { + if (!empty($fieldValidationErrorMsg) && function_exists('getFieldErrorIcon')) { $out .= ' '.getFieldErrorIcon($fieldValidationErrorMsg); } @@ -7335,6 +7331,9 @@ abstract class CommonObject */ public function setFieldError($fieldKey, $msg = '') { + global $langs; + if (empty($msg)) { $msg = $langs->trans("UnknowError"); } + $this->error = $this->validateFieldsErrors[$fieldKey] = $msg; } @@ -7369,6 +7368,7 @@ abstract class CommonObject $this->clearFieldError($fieldKey); if (!isset($val[$fieldKey])) { + $this->setFieldError($fieldKey, $langs->trans('FieldNotFoundInObject')); return false; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 5dd500a26a0..2c5d2144180 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -9756,13 +9756,14 @@ function dolGetButtonTitleSeparator($moreClass = "") /** * get field error icon * - * @param string $fieldValidationErrorMsg + * @param string $fieldValidationErrorMsg message to add in tooltip + * @return string html output */ function getFieldErrorIcon($fieldValidationErrorMsg) { $out = ''; - if (!empty($fieldValidationErrorMesg)) { - $out.= ''; // role alert is used for accessibility + if (!empty($fieldValidationErrorMsg)) { + $out.= ''; // role alert is used for accessibility $out.= ''; // For accessibility icon is separated and aria-hidden $out.= ''; } diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index be8736f9d49..118c60275f1 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -101,16 +101,16 @@ class MyObject extends CommonObject */ public $fields = array( 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id', 'css'=>'left'), - 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'noteditable'=>0, 'default'=>'', 'notnull'=> 1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), + 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'noteditable'=>0, 'default'=>'', 'notnull'=> 1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object', 'validate'=>1), 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'notnull'=> 1, 'default'=>1, 'index'=>1, 'position'=>20), - 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'help'=>'Help text', 'showoncombobox'=>1), - 'amount' => array('type'=>'price', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for amount'), - 'qty' => array('type'=>'real', 'label'=>'Qty', 'enabled'=>1, 'visible'=>1, 'default'=>'0', 'position'=>45, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for quantity', 'css'=>'maxwidth75imp'), - 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'picto'=>'company', 'label'=>'ThirdParty', 'visible'=> 1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'help'=>'LinkToThirparty'), - 'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'picto'=>'project', 'enabled'=>1, 'visible'=>-1, 'position'=>52, 'notnull'=>-1, 'index'=>1), - 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>3, 'position'=>60), - 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61), - 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62), + 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>30, 'searchall'=>1, 'css'=>'minwidth300', 'cssview'=>'wordbreak', 'help'=>'Help text', 'showoncombobox'=>1, 'validate'=>1), + 'amount' => array('type'=>'price', 'label'=>'Amount', 'enabled'=>1, 'visible'=>1, 'default'=>'null', 'position'=>40, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for amount', 'validate'=>1), + 'qty' => array('type'=>'real', 'label'=>'Qty', 'enabled'=>1, 'visible'=>1, 'default'=>'0', 'position'=>45, 'searchall'=>0, 'isameasure'=>1, 'help'=>'Help text for quantity', 'css'=>'maxwidth75imp', 'validate'=>1), + 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status=1 AND entity IN (__SHARED_ENTITIES__)', 'picto'=>'company', 'label'=>'ThirdParty', 'visible'=> 1, 'enabled'=>1, 'position'=>50, 'notnull'=>-1, 'index'=>1, 'help'=>'LinkToThirparty', 'validate'=>1), + 'fk_project' => array('type'=>'integer:Project:projet/class/project.class.php:1', 'label'=>'Project', 'picto'=>'project', 'enabled'=>1, 'visible'=>-1, 'position'=>52, 'notnull'=>-1, 'index'=>1, 'validate'=>1), + 'description' => array('type'=>'text', 'label'=>'Description', 'enabled'=>1, 'visible'=>3, 'position'=>60, 'validate'=>1), + 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61, 'validate'=>1), + 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>62, 'validate'=>1), 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=> 1, 'position'=>500), 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=> 0, 'position'=>501), //'date_validation ' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>502), @@ -120,7 +120,7 @@ class MyObject extends CommonObject 'last_main_doc' => array('type'=>'varchar(255)', 'label'=>'LastMainDoc', 'enabled'=>1, 'visible'=>0, 'notnull'=>0, 'position'=>600), 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>0, 'position'=>1000), 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'notnull'=>-1, 'position'=>1010), - 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=> 1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Validated', 9=>'Canceled')), + 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'notnull'=> 1, 'default'=>0, 'index'=>1, 'position'=>1000, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Validated', 9=>'Canceled'), 'validate'=>1), ); /** diff --git a/htdocs/theme/eldy/global.inc.php b/htdocs/theme/eldy/global.inc.php index 4468c36a7da..c14289ba4b3 100644 --- a/htdocs/theme/eldy/global.inc.php +++ b/htdocs/theme/eldy/global.inc.php @@ -234,10 +234,12 @@ input.button.massactionconfirmed { margin: 4px; } -input:invalid, select:invalid { +input:invalid, select:invalid, input.--error , select.--error { border-color: #ea1212; } +.field-error-icon { color: #ea1212; !important; } + /* Focus definitions must be after standard definition */ textarea:focus { border: 1px solid #aaa !important; @@ -433,7 +435,7 @@ input.pageplusone { transform: scale(-1, 1); } -select:invalid { +select:invalid, select.--error { color: gray; } input:disabled, textarea:disabled, select[disabled='disabled'] @@ -2076,7 +2078,7 @@ span.widthpictotitle.pictotitle { vertical-align: middle; margin-top: -3px } -.pictowarning, .pictoerror, .pictopreview { +.pictowarning, .picto.error, .pictopreview { padding-: 3px; } .pictowarning { From d0a4ae88b144d1d6fa03ebd8001f1f2b6807d9a8 Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Thu, 24 Jun 2021 10:21:56 +0200 Subject: [PATCH 046/628] NEW: make it easier to set the `keyword`, `keywords` and `description` attributes of an ecm file object --- htdocs/core/lib/files.lib.php | 4 +++- htdocs/ecm/class/ecmfiles.class.php | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 7e34eec5ecd..8e44e30f445 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1789,7 +1789,9 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo if (is_object($object) && $object->id > 0) { $ecmfile->src_object_id = $object->id; - $ecmfile->src_object_type = $object->table_element; + if (isset($object->table_element)) $ecmfile->src_object_type = $object->table_element; + if (isset($object->src_object_description)) $ecmfile->description = $object->src_object_description; + if (isset($object->src_object_keyword)) $ecmfile->keyword = $object->src_object_keyword; } if ($setsharekey) { diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index 035a7aee9c6..df18aa13d2f 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -288,6 +288,7 @@ class EcmFiles extends CommonObject $sql .= 'fullpath_orig,'; $sql .= 'description,'; $sql .= 'keywords,'; + $sql .= 'keyword,'; $sql .= 'cover,'; $sql .= 'position,'; $sql .= 'gen_or_uploaded,'; @@ -309,6 +310,7 @@ class EcmFiles extends CommonObject $sql .= ' '.(!isset($this->fullpath_orig) ? 'NULL' : "'".$this->db->escape($this->fullpath_orig)."'").','; $sql .= ' '.(!isset($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").','; $sql .= ' '.(!isset($this->keywords) ? 'NULL' : "'".$this->db->escape($this->keywords)."'").','; + $sql .= ' '.(!isset($this->keyword) ? 'NULL' : "'".$this->db->escape($this->keyword)."'").','; $sql .= ' '.(!isset($this->cover) ? 'NULL' : "'".$this->db->escape($this->cover)."'").','; $sql .= ' '.$maxposition.','; $sql .= ' '.(!isset($this->gen_or_uploaded) ? 'NULL' : "'".$this->db->escape($this->gen_or_uploaded)."'").','; From 8332385bd5962eee9fbe2ad48c8d8276fa8299ad Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sun, 27 Jun 2021 08:40:37 +0200 Subject: [PATCH 047/628] Fix links in box last BOM --- htdocs/core/boxes/box_boms.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/htdocs/core/boxes/box_boms.php b/htdocs/core/boxes/box_boms.php index ee248d0a083..23e525fc00b 100644 --- a/htdocs/core/boxes/box_boms.php +++ b/htdocs/core/boxes/box_boms.php @@ -85,7 +85,11 @@ class box_boms extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedBoms", $max)); if ($user->rights->bom->read) { - $sql = "SELECT p.ref as product_ref, p.tobuy, p.tosell"; + $sql = "SELECT p.ref as product_ref"; + $sql .= ", p.rowid as productid"; + $sql .= ", p.tosell"; + $sql .= ", p.tobuy"; + $sql .= ", p.tobatch"; $sql .= ", c.rowid"; $sql .= ", c.date_creation"; $sql .= ", c.tms"; @@ -111,12 +115,13 @@ class box_boms extends ModeleBoxes $bomstatic->id = $objp->rowid; $bomstatic->ref = $objp->ref; - $bomstatic->id = $objp->socid; $bomstatic->status = $objp->status; + $productstatic->id = $objp->productid; $productstatic->ref = $objp->product_ref; - $productstatic->status = $objp->tobuy; - $productstatic->status_buy = $objp->tosell; + $productstatic->status = $objp->tosell; + $productstatic->status_buy = $objp->tobuy; + $productstatic->status_batch = $objp->tobatch; $this->info_box_contents[$line][] = array( 'td' => 'class="nowraponall"', @@ -130,17 +135,6 @@ class box_boms extends ModeleBoxes 'asis' => 1, ); - if (!empty($conf->global->BOM_BOX_LAST_BOMS_SHOW_VALIDATE_USER)) { - if ($objp->fk_user_valid > 0) { - $userstatic->fetch($objp->fk_user_valid); - } - $this->info_box_contents[$line][] = array( - 'td' => 'class="right"', - 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''), - 'asis' => 1, - ); - } - $this->info_box_contents[$line][] = array( 'td' => 'class="right"', 'text' => dol_print_date($datem, 'day', 'tzuserrel'), From 477b1272e01c881dfef4a2df8a5fdc671b52efe2 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Mon, 28 Jun 2021 13:30:26 +0200 Subject: [PATCH 048/628] Fix CI bot error --- htdocs/langs/nl_NL/main.lang | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/langs/nl_NL/main.lang b/htdocs/langs/nl_NL/main.lang index 4a0eb506398..75529001b12 100644 --- a/htdocs/langs/nl_NL/main.lang +++ b/htdocs/langs/nl_NL/main.lang @@ -10,8 +10,8 @@ SeparatorDecimal=, SeparatorThousand=Space FormatDateShort=%m/%d/%Y FormatDateShortInput=%m/%d/%Y -FormatDateShortJava=MM/dd/jjjj -FormatDateShortJavaInput=MM/dd/jjjj +FormatDateShortJava=MM/dd/yyyy +FormatDateShortJavaInput=MM/dd/yyyy FormatDateShortJQuery=mm/dd/jj FormatDateShortJQueryInput=mm/dd/jj FormatHourShortJQuery=HH:MI From c90730d5304ca809c00df17a98409427f0915ba5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Jun 2021 02:40:05 +0200 Subject: [PATCH 049/628] Prepare branch to dev v15 --- htdocs/filefunc.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 777fde21885..1f7a51c706d 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -34,7 +34,7 @@ if (!defined('DOL_APPLICATION_TITLE')) { define('DOL_APPLICATION_TITLE', 'Dolibarr'); } if (!defined('DOL_VERSION')) { - define('DOL_VERSION', '14.0.0-beta'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c + define('DOL_VERSION', '15.0.0-alpha'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c } if (!defined('EURO')) { From ef8aaa7fd72f7825deb4703d0a6c9d7a9d49adf3 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 29 Jun 2021 15:26:04 +0200 Subject: [PATCH 050/628] generate intervention from time spent --- htdocs/core/class/html.form.class.php | 166 ++++++++++++++++++++++++++ htdocs/langs/en_US/interventions.lang | 1 + htdocs/langs/en_US/projects.lang | 7 +- htdocs/langs/fr_FR/interventions.lang | 1 + htdocs/langs/fr_FR/projects.lang | 7 +- htdocs/projet/tasks/time.php | 134 +++++++++++++++++++-- 6 files changed, 307 insertions(+), 9 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index b3ed477596c..9e1bcb34251 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -8741,6 +8741,172 @@ class Form return $out; } + /** + * Output a combo list with interventions qualified for a third party + * + * @param int $socid Id third party (-1=all, 0=only projects not linked to a third party, id=projects not linked or linked to third party id) + * @param int $selected Id intervention preselected + * @param string $htmlname Name of HTML select + * @param int $maxlength Maximum length of label + * @param int $option_only Return only html options lines without the select tag + * @param string $show_empty Add an empty line ('1' or string to show for empty line) + * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) + * @param int $forcefocus Force focus on field (works with javascript only) + * @param int $disabled Disabled + * @param string $morecss More css added to the select component + * @param string $projectsListId ''=Automatic filter on project allowed. List of id=Filter on project ids. + * @param string $showproject 'all' = Show project info, ''=Hide project info + * @param User $usertofilter User object to use for filtering + * @return int Nbr of project if OK, <0 if KO + */ + public function selectIntervention($socid = -1, $selected = '', $htmlname = 'interid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showproject = 'all', $usertofilter = null) + { + global $user, $conf, $langs; + + require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + + if (is_null($usertofilter)) + { + $usertofilter = $user; + } + + $out = ''; + + $hideunselectables = false; + if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true; + + if (empty($projectsListId)) + { + if (empty($usertofilter->rights->projet->all->lire)) + { + $projectstatic = new Project($this->db); + $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1); + } + } + + // Search all projects + $sql = 'SELECT i.rowid, i.ref as ref, p.fk_soc, p.fk_statut, p.public,'; + $sql .= ' s.nom as name'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,'; + $sql .= ' '.MAIN_DB_PREFIX.'fichinter as i'; + $sql .= " WHERE p.entity IN (".getEntity('project').")"; + $sql .= " AND i.fk_projet = p.rowid AND i.fk_statut=0"; //Brouillons seulement + if ($projectsListId) $sql.= " AND p.rowid IN (".$projectsListId.")"; + if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; + if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)"; + $sql .= " GROUP BY i.ref ORDER BY p.ref, i.ref ASC"; + + $resql = $this->db->query($sql); + if ($resql) + { + // Use select2 selector + if (!empty($conf->use_javascript_ajax)) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; + $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus); + $out .= $comboenhancement; + $morecss = 'minwidth200imp maxwidth500'; + } + + if (empty($option_only)) { + $out .= ''; + } + + print $out; + + $this->db->free($resql); + return $num; + } + else + { + dol_print_error($this->db); + return -1; + } + } + /** * Output a combo list with invoices qualified for a third party * diff --git a/htdocs/langs/en_US/interventions.lang b/htdocs/langs/en_US/interventions.lang index 51079fca278..ff5de8b1b3e 100644 --- a/htdocs/langs/en_US/interventions.lang +++ b/htdocs/langs/en_US/interventions.lang @@ -66,3 +66,4 @@ RepeatableIntervention=Template of intervention ToCreateAPredefinedIntervention=To create a predefined or recurring intervention, create a common intervention and convert it into intervention template Reopen=Reopen ConfirmReopenIntervention=Are you sure you want to open back the intervention %s? +GenerateInter=Generate intervention diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 2fda7e1df0e..0bc78b8c62d 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -241,6 +241,7 @@ LatestModifiedProjects=Latest %s modified projects OtherFilteredTasks=Other filtered tasks NoAssignedTasks=No assigned tasks found (assign project/tasks to the current user from the top select box to enter time on it) ThirdPartyRequiredToGenerateInvoice=A third party must be defined on project to be able to invoice it. +ThirdPartyRequiredToGenerateInvoice=A third party must be defined on project to be able to create intervention. ChooseANotYetAssignedTask=Choose a task not yet assigned to you # Comments trans AllowCommentOnTask=Allow user comments on tasks @@ -252,10 +253,12 @@ SendProjectRef=Information project %s ModuleSalaryToDefineHourlyRateMustBeEnabled=Module 'Salaries' must be enabled to define employee hourly rate to have time spent valorized NewTaskRefSuggested=Task ref already used, a new task ref is required TimeSpentInvoiced=Time spent billed +TimeSpentForIntervention=Time spent TimeSpentForInvoice=Time spent OneLinePerUser=One line per user ServiceToUseOnLines=Service to use on lines InvoiceGeneratedFromTimeSpent=Invoice %s has been generated from time spent on project +InterventionGeneratedFromTimeSpent=Intervention %s has been generated from time spent on project ProjectBillTimeDescription=Check if you enter timesheet on tasks of project AND you plan to generate invoice(s) from the timesheet to bill the customer of the project (do not check if you plan to create invoice that is not based on entered timesheets). Note: To generate invoice, go on tab 'Time spent' of the project and select lines to include. ProjectFollowOpportunity=Follow opportunity ProjectFollowTasks=Follow tasks or time spent @@ -264,7 +267,9 @@ UsageOpportunity=Usage: Opportunity UsageTasks=Usage: Tasks UsageBillTimeShort=Usage: Bill time InvoiceToUse=Draft invoice to use +InterToUse=Draft intervention to use NewInvoice=New invoice +NewInter=New intervention OneLinePerTask=One line per task OneLinePerPeriod=One line per period OneLinePerTimeSpentLine=One line for each time spent declaration @@ -274,4 +279,4 @@ AddPersonToTask=Add also to tasks UsageOrganizeEvent=Usage: Event Organization PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE=Classify project as closed when all its tasks are completed (100%% progress) PROJECT_CLASSIFY_CLOSED_WHEN_ALL_TASKS_DONE_help=Note: existing projects with all tasks at 100 %% progress won't be affected: you will have to close them manually. This option only affects open projects. -SelectLinesOfTimeSpentToInvoice=Select lines of time spent that are unbilled, then bulk action "Generate Invoice" to bill them \ No newline at end of file +SelectLinesOfTimeSpentToInvoice=Select lines of time spent that are unbilled, then bulk action "Generate Invoice" to bill them diff --git a/htdocs/langs/fr_FR/interventions.lang b/htdocs/langs/fr_FR/interventions.lang index 43722fe2bfd..50c24662069 100644 --- a/htdocs/langs/fr_FR/interventions.lang +++ b/htdocs/langs/fr_FR/interventions.lang @@ -64,3 +64,4 @@ InterLineDuration=Durée ligne intervention InterLineDesc=Description ligne intervention RepeatableIntervention=Modèle d'intervention ToCreateAPredefinedIntervention=Pour créer une intervention prédéfinie ou récurrente, créez une intervention standard et convertissez-la en modèle d'intervention +GenerateInter=Générer une fiche d'intervention diff --git a/htdocs/langs/fr_FR/projects.lang b/htdocs/langs/fr_FR/projects.lang index 6b342e4eb88..d574362118a 100644 --- a/htdocs/langs/fr_FR/projects.lang +++ b/htdocs/langs/fr_FR/projects.lang @@ -241,6 +241,7 @@ LatestModifiedProjects=Les %s derniers projets modifiés OtherFilteredTasks=Autres tâches filtrées NoAssignedTasks=Aucune tâche assignée (assignez un projet/tâche à l'utilisateur depuis la liste déroulante utilisateur en haut pour pouvoir saisir du temps dessus) ThirdPartyRequiredToGenerateInvoice=Un tiers doit être défini sur le projet pour pouvoir le facturer. +ThirdPartyRequiredToGenerateIntervention=Un tiers doit être défini sur le projet pour pouvoir créer une intervention. ChooseANotYetAssignedTask=Choisissez une tâche qui ne vous est pas encore assignée # Comments trans AllowCommentOnTask=Autoriser les utilisateurs à ajouter des commentaires sur les tâches @@ -253,18 +254,22 @@ ModuleSalaryToDefineHourlyRateMustBeEnabled=Le module 'Paiement des salaires des NewTaskRefSuggested=Réf de tâche déjà utilisée, une nouvelle référence de tâche est requise TimeSpentInvoiced=Temps passé facturé TimeSpentForInvoice=Temps consommés +TimeSpentForIntervention=Temps consommés OneLinePerUser=Une ligne par utilisateur ServiceToUseOnLines=Service à utiliser sur les lignes InvoiceGeneratedFromTimeSpent=La facture %s a été générée à partir du temps passé sur le projet +InterventionGeneratedFromTimeSpent=L'intervention %s a été générée à partir du temps passé sur le projet ProjectBillTimeDescription=Cochez si vous saisissez du temps sur les tâches du projet ET prévoyez de générer des factures à partir des temps pour facturer le client du projet (ne cochez pas si vous comptez créer une facture qui n'est pas basée sur la saisie des temps). Note: Pour générer une facture, aller sur l'onglet 'Temps consommé' du project et sélectionnez les lignes à inclure. -ProjectFollowOpportunity=Suivre une opportunité +ProjectFollowOpportunity=Suivre une opportunité ProjectFollowTasks=Suivre des tâches ou du temps passé Usage=Usage UsageOpportunity=Utilisation: Opportunité UsageTasks=Utilisation: Tâches UsageBillTimeShort=Utilisation: Facturation du temps InvoiceToUse=Facture brouillon à utiliser +InterToUse=Intervention brouillon à utiliser NewInvoice=Nouvelle facture +NewInter=Nouvelle intervention OneLinePerTask=Une ligne par tâche OneLinePerPeriod=Une ligne par période OneLinePerTimeSpentLine=One line for each time spent declaration diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index a9316bcedcd..62890b5b749 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -5,7 +5,7 @@ * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2018 Ferran Marcet * Copyright (C) 2018 Frédéric France - * Copyright (C) 2019 Christophe Battarel + * Copyright (C) 2019-2021 Christophe Battarel * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -115,7 +115,7 @@ $extrafields->fetch_name_optionals_label($object->table_element); if (GETPOST('cancel', 'alpha')) { $action = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_generateinvoice') { +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_generateinvoice' && $massaction != 'confirm_generateinter') { $massaction = ''; } @@ -536,6 +536,90 @@ if ($action == 'confirm_generateinvoice') { } } +if ($action == 'confirm_generateinter') +{ + $langs->load('interventions'); + + if (!empty($projectstatic->socid)) $projectstatic->fetch_thirdparty(); + + if (!($projectstatic->thirdparty->id > 0)) { + setEventMessages($langs->trans("ThirdPartyRequiredToGenerateIntervention"), null, 'errors'); + } else { + include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + + + require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; + $tmpinter = new Fichinter($db); + $tmptimespent = new Task($db); + $fuser = new User($db); + + $db->begin(); + $interToUse = GETPOST('interid', 'int'); + + + $tmpinter->socid = $projectstatic->thirdparty->id; + $tmpinter->date = dol_mktime(GETPOST('rehour', 'int'), GETPOST('remin', 'int'), GETPOST('resec', 'int'), GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); + $tmpinter->fk_project = $projectstatic->id; + $tmpinter->description = $projectstatic->title . ( ! empty($projectstatic->description) ? '-' . $projectstatic->label : '' ); + + if ($interToUse) { + $tmpinter->fetch($interToUse); + } + else { + $result = $tmpinter->create($user); + if ($result <= 0) + { + $error++; + setEventMessages($tmpinter->error, $tmpinter->errors, 'errors'); + } + } + + if (!$error) + { + $arrayoftasks = array(); + foreach ($toselect as $key => $value) + { + // Get userid, timepent + $object->fetchTimeSpent($value); + // $object->id is the task id + $arrayoftasks[$object->timespent_id]['timespent'] = $object->timespent_duration; + $arrayoftasks[$object->timespent_id]['totalvaluetodivideby3600'] = $object->timespent_duration * $object->timespent_thm; + $arrayoftasks[$object->timespent_id]['note'] = $object->timespent_note; + $arrayoftasks[$object->timespent_id]['date'] = date('Y-m-d H:i:s', $object->timespent_datehour); + } + + foreach ($arrayoftasks as $timespent_id => $value) + { + $ftask = new Task($db); + $ftask->fetch($object->id); + // Define qty per hour + $qtyhour = $value['timespent'] / 3600; + $qtyhourtext = convertSecondToTime($value['timespent'], 'all', $conf->global->MAIN_DURATION_OF_WORKDAY); + + // Add lines + $lineid = $tmpinter->addline($user, $tmpinter->id, $ftask->label . ( ! empty($value['note']) ? ' - ' . $value['note'] : '' ), $value['date'], $value['timespent']); + } + } + + if (!$error) + { + $urltointer = $tmpinter->getNomUrl(0); + $mesg = $langs->trans("InterventionGeneratedFromTimeSpent", '{s1}'); + $mesg = str_replace('{s1}', $urltointer, $mesg); + setEventMessages($mesg, null, 'mesgs'); + + //var_dump($tmpinvoice); + + $db->commit(); + } + else + { + $db->rollback(); + } + } +} /* * View @@ -749,12 +833,16 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { 'generateinvoice'=>$langs->trans("GenerateBill"), //'builddoc'=>$langs->trans("PDFMerge"), ); - //if ($user->rights->projet->creer) $arrayofmassactions['predelete']=''.$langs->trans("Delete"); - if (in_array($massaction, array('presend', 'predelete', 'generateinvoice'))) { - $arrayofmassactions = array(); - } - $massactionbutton = $form->selectMassAction('', $arrayofmassactions); } + if ( ! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer) { + $langs->load("interventions"); + $arrayofmassactions['generateinter'] = $langs->trans("GenerateInter"); + } + //if ($user->rights->projet->creer) $arrayofmassactions['predelete']=''.$langs->trans("Delete"); + if (in_array($massaction, array('presend', 'predelete', 'generateinvoice', 'generateinter'))) { + $arrayofmassactions = array(); + } + $massactionbutton = $form->selectMassAction('', $arrayofmassactions); // Show section with information of task. If id of task is not defined and project id defined, then $projectidforalltimes is not empty. if (empty($projectidforalltimes)) { @@ -944,6 +1032,8 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { print ''; } elseif ($massaction == 'generateinvoice' && $user->rights->facture->lire) { print ''; + } elseif ($massaction == 'generateinter' && $user->rights->ficheinter->lire) { + print ''; } else { print ''; } @@ -1026,6 +1116,36 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { print '
'; $massaction = ''; } + } elseif ($massaction == 'generateinter') { + // Form to convert time spent into invoice + print ''; + + if ($projectstatic->thirdparty->id > 0) { + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + print $langs->trans('InterToUse'); + print ''; + $form->selectIntervention($projectstatic->thirdparty->id, '', 'interid', 24, 0, $langs->trans('NewInter'), + 1, 0, 0, 'maxwidth500', '', 'all'); + print '
'; + + print '
'; + print '
'; + print ' '; + print ''; + print '
'; + print '
'; + } else { + print '
'.$langs->trans("ThirdPartyRequiredToGenerateInter").'
'; + print '
'; + print ''; + print '
'; + $massaction = ''; + } } /* From 6d77f5e12f856949df49bab9806c27f072647f8a Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 29 Jun 2021 15:38:24 +0200 Subject: [PATCH 051/628] fix translation string --- htdocs/projet/tasks/time.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 62890b5b749..b4b0f46f8ba 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -1140,7 +1140,7 @@ if (($id > 0 || !empty($ref)) || $projectidforalltimes > 0) { print ''; print '
'; } else { - print '
'.$langs->trans("ThirdPartyRequiredToGenerateInter").'
'; + print '
'.$langs->trans("ThirdPartyRequiredToGenerateIntervention").'
'; print '
'; print ''; print '
'; From 474df5fef29c85a7aa28204a17f1002542a8db33 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Jun 2021 15:41:21 +0200 Subject: [PATCH 052/628] Update box_boms.php --- htdocs/core/boxes/box_boms.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/core/boxes/box_boms.php b/htdocs/core/boxes/box_boms.php index 23e525fc00b..fb0bdeb0625 100644 --- a/htdocs/core/boxes/box_boms.php +++ b/htdocs/core/boxes/box_boms.php @@ -135,6 +135,17 @@ class box_boms extends ModeleBoxes 'asis' => 1, ); + if (!empty($conf->global->BOM_BOX_LAST_BOMS_SHOW_VALIDATE_USER)) { + if ($objp->fk_user_valid > 0) { + $userstatic->fetch($objp->fk_user_valid); + } + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''), + 'asis' => 1, + ); + } + $this->info_box_contents[$line][] = array( 'td' => 'class="right"', 'text' => dol_print_date($datem, 'day', 'tzuserrel'), From ab4dbcf5aecadae3a36130a82914f0531941031b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 29 Jun 2021 15:41:48 +0200 Subject: [PATCH 053/628] Update box_mos.php --- htdocs/core/boxes/box_mos.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/core/boxes/box_mos.php b/htdocs/core/boxes/box_mos.php index 171d129dbd3..8305bbabf32 100644 --- a/htdocs/core/boxes/box_mos.php +++ b/htdocs/core/boxes/box_mos.php @@ -132,6 +132,17 @@ class box_mos extends ModeleBoxes 'asis' => 1, ); + if (!empty($conf->global->MRP_BOX_LAST_MOS_SHOW_VALIDATE_USER)) { + if ($objp->fk_user_valid > 0) { + $userstatic->fetch($objp->fk_user_valid); + } + $this->info_box_contents[$line][] = array( + 'td' => 'class="right"', + 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''), + 'asis' => 1, + ); + } + $this->info_box_contents[$line][] = array( 'td' => 'class="center nowraponall"', 'text' => dol_print_date($datem, 'day', 'tzuserrel'), From d423e47d3b839e1ac6a779a377450b055508bc1a Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Tue, 29 Jun 2021 15:50:41 +0200 Subject: [PATCH 054/628] stickler --- htdocs/core/class/html.form.class.php | 71 +++++++++------------------ htdocs/projet/tasks/time.php | 47 ++++++++---------- 2 files changed, 43 insertions(+), 75 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 9e1bcb34251..bf284a77997 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -8751,22 +8751,21 @@ class Form * @param int $option_only Return only html options lines without the select tag * @param string $show_empty Add an empty line ('1' or string to show for empty line) * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) - * @param int $forcefocus Force focus on field (works with javascript only) - * @param int $disabled Disabled + * @param int $forcefocus Force focus on field (works with javascript only) + * @param int $disabled Disabled * @param string $morecss More css added to the select component * @param string $projectsListId ''=Automatic filter on project allowed. List of id=Filter on project ids. * @param string $showproject 'all' = Show project info, ''=Hide project info * @param User $usertofilter User object to use for filtering * @return int Nbr of project if OK, <0 if KO */ - public function selectIntervention($socid = -1, $selected = '', $htmlname = 'interid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showproject = 'all', $usertofilter = null) + public function selectIntervention($socid = -1, $selected = '', $htmlname = 'interid', $maxlength = 24, $option_only = 0, $show_empty = '1', $discard_closed = 0, $forcefocus = 0, $disabled = 0, $morecss = 'maxwidth500', $projectsListId = '', $showproject = 'all', $usertofilter = null) { global $user, $conf, $langs; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - if (is_null($usertofilter)) - { + if (is_null($usertofilter)) { $usertofilter = $user; } @@ -8775,17 +8774,15 @@ class Form $hideunselectables = false; if (!empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true; - if (empty($projectsListId)) - { - if (empty($usertofilter->rights->projet->all->lire)) - { + if (empty($projectsListId)) { + if (empty($usertofilter->rights->projet->all->lire)) { $projectstatic = new Project($this->db); $projectsListId = $projectstatic->getProjectsAuthorizedForUser($usertofilter, 0, 1); } } // Search all projects - $sql = 'SELECT i.rowid, i.ref as ref, p.fk_soc, p.fk_statut, p.public,'; + $sql = 'SELECT i.rowid, i.ref as ref, p.fk_soc, p.fk_statut, p.public,'; $sql .= ' s.nom as name'; $sql .= ' FROM '.MAIN_DB_PREFIX.'projet as p'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON s.rowid = p.fk_soc,'; @@ -8798,11 +8795,9 @@ class Form $sql .= " GROUP BY i.ref ORDER BY p.ref, i.ref ASC"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { // Use select2 selector - if (!empty($conf->use_javascript_ajax)) - { + if (!empty($conf->use_javascript_ajax)) { include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; $comboenhancement = ajax_combobox($htmlname, '', 0, $forcefocus); $out .= $comboenhancement; @@ -8820,63 +8815,45 @@ class Form } $num = $this->db->num_rows($resql); $i = 0; - if ($num) - { - while ($i < $num) - { + if ($num) { + while ($i < $num) { $obj = $this->db->fetch_object($resql); // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project. - if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire)) - { + if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && empty($usertofilter->rights->societe->lire)) { // Do nothing - } - else - { - if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) - { + } else { + if ($discard_closed == 1 && $obj->fk_statut == Project::STATUS_CLOSED) { $i++; continue; } $labeltoshow = ''; - if ($showproject == 'all') - { + if ($showproject == 'all') { $labeltoshow .= dol_trunc($obj->ref, 18); // Intervention ref if ($obj->name) $labeltoshow .= ' - '.$obj->name; // Soc name $disabled = 0; - if ($obj->fk_statut == Project::STATUS_DRAFT) - { + if ($obj->fk_statut == Project::STATUS_DRAFT) { $disabled = 1; $labeltoshow .= ' - '.$langs->trans("Draft"); - } - elseif ($obj->fk_statut == Project::STATUS_CLOSED) - { + } elseif ($obj->fk_statut == Project::STATUS_CLOSED) { if ($discard_closed == 2) $disabled = 1; $labeltoshow .= ' - '.$langs->trans("Closed"); - } - elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) - { + } elseif ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid)) { $disabled = 1; $labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany"); } } - if (!empty($selected) && $selected == $obj->rowid) - { + if (!empty($selected) && $selected == $obj->rowid) { $out .= '