StructController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. class StructController
  3. {
  4. private $dir;
  5. private $config;
  6. private $pattern;
  7. private $result;
  8. public static function Validate ($action, $filename, $logfile = "") {
  9. if (!file_exists($filename)) return;
  10. $struct = new StructController($filename);
  11. $result = $struct->ValidateFinance();
  12. if ($logfile == "") {
  13. echo "FEHLER:";
  14. foreach($result['error'] as $type => $list) {
  15. echo "\r\n\r\n" . $type . ": \r\n";
  16. echo implode("\r\n", $list);
  17. }
  18. } else {
  19. file_put_contents($logfile, json_encode($result));
  20. }
  21. }
  22. public function __construct ($configFile) {
  23. $this->dir = dirname(dirname($configFile));
  24. $xml = simplexml_load_file($configFile);
  25. $this->config = $this->xmlToArray($xml);
  26. }
  27. public function ExportSKR51 ($csvFile) {
  28. }
  29. public function ValidateFinance () {
  30. $this->pattern = array(
  31. 'error' => array(
  32. 'Neues Konto' => '^[^;]*;[^;]*;[^;]*$',
  33. 'Konto_Art' => '^([^;]*;){2};',
  34. 'Kostenstelle' => '^([^;]*;){2}[02];;',
  35. 'Konto_1' => '^([^;]*;){5};'
  36. ),
  37. 'info' => array(
  38. 'FB' => '^([^;]*;){10};',
  39. 'TEK' => '^([^;]*;){20};',
  40. 'GuV' => '^([^;]*;){2}[02];([^;]*;){27};',
  41. 'Bilanz' => '^([^;]*;){2}1;([^;]*;){37};',
  42. 'GuV_extern' => '^([^;]*;){2}[02];([^;]*;){47};'
  43. )
  44. );
  45. $csvFile = $this->dir . "\\" . $this->config['Dateipfade']['KontenrahmenPfad'] . $this->config['Dateipfade']['KontenrahmenCsv'];
  46. $this->result = array('error' => array(), 'info' => array());
  47. foreach(file($csvFile) as $i => $row) {
  48. if ($i == 0) continue;
  49. $this->CheckRow(mb_convert_encoding($row, "ISO-8859-1", "UTF-8"));
  50. }
  51. return $this->result;
  52. }
  53. public function CheckRow ($row) {
  54. $info = "";
  55. if (!preg_match("/^([^;]*);([^;]*)/", $row, $info)) {
  56. return;
  57. }
  58. foreach ($this->pattern as $level => $list) {
  59. foreach ($list as $type => $p) {
  60. if (preg_match("/". $p . "/", $row)) {
  61. $this->result[$level][$type][] = mb_convert_encoding($info[1] . " - " . $info[2], "UTF-8", "Windows-1252");
  62. }
  63. }
  64. }
  65. }
  66. public function xmlToArray ($xml) {
  67. $s = array();
  68. $s['Kunde'] = (string)$xml->Kunde->Firma;
  69. $s['Dateipfade'] = (array)$xml->Dateipfade;
  70. $sd = array();
  71. for ($i=0; $i < count($xml->Strukturdefinitionen->Struktur); $i++) {
  72. $str = $xml->Strukturdefinitionen->Struktur[$i];
  73. $attr = $xml->Strukturdefinitionen->Struktur[$i]->attributes();
  74. $sd[] = array(
  75. 'KontenInStruktur' => (string)$attr->KontenInStruktur,
  76. 'Name' => (string)$str->Name,
  77. 'Beschreibung' => (string)$str->Beschreibung,
  78. 'Kontenfilter' => (string)$str->Kontenfilter,
  79. 'ExportStk' => (string)$str->ExportStk,
  80. 'ExportUebersetzung' => (string)$str->ExportUebersetzung,
  81. 'ExportUebersetzungStk' => (string)$str->ExportUebersetzungStk,
  82. 'ExportAdjazenz' => (string)$str->ExportAdjazenz,
  83. 'ExportHerstellerKontenrahmen' => (string)$str->ExportHerstellerKontenrahmen
  84. );
  85. }
  86. $s['Strukturdefinitionen'] = $sd;
  87. $sf = array();
  88. for ($i=0; $i < count($xml->Suchfilter->Filter); $i++) {
  89. $attr = $xml->Suchfilter->Filter[$i]->attributes();
  90. $sf[] = array(
  91. 'Name' => (string)$attr->Bezeichnung,
  92. 'Kontenfilter' => (string)$attr->Regex
  93. );
  94. }
  95. $s['Suchfilter'] = $sf;
  96. $kdf = array();
  97. for ($i=0; $i < count($xml->KontoDatenfelder->Feld); $i++) {
  98. $str = $xml->KontoDatenfelder->Feld[$i];
  99. $attr = $xml->KontoDatenfelder->Feld[$i]->attributes();
  100. $opt = array();
  101. for ($j = 0; $j < count($str->Optionen->Option); $j++) {
  102. $optAttr = $str->Optionen->Option[$j]->attributes();
  103. $opt[] = array(
  104. 'Name' => (string)$optAttr->Name,
  105. 'Wert' => (string)$optAttr->Wert
  106. );
  107. }
  108. $kdf[] = array(
  109. 'id' => (string)$attr->id,
  110. 'Aktiv' => (string)$str->Aktiv,
  111. 'Optionen' => $opt,
  112. 'Name' => (string)$str->Name,
  113. 'Beschreibung' => (string)$str->Beschreibung,
  114. 'Default' => (string)$str->Default,
  115. 'Darstellung' => (string)$str->Darstellung
  116. );
  117. }
  118. $s['KontoDatenfelder'] = $kdf;
  119. return $s;
  120. }
  121. }