diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index 17657431f9a..991e71e8635 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -711,6 +711,44 @@ class Export $remaintopay = $tmpobjforcomputecall->getRemainToPay(); } $obj->$alias = $remaintopay; + } elseif (is_array($this->array_export_special[$indice][$key]) && + !empty($this->array_export_special[$indice][$key]['rule']) && + $this->array_export_special[$indice][$key]['rule'] == 'compute' + ) { + // Custom compute + $alias = str_replace(array('.', '-', '(', ')'), '_', $key); + $value = ''; + if (!empty($this->array_export_special[$indice][$key]['class']) && + !empty($this->array_export_special[$indice][$key]['classfile']) && + !empty($this->array_export_special[$indice][$key]['method']) + ) { + if (!dol_include_once($this->array_export_special[$indice][$key]['classfile'])) { + $this->error = "Computed field bad configuration: {$this->array_export_special[$indice][$key]['classfile']} not found"; + return -1; + } + + if (!class_exists($this->array_export_special[$indice][$key]['class'])) { + $this->error = "Computed field bad configuration: {$this->array_export_special[$indice][$key]['class']} class doesn't exist"; + return -1; + } + + $className = $this->array_export_special[$indice][$key]['class']; + $tmpObject = new $className($this->db); + if (!method_exists($tmpObject, $this->array_export_special[$indice][$key]['method'])) { + $this->error = "Computed field bad configuration: {$this->array_export_special[$indice][$key]['method']} method doesn't exist"; + return -1; + } + + $methodName = $this->array_export_special[$indice][$key]['method']; + $params = []; + if (!empty($this->array_export_special[$indice][$key]['method_params'])) { + foreach ($this->array_export_special[$indice][$key]['method_params'] as $paramName) { + $params[] = $obj->$paramName ?? null; + } + } + $value = $tmpObject->$methodName(...$params); + } + $obj->$alias = $value; } else { // TODO FIXME // Export of compute field does not work. $obj contains $obj->alias_field and formula may contains $obj->field