some big beautfiul update
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\FieldValidators\WorkingTimeRange\Calendars;
|
||||
|
||||
use Espo\Core\FieldValidation\Validator;
|
||||
use Espo\Core\FieldValidation\Validator\Data;
|
||||
use Espo\Core\FieldValidation\Validator\Failure;
|
||||
use Espo\Entities\WorkingTimeRange;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements Validator<WorkingTimeRange>
|
||||
*/
|
||||
class OnlyIfNoUsers implements Validator
|
||||
{
|
||||
public function validate(Entity $entity, string $field, Data $data): ?Failure
|
||||
{
|
||||
if ($entity->getCalendars()->getCount() === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($entity->getUsers()->getCount() === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Failure::create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\FieldValidators\WorkingTimeRange\Calendars;
|
||||
|
||||
use Espo\Core\FieldValidation\Validator;
|
||||
use Espo\Core\FieldValidation\Validator\Data;
|
||||
use Espo\Core\FieldValidation\Validator\Failure;
|
||||
use Espo\Entities\WorkingTimeRange;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements Validator<WorkingTimeRange>
|
||||
*/
|
||||
class RequiredIfNoUsers implements Validator
|
||||
{
|
||||
|
||||
public function validate(Entity $entity, string $field, Data $data): ?Failure
|
||||
{
|
||||
if ($entity->getCalendars()->getCount() !== 0 || $entity->getUsers()->getCount() !== 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Failure::create();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Classes\FieldValidators\WorkingTimeRange\Users;
|
||||
|
||||
use Espo\Core\FieldValidation\Validator;
|
||||
use Espo\Core\FieldValidation\Validator\Data;
|
||||
use Espo\Core\FieldValidation\Validator\Failure;
|
||||
use Espo\Entities\WorkingTimeRange;
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @implements Validator<WorkingTimeRange>
|
||||
*/
|
||||
class OnlyIfNoCalendars implements Validator
|
||||
{
|
||||
public function validate(Entity $entity, string $field, Data $data): ?Failure
|
||||
{
|
||||
if ($entity->getUsers()->getCount() === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($entity->getCalendars()->getCount() === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Failure::create();
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ use DivisionByZeroError;
|
||||
|
||||
class CalculatorUtil
|
||||
{
|
||||
private const SCALE = 14;
|
||||
private const int SCALE = 14;
|
||||
|
||||
/**
|
||||
* @param numeric-string $arg1
|
||||
@@ -43,16 +43,10 @@ class CalculatorUtil
|
||||
public static function add(string $arg1, string $arg2): string
|
||||
{
|
||||
if (!function_exists('bcadd')) {
|
||||
return (string) (
|
||||
(float) $arg1 + (float) $arg2
|
||||
);
|
||||
return self::floatToString((float) $arg1 + (float) $arg2);
|
||||
}
|
||||
|
||||
return bcadd(
|
||||
$arg1,
|
||||
$arg2,
|
||||
self::SCALE
|
||||
);
|
||||
return bcadd($arg1, $arg2, self::SCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,56 +57,42 @@ class CalculatorUtil
|
||||
public static function subtract(string $arg1, string $arg2): string
|
||||
{
|
||||
if (!function_exists('bcsub')) {
|
||||
return (string) (
|
||||
(float) $arg1 - (float) $arg2
|
||||
);
|
||||
return self::floatToString((float) $arg1 - (float) $arg2);
|
||||
}
|
||||
|
||||
return bcsub(
|
||||
$arg1,
|
||||
$arg2,
|
||||
self::SCALE
|
||||
);
|
||||
return bcsub($arg1, $arg2, self::SCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numeric-string $arg1
|
||||
* @param numeric-string $arg2
|
||||
* @return numeric-string
|
||||
*
|
||||
* @todo For the result, trim right zeros. Then, trim dot.
|
||||
*/
|
||||
public static function multiply(string $arg1, string $arg2): string
|
||||
{
|
||||
if (!function_exists('bcmul')) {
|
||||
return (string) (
|
||||
(float) $arg1 * (float) $arg2
|
||||
);
|
||||
return self::floatToString((float) $arg1 * (float) $arg2);
|
||||
}
|
||||
|
||||
return bcmul(
|
||||
$arg1,
|
||||
$arg2,
|
||||
self::SCALE
|
||||
);
|
||||
return bcmul($arg1, $arg2, self::SCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numeric-string $arg1
|
||||
* @param numeric-string $arg2
|
||||
* @return numeric-string
|
||||
*
|
||||
* @todo For the result, trim right zeros. Then, trim dot.
|
||||
*/
|
||||
public static function divide(string $arg1, string $arg2): string
|
||||
{
|
||||
if (!function_exists('bcdiv')) {
|
||||
return (string) (
|
||||
(float) $arg1 / (float) $arg2
|
||||
);
|
||||
return self::floatToString((float) $arg1 / (float) $arg2);
|
||||
}
|
||||
|
||||
$result = bcdiv(
|
||||
$arg1,
|
||||
$arg2,
|
||||
self::SCALE
|
||||
);
|
||||
$result = bcdiv($arg1, $arg2, self::SCALE);
|
||||
|
||||
if ($result === null) { /** @phpstan-ignore-line */
|
||||
throw new DivisionByZeroError();
|
||||
@@ -128,7 +108,9 @@ class CalculatorUtil
|
||||
public static function round(string $arg, int $precision = 0): string
|
||||
{
|
||||
if (!function_exists('bcadd')) {
|
||||
return (string) round((float) $arg, $precision);
|
||||
return self::floatToString(
|
||||
round((float) $arg, $precision)
|
||||
);
|
||||
}
|
||||
|
||||
$addition = '0.' . str_repeat('0', $precision) . '5';
|
||||
@@ -139,11 +121,7 @@ class CalculatorUtil
|
||||
|
||||
assert(is_numeric($addition));
|
||||
|
||||
return bcadd(
|
||||
$arg,
|
||||
$addition,
|
||||
$precision
|
||||
);
|
||||
return bcadd($arg, $addition, $precision);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,10 +134,15 @@ class CalculatorUtil
|
||||
return (float) $arg1 <=> (float) $arg2;
|
||||
}
|
||||
|
||||
return bccomp(
|
||||
$arg1,
|
||||
$arg2,
|
||||
self::SCALE
|
||||
);
|
||||
return bccomp($arg1, $arg2, self::SCALE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return numeric-string
|
||||
*/
|
||||
private static function floatToString(float $amount): string
|
||||
{
|
||||
/** @var numeric-string */
|
||||
return rtrim(rtrim(sprintf('%.' . self::SCALE . 'f', $amount), '0'), '.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ use InvalidArgumentException;
|
||||
*/
|
||||
class Currency
|
||||
{
|
||||
private const int DEFAULT_SCALE = 14;
|
||||
|
||||
/** @var numeric-string */
|
||||
private string $amount;
|
||||
private string $code;
|
||||
@@ -57,8 +59,10 @@ class Currency
|
||||
throw new InvalidArgumentException("Bad currency code.");
|
||||
}
|
||||
|
||||
if (is_float($amount) || is_int($amount)) {
|
||||
if (is_int($amount)) {
|
||||
$amount = (string) $amount;
|
||||
} else if (is_float($amount)) {
|
||||
$amount = self::floatToString($amount);
|
||||
}
|
||||
|
||||
$this->amount = $amount;
|
||||
@@ -136,10 +140,9 @@ class Currency
|
||||
*/
|
||||
public function multiply(float|int|string $multiplier): self
|
||||
{
|
||||
$amount = CalculatorUtil::multiply(
|
||||
$this->getAmountAsString(),
|
||||
(string) $multiplier
|
||||
);
|
||||
$multiplier = is_float($multiplier) ? self::floatToString($multiplier) : (string) $multiplier;
|
||||
|
||||
$amount = CalculatorUtil::multiply($this->getAmountAsString(), $multiplier);
|
||||
|
||||
return new self($amount, $this->getCode());
|
||||
}
|
||||
@@ -151,10 +154,9 @@ class Currency
|
||||
*/
|
||||
public function divide(float|int|string $divider): self
|
||||
{
|
||||
$amount = CalculatorUtil::divide(
|
||||
$this->getAmountAsString(),
|
||||
(string) $divider
|
||||
);
|
||||
$divider = is_float($divider) ? self::floatToString($divider) : (string) $divider;
|
||||
|
||||
$amount = CalculatorUtil::divide($this->getAmountAsString(), $divider);
|
||||
|
||||
return new self($amount, $this->getCode());
|
||||
}
|
||||
@@ -208,4 +210,13 @@ class Currency
|
||||
{
|
||||
return new self($amount, $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return numeric-string
|
||||
*/
|
||||
private static function floatToString(float $amount): string
|
||||
{
|
||||
/** @var numeric-string */
|
||||
return rtrim(rtrim(sprintf('%.' . self::DEFAULT_SCALE . 'f', $amount), '0'), '.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,11 @@ class ListLoader implements LoaderInterface
|
||||
foreach ($this->getFieldList($entityType) as $field) {
|
||||
if (
|
||||
!in_array($field . 'Ids', $select) &&
|
||||
!in_array($field . 'Names', $select)
|
||||
!in_array($field . 'Names', $select) &&
|
||||
(
|
||||
!$entity->hasAttribute($field . 'Columns') ||
|
||||
!in_array($field . 'Columns', $select)
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ use Espo\ORM\Repository\Option\RelateOptions;
|
||||
* An afterRelate hook.
|
||||
*
|
||||
* @template TEntity of Entity = Entity
|
||||
* @template TRelatedEntity of Entity = Entity
|
||||
*/
|
||||
interface AfterRelate
|
||||
{
|
||||
@@ -45,7 +44,6 @@ interface AfterRelate
|
||||
*
|
||||
* @param TEntity $entity An entity.
|
||||
* @param string $relationName A relation name.
|
||||
* @param TRelatedEntity $relatedEntity An entity is being related.
|
||||
* @param array<string, mixed> $columnData Middle table role values.
|
||||
* @param RelateOptions $options Options.
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,6 @@ use Espo\ORM\Repository\Option\UnrelateOptions;
|
||||
* An afterUnrelate hook.
|
||||
*
|
||||
* @template TEntity of Entity = Entity
|
||||
* @template TRelatedEntity of Entity = Entity
|
||||
*/
|
||||
interface AfterUnrelate
|
||||
{
|
||||
@@ -45,7 +44,6 @@ interface AfterUnrelate
|
||||
*
|
||||
* @param TEntity $entity An entity.
|
||||
* @param string $relationName A relation name.
|
||||
* @param TRelatedEntity $relatedEntity An entity is being unrelated.
|
||||
* @param UnrelateOptions $options Options.
|
||||
*/
|
||||
public function afterUnrelate(
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM – Open Source CRM application.
|
||||
* Copyright (C) 2014-2026 EspoCRM, Inc.
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\ORM\QueryComposer\Part\FunctionConverters;
|
||||
|
||||
use Espo\Core\Currency\ConfigDataProvider;
|
||||
use Espo\ORM\Query\Part\Expression;
|
||||
use Espo\ORM\QueryComposer\Part\FunctionConverter;
|
||||
use Espo\ORM\QueryComposer\Util;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class CurrencyRate implements FunctionConverter
|
||||
{
|
||||
private const int PRECISION = 5;
|
||||
|
||||
public function __construct(
|
||||
private ConfigDataProvider $config,
|
||||
) {}
|
||||
|
||||
public function convert(string ...$argumentList): string
|
||||
{
|
||||
$arg = $argumentList[0] ?? null;
|
||||
|
||||
if (!is_string($arg) || !Util::isArgumentString($arg)) {
|
||||
throw new RuntimeException("CURRENCY_RATE function accepts only literal string argument.");
|
||||
}
|
||||
|
||||
$code = substr($arg, 1, -1);
|
||||
|
||||
if (!in_array($code, $this->config->getCurrencyList())) {
|
||||
return Expression::value(0)->getValue();
|
||||
}
|
||||
|
||||
$baseCurrency = $this->config->getBaseCurrency();
|
||||
$defaultCurrency = $this->config->getDefaultCurrency();
|
||||
|
||||
$rates = $this->config->getCurrencyRates()->toAssoc();
|
||||
|
||||
if ($defaultCurrency !== $baseCurrency) {
|
||||
$rates = $this->exchangeRates($baseCurrency, $defaultCurrency, $rates);
|
||||
}
|
||||
|
||||
$rate = $rates[$code] ?? 1.0;
|
||||
|
||||
return Expression::value($rate)->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, float> $currencyRates
|
||||
* @return array<string, float>
|
||||
*/
|
||||
private function exchangeRates(string $baseCurrency, string $defaultCurrency, array $currencyRates): array
|
||||
{
|
||||
$defaultCurrencyRate = round(1 / $currencyRates[$defaultCurrency], self::PRECISION);
|
||||
|
||||
$exchangedRates = [];
|
||||
$exchangedRates[$baseCurrency] = $defaultCurrencyRate;
|
||||
|
||||
unset($currencyRates[$baseCurrency], $currencyRates[$defaultCurrency]);
|
||||
|
||||
foreach ($currencyRates as $code => $rate) {
|
||||
$exchangedRates[$code] = round($rate * $defaultCurrencyRate, self::PRECISION);
|
||||
}
|
||||
|
||||
return $exchangedRates;
|
||||
}
|
||||
}
|
||||
@@ -124,12 +124,8 @@ class Currency implements FieldConverter
|
||||
$currencyAttribute = $name . 'Currency';
|
||||
|
||||
$defaultCurrency = $this->configDataProvider->getDefaultCurrency();
|
||||
$baseCurrency = $this->configDataProvider->getBaseCurrency();
|
||||
$rates = $this->configDataProvider->getCurrencyRates()->toAssoc();
|
||||
|
||||
if ($defaultCurrency !== $baseCurrency) {
|
||||
$rates = $this->exchangeRates($baseCurrency, $defaultCurrency, $rates);
|
||||
}
|
||||
$rates = $this->configDataProvider->getCurrencyList();
|
||||
|
||||
$expr = Expr::multiply(
|
||||
Expr::column($name),
|
||||
@@ -216,28 +212,7 @@ class Currency implements FieldConverter
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, float> $currencyRates
|
||||
* @return array<string, float>
|
||||
*/
|
||||
private function exchangeRates(string $baseCurrency, string $defaultCurrency, array $currencyRates): array
|
||||
{
|
||||
$precision = 5;
|
||||
$defaultCurrencyRate = round(1 / $currencyRates[$defaultCurrency], $precision);
|
||||
|
||||
$exchangedRates = [];
|
||||
$exchangedRates[$baseCurrency] = $defaultCurrencyRate;
|
||||
|
||||
unset($currencyRates[$baseCurrency], $currencyRates[$defaultCurrency]);
|
||||
|
||||
foreach ($currencyRates as $currencyName => $rate) {
|
||||
$exchangedRates[$currencyName] = round($rate * $defaultCurrencyRate, $precision);
|
||||
}
|
||||
|
||||
return $exchangedRates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, float> $rates
|
||||
* @param string[] $rates
|
||||
*/
|
||||
private function buildExpression(string $currencyAttribute, array $rates): Expr|float
|
||||
{
|
||||
@@ -245,13 +220,11 @@ class Currency implements FieldConverter
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$currency = array_key_first($rates);
|
||||
$value = $rates[$currency];
|
||||
unset($rates[$currency]);
|
||||
$currency = array_shift($rates);
|
||||
|
||||
return Expr::if(
|
||||
Expr::equal(Expr::column($currencyAttribute), $currency),
|
||||
$value,
|
||||
Expr::create("CURRENCY_RATE:('$currency')"),
|
||||
$this->buildExpression($currencyAttribute, $rates)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,4 +128,13 @@ class WorkingTimeRange extends Entity
|
||||
/** @var LinkMultiple */
|
||||
return $this->getValueObject('users');
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 9.3.1
|
||||
*/
|
||||
public function getCalendars(): LinkMultiple
|
||||
{
|
||||
/** @var LinkMultiple */
|
||||
return $this->getValueObject('calendars');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,8 +267,12 @@ class Image implements EntryPoint
|
||||
}
|
||||
}
|
||||
|
||||
if ($targetWidth < 1 || $targetHeight < 1) {
|
||||
throw new RuntimeException("No width or height.");
|
||||
if ($targetWidth < 1) {
|
||||
$targetWidth = 1;
|
||||
}
|
||||
|
||||
if ($targetHeight < 1) {
|
||||
$targetHeight = 1;
|
||||
}
|
||||
|
||||
$targetImage = imagecreatetruecolor($targetWidth, $targetHeight);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"labels": {
|
||||
"Create ApiUser": "Create API User"
|
||||
"Create ApiUser": "Create API User",
|
||||
"OpenAPI spec": "OpenAPI spec"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,13 @@
|
||||
{"name": "timeRanges"},
|
||||
false
|
||||
],
|
||||
[
|
||||
{"name": "users"},
|
||||
false
|
||||
],
|
||||
[
|
||||
{"name": "calendars"},
|
||||
{"name": "users"}
|
||||
false
|
||||
],
|
||||
[
|
||||
{"name": "description"}
|
||||
|
||||
@@ -13,9 +13,13 @@
|
||||
{"name": "timeRanges"},
|
||||
false
|
||||
],
|
||||
[
|
||||
{"name": "users"},
|
||||
false
|
||||
],
|
||||
[
|
||||
{"name": "calendars"},
|
||||
{"name": "users"}
|
||||
false
|
||||
],
|
||||
[
|
||||
{"name": "description"}
|
||||
|
||||
@@ -4,14 +4,16 @@
|
||||
"queryComposerClassName": "Espo\\ORM\\QueryComposer\\MysqlQueryComposer",
|
||||
"pdoFactoryClassName": "Espo\\ORM\\PDO\\MysqlPDOFactory",
|
||||
"functionConverterClassNameMap": {
|
||||
"ABS": "Espo\\Core\\ORM\\QueryComposer\\Part\\FunctionConverters\\Abs"
|
||||
"ABS": "Espo\\Core\\ORM\\QueryComposer\\Part\\FunctionConverters\\Abs",
|
||||
"CURRENCY_RATE": "Espo\\Core\\ORM\\QueryComposer\\Part\\FunctionConverters\\CurrencyRate"
|
||||
}
|
||||
},
|
||||
"Postgresql": {
|
||||
"queryComposerClassName": "Espo\\ORM\\QueryComposer\\PostgresqlQueryComposer",
|
||||
"pdoFactoryClassName": "Espo\\ORM\\PDO\\PostgresqlPDOFactory",
|
||||
"functionConverterClassNameMap": {
|
||||
"ABS": "Espo\\Core\\ORM\\QueryComposer\\Part\\FunctionConverters\\Abs"
|
||||
"ABS": "Espo\\Core\\ORM\\QueryComposer\\Part\\FunctionConverters\\Abs",
|
||||
"CURRENCY_RATE": "Espo\\Core\\ORM\\QueryComposer\\Part\\FunctionConverters\\CurrencyRate"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,5 +30,18 @@
|
||||
},
|
||||
"filterList": [
|
||||
],
|
||||
"boolFilterList": []
|
||||
}
|
||||
"boolFilterList": [],
|
||||
"menu": {
|
||||
"list": {
|
||||
"dropdown": [
|
||||
{
|
||||
"name": "openApiSpec",
|
||||
"label": "OpenAPI spec",
|
||||
"link": "api/v1/OpenApi",
|
||||
"handler": "handlers/api-user/open-api-spec-action",
|
||||
"actionFunction": "process"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
"type": "decimal",
|
||||
"decimalPlaces": 6,
|
||||
"min": 0.0001,
|
||||
"precision": 15,
|
||||
"precision": 20,
|
||||
"scale": 8,
|
||||
"required": true,
|
||||
"audited": true,
|
||||
|
||||
@@ -119,7 +119,8 @@
|
||||
},
|
||||
"fontFace": {
|
||||
"type": "enum",
|
||||
"view": "views/template/fields/font-face"
|
||||
"view": "views/template/fields/font-face",
|
||||
"isSorted": true
|
||||
},
|
||||
"title": {
|
||||
"type": "varchar"
|
||||
|
||||
@@ -34,12 +34,20 @@
|
||||
},
|
||||
"calendars": {
|
||||
"type": "linkMultiple",
|
||||
"tooltip": true
|
||||
"tooltip": true,
|
||||
"validatorClassNameList": [
|
||||
"Espo\\Classes\\FieldValidators\\WorkingTimeRange\\Calendars\\OnlyIfNoUsers",
|
||||
"Espo\\Classes\\FieldValidators\\WorkingTimeRange\\Calendars\\RequiredIfNoUsers"
|
||||
],
|
||||
"autocompleteOnEmpty": true
|
||||
},
|
||||
"users": {
|
||||
"type": "linkMultiple",
|
||||
"view": "views/working-time-range/fields/users",
|
||||
"tooltip": true
|
||||
"tooltip": true,
|
||||
"validatorClassNameList": [
|
||||
"Espo\\Classes\\FieldValidators\\WorkingTimeRange\\Users\\OnlyIfNoCalendars"
|
||||
]
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "datetime",
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"users": {
|
||||
"calendars": {
|
||||
"visible": {
|
||||
"conditionGroup": [
|
||||
{
|
||||
@@ -19,8 +19,36 @@
|
||||
"value": [
|
||||
{
|
||||
"type": "isNotEmpty",
|
||||
"attribute": "id"
|
||||
"attribute": "calendarsIds"
|
||||
},
|
||||
{
|
||||
"type": "isEmpty",
|
||||
"attribute": "usersIds"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"users": {
|
||||
"required": {
|
||||
"conditionGroup": [
|
||||
{
|
||||
"type": "or",
|
||||
"value": [
|
||||
{
|
||||
"type": "isEmpty",
|
||||
"attribute": "calendarsIds"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"visible": {
|
||||
"conditionGroup": [
|
||||
{
|
||||
"type": "or",
|
||||
"value": [
|
||||
{
|
||||
"type": "isNotEmpty",
|
||||
"attribute": "usersIds"
|
||||
|
||||
@@ -724,6 +724,7 @@ class EntityManager
|
||||
'collection.order',
|
||||
'collection.textFilterFields',
|
||||
'collection.fullTextSearch',
|
||||
'collection.countDisabled',
|
||||
]);
|
||||
|
||||
foreach ($this->getAdditionalParamLocationMap($name) as $it) {
|
||||
|
||||
@@ -84,6 +84,7 @@ class Service
|
||||
|
||||
$this->entityManager->saveEntity($entity);
|
||||
|
||||
$service->loadAdditionalFields($entity);
|
||||
$service->prepareEntityForOutput($entity);
|
||||
|
||||
return $entity;
|
||||
@@ -108,6 +109,7 @@ class Service
|
||||
|
||||
$this->entityManager->saveEntity($entity);
|
||||
|
||||
$service->loadAdditionalFields($entity);
|
||||
$service->prepareEntityForOutput($entity);
|
||||
|
||||
return $entity;
|
||||
|
||||
@@ -472,12 +472,15 @@ class RecordService
|
||||
|
||||
private function prepareSetFields(Notification $entity): void
|
||||
{
|
||||
if ($entity->getRelated() && $entity->getData()?->relatedName) {
|
||||
$entity->set('relatedName', $entity->getData()->relatedName);
|
||||
$relatedName = $entity->getData()->relatedName ?? null;
|
||||
$createdByName = $entity->getData()->createdByName ?? null;
|
||||
|
||||
if ($entity->getRelated() && $relatedName !== null) {
|
||||
$entity->set('relatedName', $relatedName);
|
||||
}
|
||||
|
||||
if ($entity->getCreatedBy() && $entity->getData()?->createdByName) {
|
||||
$entity->set('createdByName', $entity->getData()->createdByName);
|
||||
if ($entity->getCreatedBy() && $createdByName !== null) {
|
||||
$entity->set('createdByName', $createdByName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,33 +30,61 @@
|
||||
namespace Espo\Tools\Pdf\Dompdf;
|
||||
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\FontMetrics;
|
||||
use Dompdf\Options;
|
||||
use Espo\Core\Utils\Config;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Tools\Pdf\Params;
|
||||
use Espo\Tools\Pdf\Template;
|
||||
|
||||
class DompdfInitializer
|
||||
{
|
||||
private string $defaultFontFace = 'DejaVu Sans';
|
||||
private string $cacheDir = 'data/cache/application/dompdf';
|
||||
private string $pdfaCacheDir = 'data/cache/application/pdfa-dompdf';
|
||||
|
||||
private const PT = 2.83465;
|
||||
|
||||
/** @var array<string, string> */
|
||||
private array $standardFontMapping = [
|
||||
'courier' => 'DejaVu Sans Mono',
|
||||
'fixed' => 'DejaVu Sans Mono',
|
||||
'helvetica' => 'DejaVu Sans',
|
||||
'monospace' => 'DejaVu Sans Mono',
|
||||
'sans-serif' => 'DejaVu Sans',
|
||||
'serif' => 'DejaVu Serif',
|
||||
'times' => 'DejaVu Serif',
|
||||
'times-roman' => 'DejaVu Serif',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private Config $config,
|
||||
private Metadata $metadata,
|
||||
private FileManager $fileManager,
|
||||
) {}
|
||||
|
||||
public function initialize(Template $template, Params $params): Dompdf
|
||||
{
|
||||
$options = new Options();
|
||||
|
||||
$options->setIsPdfAEnabled($params->isPdfA());
|
||||
$options->setDefaultFont($this->getFontFace($template));
|
||||
$options
|
||||
->setIsPdfAEnabled($params->isPdfA())
|
||||
->setDefaultFont($this->getFontFace($template))
|
||||
->setIsJavascriptEnabled(false);
|
||||
|
||||
$dir = $params->isPdfA() ? $this->pdfaCacheDir : $this->cacheDir;
|
||||
|
||||
$options->setFontDir($dir);
|
||||
$options->setFontCache($dir);
|
||||
|
||||
if (!$this->fileManager->isDir($dir)) {
|
||||
$this->fileManager->mkdir($dir);
|
||||
}
|
||||
|
||||
$pdf = new Dompdf($options);
|
||||
|
||||
if ($params->isPdfA()) {
|
||||
$this->mapFonts($pdf);
|
||||
}
|
||||
$this->mapFonts($pdf, $params->isPdfA(), $dir);
|
||||
|
||||
$size = $template->getPageFormat() === Template::PAGE_FORMAT_CUSTOM ?
|
||||
[0.0, 0.0, $template->getPageWidth() * self::PT, $template->getPageHeight() * self::PT] :
|
||||
@@ -79,18 +107,36 @@ class DompdfInitializer
|
||||
$this->defaultFontFace;
|
||||
}
|
||||
|
||||
private function mapFonts(Dompdf $pdf): void
|
||||
private function mapFonts(Dompdf $pdf, bool $isPdfA, string $dir): void
|
||||
{
|
||||
// Fonts are included in PDF/A. Map standard fonts to open source analogues.
|
||||
$file = $dir . '/' . FontMetrics::USER_FONTS_FILE;
|
||||
|
||||
if ($this->fileManager->exists($file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// When fonts are included in PDF/A, we need to map standard fonts to open source analogues.
|
||||
// Also need to support popular fonts specified in CSS styles.
|
||||
$fontMetrics = $pdf->getFontMetrics();
|
||||
|
||||
$fontMetrics->setFontFamily('courier', $fontMetrics->getFamily('DejaVu Sans Mono'));
|
||||
$fontMetrics->setFontFamily('fixed', $fontMetrics->getFamily('DejaVu Sans Mono'));
|
||||
$fontMetrics->setFontFamily('helvetica', $fontMetrics->getFamily('DejaVu Sans'));
|
||||
$fontMetrics->setFontFamily('monospace', $fontMetrics->getFamily('DejaVu Sans Mono'));
|
||||
$fontMetrics->setFontFamily('sans-serif', $fontMetrics->getFamily('DejaVu Sans'));
|
||||
$fontMetrics->setFontFamily('serif', $fontMetrics->getFamily('DejaVu Serif'));
|
||||
$fontMetrics->setFontFamily('times', $fontMetrics->getFamily('DejaVu Serif'));
|
||||
$fontMetrics->setFontFamily('times-roman', $fontMetrics->getFamily('DejaVu Serif'));
|
||||
if ($isPdfA) {
|
||||
foreach ($this->standardFontMapping as $key => $value) {
|
||||
$fontMetrics->setFontFamily($key, $fontMetrics->getFamily($value));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var string[] $fontList */
|
||||
$fontList = $this->metadata->get('app.pdfEngines.Dompdf.fontFaceList') ?? [];
|
||||
$fontList = array_map(fn ($it) => strtolower($it), $fontList);
|
||||
|
||||
foreach ($this->standardFontMapping as $key => $value) {
|
||||
if (in_array(strtolower($key), $fontList)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$fontMetrics->setFontFamily($key, $fontMetrics->getFamily($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user