Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop
This commit is contained in:
commit
5baee45cbc
4 changed files with 125 additions and 7 deletions
|
|
@ -12,7 +12,7 @@
|
|||
* Copyright (C) 2017 ATM Consulting <support@atm-consulting.fr>
|
||||
* Copyright (C) 2017-2026 Nicolas ZABOURI <info@inovea-conseil.com>
|
||||
* Copyright (C) 2017 Rui Strecht <rui.strecht@aliartalentos.com>
|
||||
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2018 Josep Lluís Amador <joseplluis@lliuretic.cat>
|
||||
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
|
||||
* Copyright (C) 2021 Grégory Blémand <gregory.blemand@atm-consulting.fr>
|
||||
|
|
@ -93,7 +93,13 @@ abstract class CommonObject
|
|||
public $errors = array();
|
||||
|
||||
/**
|
||||
* @var string[] Array of warning strings
|
||||
* @var string Warning string
|
||||
* @see $warnings
|
||||
*/
|
||||
public $warning;
|
||||
|
||||
/**
|
||||
* @var string[] Array of warning strings
|
||||
*/
|
||||
public $warnings = array();
|
||||
|
||||
|
|
|
|||
|
|
@ -2004,11 +2004,87 @@ class FormMail extends Form
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a text for equality checks.
|
||||
* @param string $value Raw text to normalize.
|
||||
* @return string
|
||||
*/
|
||||
private static function normalizeTextForComparison($value)
|
||||
{
|
||||
$value = dol_string_nohtmltag((string) $value);
|
||||
$value = preg_replace('/\s+/', ' ', $value);
|
||||
return trim((string) $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return language prefix from a language code.
|
||||
* @param string $langcode Full language code (for example fr_FR).
|
||||
* @return string
|
||||
*/
|
||||
private static function getLangPrefix($langcode)
|
||||
{
|
||||
$langcode = trim((string) $langcode);
|
||||
if ($langcode === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$prefix = preg_replace('/[_-].*$/', '', $langcode);
|
||||
$prefix = strtolower((string) $prefix);
|
||||
return preg_replace('/[^a-z]/', '', $prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick best translated label/description from product multilangs.
|
||||
*
|
||||
* @param array<string,array{label?:string,description?:string,note?:string,other?:string}>|null $multilangs Product multilang rows indexed by language code.
|
||||
* @param string $langcode Preferred language code.
|
||||
* @return array{label:string,description:string}
|
||||
*/
|
||||
private static function getBestProductTranslation($multilangs, $langcode)
|
||||
{
|
||||
$langcode = trim((string) $langcode);
|
||||
if ($langcode === '' || !is_array($multilangs) || empty($multilangs)) {
|
||||
return array('label' => '', 'description' => '');
|
||||
}
|
||||
|
||||
$prefix = self::getLangPrefix($langcode);
|
||||
$candidates = array($langcode);
|
||||
if ($prefix !== '' && $prefix !== $langcode) {
|
||||
$candidates[] = $prefix;
|
||||
}
|
||||
|
||||
foreach ($candidates as $candidate) {
|
||||
if (empty($multilangs[$candidate]) || !is_array($multilangs[$candidate])) {
|
||||
continue;
|
||||
}
|
||||
$label = trim((string) (isset($multilangs[$candidate]['label']) ? $multilangs[$candidate]['label'] : ''));
|
||||
$description = trim((string) (isset($multilangs[$candidate]['description']) ? $multilangs[$candidate]['description'] : ''));
|
||||
if ($label !== '' || $description !== '') {
|
||||
return array('label' => $label, 'description' => $description);
|
||||
}
|
||||
}
|
||||
|
||||
if ($prefix !== '') {
|
||||
foreach ($multilangs as $code => $row) {
|
||||
if (!is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
if (!(strpos($code, $prefix.'_') === 0 || strpos($code, $prefix.'-') === 0)) {
|
||||
continue;
|
||||
}
|
||||
$label = trim((string) (isset($row['label']) ? $row['label'] : ''));
|
||||
$description = trim((string) (isset($row['description']) ? $row['description'] : ''));
|
||||
if ($label !== '' || $description !== '') {
|
||||
return array('label' => $label, 'description' => $description);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array('label' => '', 'description' => '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ->substit (and ->substit_line) array from object. This is call when suggesting the email template into forms before sending email.
|
||||
*
|
||||
* @param CommonObject $object Object to use
|
||||
* @param Translate $outputlangs Object lang
|
||||
* @return void
|
||||
|
|
@ -2023,6 +2099,10 @@ class FormMail extends Form
|
|||
complete_substitutions_array($tmparray, $outputlangs, null, $parameters);
|
||||
|
||||
$this->substit = $tmparray;
|
||||
$targetLang = '';
|
||||
if (is_object($outputlangs) && !empty($outputlangs->defaultlang)) {
|
||||
$targetLang = trim((string) $outputlangs->defaultlang);
|
||||
}
|
||||
|
||||
// Fill substit_lines with each object lines content
|
||||
if (is_array($object->lines)) {
|
||||
|
|
@ -2050,6 +2130,28 @@ class FormMail extends Form
|
|||
$product->fetch($line->fk_product, '', '', '1');
|
||||
$product->fetch_optionals();
|
||||
|
||||
if (getDolGlobalInt('MAIN_MULTILANGS') && $targetLang !== '' && !empty($product->multilangs) && is_array($product->multilangs)) {
|
||||
$translated = self::getBestProductTranslation($product->multilangs, $targetLang);
|
||||
$translatedLabel = trim((string) (isset($translated['label']) ? $translated['label'] : ''));
|
||||
$translatedDescription = trim((string) (isset($translated['description']) ? $translated['description'] : ''));
|
||||
|
||||
$currentLabelNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_LABEL__']);
|
||||
$currentProductDescriptionNorm = self::normalizeTextForComparison($substit_line['__PRODUCT_DESCRIPTION__']);
|
||||
$currentLineDescriptionNorm = self::normalizeTextForComparison($substit_line['__DESCRIPTION__']);
|
||||
$productLabelNorm = self::normalizeTextForComparison($product->label);
|
||||
$productDescriptionNorm = self::normalizeTextForComparison($product->description);
|
||||
|
||||
if ($translatedLabel !== '' && ($currentLabelNorm === '' || $currentLabelNorm === $productLabelNorm)) {
|
||||
$substit_line['__PRODUCT_LABEL__'] = $translatedLabel;
|
||||
}
|
||||
if ($translatedDescription !== '' && ($currentProductDescriptionNorm === '' || $currentProductDescriptionNorm === $productDescriptionNorm)) {
|
||||
$substit_line['__PRODUCT_DESCRIPTION__'] = $translatedDescription;
|
||||
}
|
||||
if ($translatedDescription !== '' && ($currentLineDescriptionNorm === '' || $currentLineDescriptionNorm === $productDescriptionNorm || $currentLineDescriptionNorm === $currentProductDescriptionNorm)) {
|
||||
$substit_line['__DESCRIPTION__'] = $translatedDescription;
|
||||
}
|
||||
}
|
||||
|
||||
$extrafields->fetch_name_optionals_label($product->table_element, true);
|
||||
|
||||
if (!empty($extrafields->attributes[$product->table_element]['label']) && is_array($extrafields->attributes[$product->table_element]['label']) && count($extrafields->attributes[$product->table_element]['label']) > 0) {
|
||||
|
|
@ -2067,7 +2169,6 @@ class FormMail extends Form
|
|||
/**
|
||||
* Get list of substitution keys available for emails. This is used for tooltips help.
|
||||
* This include the complete_substitutions_array.
|
||||
*
|
||||
* @param string $mode 'formemail', 'formemailwithlines', 'formemailforlines', 'emailing', ...
|
||||
* @param ?Object $object Object if applicable
|
||||
* @return array<string,string> Array of substitution values for emails.
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ if ($action == 'presend') {
|
|||
// Make substitution in email content
|
||||
if (!empty($object)) {
|
||||
// First we set ->substit (useless, it will be erased later) and ->substit_lines
|
||||
$formmail->setSubstitFromObject($object, $langs);
|
||||
$formmail->setSubstitFromObject($object, $outputlangs);
|
||||
}
|
||||
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $arrayoffamiliestoexclude, $object);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
/* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
|
||||
* Copyright (C) 2017-2018 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
|
||||
* Copyright (C) 2025-2026 Frédéric France <frederic.france@free.fr>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -106,13 +106,14 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
|
|||
|
||||
|
||||
if ($action === 'BILL_UNVALIDATE') {
|
||||
/** @var Facture $object */
|
||||
'@phan-var-force Facture $object';
|
||||
if ($object->isEditable() <= 0) {
|
||||
$this->errors[] = 'Modifying this invoice is not allowed';
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** @var Facture|Don|Paiement|PaymentDonation|Subscription|PaymentVarious|CashControl $object */
|
||||
dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);
|
||||
|
||||
|
|
@ -128,6 +129,8 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
|
|||
// If we are here, we are on an action code that will have a control or will generate a record in blockedlog database.
|
||||
|
||||
if ($action === 'PAYMENT_CUSTOMER_CREATE' && $object->element == 'payment') {
|
||||
/** @var Paiement $object */
|
||||
'@phan-var-force Paiement $object';
|
||||
include_once DOL_DOCUMENT_ROOT.'/blockedlog/lib/blockedlog.lib.php';
|
||||
if (isALNERunningVersion() && $mysoc->country_code == 'FR') {
|
||||
if (empty($object->paiementcode) && !empty($object->paiementid)) {
|
||||
|
|
@ -158,6 +161,8 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
|
|||
|
||||
// Protect against modification of data that should be immutable on a validated invoice (memory test only, no database access)
|
||||
if ($action === 'BILL_MODIFY' && !empty($object->oldcopy) && in_array($object->element, array('invoice', 'facture')) && $object->status != 0) {
|
||||
/** @var Facture $object */
|
||||
'@phan-var-force Facture $object';
|
||||
if ($object->oldcopy->ref != $object->ref) {
|
||||
$this->errors[] = 'Modifying the property Ref of a non draft invoice is not allowed';
|
||||
return -2;
|
||||
|
|
@ -196,9 +201,11 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
|
|||
'MEMBER_SUBSCRIPTION_CREATE', 'MEMBER_SUBSCRIPTION_MODIFY', 'MEMBER_SUBSCRIPTION_DELETE',
|
||||
'DON_VALIDATE', 'DON_MODIFY', 'DON_DELETE'))) {
|
||||
/** @var Don|Subscription $object */
|
||||
'@phan-var-force Don|Subscription $object';
|
||||
$amounts = (float) $object->amount;
|
||||
} elseif ($action == 'CASHCONTROL_CLOSE') {
|
||||
/** @var CashControl $object */
|
||||
'@phan-var-force CashControl $object';
|
||||
$amounts = (float) $object->cash + (float) $object->cheque + (float) $object->card;
|
||||
} else {
|
||||
if (property_exists($object, 'total_ht')) {
|
||||
|
|
@ -211,6 +218,8 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
|
|||
}
|
||||
if ($action === 'PAYMENT_CUSTOMER_CREATE' || $action === 'PAYMENT_SUPPLIER_CREATE' || $action === 'DONATION_PAYMENT_CREATE'
|
||||
|| $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') {
|
||||
/** @var Paiement $object */
|
||||
'@phan-var-force Paiement $object';
|
||||
$qualified++;
|
||||
if (!empty($object->amounts)) {
|
||||
foreach ($object->amounts as $amount) {
|
||||
|
|
@ -220,6 +229,8 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers
|
|||
$amounts = $object->amount;
|
||||
}
|
||||
} elseif (strpos($action, 'PAYMENT') !== false && !in_array($action, array('PAYMENT_ADD_TO_BANK'))) {
|
||||
/** @var Paiement $object */
|
||||
'@phan-var-force Paiement $object';
|
||||
$qualified++;
|
||||
$amounts = (float) $object->amount;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue