public function getChart() { $c = new ChartOfAccounts(); $c->addAccount(new Account('1920', 'T', 'Bank')); $c->addAccount(new Account('1510', 'T', 'Claims')); $c->addAccount(new Account('3000', 'I', 'Incomes')); $c->addAccount(new Account('3990', 'I', 'Benefits')); return $c; }
/** * 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; }
public function testExportChart() { $chart = new ChartOfAccounts(); $chart->addAccount(new Account('1920', 'T', 'Bank')); $chart->addAccount(new Account('3000', 'I', 'Income')); $sie = new SIE(); $txt = $sie->exportChart('FOOBAR', $chart); $date = date('Ymd'); $expected = "#FILTYP KONTO\r\n#PROGRAM \"ledgr_SIE\" \"1.0\"\r\n#TEXT" . " \"FOOBAR\"\r\n#FORMAT PC8\r\n#GEN {$date} \"ledgr_SIE\"\r\n#KPTYP" . " \"EUBAS97\"\r\n\r\n" . "#KONTO \"1920\" \"Bank\"\r\n#KTYP \"1920\" \"T\"\r\n#KONTO \"3000\"" . " \"Income\"\r\n#KTYP \"3000\" \"I\"\r\n"; $expected = iconv("UTF-8", "CP437", $expected); $this->assertEquals($expected, $txt); }
/** * Create verification from template * * @param ChartOfAccounts $chart * @return Verification * @throws UnexpectedValueException If any key is NOT substituted */ public function buildVerification(ChartOfAccounts $chart) { if (!$this->ready($key)) { throw new UnexpectedValueException("Unable to substitute template key <{$key}>"); } // Build verification $ver = new Verification($this->getText()); foreach ($this->getTransactions() as $arTransData) { list($number, $amount) = $arTransData; // Ignore 0 amount transactions if (0 != floatval($amount)) { $ver->addTransaction(new Transaction($chart->getAccount($number), new Amount($amount))); } } return $ver; }