From d4c5c67b05159ca82966733b66947ee591275af9 Mon Sep 17 00:00:00 2001 From: OpenXE <> Date: Mon, 2 Dec 2024 22:11:29 +0100 Subject: [PATCH] Decide if XML Smarty invoice according to address and group --- www/pages/rechnung.php | 43 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/www/pages/rechnung.php b/www/pages/rechnung.php index 3a3aafc5..c6cfbabd 100644 --- a/www/pages/rechnung.php +++ b/www/pages/rechnung.php @@ -1339,10 +1339,8 @@ class Rechnung extends GenRechnung header('Content-Disposition: attachment;filename='.$filename.'.json'); echo(json_encode($result,JSON_PRETTY_PRINT)); } else { - - $template = $this->app->DB->Select("SELECT template from smarty_templates WHERE id = '".$adresse[0]['rechnung_smarty_template']."' LIMIT 1"); - - if(empty($template)) { + $template_id = $this->GetXMLSmartyTemplate($id); + if(empty($template_id)) { header('Content-type:text/xml'); header('Content-Disposition: attachment;filename='.$filename.'.xml'); echo(' @@ -1350,6 +1348,7 @@ class Rechnung extends GenRechnung Kein Smarty Template an der Addresse hinterlegt! '); } else { + $template = $this->app->DB->Select("SELECT template from smarty_templates WHERE id = '$template_id' LIMIT 1"); $smarty = new Smarty; $directory = $this->app->erp->GetTMP().'/smarty/templates'; $smarty->setCompileDir($directory); @@ -2559,27 +2558,29 @@ class Rechnung extends GenRechnung $this->app->Tpl->Parse('PAGE','rechnunguebersicht.tpl'); } - // Decide if XML Smarty invoice according to address + public function GetXMLSmartyTemplate($id) { + $adresse = $this->app->DB->Select("SELECT adresse FROM rechnung WHERE id = '".$id."'"); + $rechnung_smarty_template = $this->app->DB->Select("SELECT rechnung_smarty_template FROM adresse WHERE id = '".$adresse."'"); + if (!empty($rechnung_smarty_template)) { + return($rechnung_smarty_template); + } else { + $sql = "SELECT id, rechnung_smarty_template FROM gruppen WHERE rechnung_smarty_template <> '' and aktiv"; + $gruppen = $this->app->DB->SelectArr($sql); + foreach ($gruppen as $gruppe) { + if ($this->app->erp->IsAdresseInGruppe($adresse,$gruppe['id'])) { + return($gruppe['rechnung_smarty_template']); + } + } + } + return(null); + } + + // Decide if XML Smarty invoice according to address and group public function SetXMLRechnung($id) { $adresse = $this->app->DB->Select("SELECT adresse FROM rechnung WHERE id = '".$id."' LIMIT 1"); if (!empty($adresse)) { // Check XML Smarty template - $erechnung = false; - $sql = "SELECT rechnung_smarty_template FROM adresse WHERE id = '".$adresse."'"; - $rechnung_smarty_template = $this->app->DB->Select($sql); - - if (!empty($rechnung_smarty_template)) { - $erechnung = true; - } else { - $sql = "SELECT id FROM gruppen WHERE rechnung_smarty_template <> '' and aktiv"; - $gruppen = $this->app->DB->SelectArr($sql); - foreach ($gruppen as $gruppe) { - if ($this->app->erp->IsAdresseInGruppe($adresse,$gruppe['id'])) { - $erechnung = true; - } - } - } - if ($erechnung) { + if (!empty($this->GetXMLSmartyTemplate($id))) { $this->app->DB->Update("UPDATE rechnung SET erechnung = 1 WHERE id = '".$id."' AND schreibschutz <> 1"); } }