Hi,
how to make formula for V7.4.
Espo\Custom\Resources\metadata/app/formula.json
Espo\Custom\FormulaFunctions\Mod97
clear cache. (rebuild)
It's certainly better to make as Yuri do, group.
doc : https://docs.espocrm.com/development...func-interface
how to make formula for V7.4.
Espo\Custom\Resources\metadata/app/formula.json
PHP Code:
{
"functionClassNameMap": {
"mod97": "Espo\\Custom\\FormulaFunctions\\Mod97"
},
"functionList": [
"__APPEND__",
{
"name": "mod97",
"insertText": "mod97(NUMBER, DOFBIRTH)"
}
]
}
PHP Code:
<?php
namespace Espo\Custom\FormulaFunctions;
use Espo\Core\Formula\EvaluatedArgumentList;
use Espo\Core\Formula\Exceptions\TooFewArguments;
use Espo\Core\Formula\Exceptions\BadArgumentValue;
use Espo\Core\Formula\Func;
use Espo\ORM\Entity;
use Espo\ORM\EntityManager;
use Espo\Core\Utils\Log;
class Mod97 implements Func
{
public function __construct( EntityManager $entityManager , Log $log)
{
$this->em = $entityManager;
$this->log = $log;
}
public function process(EvaluatedArgumentList $arguments): string
{
// len 10 + 2
if (count($arguments) < 2) {
throw TooFewArguments::create(2);
}
$number = $arguments[0];
if (strlen($number) != 6){
throw BadArgumentValue::create(1);
}
$digitDofbirth = preg_replace("/[^0-9]/", "", $arguments[1]);
if (strlen($digitDofbirth) != 8){
throw BadArgumentValue::create(2);
}
$val = substr(strrev($digitDofbirth), 0, 4);
$sequence = $number .$val;
$control = $sequence % 97;
$check = ($control < 10) ? "0" .$control : strval($control);
if (intval($check) == 0) {
$check = "97" ;
}
return $sequence .$check;
}
}
It's certainly better to make as Yuri do, group.
doc : https://docs.espocrm.com/development...func-interface