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 01/15] 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 02/15] 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 110b0fecf5cc040e1de44f981619c77522deadc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20David?= Date: Thu, 1 Jul 2021 19:30:00 +0200 Subject: [PATCH 03/15] NEW #18046 Add ticket categories views --- htdocs/categories/viewcat.php | 90 +++++++++++++++++++++++++++++- htdocs/langs/fr_FR/categories.lang | 2 + htdocs/ticket/card.php | 18 +++++- 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index eeca990ef28..12263d8df2c 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -142,6 +142,11 @@ if ($id > 0 && $removeelem > 0) { $tmpobject = new User($db); $result = $tmpobject->fetch($removeelem); $elementtype = 'user'; + } elseif ($type == Categorie::TYPE_TICKET && $user->rights->ticket->write) { + require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; + $tmpobject = new Ticket($db); + $result = $tmpobject->fetch($removeelem); + $elementtype = 'ticket'; } $result = $object->del_type($tmpobject, $elementtype); @@ -167,7 +172,8 @@ if ($user->rights->categorie->supprimer && $action == 'confirm_delete' && $confi if ($elemid && $action == 'addintocategory' && (($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer)) || ($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer) || - ($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer) + ($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer) || + ($type == Categorie::TYPE_TICKET && $user->rights->ticket->write) )) { if ($type == Categorie::TYPE_PRODUCT) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; @@ -181,6 +187,10 @@ if ($elemid && $action == 'addintocategory' && require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $newobject = new Societe($db); $elementtype = 'supplier'; + } elseif ($type == Categorie::TYPE_TICKET) { + require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php'; + $newobject = new Ticket($db); + $elementtype = 'ticket'; } $result = $newobject->fetch($elemid); @@ -1024,6 +1034,84 @@ if ($type == Categorie::TYPE_WAREHOUSE) { } } +if ($type == Categorie::TYPE_TICKET) +{ + $permission = ($user->rights->categorie->creer || $user->rights->categorie->creer); + + $tickets = $object->getObjectsInCateg($type, 0, $limit, $offset); + if ($tickets < 0) + { + dol_print_error($db, $object->error, $object->errors); + } else { + // Form to add record into a category + $showclassifyform = 1; + if ($showclassifyform) + { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + print $langs->trans("AddTicketIntoCategory").'  '; + $form->select_tickets('', 'elemid'); + print '
'; + print ''; + } + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + print '
'; + $param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($tickets); $nbtotalofrecords = ''; $newcardbutton = ''; + print_barre_liste($langs->trans("Ticket"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'ticket', 0, $newcardbutton, '', $limit); + + + print ''."\n"; + print ''."\n"; + + if (count($tickets) > 0) + { + $i = 0; + foreach ($tickets as $ticket) + { + $i++; + if ($i > $limit) break; + + print "\t".''."\n"; + print '\n"; + print '\n"; + // Link to delete from category + print ''; + print "\n"; + } + } else { + print ''; + } + print "
'.$langs->trans("Ref").'
'; + print $ticket->getNomUrl(1); + print "'.$ticket->label."'; + if ($permission) + { + print ""; + print $langs->trans("DeleteFromCat"); + print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); + print ""; + } + print '
'.$langs->trans("ThisCategoryHasNoItems").'
\n"; + + print '
'."\n"; + } +} // End of page llxFooter(); diff --git a/htdocs/langs/fr_FR/categories.lang b/htdocs/langs/fr_FR/categories.lang index 4b806e1edbd..20bfb122c75 100644 --- a/htdocs/langs/fr_FR/categories.lang +++ b/htdocs/langs/fr_FR/categories.lang @@ -17,6 +17,7 @@ ContactsCategoriesArea=Espace tags/catégories de contacts AccountsCategoriesArea=Espace des tags/categories de comptes bancaires ProjectsCategoriesArea=Espace des tags/catégories des projets UsersCategoriesArea=Espace des tags/catégories des utilisateurs +TicketsCategoriesArea=Espace tags/catégories des tickets SubCats=Sous-catégories CatList=Liste des tags/catégories CatListAll=Liste de toutes les catégories (de tous types) @@ -90,6 +91,7 @@ CategorieRecursivHelp=Si l'option est activé, quand un produit est ajouté dans AddProductServiceIntoCategory=Ajouter le produit/service suivant AddCustomerIntoCategory=Assigner cette catégorie au client AddSupplierIntoCategory=Assigner cette catégorie au fournisseur +AddTicketIntoCategory=Assigner cette catégorie au ticket ShowCategory=Afficher tag/catégorie ByDefaultInList=Par défaut dans la liste ChooseCategory=Choisissez une catégorie diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 5faa7b201b7..9be858fd795 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -31,6 +31,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; if (!empty($conf->projet->enabled)) { include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; @@ -202,6 +203,10 @@ if (empty($reshook)) { $contactid = GETPOST('contactid', 'int'); $type_contact = GETPOST("type", 'alpha'); + // Category association + $categories = GETPOST('categories', 'array'); + $object->setCategories($categories); + if ($contactid > 0 && $type_contact) { $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); $result = $object->add_contact($contactid, $typeid, 'external'); @@ -312,7 +317,11 @@ if (empty($reshook)) { $object->severity_code = GETPOST('severity_code', 'alpha'); $ret = $object->update($user); - if ($ret <= 0) { + if ($ret > 0) { + // Category association + $categories = GETPOST('categories', 'array'); + $object->setCategories($categories); + } else { $error++; } @@ -1054,6 +1063,13 @@ if ($action == 'create' || $action == 'presend') { print ''; } + // Categories + if ($conf->categorie->enabled) { + print ''.$langs->trans("Categories").''; + print $form->showCategories($object->id, Categorie::TYPE_TICKET, 1); + print ""; + } + // Other attributes include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; From ce9bd51cb203a249763b3078bdd0f4d80bbff236 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 12 Jul 2021 07:17:08 +0000 Subject: [PATCH 04/15] Fixing style errors. --- htdocs/categories/viewcat.php | 18 ++++++------------ htdocs/ticket/card.php | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 12263d8df2c..fb7e34fb9a0 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -1034,19 +1034,16 @@ if ($type == Categorie::TYPE_WAREHOUSE) { } } -if ($type == Categorie::TYPE_TICKET) -{ +if ($type == Categorie::TYPE_TICKET) { $permission = ($user->rights->categorie->creer || $user->rights->categorie->creer); $tickets = $object->getObjectsInCateg($type, 0, $limit, $offset); - if ($tickets < 0) - { + if ($tickets < 0) { dol_print_error($db, $object->error, $object->errors); } else { // Form to add record into a category $showclassifyform = 1; - if ($showclassifyform) - { + if ($showclassifyform) { print '
'; print '
'; print ''; @@ -1079,11 +1076,9 @@ if ($type == Categorie::TYPE_TICKET) print ''."\n"; print ''."\n"; - if (count($tickets) > 0) - { + if (count($tickets) > 0) { $i = 0; - foreach ($tickets as $ticket) - { + foreach ($tickets as $ticket) { $i++; if ($i > $limit) break; @@ -1094,8 +1089,7 @@ if ($type == Categorie::TYPE_TICKET) print '\n"; // Link to delete from category print '"; } - + // Other attributes include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; From d8db447112ef4b4fa688d551f6e0308435c62f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20David?= Date: Mon, 12 Jul 2021 14:12:20 +0200 Subject: [PATCH 05/15] fix: rename select_tickets into selectTickets --- htdocs/categories/viewcat.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index fb7e34fb9a0..8ebb9f43b1e 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -1054,7 +1054,7 @@ if ($type == Categorie::TYPE_TICKET) { print '
'.$langs->trans("Ref").'
'.$ticket->label."'; - if ($permission) - { + if ($permission) { print ""; print $langs->trans("DeleteFromCat"); print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft'); diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 9be858fd795..be53c46b051 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -1069,7 +1069,7 @@ if ($action == 'create' || $action == 'presend') { print $form->showCategories($object->id, Categorie::TYPE_TICKET, 1); print "
'; print ''; print ''; print '
'; print $langs->trans("AddTicketIntoCategory").'  '; - $form->select_tickets('', 'elemid'); + $form->selectTickets('', 'elemid'); print '
'; From 901a158238d9e7071f1981f3ea77596eaa743894 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Jul 2021 17:19:43 +0200 Subject: [PATCH 06/15] Fix backward compatibility --- htdocs/societe/class/societe.class.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index eff2ba39c21..422a3f118d8 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1280,7 +1280,8 @@ class Societe extends CommonObject $this->get_codefournisseur($this, 1); } - $this->code_compta = trim($this->code_compta); + $this->code_compta_client = trim(empty($this->code_compta) ? $this->code_compta_client : $this->code_compta); + $this->code_compta = $this->code_compta_client; // for backward compatbility $this->code_compta_fournisseur = trim($this->code_compta_fournisseur); // Check parameters. More tests are done later in the ->verify() @@ -1292,8 +1293,8 @@ class Societe extends CommonObject $customer = false; if (!empty($allowmodcodeclient) && !empty($this->client)) { - // Attention get_codecompta peut modifier le code suivant le module utilise - if (empty($this->code_compta)) { + // If $allowmodcodeclient is set and value is not set, we generate it + if (empty($this->code_compta_client)) { $ret = $this->get_codecompta('customer'); if ($ret < 0) { return -1; @@ -1305,8 +1306,8 @@ class Societe extends CommonObject $supplier = false; if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur)) { - // Attention get_codecompta peut modifier le code suivant le module utilise - if ($this->code_compta_fournisseur == "") { + // If $allowmodcodefournisseur is set and value is not set, we generate it + if (empty($this->code_compta_fournisseur)) { $ret = $this->get_codecompta('supplier'); if ($ret < 0) { return -1; @@ -1460,7 +1461,7 @@ class Societe extends CommonObject if ($customer) { $sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null"); - $sql .= ", code_compta = ".(!empty($this->code_compta) ? "'".$this->db->escape($this->code_compta)."'" : "null"); + $sql .= ", code_compta = ".(!empty($this->code_compta_client) ? "'".$this->db->escape($this->code_compta_client)."'" : "null"); } if ($supplier) { @@ -3311,7 +3312,8 @@ class Societe extends CommonObject $result = $mod->get_code($this->db, $this, $type); if ($type == 'customer') { - $this->code_compta = $mod->code; + $this->code_compta_client = $mod->code; + $this->code_compta = $this->code_compta_client; // For backward compatibility } elseif ($type == 'supplier') { $this->code_compta_fournisseur = $mod->code; } @@ -3323,6 +3325,7 @@ class Societe extends CommonObject } } else { if ($type == 'customer') { + $this->code_compta_client = ''; $this->code_compta = ''; } elseif ($type == 'supplier') { $this->code_compta_fournisseur = ''; From 83d931f3c740f88b1e15e09f3ccb87b76959fb4e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 14 Jul 2021 17:40:36 +0200 Subject: [PATCH 07/15] FIX #18143 --- htdocs/core/lib/functions.lib.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index a53162b7f2c..6e259e3c7fb 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -6828,6 +6828,8 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray = array_merge($substitutionarray, array( '__MYCOMPANY_NAME__' => $mysoc->name, '__MYCOMPANY_EMAIL__' => $mysoc->email, + '__MYCOMPANY_PHONE__' => $mysoc->phone, + '__MYCOMPANY_FAX__' => $mysoc->fax, '__MYCOMPANY_PROFID1__' => $mysoc->idprof1, '__MYCOMPANY_PROFID2__' => $mysoc->idprof2, '__MYCOMPANY_PROFID3__' => $mysoc->idprof3, From 5da40d80f71b2a00fba9b4e8c86c2f12b3e889e9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 15 Jul 2021 16:35:06 +0200 Subject: [PATCH 08/15] Fix css --- htdocs/core/class/commonobject.class.php | 2 +- htdocs/societe/project.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index b3ae722a5d3..e372e2211b3 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7492,7 +7492,7 @@ abstract class CommonObject if ($display_type == 'card') { $out .= ''; - if ( ! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ) { + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER) && $action == 'view') { $out .= ''; } $out .= 'id.'&backtopage='.urlencode($backtopage), '', 1, $params); + $newcardbutton = dolGetButtonTitle($langs->trans("NewProject"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/projet/card.php?action=create&socid='.$object->id.'&backtopageforcancel='.urlencode($backtopage), '', 1, $params); print '
'; From 9aad07f20c3ce870692b4416b57a25cc4af35dad Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 15 Jul 2021 21:57:32 +0200 Subject: [PATCH 09/15] Remove log --- htdocs/core/class/commonobject.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e372e2211b3..cd1810ed06c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8532,7 +8532,6 @@ abstract class CommonObject // Retrieve all extrafield // fetch optionals attributes and labels $this->fetch_optionals(); - dol_syslog("aaa=".$this->id); return $this->id; } else { From 1e93a3f8f42a69246cfc1b509a41d1342553c2d8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 15 Jul 2021 22:29:03 +0200 Subject: [PATCH 10/15] More log on imap card --- htdocs/admin/emailcollector_card.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/emailcollector_card.php b/htdocs/admin/emailcollector_card.php index 4e2c9e34bf9..fdc0b893087 100644 --- a/htdocs/admin/emailcollector_card.php +++ b/htdocs/admin/emailcollector_card.php @@ -103,6 +103,7 @@ $debuginfo = ''; $parameters = array(); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } @@ -239,7 +240,6 @@ if ($action == 'confirm_collect') { - /* * View */ @@ -434,6 +434,14 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $connectstringtarget = $connectstringserver.$object->getEncodedUtf7($targetdir); } + $timeoutconnect = empty($conf->global->MAIN_USE_CONNECT_TIMEOUT) ? 10 : $conf->global->MAIN_USE_CONNECT_TIMEOUT; + $timeoutread = empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT) ? 30 : $conf->global->MAIN_USE_RESPONSE_TIMEOUT; + + dol_syslog("imap_open connectstring=".$connectstringsource." login=".$object->login." password=".$object->password." timeoutconnect=".$timeoutconnect." timeoutread=".$timeoutread); + + imap_timeout(IMAP_OPENTIMEOUT, $timeoutconnect); + imap_timeout(IMAP_READTIMEOUT, $timeoutread); + $connection = imap_open($connectstringsource, $object->login, $object->password); } catch (Exception $e) { print $e->getMessage(); @@ -449,12 +457,15 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if (function_exists('imap_last_error')) { $morehtml .= '
'.imap_last_error(); } + dol_syslog("Error ".$morehtml, LOG_WARNING); //var_dump(imap_errors()) } else { + dol_syslog("Imap connected. Now we call imap_num_msg()"); $morehtml .= imap_num_msg($connection); } if ($connection) { + dol_syslog("Imap close"); imap_close($connection); } From ce27feda84e75c916980bf58ef20eab7433b20c6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 16 Jul 2021 00:05:00 +0200 Subject: [PATCH 11/15] Debug v14 Fix email collector (Creation of thirparty, set of extrafields) --- htdocs/core/class/commonobject.class.php | 4 +- .../class/emailcollector.class.php | 63 +++++++++++++------ htdocs/langs/en_US/admin.lang | 2 +- htdocs/societe/class/societe.class.php | 31 +-------- 4 files changed, 48 insertions(+), 52 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index cd1810ed06c..ceac7015065 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6521,11 +6521,11 @@ abstract class CommonObject } elseif (in_array($type, array('int', 'integer'))) { $tmp = explode(',', $size); $newsize = $tmp[0]; - $out = ''; + $out = ' 0 ? ' maxlength="'.$newsize.'"' : '').' value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>'; } elseif (in_array($type, array('real'))) { $out = ''; } elseif (preg_match('/varchar/', $type)) { - $out = ''; + $out = ' 0 ? ' maxlength="'.$size.'"' : '').' value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>'; } elseif (in_array($type, array('mail', 'phone', 'url'))) { $out = ''; } elseif (preg_match('/^text/', $type)) { diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 0b45db6a808..16df7774470 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -324,6 +324,9 @@ class EmailCollector extends CommonObject // Clear fields $object->ref = "copy_of_".$object->ref; $object->title = $langs->trans("CopyOf")." ".$object->title; + if (empty($object->host)) { + $object->host = 'imap.example.com'; + } // ... // Clear extrafields that are unique if (is_array($object->array_options) && count($object->array_options) > 0) { @@ -849,11 +852,11 @@ class EmailCollector extends CommonObject $regexstring = ''; //$transformationstring=''; $regforregex = array(); - if (preg_match('/^EXTRACT:([a-zA-Z0-9]+):(.*):([^:])$/', $valueforproperty, $regforregex)) { + if (preg_match('/^EXTRACT:([a-zA-Z0-9_]+):(.*):([^:])$/', $valueforproperty, $regforregex)) { $sourcefield = $regforregex[1]; $regexstring = $regforregex[2]; //$transofrmationstring=$regforregex[3]; - } elseif (preg_match('/^EXTRACT:([a-zA-Z0-9]+):(.*)$/', $valueforproperty, $regforregex)) { + } elseif (preg_match('/^EXTRACT:([a-zA-Z0-9_]+):(.*)$/', $valueforproperty, $regforregex)) { $sourcefield = $regforregex[1]; $regexstring = $regforregex[2]; } @@ -1199,15 +1202,20 @@ class EmailCollector extends CommonObject $iforemailloop = 0; foreach ($arrayofemail as $imapemail) { if ($nbemailprocessed > 1000) { - break; // Do not process more than 1000 email per launch (this is a different protection than maxnbcollectedpercollect + break; // Do not process more than 1000 email per launch (this is a different protection than maxnbcollectedpercollect) } $iforemailloop++; + // GET header and overview datas + $header = imap_fetchheader($connection, $imapemail, 0); + $overview = imap_fetch_overview($connection, $imapemail, 0); + + /* print $header; var_dump($overview); */ + + // Process $header of email $header = preg_replace('/\r\n\s+/m', ' ', $header); // When a header line is on several lines, merge lines - /*print $header; - print $header;*/ $matches = array(); preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m', $header, $matches); @@ -1297,9 +1305,6 @@ class EmailCollector extends CommonObject $this->db->begin(); - // GET Email meta datas - $overview = imap_fetch_overview($connection, $imapemail, 0); - dol_syslog("msgid=".$overview[0]->message_id." date=".dol_print_date($overview[0]->udate, 'dayrfc', 'gmt')." from=".$overview[0]->from." to=".$overview[0]->to." subject=".$overview[0]->subject); $overview[0]->subject = $this->decodeSMTPSubject($overview[0]->subject); @@ -1309,10 +1314,14 @@ class EmailCollector extends CommonObject // Removed emojis $overview[0]->subject = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $overview[0]->subject); - // Parse IMAP email structure + // GET IMAP email structure/content + global $htmlmsg, $plainmsg, $charset, $attachments; + $this->getmsg($connection, $imapemail); + //print $plainmsg; var_dump($plainmsg); exit; + //$htmlmsg,$plainmsg,$charset,$attachments $messagetext = $plainmsg ? $plainmsg : dol_string_nohtmltag($htmlmsg, 0); // Removed emojis @@ -1640,13 +1649,15 @@ class EmailCollector extends CommonObject if ($operation['type'] == 'loadthirdparty' || $operation['type'] == 'loadandcreatethirdparty') { if (empty($operation['actionparam'])) { $errorforactions++; - $this->error = "Action loadthirdparty or loadandcreatethirdparty has empty parameter. Must be a rule like 'SET:xxx' or 'EXTRACT:(body|subject):regex' to define how to set or extract data"; + $this->error = "Action loadthirdparty or loadandcreatethirdparty has empty parameter. Must be a rule like 'name=HEADER:^From:(.*);' or 'name=SET:xxx' or 'name=EXTRACT:(body|subject):regex where 'name' can be replaced with 'id' or 'email' to define how to set or extract data. More properties can also be set, for example client=SET:2;"; $this->errors[] = $this->error; } else { $actionparam = $operation['actionparam']; + $idtouseforthirdparty = ''; $nametouseforthirdparty = ''; + $emailtouseforthirdparty = ''; - // $this->actionparam = 'SET:aaa' or 'EXTRACT:BODY:....' + // $actionparam = 'param=SET:aaa' or 'param=EXTRACT:BODY:....' $arrayvaluetouse = dolExplodeIntoArray($actionparam, ';', '='); foreach ($arrayvaluetouse as $propertytooverwrite => $valueforproperty) { $sourcestring = ''; @@ -1654,7 +1665,7 @@ class EmailCollector extends CommonObject $regexstring = ''; $regforregex = array(); - if (preg_match('/^EXTRACT:([a-zA-Z0-9]+):(.*)$/', $valueforproperty, $regforregex)) { + if (preg_match('/^EXTRACT:([a-zA-Z0-9_]+):(.*)$/', $valueforproperty, $regforregex)) { $sourcefield = $regforregex[1]; $regexstring = $regforregex[2]; } @@ -1674,10 +1685,18 @@ class EmailCollector extends CommonObject if (preg_match('/'.$regexstring.'/ms', $sourcestring, $regforval)) { //var_dump($regforval[count($regforval)-1]);exit; // Overwrite param $tmpproperty - $nametouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null; + if ($propertytooverwrite == 'id') { + $idtouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null; + } elseif ($propertytooverwrite == 'email') { + $emailtouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null; + } else { + $nametouseforthirdparty = isset($regforval[count($regforval) - 1]) ? trim($regforval[count($regforval) - 1]) : null; + } } else { // Regex not found + $idtouseforthirdparty = null; $nametouseforthirdparty = null; + $emailtouseforthirdparty = null; } //var_dump($object->$tmpproperty);exit; } else { @@ -1689,7 +1708,13 @@ class EmailCollector extends CommonObject } elseif (preg_match('/^(SET|SETIFEMPTY):(.*)$/', $valueforproperty, $reg)) { //if (preg_match('/^options_/', $tmpproperty)) $object->array_options[preg_replace('/^options_/', '', $tmpproperty)] = $reg[1]; //else $object->$tmpproperty = $reg[1]; - $nametouseforthirdparty = $reg[2]; + if ($propertytooverwrite == 'id') { + $idtouseforthirdparty = $reg[2]; + } elseif ($propertytooverwrite == 'email') { + $emailtouseforthirdparty = $reg[2]; + } else { + $nametouseforthirdparty = $reg[2]; + } } else { $errorforactions++; $this->error = 'Bad syntax for description of action parameters: '.$actionparam; @@ -1698,8 +1723,8 @@ class EmailCollector extends CommonObject } } - if (!$errorforactions && $nametouseforthirdparty) { - $result = $thirdpartystatic->fetch(0, $nametouseforthirdparty); + if (!$errorforactions && ($idtouseforthirdparty || $emailtouseforthirdparty || $nametouseforthirdparty)) { + $result = $thirdpartystatic->fetch($idtouseforthirdparty, $nametouseforthirdparty, '', '', '', '', '', '', '', '', $emailtouseforthirdparty); if ($result < 0) { $errorforactions++; $this->error = 'Error when getting thirdparty with name '.$nametouseforthirdparty.' (may be 2 record exists with same name ?)'; @@ -1707,20 +1732,20 @@ class EmailCollector extends CommonObject break; } elseif ($result == 0) { if ($operation['type'] == 'loadthirdparty') { - dol_syslog("Third party with name ".$nametouseforthirdparty." was not found"); + dol_syslog("Third party with id=".$idtouseforthirdparty." email=".$emailtouseforthirdparty." name=".$nametouseforthirdparty." was not found"); $errorforactions++; $this->error = 'ErrorFailedToLoadThirdParty'; $this->errors[] = 'ErrorFailedToLoadThirdParty'; } elseif ($operation['type'] == 'loadandcreatethirdparty') { - dol_syslog("Third party with name ".$nametouseforthirdparty." was not found. We try to create it."); + dol_syslog("Third party with id=".$idtouseforthirdparty." email=".$emailtouseforthirdparty." name=".$nametouseforthirdparty." was not found. We try to create it."); // Create thirdparty $thirdpartystatic->name = $nametouseforthirdparty; if ($fromtext != $nametouseforthirdparty) { $thirdpartystatic->name_alias = $fromtext; } - $thirdpartystatic->email = $from; + $thirdpartystatic->email = ($emailtouseforthirdparty ? $emailtouseforthirdparty : $from); // Overwrite values with values extracted from source email $errorforthisaction = $this->overwritePropertiesOfObject($thirdpartystatic, $operation['actionparam'], $messagetext, $subject, $header); diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 7af07369759..aca631eef99 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -2090,7 +2090,7 @@ LargerThan=Larger than IfTrackingIDFoundEventWillBeLinked=Note that If a tracking ID of an object is found into email, or if the email is an answer of an email aready collected and linked to an object, the created event will be automatically linked to the known related object. WithGMailYouCanCreateADedicatedPassword=With a GMail account, if you enabled the 2 steps validation, it is recommanded to create a dedicated second password for the application instead of using your own account passsword from https://myaccount.google.com/. EmailCollectorTargetDir=It may be a desired behaviour to move the email into another tag/directory when it was processed successfully. Just set name of directory here to use this feature (Do NOT use special characters in name). Note that you must also use a read/write login account. -EmailCollectorLoadThirdPartyHelp=You can use this action to use the email content to find and load an existing thirdparty in your database. The found (or created) thirdparty will be used for following actions that need it. In the parameter field you can use for example 'EXTRACT:BODY:Name:\s([^\s]*)' if you want to extract the name of the thirdparty from a string 'Name: name to find' found into the body. +EmailCollectorLoadThirdPartyHelp=You can use this action to use the email content to find and load an existing thirdparty in your database. The found (or created) thirdparty will be used for following actions that need it.
For example, if you want to create a thirdparty with a name extracted a string 'Name: name to find' found into the body, use sender email as email, you can set the parameter field like this:
'email=HEADER:^From:(.*);name=EXTRACT:BODY:Name:\s([^\s]*);client=SET:2;'
EndPointFor=End point for %s : %s DeleteEmailCollector=Delete email collector ConfirmDeleteEmailCollector=Are you sure you want to delete this email collector? diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 422a3f118d8..dc074c817f8 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2019 Laurent Destailleur + * Copyright (C) 2004-2021 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2003 Brian Fraval * Copyright (C) 2006 Andre Cianfarani @@ -4265,21 +4265,6 @@ class Societe extends CommonObject return $lib; } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Set prospect level - * - * @param User $user User who sets the discount - * @return int <0 if KO, >0 if OK - * @deprecated Use update function instead - */ - public function set_prospect_level(User $user) - { - // phpcs:enable - return $this->update($this->id, $user); - } - /** * Return status of prospect * @@ -4359,20 +4344,6 @@ class Societe extends CommonObject return "Error, mode/status not found"; } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Set outstanding value - * - * @param User $user User making change - * @return int <0 if KO, >0 if OK - * @deprecated Use update function instead - */ - public function set_OutstandingBill(User $user) - { - // phpcs:enable - return $this->update($this->id, $user); - } - /** * Return amount of order not paid and total * From 180527d23a582498f8fd3330a708a9d40c1b0c3b Mon Sep 17 00:00:00 2001 From: Florian Mortgat Date: Fri, 16 Jul 2021 10:10:57 +0200 Subject: [PATCH 12/15] FIX 13.0: class CommandeFournisseurDispatch provides trigger for UPDATE but not for CREATE / DELETE --- .../fourn/class/fournisseur.commande.dispatch.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php index a7abed27369..0cffacc19a3 100644 --- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php +++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php @@ -204,8 +204,8 @@ class CommandeFournisseurDispatch extends CommonObject // want this action calls a trigger. //// Call triggers - //$result=$this->call_trigger('MYOBJECT_CREATE',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + $result=$this->call_trigger('LINERECEPTION_CREATE', $user); + if ($result < 0) $error++; //// End call triggers } } @@ -419,8 +419,8 @@ class CommandeFournisseurDispatch extends CommonObject // want this action calls a trigger. //// Call triggers - //$result=$this->call_trigger('MYOBJECT_DELETE',$user); - //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + $result=$this->call_trigger('LINERECEPTION_DELETE', $user); + if ($result < 0) $error++; //// End call triggers } } From c928de89c6c3b84f5192a4740785b384bf98759d Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Fri, 16 Jul 2021 10:41:06 +0200 Subject: [PATCH 13/15] fix: print barcode sould not be available for external user --- htdocs/core/modules/modBarcode.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/modBarcode.class.php b/htdocs/core/modules/modBarcode.class.php index 6a894972eb7..4b55f2e438f 100644 --- a/htdocs/core/modules/modBarcode.class.php +++ b/htdocs/core/modules/modBarcode.class.php @@ -104,7 +104,7 @@ class modBarcode extends DolibarrModules 'enabled'=>'$conf->barcode->enabled', // Define condition to show or hide menu entry. Use '$conf->mymodule->enabled' if entry must be visible if module is enabled. Use '$leftmenu==\'system\'' to show if leftmenu system is selected. 'perms'=>'($conf->global->MAIN_USE_ADVANCED_PERMS && $user->rights->barcode->lire_advance) || (! $conf->global->MAIN_USE_ADVANCED_PERMS)', // Use 'perms'=>'$user->rights->mymodule->level1->level2' if you want your menu with a permission rules 'target'=>'', - 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both + 'user'=>0); // 0=Menu for internal users, 1=external users, 2=both $r++; $this->menu[$r] = array('fk_menu'=>'fk_mainmenu=home,fk_leftmenu=admintools', // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode From 4d6372dda12f9c36c00c1901fb0c9f529f7a8ab1 Mon Sep 17 00:00:00 2001 From: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Date: Fri, 16 Jul 2021 12:10:25 +0200 Subject: [PATCH 14/15] FIX: holiday balances: revert part of commit 1e7df0ba9 to still increment on page visit --- htdocs/holiday/define_holiday.php | 4 ++++ htdocs/holiday/list.php | 3 +++ htdocs/hrm/index.php | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index fcb8b73d486..b3d2c25adda 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -193,6 +193,10 @@ 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 9d569f4344e..c62185d5f2a 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -231,6 +231,9 @@ $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 6cc4dc3b5bd..50fd4c3f521 100644 --- a/htdocs/hrm/index.php +++ b/htdocs/hrm/index.php @@ -68,6 +68,16 @@ 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 From 501bc853af6c32b74c9a3c8fc6e939f969f643bd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 16 Jul 2021 12:44:15 +0200 Subject: [PATCH 15/15] Fix default value --- htdocs/install/mysql/tables/llx_object_lang.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_object_lang.sql b/htdocs/install/mysql/tables/llx_object_lang.sql index cc4352f3acc..01b70b208ff 100644 --- a/htdocs/install/mysql/tables/llx_object_lang.sql +++ b/htdocs/install/mysql/tables/llx_object_lang.sql @@ -25,7 +25,7 @@ create table llx_object_lang fk_object integer DEFAULT 0 NOT NULL, type_object varchar(32) NOT NULL, -- value found into $object->element: 'thirdparty', 'contact', '...' property varchar(32) NOT NULL, -- name of property - lang varchar(5) DEFAULT 0 NOT NULL, + lang varchar(5) DEFAULT '' NOT NULL, value text, import_key varchar(14) DEFAULT NULL )ENGINE=innodb;