From d7673084cffc3c5fdb5f4870a33948f6272996f0 Mon Sep 17 00:00:00 2001 From: Jyhere Date: Thu, 25 May 2023 16:53:26 +0200 Subject: [PATCH] ADD: custom compute for exports --- htdocs/exports/class/export.class.php | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index 6563e9d6338..b257269a616 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -706,6 +706,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