/** * Create a ChartOfAccounts object from SIE string (in charset CP437) * * @param string $sie * @throws RangeException If $sie is not valid * @return ChartOfAccounts */ public function importChart($sie) { $sie = iconv("CP437", "UTF-8", $sie); $lines = explode(self::EOL, $sie); $chart = new ChartOfAccounts(); $current = array(); foreach ($lines as $nr => $line) { $data = str_getcsv($line, ' ', '"'); switch ($data[0]) { case '#KPTYP': if (!isset($data[1])) { throw new RangeException("Invalid chart type at line {$nr}"); } $chart->setChartType($data[1]); break; case '#KONTO': // Account must have form #KONTO number name if (!isset($data[2])) { throw new RangeException("Invalid account values at line {$nr}"); } $current = array($data[1], $data[2]); break; case '#KTYP': // Account type must have form #KTYP number type if (!isset($data[2])) { throw new RangeException("Invalid account values at line {$nr}"); } // Type must referer to current account if ($data[1] != $current[0]) { throw new RangeException("Unexpected account type at line {$nr}"); } $account = new Account($data[1], $data[2], $current[1]); $chart->addAccount($account); $current = array(); break; } } // There should be no half way processed accounts if (!empty($current)) { throw new RangeException("Account type missing for '{$current[0]}'"); } return $chart; }