Revize 2450
Přidáno uživatelem Ondřej Fibich před více než 9 roky(ů)
freenetis/branches/1.2/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'interval of update' => 'Interval aktualizace',
|
||
'interval of update in seconds' => 'Interval aktualizace v sekundách',
|
||
'invalid address point' => 'Neplatná adresa',
|
||
'invalid amount format' => 'Chybný formát částka',
|
||
'invalid api token' => 'Chybný API token',
|
||
'invalid connect to interface - already has different link' => 'Nelze se připojit k rozhraní - již má jinou linku',
|
||
'invalid date' => 'Neplatné datum!',
|
||
'invalid date format' => 'Chybný formát datumu',
|
||
'invalid data - no data available' => 'Neplatná data - žádné data k dispozici',
|
||
'invalid domain name' => 'Neplatné doménové jméno.',
|
||
'invalid file format (json_decode failed): %s' => 'chybný formát souboru (json_decode selhal): %s',
|
freenetis/branches/1.2/application/libraries/Bank_Statement_File_Importer.php | ||
---|---|---|
/* check header of statement */
|
||
$header_data = $driver->get_header_data();
|
||
|
||
if (!$header_data ||
|
||
$header_data->get_bank_id() != $bank_account->bank_nr ||
|
||
$header_data->get_account_id() != $bank_account->account_nr)
|
||
{
|
||
$an = $header_data->get_account_id() . '/' . $header_data->get_bank_id();
|
||
$m = __('Bank account number in listing (%s) header does not match ' .
|
||
'bank account %s in database!', array($an, $acc));
|
||
throw new Exception($m);
|
||
}
|
||
if ($header_data !== NULL)
|
||
{
|
||
if (!$header_data ||
|
||
$header_data->get_bank_id() != $bank_account->bank_nr ||
|
||
$header_data->get_account_id() != $bank_account->account_nr)
|
||
{
|
||
$an = $header_data->get_account_id() . '/'
|
||
. $header_data->get_bank_id();
|
||
$m = __('Bank account number in listing (%s) header does not ' .
|
||
'match bank account %s in database!', array($an, $acc));
|
||
throw new Exception($m);
|
||
}
|
||
}
|
||
|
||
/* parse file */
|
||
if (!$driver->parse_file_data())
|
||
... | ... | |
*
|
||
* An error in the format may be add into error stack (addError) that is later
|
||
* displayed to user if this function returns FALSE.
|
||
*
|
||
* If bank statement file not providing any header information NULL can
|
||
* be returned to skip assert for bank account match.
|
||
*
|
||
* @return Header_Data
|
||
* @return Header_Data|boolean|null
|
||
*/
|
||
protected abstract function get_header_data();
|
||
|
freenetis/branches/1.2/application/libraries/importers/Csv_Fio_Bank_Statement_File_Importer.php | ||
---|---|---|
*/
|
||
|
||
require_once __DIR__ . '/Fio_Bank_Statement_File_Importer.php';
|
||
require_once __DIR__ . '/Fio/FioCsvStatement.php';
|
||
require_once __DIR__ . '/Fio/FioCsvParser.php';
|
||
require_once __DIR__ . '/Fio/NewFioCsvParser.php';
|
||
|
||
/**
|
||
* FIO importer for statements in CSV format that are obtained from the FIO
|
||
... | ... | |
* @var FioCsvStatement
|
||
*/
|
||
private $data = NULL;
|
||
|
||
/**
|
||
* Indicates whether header is available or not.
|
||
*
|
||
* @var boolean
|
||
*/
|
||
private $header_available = TRUE;
|
||
|
||
/*
|
||
/*
|
||
* @Override
|
||
*/
|
||
protected function check_file_data_format()
|
||
{
|
||
// reset
|
||
$this->data = NULL;
|
||
$this->header_available = TRUE;
|
||
// parse (we have no function for checking)
|
||
try
|
||
{
|
||
// parse
|
||
$parser = new FioCsvParser;
|
||
$this->data = $parser->parse($this->get_file_data(), 'cp1250');
|
||
$file_data = $this->get_file_data();
|
||
// new parser
|
||
$parserNew = new NewFioCsvParser;
|
||
if ($parserNew->accept_file($file_data))
|
||
{
|
||
$this->header_available = FALSE;
|
||
$this->data = $parserNew->parse($file_data);
|
||
}
|
||
// old parser
|
||
else
|
||
{
|
||
$parserOld = new FioCsvParser;
|
||
$this->data = $parserOld->parse($file_data, 'cp1250');
|
||
}
|
||
// correct each data row
|
||
for ($i = 0; $i < count($this->data->items); $i++)
|
||
{
|
||
... | ... | |
*/
|
||
protected function get_header_data()
|
||
{
|
||
if (!$this->header_available)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
if (empty($this->data))
|
||
{
|
||
throw new InvalidArgumentException('Check CSV first');
|
freenetis/branches/1.2/application/libraries/importers/Fio/FioCsvParser.php | ||
---|---|---|
*
|
||
*/
|
||
|
||
require_once __DIR__ . '/FioCsvParserUtil.php';
|
||
|
||
/**
|
||
* Auxiliary class for parsing CSV bank account listings from czech bank
|
||
* "FIO banka". Listing may be obtain from from the ebanking web application
|
||
... | ... | |
$result = new FioCsvStatement();
|
||
$sum = 0;
|
||
$keys = array_keys(self::$fields);
|
||
$lines = $this->transformFileToLineArray($csv, $charset);
|
||
$lines = FioCsvParserUtil::transformFileToLineArray($csv, $charset);
|
||
// check each line of CSV
|
||
for ($i = 0; $i < count($lines); $i++)
|
||
{
|
||
... | ... | |
}
|
||
return array
|
||
(
|
||
self::parseDate($period_parts[0]),
|
||
self::parseDate($period_parts[1])
|
||
FioCsvParserUtil::parseDate($period_parts[0]),
|
||
FioCsvParserUtil::parseDate($period_parts[1])
|
||
);
|
||
}
|
||
|
||
... | ... | |
throw new Exception("Nemohu najít počáteční zůstatek.");
|
||
}
|
||
$amount = str_replace(" CZK", "", $line_arr[1]);
|
||
return self::parseAmount($amount);
|
||
return FioCsvParserUtil::parseAmount($amount);
|
||
}
|
||
|
||
/**
|
||
... | ... | |
throw new Exception("Nemohu najít konečný zůstatek.");
|
||
}
|
||
$amount = str_replace(" CZK", "", $line_arr[1]);
|
||
return self::parseAmount($amount);
|
||
return FioCsvParserUtil::parseAmount($amount);
|
||
}
|
||
|
||
/**
|
||
... | ... | |
}
|
||
|
||
/**
|
||
* Normalize string amount to double value.
|
||
*
|
||
* @example " 1000 278,40 " -> "1000278.40"
|
||
* @param string $amount
|
||
* @return double
|
||
* @throws InvalidArgumentException on invalid passed amount
|
||
*/
|
||
public static function parseAmount($amount)
|
||
{
|
||
$norm_amount = str_replace(array(' ', ','), array('', '.'), $amount);
|
||
if (!is_numeric($norm_amount))
|
||
{
|
||
throw new InvalidArgumentException('Chybný formát částky převodu.');
|
||
}
|
||
return doubleval($norm_amount);
|
||
}
|
||
|
||
/**
|
||
* Parse date from format DD.MM.YYYY into YYYY-MM-DD.
|
||
*
|
||
* @param string $date in format DD.MM.YYYY
|
||
* @return string date in format YYYY-MM-DD
|
||
* @throws InvalidArgumentException on invalid date format
|
||
*/
|
||
public static function parseDate($date)
|
||
{
|
||
$matches = NULL;
|
||
if (!preg_match("/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/", $date, $matches))
|
||
{
|
||
throw new InvalidArgumentException('Chybný formát data: ' . $date);
|
||
}
|
||
$timestamp = mktime(0, 0, 0, $matches[2], $matches[1], $matches[3]);
|
||
return date("Y-m-d", $timestamp);
|
||
}
|
||
|
||
/**
|
||
* Parse line of dump
|
||
*
|
||
* @param string $line
|
||
... | ... | |
// Convert date
|
||
if ($assoc_cols['datum'] != self::LAST_LINE_DATE_VALUE)
|
||
{
|
||
$assoc_cols['datum'] = self::parseDate($assoc_cols['datum']);
|
||
$assoc_cols['datum'] = FioCsvParserUtil::parseDate($assoc_cols['datum']);
|
||
}
|
||
|
||
// Amount has to be converted
|
||
$assoc_cols['castka'] = self::parseAmount($assoc_cols['castka']);
|
||
$assoc_cols['castka'] = FioCsvParserUtil::parseAmount($assoc_cols['castka']);
|
||
|
||
// Trim leading zeros from VS
|
||
$assoc_cols['vs'] = ltrim($assoc_cols['vs'], '0');
|
||
... | ... | |
}
|
||
}
|
||
|
||
/**
|
||
* Transforms file content in passed charset into array of its lines encoded
|
||
* in UTF-8 encoding. This function must handle differences of end of line
|
||
* separators on all platforms.
|
||
*
|
||
* @param string $file_content file countent to be transformed
|
||
* @param string $charset charset of file content
|
||
* @return array array of lines in UTF-8 charset
|
||
*/
|
||
private function transformFileToLineArray($file_content, $charset)
|
||
{
|
||
$internal_charset = 'UTF-8';
|
||
$fc_utf8 = NULL;
|
||
// transform to uTF-8
|
||
if (strtolower($charset) != strtolower($internal_charset))
|
||
{
|
||
$fc_utf8 = iconv($charset, $internal_charset, $file_content);
|
||
}
|
||
else
|
||
{
|
||
$fc_utf8 = $file_content;
|
||
}
|
||
// eplode lines
|
||
return preg_split("/\r\n|\n|\r/", $fc_utf8);
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* CSV parser result.
|
||
*/
|
||
class FioCsvStatement
|
||
{
|
||
/**
|
||
* Account number
|
||
*
|
||
* @var integer
|
||
*/
|
||
public $account_nr = 0;
|
||
|
||
/**
|
||
* Bank number
|
||
*
|
||
* @var integer
|
||
*/
|
||
public $bank_nr;
|
||
|
||
/**
|
||
* Statement period from date in format YYYY-MM-DD
|
||
*
|
||
* @var string
|
||
*/
|
||
public $from;
|
||
|
||
/**
|
||
* Statement period to date in format YYYY-MM-DD
|
||
*
|
||
* @var string
|
||
*/
|
||
public $to;
|
||
|
||
/**
|
||
* Openning balance
|
||
*
|
||
* @var double
|
||
*/
|
||
public $opening_balance;
|
||
|
||
/**
|
||
* Closing balance
|
||
*
|
||
* @var double
|
||
*/
|
||
public $closing_balance;
|
||
|
||
/**
|
||
* Items of statement that contain array of associative array where
|
||
* each item contains fields defined by FioCsvParser::$field array keys.
|
||
*
|
||
* @var array
|
||
*/
|
||
public $items;
|
||
|
||
/**
|
||
* Returns account number as array
|
||
*
|
||
* @return associative array("account_nr"=>"XXXXXXX", "bank_nr" => "YYYY"
|
||
*/
|
||
public function getAccountNumberAsArray()
|
||
{
|
||
return array
|
||
(
|
||
"account_nr" => $this->account_nr,
|
||
"bank_nr" => $this->bank_nr
|
||
);
|
||
}
|
||
|
||
/**
|
||
* Returns associative array containing important listing header information.
|
||
* Must be called after parsing.
|
||
*
|
||
* @author Jiri Svitak
|
||
* @return header information
|
||
*/
|
||
public function getListingHeader()
|
||
{
|
||
// account number
|
||
$header = $this->getAccountNumberAsArray();
|
||
// date from to
|
||
$header["from"] = $this->from;
|
||
$header["to"] = $this->to;
|
||
// opening and closing balance
|
||
$header["opening_balance"] = $this->opening_balance;
|
||
$header["closing_balance"] = $this->closing_balance;
|
||
|
||
return $header;
|
||
}
|
||
|
||
}
|
freenetis/branches/1.2/application/libraries/importers/Fio/FioCsvParserUtil.php | ||
---|---|---|
<?php
|
||
|
||
/*
|
||
* This file is part of open source system FreenetIS
|
||
* and it is release under GPLv3 licence.
|
||
*
|
||
* More info about licence can be found:
|
||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||
*
|
||
* More info about project can be found:
|
||
* http://www.freenetis.org/
|
||
*/
|
||
|
||
/**
|
||
* Utility methods for FIO CSV parsers.
|
||
*
|
||
* @author Ondřej Fibich <fibich@freenetis.org>
|
||
* @since 1.2
|
||
*/
|
||
final class FioCsvParserUtil
|
||
{
|
||
/**
|
||
* Utility pattern - instance cannot be created.
|
||
*/
|
||
private function __construct()
|
||
{
|
||
}
|
||
|
||
/**
|
||
* Normalize string amount to double value.
|
||
*
|
||
* @example " 1000 278,40 " -> "1000278.40"
|
||
* @param string $amount
|
||
* @return double
|
||
* @throws InvalidArgumentException on invalid passed amount
|
||
*/
|
||
public static function parseAmount($amount)
|
||
{
|
||
$norm_amount = str_replace(array(' ', ','), array('', '.'), $amount);
|
||
if (!is_numeric($norm_amount))
|
||
{
|
||
$m = __('Invalid amount format') . ': ' . $amount;
|
||
throw new InvalidArgumentException($m);
|
||
}
|
||
return doubleval($norm_amount);
|
||
}
|
||
|
||
/**
|
||
* Parse date from format DD.MM.YYYY into YYYY-MM-DD.
|
||
*
|
||
* @param string $date in format DD.MM.YYYY
|
||
* @return string date in format YYYY-MM-DD
|
||
* @throws InvalidArgumentException on invalid date format
|
||
*/
|
||
public static function parseDate($date)
|
||
{
|
||
$matches = NULL;
|
||
if (!preg_match("/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/", $date, $matches))
|
||
{
|
||
$m = __('Invalid date format') . ': ' . $date;
|
||
throw new InvalidArgumentException($m);
|
||
}
|
||
$timestamp = mktime(0, 0, 0, $matches[2], $matches[1], $matches[3]);
|
||
return date('Y-m-d', $timestamp);
|
||
}
|
||
|
||
/**
|
||
* Transforms file content in passed charset into array of its lines encoded
|
||
* in UTF-8 encoding. This function must handle differences of end of line
|
||
* separators on all platforms.
|
||
*
|
||
* @param string $file_content file countent to be transformed
|
||
* @param string $charset charset of file content
|
||
* @return array array of lines in UTF-8 charset
|
||
*/
|
||
public static function transformFileToLineArray($file_content, $charset)
|
||
{
|
||
$internal_charset = 'UTF-8';
|
||
$fc_utf8 = NULL;
|
||
// transform to uTF-8
|
||
if (strtolower($charset) != strtolower($internal_charset))
|
||
{
|
||
$fc_utf8 = iconv($charset, $internal_charset, $file_content);
|
||
}
|
||
else
|
||
{
|
||
$fc_utf8 = $file_content;
|
||
}
|
||
// eplode lines
|
||
return preg_split("/\r\n|\n|\r/", $fc_utf8);
|
||
}
|
||
|
||
}
|
freenetis/branches/1.2/application/libraries/importers/Fio/FioCsvStatement.php | ||
---|---|---|
<?php
|
||
|
||
/*
|
||
* This file is part of open source system FreenetIS
|
||
* and it is release under GPLv3 licence.
|
||
*
|
||
* More info about licence can be found:
|
||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||
*
|
||
* More info about project can be found:
|
||
* http://www.freenetis.org/
|
||
*/
|
||
|
||
/**
|
||
* CSV parser result.
|
||
*
|
||
* @author Ondřej Fibich <fibich@freenetis.org>
|
||
*/
|
||
class FioCsvStatement
|
||
{
|
||
/**
|
||
* Account number
|
||
*
|
||
* @var integer
|
||
*/
|
||
public $account_nr = 0;
|
||
|
||
/**
|
||
* Bank number
|
||
*
|
||
* @var integer
|
||
*/
|
||
public $bank_nr;
|
||
|
||
/**
|
||
* Statement period from date in format YYYY-MM-DD
|
||
*
|
||
* @var string
|
||
*/
|
||
public $from;
|
||
|
||
/**
|
||
* Statement period to date in format YYYY-MM-DD
|
||
*
|
||
* @var string
|
||
*/
|
||
public $to;
|
||
|
||
/**
|
||
* Openning balance
|
||
*
|
||
* @var double
|
||
*/
|
||
public $opening_balance;
|
||
|
||
/**
|
||
* Closing balance
|
||
*
|
||
* @var double
|
||
*/
|
||
public $closing_balance;
|
||
|
||
/**
|
||
* Items of statement that contain array of associative array where
|
||
* each item contains fields defined by FioCsvParser::$field array keys.
|
||
*
|
||
* @var array
|
||
*/
|
||
public $items;
|
||
|
||
/**
|
||
* Returns account number as array
|
||
*
|
||
* @return associative array('account_nr'=>'XXXXXXX', 'bank_nr' => 'YYYY'
|
||
*/
|
||
public function getAccountNumberAsArray()
|
||
{
|
||
return array
|
||
(
|
||
'account_nr' => $this->account_nr,
|
||
'bank_nr' => $this->bank_nr
|
||
);
|
||
}
|
||
|
||
/**
|
||
* Returns associative array containing important listing header information.
|
||
* Must be called after parsing.
|
||
*
|
||
* @author Jiri Svitak
|
||
* @return header information
|
||
*/
|
||
public function getListingHeader()
|
||
{
|
||
// account number
|
||
$header = $this->getAccountNumberAsArray();
|
||
// date from to
|
||
$header['from'] = $this->from;
|
||
$header['to'] = $this->to;
|
||
// opening and closing balance
|
||
$header['opening_balance'] = $this->opening_balance;
|
||
$header['closing_balance'] = $this->closing_balance;
|
||
|
||
return $header;
|
||
}
|
||
|
||
}
|
freenetis/branches/1.2/application/libraries/importers/Fio/NewFioCsvParser.php | ||
---|---|---|
<?php
|
||
|
||
/*
|
||
* This file is part of open source system FreenetIS
|
||
* and it is released under GPLv3 licence.
|
||
*
|
||
* More info about licence can be found:
|
||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||
*
|
||
* More info about project can be found:
|
||
* http://www.freenetis.org/
|
||
*
|
||
*/
|
||
|
||
require_once __DIR__ . '/FioCsvParserUtil.php';
|
||
|
||
/**
|
||
* Auxiliary class for parsing CSV bank account listings from czech bank
|
||
* "FIO banka". Listing may be obtain from from the ebanking web application
|
||
* of FIO bank.
|
||
*
|
||
* The CSV format looks like this:
|
||
* "Datum";"ID operace";"ID pokynu";"KS";"Název banky";"Název protiúčtu";
|
||
* "Objem";"Měna";"Protiúčet";"Kód banky";"Zadal";"SS";"Typ";"Poznámka";
|
||
* "VS";"Upřesnění - objem";"Upřesnění - měna";"Zpráva pro příjemce"
|
||
* "Suma";"";"";"";"";"";"-188170,4";"CZK";"";"";"";"";"";"";"";"";"";""
|
||
*
|
||
* @author Ondřej Fibich <fibich@freenetis.org>
|
||
* @since 1.2
|
||
* @todo i18n of error messages
|
||
*/
|
||
class NewFioCsvParser
|
||
{
|
||
/**
|
||
* CSV column separator.
|
||
*/
|
||
const CSV_COL_DELIM = ';';
|
||
|
||
/**
|
||
* CSV column value wrapper.
|
||
*/
|
||
const CSV_COL_WRAPPER = '"';
|
||
|
||
/**
|
||
* Last line date string that is used for end of statement detection.
|
||
*/
|
||
const HEADER_LINE_DATE_VALUE = 'Suma';
|
||
|
||
/**
|
||
* Default CSV file encoding.
|
||
*/
|
||
const DEFAULT_CHARSET = 'UTF-8';
|
||
|
||
/**
|
||
* All fields available must be used and sorted alphabetically
|
||
*
|
||
* @var array[string]
|
||
*/
|
||
private static $fields = array
|
||
(
|
||
'datum' => 'Datum',
|
||
'id_pohybu' => 'ID operace',
|
||
'id_pokynu' => 'ID pokynu',
|
||
'ks' => 'KS',
|
||
'nazev_banky' => 'Název banky',
|
||
'nazev_protiuctu' => 'Název protiúčtu',
|
||
'castka' => 'Objem',
|
||
'mena' => 'Měna',
|
||
'protiucet' => 'Protiúčet',
|
||
'kod_banky' => 'Kód banky',
|
||
'provedl' => 'Zadal',
|
||
'ss' => 'SS',
|
||
'typ' => 'Typ',
|
||
'identifikace' => 'Poznámka',
|
||
'vs' => 'VS',
|
||
'upresneni_objem' => 'Upřesnění - objem',
|
||
'upresneni_mena' => 'Upřesnění - měna',
|
||
'zprava' => 'Zpráva pro příjemce'
|
||
);
|
||
|
||
/**
|
||
* FIO statement columns fields names.
|
||
*
|
||
* @return array
|
||
*/
|
||
public static function get_fields()
|
||
{
|
||
return self::$fields;
|
||
}
|
||
|
||
/**
|
||
* Parse bank statement in CSV format that is passed as string.
|
||
*
|
||
* @param string $csv string containing the original csv file.
|
||
* @param string $charset optional charset name of file, default is UTF-8
|
||
* @return FioCsvStatement result
|
||
* @throws Exception on parse error
|
||
*/
|
||
public function parse($csv, $charset = self::DEFAULT_CHARSET)
|
||
{
|
||
$total_sum = -1;
|
||
$sum = 0;
|
||
$keys = array_keys(self::$fields);
|
||
$lines = FioCsvParserUtil::transformFileToLineArray($csv, $charset);
|
||
$result = new FioCsvStatement;
|
||
// check each line of CSV
|
||
for ($i = 0; $i < count($lines); $i++)
|
||
{
|
||
$line = trim($lines[$i]);
|
||
// header
|
||
if ($i == 0)
|
||
{
|
||
$this->checkHeaders($line);
|
||
}
|
||
else if ($i == 1)
|
||
{
|
||
$total_sum = $this->parseHeaderLine($line);
|
||
}
|
||
else if (empty($line)) // empty last line?
|
||
{
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
// data lines
|
||
$cols = $this->parseLine($line, $keys);
|
||
// add data row
|
||
$sum += $cols['castka'];
|
||
$result->items[] = $cols;
|
||
}
|
||
}
|
||
$this->checkIntegrity($total_sum, $sum);
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* Check whether parser accept given CSV file.
|
||
*
|
||
* @param string $csv string containing the original csv file.
|
||
* @param string $charset optional charset name of file, default is UTF-8
|
||
* @return boolean
|
||
*/
|
||
public function accept_file($csv, $charset = self::DEFAULT_CHARSET)
|
||
{
|
||
$lines = FioCsvParserUtil::transformFileToLineArray($csv, $charset);
|
||
if (count($lines) < 3)
|
||
{
|
||
return FALSE;
|
||
}
|
||
try
|
||
{
|
||
$this->checkHeaders(trim($lines[0]));
|
||
$this->parseHeaderLine(trim($lines[1]));
|
||
return TRUE;
|
||
}
|
||
catch (Exception $ex)
|
||
{
|
||
return FALSE;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Parse statement header line with total sum.
|
||
*
|
||
* @param string $line_str raw CSV line
|
||
*/
|
||
private function parseHeaderLine($line_str)
|
||
{
|
||
$fields_keys = array_keys(self::$fields);
|
||
$columns = $this->parseLine($line_str, $fields_keys, FALSE);
|
||
if ($columns['datum'] != self::HEADER_LINE_DATE_VALUE)
|
||
{
|
||
throw new Exception('Chybná hlavička výpisu.');
|
||
}
|
||
if (empty($columns['castka']))
|
||
{
|
||
throw new Exception('Chybná hlavička výpisu (suma).');
|
||
}
|
||
return $columns['castka'];
|
||
}
|
||
|
||
/**
|
||
* Checks headers that start data part of statement.
|
||
*
|
||
* @param integer $header_line header line
|
||
* @throws Exception
|
||
*/
|
||
private function checkHeaders($header_line)
|
||
{
|
||
$em = __("Nelze parsovat hlavičku Fio výpisu. Ujistěte se, že jste "
|
||
. "zvolili všech " . count(self::$fields) . " sloupců k importu "
|
||
. "v internetovém bankovnictví.");
|
||
$expected_header_cols = array_values(self::$fields);
|
||
// first column has issue with some UTF-8 characters
|
||
$fix_hl = preg_replace('/^[\x00-\x1F\x80-\xFF]+/', '', $header_line);
|
||
// extract header
|
||
$header_cols = str_getcsv($fix_hl, self::CSV_COL_DELIM,
|
||
self::CSV_COL_WRAPPER);
|
||
// check if extracted
|
||
if (empty($header_cols))
|
||
{
|
||
throw new Exception($em);
|
||
}
|
||
// check if count match
|
||
if (count($header_cols) != count($expected_header_cols))
|
||
{
|
||
throw new Exception($em);
|
||
}
|
||
// check each column
|
||
for ($i = count($header_cols) - 1; $i >= 0; $i--)
|
||
{
|
||
if ($header_cols[$i] != $expected_header_cols[$i])
|
||
{
|
||
throw new Exception($em);
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Parse line of dump
|
||
*
|
||
* @param string $line
|
||
* @param array $keys
|
||
* @param boolean $parse_date
|
||
* @return array
|
||
* @throws Exception
|
||
*/
|
||
private function parseLine($line, $keys, $parse_date = TRUE)
|
||
{
|
||
$cols = str_getcsv($line, self::CSV_COL_DELIM, self::CSV_COL_WRAPPER);
|
||
|
||
if (count($cols) != count($keys))
|
||
{
|
||
throw new Exception('Chybný počet políček v položce výpisu.');
|
||
}
|
||
|
||
// Convert to associative array
|
||
$assoc_cols = array_combine($keys, $cols);
|
||
|
||
// Convert date
|
||
if ($parse_date)
|
||
{
|
||
$assoc_cols['datum'] = FioCsvParserUtil::parseDate($assoc_cols['datum']);
|
||
}
|
||
|
||
// Amount has to be converted
|
||
$assoc_cols['castka'] = FioCsvParserUtil::parseAmount($assoc_cols['castka']);
|
||
|
||
// Trim leading zeros from VS
|
||
$assoc_cols['vs'] = ltrim($assoc_cols['vs'], '0');
|
||
|
||
// join both "upresneni"
|
||
$assoc_cols['upresneni'] = trim($assoc_cols['upresneni_objem'] . ' ' .
|
||
$assoc_cols['upresneni_mena']);
|
||
|
||
// column prevod N/A
|
||
$assoc_cols['prevod'] = NULL;
|
||
|
||
return $assoc_cols;
|
||
}
|
||
|
||
/**
|
||
* Checks parsed money amount agains data from integrity line.
|
||
*
|
||
* @param array $sum
|
||
* @param integer $calculated_sum total counted sum
|
||
* @throws Exception on integrity error
|
||
*/
|
||
private function checkIntegrity($sum, $calculated_sum)
|
||
{
|
||
if (abs($sum - $calculated_sum) > 0.0001)
|
||
{
|
||
throw new Exception("Chybný kontrolní součet částky "
|
||
. "('$calculated_sum' != '$sum').");
|
||
}
|
||
}
|
||
|
||
}
|
freenetis/branches/1.2/application/libraries/importers/Fio_Bank_Statement_File_Importer.php | ||
---|---|---|
$statement->bank_account_id = $ba->id;
|
||
$statement->user_id = $this->get_user_id();
|
||
$statement->type = $this->get_importer_name();
|
||
$statement->from = $header->dateStart;
|
||
$statement->to = $header->dateEnd;
|
||
$statement->opening_balance = $header->openingBalance;
|
||
$statement->closing_balance = $header->closingBalance;
|
||
if ($header != NULL)
|
||
{
|
||
$statement->from = $header->dateStart;
|
||
$statement->to = $header->dateEnd;
|
||
$statement->opening_balance = $header->openingBalance;
|
||
$statement->closing_balance = $header->closingBalance;
|
||
}
|
||
$statement->save_throwable();
|
||
|
||
/* transactions */
|
freenetis/branches/1.2/tests/application/libraries/importers/Csv_Fio_Bank_Statement_File_ImporterTest.php | ||
---|---|---|
}
|
||
catch (Exception $ex)
|
||
{}
|
||
|
||
/* Valid test2 with new parser */
|
||
$csv_valid_new = __DIR__ .'/fio_new.it.csv';
|
||
$statement_new = Bank_Statement_File_Importer::import($this->fio_account,
|
||
$csv_valid_new, 'csv', self::USER_ID, FALSE, FALSE);
|
||
$this->assertNotEmpty($statement_new->id);
|
||
$this->assertEquals($this->fio_account->id, $statement_new->bank_account_id);
|
||
$this->assertEmpty($statement_new->opening_balance);
|
||
$this->assertEmpty($statement_new->closing_balance);
|
||
$this->assertEmpty($statement_new->from);
|
||
$this->assertEmpty($statement_new->to);
|
||
$this->assertNotEmpty($statement_new->type);
|
||
$this->assertEquals(1, $statement_new->user_id);
|
||
$this->assertNotEmpty($statement_new->bank_transfers);
|
||
$trans_new = $statement_new->bank_transfers->as_array();
|
||
$this->assertEquals(1, count($trans_new));
|
||
|
||
//// 1 transaction: incoming with invalid VS from account not present
|
||
//// in DB
|
||
$bt1 = $trans_new[0];
|
||
// bank transfer details
|
||
$this->assertEquals('Ing. Jiří Novák - roční členské příspěvky',
|
||
$bt1->comment);
|
||
$this->assertEquals(7150326538, $bt1->transaction_code);
|
||
$this->assertEquals(0, $bt1->number);
|
||
$this->assertEmpty($bt1->constant_symbol);
|
||
$this->assertEquals('774074794', $bt1->variable_symbol);
|
||
$this->assertEmpty($bt1->specific_symbol);
|
||
// origin account (new without assigned member)
|
||
$this->assertEquals('NOVÁK JIŘÍ', $bt1->origin->name);
|
||
$this->assertEquals('7894561678', $bt1->origin->account_nr);
|
||
$this->assertEquals('600', $bt1->origin->bank_nr);
|
||
$this->assertNull($bt1->origin->member_id);
|
||
// destination account is FIO
|
||
$this->assertEquals(self::FIO_ACCOUNT_ID, $bt1->destination_id);
|
||
// transfer is unidentified (MEMBER_FEES -> BANK)
|
||
$this->assertEquals($member_fees->id, $bt1->transfer->origin->id);
|
||
$this->assertEquals($fio_ba->id, $bt1->transfer->destination->id);
|
||
$this->assertNull($bt1->transfer->member_id);
|
||
$this->assertEquals(self::USER_ID, $bt1->transfer->user_id);
|
||
$this->assertNull($bt1->transfer->type);
|
||
$this->assertEquals(strtotime('2015-03-02'),
|
||
strtotime($bt1->transfer->datetime));
|
||
$this->assertNotEmpty($bt1->transfer->creation_datetime);
|
||
$this->assertEquals('Ing. Jiří Novák - roční členské příspěvky',
|
||
$bt1->transfer->text);
|
||
$this->assertEquals(1800.4, $bt1->transfer->amount, '', 0.0001);
|
||
$this->assertNull($bt1->transfer->previous_transfer_id);
|
||
// depend transfers
|
||
$this->assertEmpty(0, $bt1->transfer->get_dependent_transfers()->count());
|
||
}
|
||
|
||
}
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/short.valid.csv | ||
---|---|---|
Výpis vybraných transakcí na účtu "1234567890/2010"
|
||
Majitel účtu: FirmaXY, Ulice 11/12, Město 13, 12345, Česká republika
|
||
Vytvořeno v aplikaci Internetbanking: 16.01.2011 10:29:39
|
||
Období: 16.12.2010 - 1.1.2011
|
||
Počáteční stav účtu k 16.12.2010: 12 345,67 CZK
|
||
Koncový stav účtu k 16.1.2011: 14 456,78 CZK
|
||
Suma příjmů: +2 111,11 CZK
|
||
Suma výdajů: -0,00 CZK
|
||
|
||
Datum;ID pohybu;ID pokynu;Kód banky;KS;Měna;Název banky;Název protiúčtu;Objem;Protiúčet;Provedl;Převod;SS;Typ;Upřesnění;Uživatelská identifikace;VS;Zpráva pro příjemce;
|
||
16.12.2010;1115992591;7848488787;6210;78945;CZK;BRE Bank S.A., organizační složka podniku;int78;2 111,11;670100-2202442842;Emanuel Bacigala;0;7845;Bezhotovostní příjem;G45;DOMINIK BUREŠ;00215;-IRONGATE VS:215;
|
||
Suma;0;;;;;;;2 111,11;;;0;;;;;;;
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/sum.invalid.csv | ||
---|---|---|
Výpis vybraných transakcí na účtu "1234567890/2010"
|
||
Majitel účtu: FirmaXY, Ulice 11/12, Město 13, 12345, Česká republika
|
||
Vytvořeno v aplikaci Internetbanking: 16.01.2011 10:29:39
|
||
Období: 16.12.2010 - 1.1.2011
|
||
Počáteční stav účtu k 16.12.2010: 12 345,67 CZK
|
||
Koncový stav účtu k 16.1.2011: 14 456,78 CZK
|
||
Suma příjmů: +2 111,11 CZK
|
||
Suma výdajů: -0,00 CZK
|
||
|
||
Datum;ID pohybu;ID pokynu;Kód banky;KS;Měna;Název banky;Název protiúčtu;Objem;Protiúčet;Provedl;Převod;SS;Typ;Upřesnění;Uživatelská identifikace;VS;Zpráva pro příjemce;
|
||
16.12.2010;1115992591;7848488787;6210;78945;CZK;BRE Bank S.A., organizační složka podniku;int78;2 111,11;670100-2202442842;Emanuel Bacigala;0;7845;Bezhotovostní příjem;G45;DOMINIK BUREŠ;00215;-IRONGATE VS:215;
|
||
Suma;0;;;;;;;2 111,12;;;0;;;;;;;
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/header.invalid.csv | ||
---|---|---|
Výpis vybraných transakcí na účtu "1234567890/2010"
|
||
Majitel účtu: FirmaXY, Ulice 11/12, Město 13, 12345, Česká republika
|
||
Vytvořeno v aplikaci Internetbanking: 16.01.2011 10:29:39
|
||
Období: 16.12.2010 - 1.1.2011
|
||
Počáteční stav účtu k 16.12.2010: 12 345,67 CZK
|
||
Koncový stav účtu k 16.1.2011: 14 456,78 CZK
|
||
Suma příjmů: +2 111,11 CZK
|
||
Suma výdajů: -0,00 CZK
|
||
|
||
Datum;ID pohybu;Kód banky;KS;Měna;Název banky;Název protiúčtu;Objem;Protiúčet;Provedl;Převod;SS;Typ;Upřesnění;Uživatelská identifikace;VS;Zpráva pro příjemce;
|
||
16.12.2010;11159925916210;78945;CZK;BRE Bank S.A., organizační složka podniku;int78;2 111,11;670100-2202442842;Emanuel Bacigala;0;7845;Bezhotovostní příjem;G45;DOMINIK BUREŠ;00215;-IRONGATE VS:215;
|
||
Suma;0;;;;;;2 111,11;;;0;;;;;;;
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/short.valid.win1250.csv | ||
---|---|---|
V?pis vybran?ch transakc? na ??tu "1234567890/2010"
|
||
Majitel ??tu: FirmaXY, Ulice 11/12, M?sto 13, 12345, ?esk? republika
|
||
Vytvo?eno v aplikaci Internetbanking: 16.01.2011 10:29:39
|
||
Obdob?: 16.12.2010 - 1.1.2011
|
||
Po??te?n? stav ??tu k 16.12.2010: 12 345,67 CZK
|
||
Koncov? stav ??tu k 16.1.2011: 14 456,78 CZK
|
||
Suma p??jm?: +2 111,11 CZK
|
||
Suma v?daj?: -0,00 CZK
|
||
|
||
Datum;ID pohybu;ID pokynu;K?d banky;KS;M?na;N?zev banky;N?zev proti??tu;Objem;Proti??et;Provedl;P?evod;SS;Typ;Up?esn?n?;U?ivatelsk? identifikace;VS;Zpr?va pro p??jemce;
|
||
16.12.2010;1115992591;7848488787;6210;78945;CZK;BRE Bank S.A., organiza?n? slo?ka podniku;int78;2 111,11;670100-2202442842;Emanuel Bacigala;0;7845;Bezhotovostn? p??jem;G45;DOMINIK BURE?;00215;-IRONGATE VS:215;
|
||
Suma;0;;;;;;;2 111,11;;;0;;;;;;;
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/FioCsvParserTest.php | ||
---|---|---|
|
||
/**
|
||
* Unit test for FioCsvParser, files used as test data are located in same
|
||
* folder as test class is.
|
||
* folder as test class is with prefix "FioCsvParserTest_".
|
||
*
|
||
* @author Ondřej Fibich <fibich@freenetis.org>
|
||
* @since 1.2
|
||
... | ... | |
)
|
||
);
|
||
|
||
$content1 = file_get_contents(__DIR__ . '/short.valid.csv');
|
||
$content1 = $this->fgcr('FioCsvParserTest_short.valid.csv');
|
||
$result1 = $this->parser->parse($content1);
|
||
$this->assertEquals('1234567890', $result1->account_nr);
|
||
$this->assertEquals('2010', $result1->bank_nr);
|
||
... | ... | |
$this->assertItemsEquals($exp_result, $result1->items);
|
||
|
||
// same test with different encoding
|
||
$content2 = file_get_contents(__DIR__ . '/short.valid.win1250.csv');
|
||
$content2 = $this->fgcr('FioCsvParserTest_short.valid.win1250.csv');
|
||
$result2 = $this->parser->parse($content2, 'WINDOWS-1250');
|
||
$this->assertEquals('1234567890', $result2->account_nr);
|
||
$this->assertEquals('2010', $result2->bank_nr);
|
||
... | ... | |
{
|
||
try
|
||
{
|
||
$content = file_get_contents(__DIR__ . '/sum.invalid.csv');
|
||
$content = $this->fgcr('FioCsvParserTest_sum.invalid.csv');
|
||
$this->parser->parse($content);
|
||
$this->fail('should fail with exception');
|
||
}
|
||
... | ... | |
{
|
||
try
|
||
{
|
||
$content = file_get_contents(__DIR__ . '/header.invalid.csv');
|
||
$content = $this->fgcr('FioCsvParserTest_header.invalid.csv');
|
||
$this->parser->parse($content);
|
||
$this->fail('should fail with exception');
|
||
}
|
||
... | ... | |
}
|
||
|
||
/**
|
||
* @covers FioCsvParser::parseAmount
|
||
*/
|
||
public function testParseAmount()
|
||
{
|
||
$this->assertEquals(11111.11, FioCsvParser::parseAmount(
|
||
' 1 1 111 , 11 '), '', 0.001);
|
||
$this->assertEquals(2564897645.52, FioCsvParser::parseAmount(
|
||
'2 564 897 645,52'), '', 0.001);
|
||
$this->assertEquals(-2564897645.52, FioCsvParser::parseAmount(
|
||
' - 2 564 897 645.52'), '', 0.001);
|
||
$this->assertEquals(-2564897645, FioCsvParser::parseAmount(
|
||
'-2 564 897 645'), '', 0.001);
|
||
|
||
try {
|
||
FioCsvParser::parseAmount('11,O');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
|
||
try {
|
||
FioCsvParser::parseAmount(' 1 1 1,11 , 11 ');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
|
||
try {
|
||
FioCsvParser::parseAmount('2 564 897 6,45.54');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
|
||
}
|
||
|
||
/**
|
||
* @covers FioCsvParser::parseDate
|
||
*/
|
||
public function testParseDate()
|
||
{
|
||
$this->assertEquals('2014-11-12', FioCsvParser::parseDate('12.11.2014'));
|
||
$this->assertEquals('1999-01-02', FioCsvParser::parseDate('2.1.1999'));
|
||
|
||
try {
|
||
FioCsvParser::parseDate('2.1.199');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
|
||
try {
|
||
FioCsvParser::parseDate('2.111.1999');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
}
|
||
|
||
/**
|
||
* Help function for comparing result items.
|
||
*
|
||
* @param array $exp
|
||
... | ... | |
}
|
||
}
|
||
|
||
private function fgcr($relative_path)
|
||
{
|
||
return file_get_contents(__DIR__ . '/' . $relative_path);
|
||
}
|
||
|
||
}
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/FioCsvParserTest_header.invalid.csv | ||
---|---|---|
Výpis vybraných transakcí na účtu "1234567890/2010"
|
||
Majitel účtu: FirmaXY, Ulice 11/12, Město 13, 12345, Česká republika
|
||
Vytvořeno v aplikaci Internetbanking: 16.01.2011 10:29:39
|
||
Období: 16.12.2010 - 1.1.2011
|
||
Počáteční stav účtu k 16.12.2010: 12 345,67 CZK
|
||
Koncový stav účtu k 16.1.2011: 14 456,78 CZK
|
||
Suma příjmů: +2 111,11 CZK
|
||
Suma výdajů: -0,00 CZK
|
||
|
||
Datum;ID pohybu;Kód banky;KS;Měna;Název banky;Název protiúčtu;Objem;Protiúčet;Provedl;Převod;SS;Typ;Upřesnění;Uživatelská identifikace;VS;Zpráva pro příjemce;
|
||
16.12.2010;11159925916210;78945;CZK;BRE Bank S.A., organizační složka podniku;int78;2 111,11;670100-2202442842;Emanuel Bacigala;0;7845;Bezhotovostní příjem;G45;DOMINIK BUREŠ;00215;-IRONGATE VS:215;
|
||
Suma;0;;;;;;2 111,11;;;0;;;;;;;
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/FioCsvParserTest_short.valid.csv | ||
---|---|---|
Výpis vybraných transakcí na účtu "1234567890/2010"
|
||
Majitel účtu: FirmaXY, Ulice 11/12, Město 13, 12345, Česká republika
|
||
Vytvořeno v aplikaci Internetbanking: 16.01.2011 10:29:39
|
||
Období: 16.12.2010 - 1.1.2011
|
||
Počáteční stav účtu k 16.12.2010: 12 345,67 CZK
|
||
Koncový stav účtu k 16.1.2011: 14 456,78 CZK
|
||
Suma příjmů: +2 111,11 CZK
|
||
Suma výdajů: -0,00 CZK
|
||
|
||
Datum;ID pohybu;ID pokynu;Kód banky;KS;Měna;Název banky;Název protiúčtu;Objem;Protiúčet;Provedl;Převod;SS;Typ;Upřesnění;Uživatelská identifikace;VS;Zpráva pro příjemce;
|
||
16.12.2010;1115992591;7848488787;6210;78945;CZK;BRE Bank S.A., organizační složka podniku;int78;2 111,11;670100-2202442842;Emanuel Bacigala;0;7845;Bezhotovostní příjem;G45;DOMINIK BUREŠ;00215;-IRONGATE VS:215;
|
||
Suma;0;;;;;;;2 111,11;;;0;;;;;;;
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/FioCsvParserTest_short.valid.win1250.csv | ||
---|---|---|
V?pis vybran?ch transakc? na ??tu "1234567890/2010"
|
||
Majitel ??tu: FirmaXY, Ulice 11/12, M?sto 13, 12345, ?esk? republika
|
||
Vytvo?eno v aplikaci Internetbanking: 16.01.2011 10:29:39
|
||
Obdob?: 16.12.2010 - 1.1.2011
|
||
Po??te?n? stav ??tu k 16.12.2010: 12 345,67 CZK
|
||
Koncov? stav ??tu k 16.1.2011: 14 456,78 CZK
|
||
Suma p??jm?: +2 111,11 CZK
|
||
Suma v?daj?: -0,00 CZK
|
||
|
||
Datum;ID pohybu;ID pokynu;K?d banky;KS;M?na;N?zev banky;N?zev proti??tu;Objem;Proti??et;Provedl;P?evod;SS;Typ;Up?esn?n?;U?ivatelsk? identifikace;VS;Zpr?va pro p??jemce;
|
||
16.12.2010;1115992591;7848488787;6210;78945;CZK;BRE Bank S.A., organiza?n? slo?ka podniku;int78;2 111,11;670100-2202442842;Emanuel Bacigala;0;7845;Bezhotovostn? p??jem;G45;DOMINIK BURE?;00215;-IRONGATE VS:215;
|
||
Suma;0;;;;;;;2 111,11;;;0;;;;;;;
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/FioCsvParserTest_sum.invalid.csv | ||
---|---|---|
Výpis vybraných transakcí na účtu "1234567890/2010"
|
||
Majitel účtu: FirmaXY, Ulice 11/12, Město 13, 12345, Česká republika
|
||
Vytvořeno v aplikaci Internetbanking: 16.01.2011 10:29:39
|
||
Období: 16.12.2010 - 1.1.2011
|
||
Počáteční stav účtu k 16.12.2010: 12 345,67 CZK
|
||
Koncový stav účtu k 16.1.2011: 14 456,78 CZK
|
||
Suma příjmů: +2 111,11 CZK
|
||
Suma výdajů: -0,00 CZK
|
||
|
||
Datum;ID pohybu;ID pokynu;Kód banky;KS;Měna;Název banky;Název protiúčtu;Objem;Protiúčet;Provedl;Převod;SS;Typ;Upřesnění;Uživatelská identifikace;VS;Zpráva pro příjemce;
|
||
16.12.2010;1115992591;7848488787;6210;78945;CZK;BRE Bank S.A., organizační složka podniku;int78;2 111,11;670100-2202442842;Emanuel Bacigala;0;7845;Bezhotovostní příjem;G45;DOMINIK BUREŠ;00215;-IRONGATE VS:215;
|
||
Suma;0;;;;;;;2 111,12;;;0;;;;;;;
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/FioCsvParserUtilTest.php | ||
---|---|---|
<?php
|
||
|
||
/*
|
||
* This file is part of open source system FreenetIS
|
||
* and it is released under GPLv3 licence.
|
||
*
|
||
* More info about licence can be found:
|
||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||
*
|
||
* More info about project can be found:
|
||
* http://www.freenetis.org/
|
||
*
|
||
*/
|
||
|
||
require_once APPPATH.'/libraries/importers/Fio/FioCsvParserUtil.php';
|
||
|
||
/**
|
||
* Unit test for FioCsvParserUtil.
|
||
*
|
||
* @author Ondřej Fibich <fibich@freenetis.org>
|
||
* @since 1.2
|
||
*/
|
||
class FioCsvParserUtilTest extends PHPUnit_Framework_TestCase
|
||
{
|
||
|
||
/**
|
||
* @covers FioCsvParserUtil::parseAmount
|
||
*/
|
||
public function testParseAmount()
|
||
{
|
||
$this->assertEquals(11111.11, FioCsvParserUtil::parseAmount(
|
||
' 1 1 111 , 11 '), '', 0.001);
|
||
$this->assertEquals(2564897645.52, FioCsvParserUtil::parseAmount(
|
||
'2 564 897 645,52'), '', 0.001);
|
||
$this->assertEquals(-2564897645.52, FioCsvParserUtil::parseAmount(
|
||
' - 2 564 897 645.52'), '', 0.001);
|
||
$this->assertEquals(-2564897645, FioCsvParserUtil::parseAmount(
|
||
'-2 564 897 645'), '', 0.001);
|
||
|
||
try {
|
||
FioCsvParserUtil::parseAmount('11,O');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
|
||
try {
|
||
FioCsvParserUtil::parseAmount(' 1 1 1,11 , 11 ');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
|
||
try {
|
||
FioCsvParserUtil::parseAmount('2 564 897 6,45.54');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
|
||
}
|
||
|
||
/**
|
||
* @covers FioCsvParserUtil::parseDate
|
||
*/
|
||
public function testParseDate()
|
||
{
|
||
$this->assertEquals('2014-11-12',
|
||
FioCsvParserUtil::parseDate('12.11.2014'));
|
||
$this->assertEquals('1999-01-02',
|
||
FioCsvParserUtil::parseDate('2.1.1999'));
|
||
|
||
try {
|
||
FioCsvParserUtil::parseDate('2.1.199');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
|
||
try {
|
||
FioCsvParserUtil::parseDate('2.111.1999');
|
||
$this->fail('should throw InvalidArgumentException');
|
||
} catch (InvalidArgumentException $ex) {}
|
||
}
|
||
|
||
}
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/NewFioCsvParserTest.php | ||
---|---|---|
<?php
|
||
|
||
/*
|
||
* This file is part of open source system FreenetIS
|
||
* and it is released under GPLv3 licence.
|
||
*
|
||
* More info about licence can be found:
|
||
* http://www.gnu.org/licenses/gpl-3.0.html
|
||
*
|
||
* More info about project can be found:
|
||
* http://www.freenetis.org/
|
||
*
|
||
*/
|
||
|
||
require APPPATH.'/libraries/importers/Fio/NewFioCsvParser.php';
|
||
|
||
/**
|
||
* Unit test for NewFioCsvParser, files used as test data are located in same
|
||
* folder as test class is with prefix "NewFioCsvParserTest_".
|
||
*
|
||
* @author Ondřej Fibich <fibich@freenetis.org>
|
||
* @since 1.2
|
||
*/
|
||
class NewFioCsvParserTest extends PHPUnit_Framework_TestCase
|
||
{
|
||
|
||
/**
|
||
* @var NewFioCsvParser
|
||
*/
|
||
private $parser;
|
||
|
||
protected function setUp()
|
||
{
|
||
$this->parser = new NewFioCsvParser;
|
||
}
|
||
|
||
/**
|
||
* Test for short.valid.csv file.
|
||
*
|
||
* @covers FioCsvParser::parse
|
||
*/
|
||
public function testParseCsvShortValid()
|
||
{
|
||
$exp_result = array
|
||
(
|
||
array
|
||
(
|
||
'datum' => '2015-03-02',
|
||
'id_pohybu' => '7150326538',
|
||
'id_pokynu' => '8005723064',
|
||
'kod_banky' => '600',
|
||
'ks' => '',
|
||
'mena' => 'CZK',
|
||
'nazev_banky' => 'GE Money Bank, a.s.',
|
||
'nazev_protiuctu' => 'NOVÁK JIŘÍ',
|
||
'castka' => 1800.4,
|
||
'protiucet' => '7894561678',
|
||
'provedl' => '',
|
||
'prevod' => '',
|
||
'ss' => '',
|
||
'typ' => 'Bezhotovostní příjem',
|
||
'upresneni' => '1800,4 CZK',
|
||
'identifikace' => 'NOVÁK JIŘÍ',
|
||
'vs' => '774074794',
|
||
'zprava' => 'Ing. Jiří Novák - roční členské příspěvky',
|
||
)
|
||
);
|
||
|
||
$content1 = $this->fgcr('NewFioCsvParserTest_short.valid.csv');
|
||
$this->assertTrue($this->parser->accept_file($content1));
|
||
$result = $this->parser->parse($content1);
|
||
$this->assertEmpty($result->account_nr);
|
||
$this->assertEmpty($result->bank_nr);
|
||
$this->assertEmpty($result->opening_balance);
|
||
$this->assertEmpty($result->closing_balance);
|
||
$this->assertEmpty($result->from);
|
||
$this->assertEmpty($result->to);
|
||
$this->assertItemsEquals($exp_result, $result->items);
|
||
}
|
||
|
||
/**
|
||
* Test for invalid transaction sum.
|
||
*
|
||
* @covers FioCsvParser::parse
|
||
*/
|
||
public function testParseCsvInvalidSum()
|
||
{
|
||
$content = $this->fgcr('NewFioCsvParserTest_sum.invalid.csv');
|
||
$this->assertTrue($this->parser->accept_file($content));
|
||
try
|
||
{
|
||
$this->parser->parse($content);
|
||
$this->fail('should fail with exception');
|
||
}
|
||
catch (Exception $ex) {}
|
||
}
|
||
|
||
/**
|
||
* Test for invalid transaction header.
|
||
*
|
||
* @covers FioCsvParser::parse
|
||
*/
|
||
public function testParseCsvInvalidHeader()
|
||
{
|
||
$content = $this->fgcr('NewFioCsvParserTest_header.invalid.csv');
|
||
$this->assertFalse($this->parser->accept_file($content));
|
||
try
|
||
{
|
||
$this->parser->parse($content);
|
||
$this->fail('should fail with exception');
|
||
}
|
||
catch (Exception $ex) {}
|
||
|
||
$content2 = $this->fgcr('NewFioCsvParserTest_header.invalid2.csv');
|
||
$this->assertFalse($this->parser->accept_file($content2));
|
||
try
|
||
{
|
||
$this->parser->parse($content2);
|
||
$this->fail('should fail with exception');
|
||
}
|
||
catch (Exception $ex) {}
|
||
}
|
||
|
||
/**
|
||
* Help function for comparing result items.
|
||
*
|
||
* @param array $exp
|
||
* @param array $result
|
||
*/
|
||
private function assertItemsEquals($exp, $result)
|
||
{
|
||
$this->assertEquals(count($exp), count($result), 'number of items');
|
||
$fields_indexes = array_keys(FioCsvParser::get_fields());
|
||
for ($i = 0; $i < count($exp); $i++)
|
||
{
|
||
foreach ($fields_indexes as $field_index)
|
||
{
|
||
$this->assertTrue(array_key_exists($field_index, $result[$i]),
|
||
'field ' . $field_index . ' is missing on line ' . $i);
|
||
$this->assertEquals($exp[$i][$field_index], $result[$i][$field_index],
|
||
'field ' . $field_index . ' invalid on line ' . $i);
|
||
}
|
||
}
|
||
}
|
||
|
||
private function fgcr($relative_path)
|
||
{
|
||
return file_get_contents(__DIR__ . '/' . $relative_path);
|
||
}
|
||
|
||
}
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/NewFioCsvParserTest_header.invalid.csv | ||
---|---|---|
"Datum";"ID operace";"ID pokynu";"KS";"Název banky";"Název protiúčtu";"Objem";"Měna";"Protiúčet";"Kód banky";"Zadal";"SS";"Typ";"Poznámka";"VS";"Upřesnění - objem";"Upřesnění - měna";"Zpráva pro příjemce"
|
||
"Sum";"";"";"";"";"";"1800,4";"CZK";"";"";"";"";"";"";"";"";"";""
|
||
"02.03.2015";"7150326538";"8005723064";"";"GE Money Bank, a.s.";"NOVÁK JIŘÍ";"1800,4";"CZK";"7894561678";"600";"";"";"Bezhotovostní příjem";"NOVÁK JIŘÍ";"774074794";"1800";"4";"CZK";"Ing. Jiří Novák - roční členské příspěvky"
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/NewFioCsvParserTest_header.invalid2.csv | ||
---|---|---|
"Datum";"ID soperace";"ID pokynu";"KS";"Název banky";"Název protiúčtu";"Objem";"Měna";"Protiúčet";"Kód banky";"Zadal";"SS";"Typ";"Poznámka";"VS";"Upřesnění - objem";"Upřesnění - měna";"Zpráva pro příjemce"
|
||
"Suma";"";"";"";"";"";"1800,4";"CZK";"";"";"";"";"";"";"";"";"";""
|
||
"02.03.2015";"7150326538";"8005723064";"";"GE Money Bank, a.s.";"NOVÁK JIŘÍ";"1800,4";"CZK";"7894561678";"600";"";"";"Bezhotovostní příjem";"NOVÁK JIŘÍ";"774074794";"1800";"4";"CZK";"Ing. Jiří Novák - roční členské příspěvky"
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/NewFioCsvParserTest_short.valid.csv | ||
---|---|---|
"Datum";"ID operace";"ID pokynu";"KS";"Název banky";"Název protiúčtu";"Objem";"Měna";"Protiúčet";"Kód banky";"Zadal";"SS";"Typ";"Poznámka";"VS";"Upřesnění - objem";"Upřesnění - měna";"Zpráva pro příjemce"
|
||
"Suma";"";"";"";"";"";"1800,4";"CZK";"";"";"";"";"";"";"";"";"";""
|
||
"02.03.2015";"7150326538";"8005723064";"";"GE Money Bank, a.s.";"NOVÁK JIŘÍ";"1800,4";"CZK";"7894561678";"600";"";"";"Bezhotovostní příjem";"NOVÁK JIŘÍ";"774074794";"1800,4";"CZK";"Ing. Jiří Novák - roční členské příspěvky"
|
freenetis/branches/1.2/tests/application/libraries/importers/Fio/NewFioCsvParserTest_sum.invalid.csv | ||
---|---|---|
"Datum";"ID operace";"ID pokynu";"KS";"Název banky";"Název protiúčtu";"Objem";"Měna";"Protiúčet";"Kód banky";"Zadal";"SS";"Typ";"Poznámka";"VS";"Upřesnění - objem";"Upřesnění - měna";"Zpráva pro příjemce"
|
||
"Suma";"";"";"";"";"";"1800,3";"CZK";"";"";"";"";"";"";"";"";"";""
|
||
"02.03.2015";"7150326538";"8005723064";"";"GE Money Bank, a.s.";"NOVÁK JIŘÍ";"1800,4";"CZK";"7894561678";"600";"";"";"Bezhotovostní příjem";"NOVÁK JIŘÍ";"774074794";"1800,4";"CZK";"Ing. Jiří Novák - roční členské příspěvky"
|
freenetis/branches/1.2/tests/application/libraries/importers/fio_new.it.csv | ||
---|---|---|
"Datum";"ID operace";"ID pokynu";"KS";"Název banky";"Název protiúčtu";"Objem";"Měna";"Protiúčet";"Kód banky";"Zadal";"SS";"Typ";"Poznámka";"VS";"Upřesnění - objem";"Upřesnění - měna";"Zpráva pro příjemce"
|
||
"Suma";"";"";"";"";"";"1800,4";"CZK";"";"";"";"";"";"";"";"";"";""
|
||
"02.03.2015";"7150326538";"8005723064";"";"GE Money Bank, a.s.";"NOVÁK JIŘÍ";"1800,4";"CZK";"7894561678";"600";"";"";"Bezhotovostní příjem";"NOVÁK JIŘÍ";"774074794";"1800,4";"CZK";"Ing. Jiří Novák - roční členské příspěvky"
|
Také k dispozici: Unified diff
Novinky: refs 982: Novy parser pro FIO CSV + integracni testy
Upravy:
- Osamostatnena utility trida pro CSV FIO parsery a trida pro vysledek parsovani
- Importovany bankovni vypis nemusi vracet hlavicku
- Restrukturalizace testovacich souboru pro integracni testy FIO parseru