Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2a3378d9

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

Downloading only newest statements from e-mail

Zobrazit rozdíly:

application/libraries/importers/Tatra_Banka_Statement_File_Importer.php
*/
abstract class Tatra_Banka_Statement_File_Importer extends Bank_Statement_File_Importer
{
protected $data;
const LAST_DOWNLOAD_SETTINGS_KEY = 'tatrabanka_email_last_download';
protected $data = array();
protected $last_download_datetime;
protected function store(&$stats = array())
{
......
$statement->bank_account_id = $ba->id;
$statement->user_id = $this->get_user_id();
$statement->type = $this->get_importer_name();
$statement->from = $header->from;
$statement->to = $header->to;
$statement->closing_balance = $header->closingBalance;
if ($header != NULL)
{
$statement->from = $header->from;
$statement->to = $header->to;
$statement->closing_balance = $header->closingBalance;
}
$statement->save_throwable();
/* transactions */
......
throw new Duplicity_Exception($dm);
}
Settings::set(self::LAST_DOWNLOAD_SETTINGS_KEY, $this->last_download_datetime);
// done
$statement->transaction_commit();
application/libraries/importers/Txt_Tatra_Banka_Statement_File_Importer.php
$accounts[] = $e;
}
return ($match_data == $match_symbols) && ($match_symbols == $match_counter) && count(array_unique($accounts)) == 1;
if (count(array_unique($accounts)) > 1)
{
$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;
}
protected function get_header_data()
{
$emails = $this->get_file_data();
unset ($emails[self::LAST_DOWNLOAD_SETTINGS_KEY]);
if (count($emails) == 0)
{
return NULL;
}
// Newest e-mail
preg_match("@(\d{1,2}\.\d{1,2}\.\d{4} \d{1,2}:\d{2}).+(\w{2}\d{2}(\d{4})(\d{16})).* (\d+,\d{2}) (.+)\.@",
$emails[0],
......
{
$emails = $this->get_file_data();
$this->last_download_datetime = $emails[self::LAST_DOWNLOAD_SETTINGS_KEY];
foreach ($emails as $email)
{
$match_data = preg_match("@(\d{1,2}\.\d{1,2}\.\d{4} \d{1,2}:\d{2}).+(\w{2}\d{2}(\d{4})(\d{16})).* (\d+,\d{2}) (.+)\.@",
......
protected function do_download(Bank_account_Model $bank_account,
Bank_Account_Settings $settings, $url)
{
$last_download = Settings::get(self::LAST_DOWNLOAD_SETTINGS_KEY);
if (empty($last_download))
{
$last_download = 0;
}
$hostname = $settings->get_download_statement_url();
$inbox = @imap_open($hostname, $settings->imap_name, $settings->imap_password, OP_READONLY);
......
$emails = imap_search($inbox, 'ALL');
$first = TRUE;
$all_mails[self::LAST_DOWNLOAD_SETTINGS_KEY] = 0;
if ($emails)
{
// Sort from newest mail
rsort($emails);
foreach ($emails as $email_number)
{
$struct = imap_fetchstructure($inbox, $email_number);
$header = imap_headerinfo($inbox, $email_number);
if ($first)
{
$all_mails[self::LAST_DOWNLOAD_SETTINGS_KEY] = $header->udate;
$first = FALSE;
}
if ($header->udate <= $last_download)
{
continue;
}
$body = imap_fetchbody($inbox,$email_number, 1);

Také k dispozici: Unified diff