Merge branch 'erechnung'

This commit is contained in:
OpenXE 2024-12-02 22:11:47 +01:00
commit aa4b34dc44

View File

@ -1339,10 +1339,8 @@ class Rechnung extends GenRechnung
header('Content-Disposition: attachment;filename='.$filename.'.json'); header('Content-Disposition: attachment;filename='.$filename.'.json');
echo(json_encode($result,JSON_PRETTY_PRINT)); echo(json_encode($result,JSON_PRETTY_PRINT));
} else { } else {
$template_id = $this->GetXMLSmartyTemplate($id);
$template = $this->app->DB->Select("SELECT template from smarty_templates WHERE id = '".$adresse[0]['rechnung_smarty_template']."' LIMIT 1"); if(empty($template_id)) {
if(empty($template)) {
header('Content-type:text/xml'); header('Content-type:text/xml');
header('Content-Disposition: attachment;filename='.$filename.'.xml'); header('Content-Disposition: attachment;filename='.$filename.'.xml');
echo('<?xml version="1.0" encoding="utf-8"?> echo('<?xml version="1.0" encoding="utf-8"?>
@ -1350,6 +1348,7 @@ class Rechnung extends GenRechnung
<body>Kein Smarty Template an der Addresse hinterlegt!</body> <body>Kein Smarty Template an der Addresse hinterlegt!</body>
</note>'); </note>');
} else { } else {
$template = $this->app->DB->Select("SELECT template from smarty_templates WHERE id = '$template_id' LIMIT 1");
$smarty = new Smarty; $smarty = new Smarty;
$directory = $this->app->erp->GetTMP().'/smarty/templates'; $directory = $this->app->erp->GetTMP().'/smarty/templates';
$smarty->setCompileDir($directory); $smarty->setCompileDir($directory);
@ -2559,27 +2558,29 @@ class Rechnung extends GenRechnung
$this->app->Tpl->Parse('PAGE','rechnunguebersicht.tpl'); $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) { public function SetXMLRechnung($id) {
$adresse = $this->app->DB->Select("SELECT adresse FROM rechnung WHERE id = '".$id."' LIMIT 1"); $adresse = $this->app->DB->Select("SELECT adresse FROM rechnung WHERE id = '".$id."' LIMIT 1");
if (!empty($adresse)) { if (!empty($adresse)) {
// Check XML Smarty template // Check XML Smarty template
$erechnung = false; if (!empty($this->GetXMLSmartyTemplate($id))) {
$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) {
$this->app->DB->Update("UPDATE rechnung SET erechnung = 1 WHERE id = '".$id."' AND schreibschutz <> 1"); $this->app->DB->Update("UPDATE rechnung SET erechnung = 1 WHERE id = '".$id."' AND schreibschutz <> 1");
} }
} }