From 686f460f598ee81cbfd5514f9af10a4bc3f44ec8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 Jul 2022 11:57:43 +0200 Subject: [PATCH 1/2] NEW Added MMK currency (Myanmar Kyat) --- ChangeLog | 1 + htdocs/install/mysql/data/llx_c_currencies.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0b0e8695a7b..41766b5839c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -118,6 +118,7 @@ NEW: VAT Report by month - Show detail by rate and also by code NEW: Ticket triggers: allow to automatically send messages on new tickets NEW: Accountancy - Add hidden feature for accounting reconciliation NEW: Can store the session into database (instead of beeing managed by PHP) +NEW: Added MMK currency (Myanmar Kyat) Modules NEW: Module Partnership Management diff --git a/htdocs/install/mysql/data/llx_c_currencies.sql b/htdocs/install/mysql/data/llx_c_currencies.sql index bc5a01c3992..04d17e98b6a 100644 --- a/htdocs/install/mysql/data/llx_c_currencies.sql +++ b/htdocs/install/mysql/data/llx_c_currencies.sql @@ -116,6 +116,7 @@ INSERT INTO llx_c_currencies ( code_iso, unicode, active, label ) VALUES ( 'MRO' INSERT INTO llx_c_currencies ( code_iso, unicode, active, label ) VALUES ( 'MUR', '[8360]', 1, 'Mauritius Rupee'); INSERT INTO llx_c_currencies ( code_iso, unicode, active, label ) VALUES ( 'MXN', '[36]', 1, 'Mexico Peso'); INSERT INTO llx_c_currencies ( code_iso, unicode, active, label ) VALUES ( 'MDL', NULL, 1, 'Moldova Leu'); +INSERT INTO llx_c_currencies ( code_iso, unicode, active, label ) VALUES ( 'MMK', '[75]', 1, 'Myanmar Kyat'); INSERT INTO llx_c_currencies ( code_iso, unicode, active, label ) VALUES ( 'MNT', '[8366]', 1, 'Mongolia Tughrik'); INSERT INTO llx_c_currencies ( code_iso, unicode, active, label ) VALUES ( 'MAD', NULL, 1, 'Morocco Dirham'); INSERT INTO llx_c_currencies ( code_iso, unicode, active, label ) VALUES ( 'MZN', '[77,84]', 1, 'Mozambique Metical'); From 245580bfa56dc5f6c21f68e08f05ddc52166ed27 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 Jul 2022 14:11:13 +0200 Subject: [PATCH 2/2] FIX Several pb in invoice remind (html detection, no event, transaction) --- htdocs/compta/facture/class/facture.class.php | 85 +++++++++++++++++-- htdocs/core/lib/functions.lib.php | 4 + .../install/mysql/migration/15.0.0-16.0.0.sql | 9 +- test/phpunit/FunctionsLibTest.php | 5 ++ 4 files changed, 91 insertions(+), 12 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 74595267a7c..0742e3d4851 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5451,8 +5451,6 @@ class Facture extends CommonInvoice dol_syslog(__METHOD__, LOG_DEBUG); - $this->db->begin(); - // Select all action comm reminder $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."facture as f"; if (!empty($paymentmode) && $paymentmode != 'all') { @@ -5541,20 +5539,92 @@ class Facture extends CommonInvoice } if (!$error && $to) { + $this->db->begin(); + // Errors Recipient $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO; $trackid = 'inv'.$tmpinvoice->id; + $sendcontext = 'standard'; + // Mail Creation - $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', $trackid, '', '', ''); + $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', $trackid, '', $sendcontext, ''); // Sending Mail if ($cMailFile->sendfile()) { $nbMailSend++; + + // Add a line into event table + require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; + + // Insert record of emails sent + $actioncomm = new ActionComm($this->db); + + $actioncomm->type_code = 'AC_OTH_AUTO'; // Event insert into agenda automatically + $actioncomm->socid = $tmpinvoice->thirdparty->id; // To link to a company + $actioncomm->contact_id = 0; + + $actioncomm->code = 'AC_EMAIL'; + $actioncomm->label = 'sendEmailsRemindersOnInvoiceDueDateOK'; + $actioncomm->note_private = $sendContent; + $actioncomm->fk_project = $tmpinvoice->fk_project; + $actioncomm->datep = dol_now(); + $actioncomm->datef = $actioncomm->datep; + $actioncomm->percentage = -1; // Not applicable + $actioncomm->authorid = $user->id; // User saving action + $actioncomm->userownerid = $user->id; // Owner of action + // Fields when action is an email (content should be added into note) + $actioncomm->email_msgid = $cMailFile->msgid; + $actioncomm->email_from = $from; + $actioncomm->email_sender = ''; + $actioncomm->email_to = $to; + //$actioncomm->email_tocc = $sendtocc; + //$actioncomm->email_tobcc = $sendtobcc; + //$actioncomm->email_subject = $subject; + $actioncomm->errors_to = $errors_to; + + //$actioncomm->extraparams = $extraparams; + + $actioncomm->create($user); } else { $errormesg = $cMailFile->error.' : '.$to; $error++; + + // Add a line into event table + require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; + + // Insert record of emails sent + $actioncomm = new ActionComm($this->db); + + $actioncomm->type_code = 'AC_OTH_AUTO'; // Event insert into agenda automatically + $actioncomm->socid = $tmpinvoice->thirdparty->id; // To link to a company + $actioncomm->contact_id = 0; + + $actioncomm->code = 'AC_EMAIL'; + $actioncomm->label = 'sendEmailsRemindersOnInvoiceDueDateKO'; + $actioncomm->note_private = $errormesg; + $actioncomm->fk_project = $tmpinvoice->fk_project; + $actioncomm->datep = dol_now(); + $actioncomm->datef = $actioncomm->datep; + $actioncomm->percentage = -1; // Not applicable + $actioncomm->authorid = $user->id; // User saving action + $actioncomm->userownerid = $user->id; // Owner of action + // Fields when action is an email (content should be added into note) + $actioncomm->email_msgid = $cMailFile->msgid; + $actioncomm->email_from = $from; + $actioncomm->email_sender = ''; + $actioncomm->email_to = $to; + //$actioncomm->email_tocc = $sendtocc; + //$actioncomm->email_tobcc = $sendtobcc; + //$actioncomm->email_subject = $subject; + $actioncomm->errors_to = $errors_to; + + //$actioncomm->extraparams = $extraparams; + + $actioncomm->create($user); } + + $this->db->commit(); // We always commit } if ($errormesg) { @@ -5572,10 +5642,8 @@ class Facture extends CommonInvoice if (!$error) { $this->output .= 'Nb of emails sent : '.$nbMailSend; - $this->db->commit(); return 0; } else { - $this->db->commit(); // We commit also on error, to have the error message recorded. $this->error = 'Nb of emails sent : '.$nbMailSend.', '.(!empty($errorsMsg)) ? join(', ', $errorsMsg) : $error; return $error; } @@ -5583,8 +5651,9 @@ class Facture extends CommonInvoice /** * See if current invoice date is posterior to the last invoice date among validated invoices of same type. + * * @param boolean $allow_validated_drafts return true if the invoice has been validated before returning to DRAFT state. - * @return boolean + * @return array return array */ public function willBeLastOfSameType($allow_validated_drafts = false) { @@ -5608,10 +5677,10 @@ class Facture extends CommonInvoice $is_last_of_same_type = $is_last_of_same_type || (!strpos($this->ref, 'PROV') && $this->status == self::STATUS_DRAFT); } - return [$is_last_of_same_type, $last_date]; + return array($is_last_of_same_type, $last_date); } else { // element is first of type to be validated - return [true]; + return array(true); } } else { dol_print_error($this->db); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index df4fe39bcfd..6d87116fd6b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7167,6 +7167,8 @@ function dol_textishtml($msg, $option = 0) } return false; } else { + // Remove all urls because 'http://aa?param1=abc&param2=def' must not be used inside detection + $msg = preg_replace('/https?:\/\/[^"\'\s]+/i', '', $msg); if (preg_match('//i', $msg)) { return true; } elseif (preg_match('/&[A-Z0-9]{1,6};/i', $msg)) { + // TODO If content is 'A link https://aaa?param=abc&param2=def', it return true but must be false return true; // Html entities names (http://www.w3schools.com/tags/ref_entities.asp) } elseif (preg_match('/&#[0-9]{2,3};/i', $msg)) { return true; // Html entities numbers (http://www.w3schools.com/tags/ref_entities.asp) @@ -7829,6 +7832,7 @@ function make_substitutions($text, $substitutionarray, $outputlangs = null, $con } else { if (! $msgishtml) { $valueishtml = dol_textishtml($value, 1); + var_dump("valueishtml=".$valueishtml); if ($valueishtml) { $text = dol_htmlentitiesbr($text); diff --git a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql index 286d28ac1a6..c090c55dee7 100644 --- a/htdocs/install/mysql/migration/15.0.0-16.0.0.sql +++ b/htdocs/install/mysql/migration/15.0.0-16.0.0.sql @@ -630,10 +630,11 @@ ALTER TABLE llx_eventorganization_conferenceorboothattendee ADD COLUMN lastname ALTER TABLE llx_eventorganization_conferenceorboothattendee ADD COLUMN email_company varchar(128) after email; -ALTER TABLE llx_c_email_template ADD COLUMN email_from varchar(255); -ALTER TABLE llx_c_email_template ADD COLUMN email_to varchar(255); -ALTER TABLE llx_c_email_template ADD COLUMN email_tocc varchar(255); -ALTER TABLE llx_c_email_template ADD COLUMN email_tobcc varchar(255); +ALTER TABLE llx_c_email_templates ADD COLUMN joinfiles text; +ALTER TABLE llx_c_email_templates ADD COLUMN email_from varchar(255); +ALTER TABLE llx_c_email_templates ADD COLUMN email_to varchar(255); +ALTER TABLE llx_c_email_templates ADD COLUMN email_tocc varchar(255); +ALTER TABLE llx_c_email_templates ADD COLUMN email_tobcc varchar(255); ALTER TABLE llx_fichinter ADD COLUMN ref_client varchar(255) after ref_ext; diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 82205369c86..47de2cbebcc 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -166,6 +166,7 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; } + /** * testNum2Alpha * @@ -535,6 +536,10 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase $input='This is a text with html comments '; // we suppose this is not enough to be html content $after=dol_textishtml($input); $this->assertFalse($after); + + $input="A text\nwith a link https://aaa?param=abc&param2=def"; + $after=dol_textishtml($input); + $this->assertFalse($after); }