Revize 1246
Přidáno uživatelem Jiří Sviták před asi 13 roky(ů)
freenetis/branches/testing/application/models/bank_transfer.php | ||
---|---|---|
", array($data->date_time, $data->comment));
|
||
}
|
||
|
||
/**
|
||
* Checks duplicities by comparing given transaction codes and
|
||
* searching them in the database. Successful search means duplicity.
|
||
* Used in Fio importer.
|
||
* @author Jiri Svitak
|
||
* @param <type> $transaction_codes
|
||
*/
|
||
public function get_transaction_code_duplicities($transaction_codes)
|
||
{
|
||
$duplicities = $this->db->query("
|
||
SELECT *
|
||
FROM bank_transfers
|
||
WHERE transaction_code IN (" . implode(",", $transaction_codes) . ")
|
||
");
|
||
$duplicate_transaction_codes = array();
|
||
foreach ($duplicities as $duplicity)
|
||
{
|
||
$duplicate_transaction_codes[] = $duplicity->transaction_code;
|
||
}
|
||
return $duplicate_transaction_codes;
|
||
}
|
||
|
||
}
|
freenetis/branches/testing/application/controllers/import.php | ||
---|---|---|
require_once APPPATH."libraries/importers/Fio/FioImport.php";
|
||
require_once APPPATH."libraries/importers/Fio/FioSaver.php";
|
||
|
||
class Statistics
|
||
{
|
||
|
||
public function __get($var)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* Handles importing of all types of bank listings into the database.
|
||
*
|
||
... | ... | |
*/
|
||
class Import_Controller extends Controller
|
||
{
|
||
// static constants of bank listing types
|
||
// static constants of supported bank listing types
|
||
const HTML_RAIFFEISENBANK = 1;
|
||
const CSV_FIO = 2;
|
||
const CSV_POSTOVNI_SPORITELNA = 3;
|
||
|
||
private static $types = array();
|
||
|
||
... | ... | |
*/
|
||
private function import_fio($bank_account_id, $file_url)
|
||
{
|
||
$ba = new Bank_account_Model($bank_account_id);
|
||
// parse bank listing items
|
||
$data = FioImport::getDataFromFile($file_url);
|
||
// check validity of bank listing
|
||
$header = FioImport::getListingHeader();
|
||
|
||
$ba = new Bank_account_Model($bank_account_id);
|
||
|
||
if ($ba->account_nr != $header["account_nr"] &&
|
||
$ba->bank_nr != $header["bank_nr"])
|
||
{
|
||
$ba_nr = $ba->account_nr."/".$ba->bank_nr;
|
||
$listing_ba_nr = $header["account_nr"]."/".$header["bank_nr"];
|
||
|
||
throw new FioException(__(
|
||
"Bank account number in listing (%s) header does not match " .
|
||
"bank account %s in database!", array($listing_ba_nr, $ba_nr)
|
||
));
|
||
}
|
||
try
|
||
{
|
||
$db = new Transfer_Model();
|
||
$db->transaction_start();
|
||
|
||
$ba = new Bank_account_Model($bank_account_id);
|
||
// parse bank listing items
|
||
$data = FioImport::getDataFromFile($file_url);
|
||
// check validity of bank listing
|
||
$header = FioImport::getListingHeader();
|
||
|
||
$ba = new Bank_account_Model($bank_account_id);
|
||
|
||
if ($ba->account_nr != $header["account_nr"] &&
|
||
$ba->bank_nr != $header["bank_nr"])
|
||
{
|
||
$ba_nr = $ba->account_nr."/".$ba->bank_nr;
|
||
$listing_ba_nr = $header["account_nr"]."/".$header["bank_nr"];
|
||
|
||
throw new FioException(__(
|
||
"Bank account number in listing (%s) header does not match " .
|
||
"bank account %s in database!", array($listing_ba_nr, $ba_nr)
|
||
));
|
||
}
|
||
|
||
// save bank statement
|
||
$statement = new Bank_statement_Model();
|
||
$statement->set_logger(FALSE);
|
||
... | ... | |
catch (FioException $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
status::error($e->getMessage());
|
||
status::error(__('Import has failed.') . ' ' .
|
||
$e->getMessage(),
|
||
FALSE
|
||
);
|
||
url::redirect(url_lang::base() . 'bank_accounts/show_all');
|
||
}
|
||
catch (Duplicity_Exception $e)
|
||
... | ... | |
$db->transaction_rollback();
|
||
status::error(
|
||
__('Import has failed.') . ' ' .
|
||
__('Bank statement contains items that were already imported.'),
|
||
__('Bank statement contains items that were already imported.') . ' ' .
|
||
$e->getMessage(),
|
||
FALSE
|
||
);
|
||
url::redirect(url_lang::base() . 'bank_accounts/show_all');
|
||
... | ... | |
|
||
$db->transaction_commit();
|
||
}
|
||
catch (RB_Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
status::error(__('Import has failed.') . ' ' .
|
||
$e->getMessage(),
|
||
FALSE
|
||
);
|
||
url::redirect(url_lang::base() . 'bank_accounts/show_all');
|
||
}
|
||
catch (Duplicity_Exception $e)
|
||
{
|
||
$db->transaction_rollback();
|
||
status::error(
|
||
__('Import has failed.') . ' ' .
|
||
__('Bank statement contains items that were already imported.'),
|
||
__('Bank statement contains items that were already imported.') . ' ' .
|
||
$e->getMessage(),
|
||
FALSE
|
||
);
|
||
url::redirect(url_lang::base() . 'bank_accounts/show_all');
|
||
... | ... | |
{
|
||
$db->transaction_rollback();
|
||
status::error(
|
||
__('Import has failed') . '.<br>' . $e->getMessage(),
|
||
__('Import has failed') . '.<br>' . $e->getMessage() . ' '.
|
||
$e->getMessage(),
|
||
FALSE
|
||
);
|
||
url::redirect(url_lang::base() . 'bank_accounts/show_all');
|
freenetis/branches/testing/application/libraries/exceptions/Duplicity_Exception.php | ||
---|---|---|
<?php defined('SYSPATH') or die('No direct script access.');
|
||
/*
|
||
* 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/
|
||
*
|
||
*/
|
||
|
||
/**
|
||
* Duplicity exception is thrown during bank statement import when
|
||
* some transfers are already imported in database.
|
||
*
|
||
* @author Jiri Svitak
|
||
*/
|
||
class Duplicity_Exception extends Exception
|
||
{
|
||
|
||
}
|
freenetis/branches/testing/application/libraries/importers/Raiffeisenbank/Parser_Ebanka.php | ||
---|---|---|
*/
|
||
|
||
require_once 'Parser_Html_Table.php';
|
||
require_once dirname(__FILE__) . '/RB_Importer.php';
|
||
require_once 'RB_Importer.php';
|
||
require_once 'RB_Exception.php';
|
||
|
||
/**
|
||
* Parser_Ebanka is a parser for getting data from bank account transaction listing
|
||
... | ... | |
|
||
if ($pos === false)
|
||
{
|
||
die("Nemůžu najít první znak '.' v řetězci ' za [období] ...'");
|
||
throw new RB_Exception("Nemůžu najít první znak '.' v řetězci ' za [období] ...'");
|
||
}
|
||
|
||
$toPos = substr($this->buffer, 0, $pos);
|
||
... | ... | |
while (($czPos = stripos($this->buffer, "CZ")) === false &&
|
||
$this->get_line()); // hledej lomítko
|
||
if ($czPos === false)
|
||
die("Nemůžu najít 'CZ' v IBAN čísle účtu'");
|
||
{
|
||
throw new RB_Exception("Nemůžu najít 'CZ' v IBAN čísle účtu");
|
||
}
|
||
else
|
||
{
|
||
$this->result->parsed_acc_bank_nr = substr($this->buffer, $czPos + 4, 4);
|
||
... | ... | |
$res = $this->result;
|
||
$first = true;
|
||
$line_nr = 0;
|
||
$rb_importer = new RB_Importer();
|
||
|
||
do
|
||
{
|
||
... | ... | |
$res->number = $line_nr;
|
||
|
||
//ted uz muzeme ulozit ziskane data do databaze:
|
||
if (isset($this->callback))
|
||
call_user_func($this->callback, $res);
|
||
|
||
//if (isset($this->callback))
|
||
// call_user_func($this->callback, $res);
|
||
$rb_importer->store_transfer_ebanka($res);
|
||
|
||
break;
|
||
} // switch
|
||
} // for
|
||
... | ... | |
{
|
||
ob_flush();
|
||
flush();
|
||
trigger_error("Parser error: " .
|
||
throw new RB_Exception("Parser error: " .
|
||
"očekával jsem číslo výpisu, ale dostal jsem:<br/>\n" . $field .
|
||
"<br/> \nPoslední správně načtený řádek výpisu má číslo " . $res->number .
|
||
"<br/> \nCelý vstupní buffer je: <br/>\n" . htmlentities($this->buffer)
|
||
... | ... | |
|
||
if (count($arr) < 2)
|
||
{
|
||
trigger_error("Parser error: " .
|
||
throw new RB_Exception("Parser error: " .
|
||
"očekávám datum/čas jako dd.mm.<br>hh:mm ale dostal jsem:<br/>\n" . $field .
|
||
"<br/> \nPoslední správně načtený řádek výpisu má číslo " . $res->number .
|
||
"<br/> \nCelý vstupní buffer je: <br/>\n" . htmlentities($this->buffer), E_USER_ERROR);
|
||
... | ... | |
{
|
||
$arrDate = explode(".", $arr[0]);
|
||
if (count($arrDate) < 2)
|
||
trigger_error("Parser error: " .
|
||
throw new RB_Exception("Parser error: " .
|
||
"očekávám datum jako dd.mm. ale dostal jsem:<br/>\n" . $arr[0] .
|
||
"<br/> \nPoslední správně načtený řádek výpisu má číslo " . $res->number .
|
||
"<br/> \nCelý vstupní buffer je: <br/>\n" . htmlentities($this->buffer), E_USER_ERROR);
|
||
... | ... | |
// chyba (toto by nikdy nemělo nastat)
|
||
if ($found == 2)
|
||
{
|
||
trigger_error("Nemohu najít začátek tabulky: '" . self::START_STRING . "'");
|
||
throw new RB_Exception("Nemohu najít začátek tabulky: '" . self::START_STRING . "'");
|
||
}
|
||
// našel jsem START_STRING => číslo účtu nemám, konec switch-e
|
||
else if ($found == 1)
|
||
... | ... | |
// chyba (toto by nikdy nemělo nastat)
|
||
if ($found === false)
|
||
{
|
||
trigger_error("Nemohu najít začátek tabulky: '" . self::START_STRING . "'");
|
||
throw new RB_Exception("Nemohu najít začátek tabulky: '" . self::START_STRING . "'");
|
||
}
|
||
break;
|
||
|
||
... | ... | |
break;
|
||
|
||
case 3:
|
||
trigger_error("Nemohu najít začátek tabulky nebo datum/rok");
|
||
throw new RB_Exception("Nemohu najít začátek tabulky nebo datum/rok");
|
||
break;
|
||
};
|
||
|
freenetis/branches/testing/application/libraries/importers/Raiffeisenbank/RB_Statistics.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/
|
||
*
|
||
*/
|
||
|
||
class RB_Statistics {}
|
||
?>
|
freenetis/branches/testing/application/libraries/importers/Raiffeisenbank/RB_Exception.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/
|
||
*
|
||
*/
|
||
|
||
/**
|
||
* Raiffeisen bank importer exception
|
||
* @author Jiri Svitak
|
||
*/
|
||
class RB_Exception extends Exception {}
|
||
|
||
?>
|
freenetis/branches/testing/application/libraries/importers/Raiffeisenbank/RB_Importer.php | ||
---|---|---|
*
|
||
*/
|
||
|
||
require_once "RB_Statistics.php";
|
||
require_once APPPATH."libraries/importers/Duplicity_Exception.php";
|
||
|
||
/**
|
||
* Raiffaisenbank importer
|
||
* Raiffeisenbank importer, saves listing items into Freenetis database
|
||
*/
|
||
class RB_Importer
|
||
{
|
||
... | ... | |
|
||
if ($first_pass)
|
||
{ // dostavame prvni radek vypisu?
|
||
$this->stats = new Statistics();
|
||
$this->stats = new RB_Statistics();
|
||
$this->time_now = date("Y-m-d H:i:s");
|
||
$member_model = new Member_Model(); // vytvorime vsechny instance, ktere potrebujeme i pro dalsi radky
|
||
$acc_model = new Account_Model();
|
||
... | ... | |
|
||
}
|
||
|
||
class RB_Exception extends Exception {}
|
freenetis/branches/testing/application/libraries/importers/Duplicity_Exception.php | ||
---|---|---|
<?php defined('SYSPATH') or die('No direct script access.');
|
||
/*
|
||
* 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/
|
||
*
|
||
*/
|
||
|
||
/**
|
||
* Duplicity exception is thrown during bank statement import when
|
||
* some transfers are already imported in database.
|
||
*
|
||
* @author Jiri Svitak
|
||
*/
|
||
class Duplicity_Exception extends Exception {}
|
freenetis/branches/testing/application/libraries/importers/Fio/FioParser.php | ||
---|---|---|
*
|
||
*/
|
||
|
||
require_once "FioException.php";
|
||
|
||
/**
|
||
* Auxiliary class for parsing CSV bank account listings from czech bank "FIO banka".
|
||
* The CSV listings are downloaded from the ebanking web application.
|
||
... | ... | |
if ($number == 0)
|
||
{
|
||
$line_arr = explode('"', $line);
|
||
if (count($line_arr) < 2)
|
||
{
|
||
throw new FioException("Nemohu najít číslo účtu na prvním řádku.");
|
||
}
|
||
self::$acc_nr = $line_arr[1];
|
||
}
|
||
// 4th line, account date from and date to
|
||
if ($number == 3)
|
||
{
|
||
$line_arr = explode(":", $line);
|
||
if (count($line_arr) < 2)
|
||
{
|
||
throw new FioException("Nemohu najít datum od a do na čtvrtém řádku.");
|
||
}
|
||
$dates = explode("-", $line_arr[1]);
|
||
if (count($dates) < 2)
|
||
{
|
||
throw new FioException("Nemohu najít oddělovač dat od a do na čtvrtém řádku.");
|
||
}
|
||
$from_arr = explode(".", $dates[0]);
|
||
if (count($from_arr) < 3)
|
||
{
|
||
throw new FioException("Chybný formát datumu od na čtvrtém řádku.");
|
||
}
|
||
$from_timestamp = mktime(0, 0, 0, intval($from_arr[1]), intval($from_arr[0]), intval($from_arr[2]));
|
||
self::$from = date("Y-m-d", $from_timestamp);
|
||
$to_arr = explode(".", $dates[1]);
|
||
if (count($to_arr) < 3)
|
||
{
|
||
throw new FioException("Chybný formát datumu do na čtvrtém řádku.");
|
||
}
|
||
$to_timestamp = mktime(0, 0, 0, intval($to_arr[1]), intval($to_arr[0]), intval($to_arr[2]));
|
||
self::$to = date("Y-m-d", $to_timestamp);
|
||
}
|
||
... | ... | |
if ($number == 4)
|
||
{
|
||
$line_arr = explode(":", $line);
|
||
if (count($line_arr) < 2)
|
||
{
|
||
throw new FioException("Nemohu najít počáteční zůstatek.");
|
||
}
|
||
self::$opening_balance = self::normalizeAmount(str_replace("CZK", "", $line_arr[1])) / 100;
|
||
}
|
||
// 6th line, closing balance
|
||
if ($number == 5)
|
||
{
|
||
$line_arr = explode(":", $line);
|
||
if (count($line_arr) < 2)
|
||
{
|
||
throw new FioException("Nemohu najít konečný zůstatek.");
|
||
}
|
||
self::$closing_balance = self::normalizeAmount(str_replace("CZK", "", $line_arr[1])) / 100;
|
||
}
|
||
// 10th line, checking column header names and count
|
||
... | ... | |
$number++;
|
||
}
|
||
|
||
throw new FioException('The CSV file is incomplete!');
|
||
throw new FioException('CSV soubor není kompletní.');
|
||
}
|
||
|
||
/**
|
||
... | ... | |
{
|
||
$expected = implode(';', self::$fields) . ';';
|
||
if ($line != $expected)
|
||
throw new FioException(__("Cannot parse Fio listing header!"));
|
||
throw new FioException(__("Nelze parsovat hlavičku Fio výpisu."));
|
||
}
|
||
|
||
/**
|
||
... | ... | |
$amount = str_replace(",", "", $amount);
|
||
|
||
if (!is_numeric($amount))
|
||
throw new FioException('Invalid amount format.');
|
||
throw new FioException('Chybný formát částky převodu.');
|
||
|
||
return doubleval($amount);
|
||
}
|
||
... | ... | |
$cols = explode(';', $line);
|
||
|
||
if (count($cols) != count(self::$fields) + 1)
|
||
throw new FioException('Invalid number of fields.');
|
||
throw new FioException('Chybný počet políček v položce.');
|
||
|
||
array_pop($cols);
|
||
|
||
... | ... | |
$amount = $cols['castka'];
|
||
|
||
if ($sum != $amount)
|
||
throw new FioException("Invalid checksum ('$sum' != '$amount').");
|
||
throw new FioException("Chybný kontrolní součet částky ('$sum' != '$amount').");
|
||
}
|
||
|
||
}
|
freenetis/branches/testing/application/libraries/importers/Fio/FioException.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/
|
||
*
|
||
*/
|
||
|
||
/**
|
||
* Fio importer exception
|
||
* @author Jiri Svitak
|
||
*/
|
||
class FioException extends Exception {}
|
||
|
||
?>
|
freenetis/branches/testing/application/libraries/importers/Fio/FioSaver.php | ||
---|---|---|
$now = date("Y-m-d H:i:s");
|
||
$number = 0;
|
||
|
||
// imported transaction codes, to check duplicities
|
||
$transaction_codes = array();
|
||
|
||
// saving each bank listing item
|
||
foreach ($data as $item)
|
||
{
|
||
... | ... | |
|
||
}
|
||
|
||
// add item transaction code to array to check duplicities later
|
||
$transaction_codes[] = $item["id_pohybu"];
|
||
|
||
// line number increase
|
||
$number++;
|
||
}
|
||
|
||
// let's check duplicities
|
||
$duplicities = $bt->get_transaction_code_duplicities($transaction_codes);
|
||
if (count($duplicities) > count($transaction_codes))
|
||
{
|
||
//$filtered_duplicities = array_diff($duplicities, $transaction_codes);
|
||
throw new Duplicity_Exception();
|
||
}
|
||
|
||
return $stats;
|
||
}
|
||
|
freenetis/branches/testing/application/libraries/importers/Fio/FioImport.php | ||
---|---|---|
*
|
||
*/
|
||
|
||
require_once dirname(__FILE__).'/FioConfig.php';
|
||
require_once dirname(__FILE__).'/FioConnection.php';
|
||
require_once dirname(__FILE__).'/FioParser.php';
|
||
require_once 'FioConfig.php';
|
||
require_once 'FioConnection.php';
|
||
require_once 'FioParser.php';
|
||
|
||
/**
|
||
* Main class for parsing bank account listings from czech bank "FIO banka".
|
||
... | ... | |
}
|
||
}
|
||
|
||
class FioException extends Exception {}
|
Také k dispozici: Unified diff
Bankovni importery - rozsireni systemu vyjimek, pridana kontrola duplicit u Fio vypisu. Restrukturalizace a ladeni.