Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 59ac513c

Přidáno uživatelem David Raška před asi 9 roky(ů)

Fixes in Tatrabanka importer for working with different formats of e-mail statements

Zobrazit rozdíly:

application/libraries/importers/Tatra_Banka_Statement_File_Importer.php
{
$counter_ba->clear();
$counter_ba->set_logger(FALSE);
$counter_ba->name = $item['counter_account'].'/'.$item['counter_bank'];
$counter_ba->account_nr = $item['counter_account'];
$counter_ba->name = self::remove_zeros($item['counter_account']).'/'.$item['counter_bank'];
$counter_ba->account_nr = self::remove_zeros($item['counter_account']);
$counter_ba->bank_nr = $item['counter_bank'];
$counter_ba->member_id = NULL;
$counter_ba->save_throwable();
......
$bt->bank_statement_id = $statement->id;
$bt->transaction_code = NULL;
$bt->number = $number;
$bt->constant_symbol = $item['ks'];
$bt->variable_symbol = $item['vs'];
$bt->specific_symbol = $item['ss'];
$bt->constant_symbol = self::remove_zeros($item['ks']);
$bt->variable_symbol = self::remove_zeros($item['vs']);
$bt->specific_symbol = self::remove_zeros($item['ss']);
$bt->save();
// assign transfer? (0 - invalid id, 1 - assoc id, other are ordinary members)
......
return NULL;
}
}
/**
* Removes zeros on beginning of string (symbols or account)
*
* @param $value
* @return string
*/
protected static function remove_zeros($value)
{
$count = preg_match('@[0-]*(\d+-?\d+)@', $value, $result);
return ($count == 1 ? $result[1] : $value);
}
}
application/libraries/importers/Txt_Tatra_Banka_Statement_File_Importer.php
// Counter account
const REGEX_CA = "@ (\d{4})/([\d-]+)@";
// Variable, specific, constant symbol
const REGEX_SYMBOLS = "@/VS(\d*)/SS(\d*)/KS(\d*)@";
const REGEX_VS = "@VS ?(\d*)@";
const REGEX_SS = "@SS ?(\d*)@";
const REGEX_CS = "@KS ?(\d*)@";
// Current balance
const REGEX_BALANCE = "@aktualny zostatok: (\d+,\d{2}) (.+)@";
const REGEX_BALANCE = "@aktualny zostatok:[^0-9]*(\d+,\d{2}) (.+)@";
protected function check_file_data_format()
......
$emails = implode('', $this->get_file_data());
// Date, account, amount
$match_data = preg_match_all(self::REGEX_DATA,
$emails,
$m1);
// Counter account
$match_counter = preg_match_all(self::REGEX_CA,
$emails,
$m2);
$match_data = preg_match_all(self::REGEX_DATA, $emails, $data);
// Variable, specific, constant symbol
$match_symbols = preg_match_all(self::REGEX_SYMBOLS,
$emails,
$m3);
$match_vs = preg_match_all(self::REGEX_VS, $emails, $vs);
$match_ss = preg_match_all(self::REGEX_SS, $emails, $ss);
$match_cs = preg_match_all(self::REGEX_CS, $emails, $cs);
$accounts = array();
foreach ($m1[2] as $e)
foreach ($data[2] as $e)
{
$accounts[] = $e;
}
......
$this->add_error(__('E-mails contains more than one destination account: %s', implode(', ', array_unique($accounts))), FALSE);
}
return ($match_data == $match_symbols) && ($match_symbols == $match_counter) && count(array_unique($accounts)) <= 1;
return $match_data == $match_vs &&
$match_vs == $match_ss &&
$match_ss == $match_cs &&
count(array_unique($accounts)) <= 1;
}
protected function get_header_data()
......
{
$match_data = preg_match(self::REGEX_DATA,
$email,
$m1);
$data);
preg_match(self::REGEX_CA,
$email,
$ca);
$match_counter = preg_match(self::REGEX_CA,
$match_vs = preg_match(self::REGEX_VS,
$email,
$m2);
$vs);
$match_symbols = preg_match(self::REGEX_SYMBOLS,
$match_ss = preg_match(self::REGEX_SS,
$email,
$m3);
$ss);
if (!$match_data || !$match_symbols || !$match_counter)
$match_cs = preg_match(self::REGEX_CS,
$email,
$cs);
if (!$match_data || !$match_vs || !$match_ss || !$match_cs)
{
continue;
}
$this->data[] = array(
'datetime' => DateTime::createFromFormat('j.n.Y G:i', $m1[1])->format('Y-m-d H:i:s'),
'iban' => $m1[2],
'bank' => $m1[3],
'account' => $m1[4],
'amount' => floatval(str_replace(',', '.', $m1[5])),
'counter_account'=> $m2[2],
'counter_bank' => $m2[1],
'currency' => $m1[6],
'vs' => $m3[1],
'ss' => $m3[2],
'ks' => $m3[3]
'datetime' => DateTime::createFromFormat('j.n.Y G:i', $data[1])->format('Y-m-d H:i:s'),
'iban' => $data[2],
'bank' => $data[3],
'account' => $data[4],
'amount' => floatval(str_replace(',', '.', $data[5])),
'counter_account'=> @$ca[2],
'counter_bank' => @$ca[1],
'currency' => $data[6],
'vs' => $vs[1],
'ss' => $ss[1],
'ks' => $cs[1]
);
}
......
preg_match(self::REGEX_DATA,
$body,
$m1);
$data);
preg_match(self::REGEX_CA,
preg_match(self::REGEX_VS,
$body,
$m2);
$vs);
preg_match(self::REGEX_SYMBOLS,
preg_match(self::REGEX_SS,
$body,
$m3);
$ss);
preg_match(self::REGEX_CS,
$body,
$cs);
if (!$m1 || !$m2 || !$m3)
if (!$data || !$vs || !$ss || !$cs)
{
continue;
}

Také k dispozici: Unified diff