bugfix exportbuchhaltung date of differences

This commit is contained in:
OpenXE 2023-05-24 10:35:56 +02:00
parent 88e1e2ebc2
commit 5ca3a7297b

View File

@ -76,14 +76,14 @@ class Exportbuchhaltung
$rgchecked = $this->app->Secure->GetPOST("rechnung"); $rgchecked = $this->app->Secure->GetPOST("rechnung");
$gschecked = $this->app->Secure->GetPOST("gutschrift"); $gschecked = $this->app->Secure->GetPOST("gutschrift");
$vbchecked = $this->app->Secure->GetPOST("verbindlichkeit"); $vbchecked = $this->app->Secure->GetPOST("verbindlichkeit");
$diffignore = $this->app->Secure->GetPOST("diffignore"); $diffignore = $this->app->Secure->GetPOST("diffignore");
$sachkonto = $this->app->Secure->GetPOST('sachkonto'); $sachkonto = $this->app->Secure->GetPOST('sachkonto');
$account_id = null; $account_id = null;
if (!empty($sachkonto)) { if (!empty($sachkonto)) {
$sachkonto_kennung = explode(' ',$sachkonto)[0]; $sachkonto_kennung = explode(' ',$sachkonto)[0];
$account_id = $this->app->DB->SelectArr("SELECT id from kontorahmen WHERE sachkonto = '".$sachkonto_kennung."'")[0]['id']; $account_id = $this->app->DB->SelectArr("SELECT id from kontorahmen WHERE sachkonto = '".$sachkonto_kennung."'")[0]['id'];
} }
$msg = ""; $msg = "";
@ -190,19 +190,19 @@ class Exportbuchhaltung
$this->app->erp->MenuEintrag("index.php?module=importvorlage&action=uebersicht", "Zurück"); $this->app->erp->MenuEintrag("index.php?module=importvorlage&action=uebersicht", "Zurück");
$this->app->YUI->AutoComplete("projekt", "projektname", 1); $this->app->YUI->AutoComplete("projekt", "projektname", 1);
$this->app->YUI->DatePicker("von"); $this->app->YUI->DatePicker("von");
$this->app->YUI->DatePicker("bis"); $this->app->YUI->DatePicker("bis");
$this->app->YUI->AutoComplete('sachkonto', 'sachkonto'); $this->app->YUI->AutoComplete('sachkonto', 'sachkonto');
$this->app->Tpl->SET('MESSAGE', $msg); $this->app->Tpl->SET('MESSAGE', $msg);
$this->app->Tpl->SET('RGCHECKED',$rgchecked?'checked':''); $this->app->Tpl->SET('RGCHECKED',$rgchecked?'checked':'');
$this->app->Tpl->SET('GSCHECKED',$gschecked?'checked':''); $this->app->Tpl->SET('GSCHECKED',$gschecked?'checked':'');
$this->app->Tpl->SET('VBCHECKED',$vbchecked?'checked':''); $this->app->Tpl->SET('VBCHECKED',$vbchecked?'checked':'');
$this->app->Tpl->SET('DIFFIGNORE',$diffignore?'checked':''); $this->app->Tpl->SET('DIFFIGNORE',$diffignore?'checked':'');
$this->app->Tpl->SET('VON', $von_form); $this->app->Tpl->SET('VON', $von_form);
$this->app->Tpl->SET('BIS', $bis_form); $this->app->Tpl->SET('BIS', $bis_form);
$this->app->Tpl->SET('PROJEKT', $projektkuerzel); $this->app->Tpl->SET('PROJEKT', $projektkuerzel);
$this->app->Tpl->SET('SACHKONTO', $sachkonto); $this->app->Tpl->SET('SACHKONTO', $sachkonto);
$this->app->Tpl->Parse('PAGE', "exportbuchhaltung_export.tpl"); $this->app->Tpl->Parse('PAGE', "exportbuchhaltung_export.tpl");
@ -509,7 +509,7 @@ class Exportbuchhaltung
b.ustid, b.ustid,
b.".$typ['field_date']." as datum, b.".$typ['field_date']." as datum,
p.id as pos_id, p.id as pos_id,
".$typ['field_betrag_gesamt']." as betrag_gesamt, ".$typ['field_betrag_gesamt']." as betrag_gesamt,
b.waehrung, b.waehrung,
ROUND(".$typ['field_betrag'].",2) as betrag, ROUND(".$typ['field_betrag'].",2) as betrag,
".$typ['field_gegenkonto']." as gegenkonto, ".$typ['field_gegenkonto']." as gegenkonto,
@ -532,11 +532,12 @@ class Exportbuchhaltung
( (
SELECT SELECT
belegnr, belegnr,
datum,
betrag_gesamt, betrag_gesamt,
ROUND(SUM(betrag),2) AS betrag_summe, ROUND(SUM(betrag),2) AS betrag_summe,
waehrung, waehrung,
kundennummer, kundennummer,
ustid, ustid,
auftrag auftrag
FROM FROM
(".$sql.") posten (".$sql.") posten
@ -546,43 +547,43 @@ class Exportbuchhaltung
WHERE betrag_gesamt <> betrag_summe OR betrag_summe IS NULL"; WHERE betrag_gesamt <> betrag_summe OR betrag_summe IS NULL";
$result = $this->app->DB->SelectArr($sql_check); $result = $this->app->DB->SelectArr($sql_check);
if (!empty($result)) { if (!empty($result)) {
if (!$sachkonto_differences) { if (!$sachkonto_differences) {
$e = new ConsistencyException(ucfirst($typ['typ']),$result); $e = new ConsistencyException(ucfirst($typ['typ']),$result);
throw $e; throw $e;
} else { } else {
// Create differences entries // Create differences entries
foreach ($result as $row) { foreach ($result as $row) {
$posid = $row['pos_id']; $posid = $row['pos_id'];
$tmpsteuersatz = 0; $tmpsteuersatz = 0;
$tmpsteuertext = ''; $tmpsteuertext = '';
$erloes = ''; $erloes = '';
$result = array(); $result = array();
$this->app->erp->GetSteuerPosition($typ['typ'], $posid, $tmpsteuersatz, $tmpsteuertext, $erloes); $this->app->erp->GetSteuerPosition($typ['typ'], $posid, $tmpsteuersatz, $tmpsteuertext, $erloes);
$data = array(); $data = array();
$difference = $row['betrag_gesamt']-$row['betrag_summe']; $difference = $row['betrag_gesamt']-$row['betrag_summe'];
$data['Umsatz'] = number_format(abs($difference), 2, ',', ''); // obligatory $data['Umsatz'] = number_format(abs($difference), 2, ',', ''); // obligatory
$data['EU-Steuersatz (Bestimmung)'] = 0; $data['EU-Steuersatz (Bestimmung)'] = 0;
$data['WKZ Umsatz'] = $row['waehrung']; $data['WKZ Umsatz'] = $row['waehrung'];
$data['Belegfeld 1'] = mb_strimwidth($row['belegnr'],0,12); $data['Belegfeld 1'] = mb_strimwidth($row['belegnr'],0,12);
$data['Konto'] = $row['kundennummer']; $data['Konto'] = $row['kundennummer'];
$data['Soll-/Haben-Kennzeichen'] = ($difference < 0)?'S':'H'; // obligatory $data['Soll-/Haben-Kennzeichen'] = ($difference < 0)?'S':'H'; // obligatory
$data['Gegenkonto (ohne BU-Schlüssel)'] = $sachkonto_differences; // obligatory $data['Gegenkonto (ohne BU-Schlüssel)'] = $sachkonto_differences; // obligatory
$data['Belegdatum'] = date_format(date_create($row['datum']),"dm"); // obligatory $data['Belegdatum'] = date_format(date_create($row['datum']),"dm"); // obligatory
$data['Buchungstext'] = "Differenz"; $data['Buchungstext'] = "Differenz";
$data['EU-Mitgliedstaat u. UStID (Bestimmung)'] = $row['ustid']; $data['EU-Mitgliedstaat u. UStID (Bestimmung)'] = $row['ustid'];
$data['Auftragsnummer'] = $row['auftrag']; $data['Auftragsnummer'] = $row['auftrag'];
$csv .= $this->create_line($datev_buchungsstapel_definition,$data); $csv .= $this->create_line($datev_buchungsstapel_definition,$data);
} }
} }
} }
} // diffignore } // diffignore
// Query position data // Query position data
@ -622,7 +623,7 @@ class Exportbuchhaltung
$data['Belegdatum'] = date_format(date_create($row['datum']),"dm"); // obligatory $data['Belegdatum'] = date_format(date_create($row['datum']),"dm"); // obligatory
$data['Buchungstext'] = mb_strimwidth($row['name'],0,60); $data['Buchungstext'] = mb_strimwidth($row['name'],0,60);
$data['EU-Mitgliedstaat u. UStID (Bestimmung)'] = $row['ustid']; $data['EU-Mitgliedstaat u. UStID (Bestimmung)'] = $row['ustid'];
$data['Auftragsnummer'] = ($row['auftrag']!=0)?$row['auftrag']:''; $data['Auftragsnummer'] = ($row['auftrag']!=0)?$row['auftrag']:'';
$csv .= $this->create_line($datev_buchungsstapel_definition,$data); $csv .= $this->create_line($datev_buchungsstapel_definition,$data);
@ -633,11 +634,11 @@ class Exportbuchhaltung
$csv = mb_convert_encoding($csv, "ISO-8859-1", "UTF-8"); $csv = mb_convert_encoding($csv, "ISO-8859-1", "UTF-8");
return($csv); return($csv);
} }
function create_line($definition, $data) : string { function create_line($definition, $data) : string {
$csv = ""; $csv = "";
$comma = ""; $comma = "";
foreach ($definition as $key => $value) { foreach ($definition as $key => $value) {
if (!isset($data[$value])) { if (!isset($data[$value])) {
$data[$value] = ''; $data[$value] = '';
@ -645,9 +646,9 @@ class Exportbuchhaltung
$csv .= $comma.'"'.$data[$value].'"'; $csv .= $comma.'"'.$data[$value].'"';
$comma = ";"; $comma = ";";
} }
$csv .= "\r\n"; $csv .= "\r\n";
return($csv); return($csv);
} }
} }