FreenetIS
 All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
Bank_Statement_File_Importer Class Reference

Subclass for all bank statements importers of new generation (since 1.1). More...

Inheritance diagram for Bank_Statement_File_Importer:
Fio_Bank_Statement_File_Importer Tatra_Banka_Statement_File_Importer Csv_Fio_Bank_Statement_File_Importer Json_Fio_Bank_Statement_File_Importer Txt_Tatra_Banka_Statement_File_Importer

Public Member Functions

 get_importer_name ()
 Get importer name.

Static Public Member Functions

static get_drivers ()
 Gets available drivers.
static download (Bank_account_Model $bank_account, Bank_Account_Settings $settings, $send_emails, $send_sms)
 Tries to download statement and then import it.
static import (Bank_account_Model $bank_account, $filename, $ext, $send_emails=TRUE, $send_sms=FALSE)
 Imports a bank statement placed in a file that is given by the filename to bank account that is given by its database model.

Public Attributes

const DIR = 'importers'
 Dir with driver classes.

Protected Member Functions

 __construct (Bank_account_Model $bam)
 Creates new instance od bank statement import.
 get_user_id ()
 User ID of caller of this importer.
 get_bank_account ()
 Gets bank account for which the importer is evaulating imports.
 set_file_data ($fd)
 Sets bank statement file data (content of a file)
 get_file_data ()
 Gets bank statement file data (content of a file)
 add_error ($error, $translate=TRUE)
 Adds given error to the start of the error stack.
 add_exception_error (Exception $e, $translate=TRUE)
 Add given exception as error to the start of the error stack.
 add_affected_member ($member_id)
 Adds member as affected by this parsed statement.
 get_errors ()
 Gets error trace.
 find_member_by_vs ($variable_symbol, $error_correction=TRUE)
 Finds member ID by variable method.
 before_download (Bank_account_Model $bank_account, Bank_Account_Settings $settings)
 This method may be implemented in order to do some action before downloading of a bank statement.
 do_download (Bank_account_Model $bank_account, Bank_Account_Settings $settings, $url)
 This method enables to download a bank statement.
 check_file_data_format ()
 Checks whether the file content that is stored into a fileData property has valid format.
 get_header_data ()
 Gets header data of file data format.
 parse_file_data ()
 Parses a file data into a semantic interpretation of its content.
 store (&$stats=array())
 Stores data that are obtain via parse_file_data method (stored internally.
 notify_affected_members ()
 Informs affected members by email or SMS according to setting variables inform_affected_member_by_email and inform_affected_member_by_sms.

Static Protected Member Functions

static factory ($bank_account, $ext)
 Creates an instance of file importer driver that is capable of importing bank statement.

Detailed Description

Subclass for all bank statements importers of new generation (since 1.1).

Import is made using import static method that is the only public method of this class (only one that is called).

New importers (drivers) should implement this abstract class and then info about them must be added into drivers array in this class. Driver handles checking of format, parsing, saving data into database. On the other hand this class handles opening of file, notifying of affected users, error handling, variable key searching and grouping drivers in order to provide an independent of driver on another parts of system. Drivers should be located at directory defined by DIR constant that contains a relative location to this class.

Lifecycle of importer is following:

  1. creation
  2. set file data (input file)
  3. format file checking
  4. parse
  5. store into database
  6. inform users
  7. end of life
Author
Ondrej Fibich
Since
1.1

Constructor & Destructor Documentation

Bank_Statement_File_Importer::__construct ( Bank_account_Model  $bam)
protected

Creates new instance od bank statement import.

Parameters
Bank_account_Model$bam

Member Function Documentation

Bank_Statement_File_Importer::add_affected_member (   $member_id)
protected

Adds member as affected by this parsed statement.

Later if statement is succefully parsed and saved these members are inform by notification.

Parameters
integer$member_id
Bank_Statement_File_Importer::add_error (   $error,
  $translate = TRUE 
)
protected

Adds given error to the start of the error stack.

Parameters
string$errorError messsage
boolean$translateShould be error message translated before adding?
Bank_Statement_File_Importer::add_exception_error ( Exception  $e,
  $translate = TRUE 
)
protected

Add given exception as error to the start of the error stack.

Parameters
Exception$e
boolean$translateShould be exception message translated before adding?
Bank_Statement_File_Importer::before_download ( Bank_account_Model  $bank_account,
Bank_Account_Settings  $settings 
)
protected

This method may be implemented in order to do some action before downloading of a bank statement.

Does not do anything by default.

Parameters
Bank_account_Model$bank_account
Bank_Account_Settings$settings
Returns
boolean Successfully run?
Exceptions
ExceptionOn any error

Reimplemented in Fio_Bank_Statement_File_Importer.

Bank_Statement_File_Importer::check_file_data_format ( )
abstractprotected

Checks whether the file content that is stored into a fileData property has valid format.

This method checks only a format (syntax), semantic meaning of content is examined later.

An error in the format may be add into error stack (addError) that is later displayed to user if this function returns FALSE.

Returns
boolean TRUE if format is corrrent, FALSE otherwise

Reimplemented in Csv_Fio_Bank_Statement_File_Importer, Json_Fio_Bank_Statement_File_Importer, and Txt_Tatra_Banka_Statement_File_Importer.

Bank_Statement_File_Importer::do_download ( Bank_account_Model  $bank_account,
Bank_Account_Settings  $settings,
  $url 
)
protected

This method enables to download a bank statement.

By default it simply download file from the specified URL. If other type of download is needed that this method should be overriden.

Parameters
Bank_account_Model$bank_account
Bank_Account_Settings$settings
string$urlPrepare download URL
Returns
string Content of downloaded file or FALSE on error

Reimplemented in Txt_Tatra_Banka_Statement_File_Importer.

static Bank_Statement_File_Importer::download ( Bank_account_Model  $bank_account,
Bank_Account_Settings  $settings,
  $send_emails,
  $send_sms 
)
static

Tries to download statement and then import it.

This action contains just getting of a file URL from bank settings. Then this URL with another info is passed to import method which does the rest of the job.

Parameters
Bank_account_Model$bank_accountBank account ot which the statement is imported
Bank_Account_Settings$settings
boolean$send_emailsSend notification of affected members by e-mail
boolean$send_smsSend notification of affected members by sms
Returns
Bank_statement_Model Stored statement
Exceptions
InvalidArgumentExceptionOn invalid bank account settings that cannot be use for proper download
static Bank_Statement_File_Importer::factory (   $bank_account,
  $ext 
)
staticprotected

Creates an instance of file importer driver that is capable of importing bank statement.

Parameters
Bank_account_Model$bank_account
string$extFile extension
Returns
Bank_Statement_File_Importer Driver or NULL if no suitable driver is available.
Exceptions
InvalidArgumentExceptionOn invalid file or bank account entity
Bank_Statement_File_Importer::find_member_by_vs (   $variable_symbol,
  $error_correction = TRUE 
)
protected

Finds member ID by variable method.

If given variable symbol is not founded in the database and a variable key generator is active and capable of error correction than the variable key is tried repared and searched again.

Variable_Symbol_Model $vk_model

Parameters
string$variable_symbol
boolean$error_correctionMay be used error correction for VS?
Returns
null|integer NULL of not founded, member ID otherwise
Bank_Statement_File_Importer::get_bank_account ( )
protected

Gets bank account for which the importer is evaulating imports.

Returns
Bank_account_Model
static Bank_Statement_File_Importer::get_drivers ( )
static

Gets available drivers.

Returns
array
Bank_Statement_File_Importer::get_errors ( )
protected

Gets error trace.

Returns
array
Bank_Statement_File_Importer::get_file_data ( )
protected

Gets bank statement file data (content of a file)

Returns
string
Bank_Statement_File_Importer::get_header_data ( )
abstractprotected

Gets header data of file data format.

This method is used for checking if the bank statement correspondes to bank account in the database.

Data must be available in any time after calling of check_file_data_format method.

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.

Returns
Header_Data|boolean|null

Reimplemented in Csv_Fio_Bank_Statement_File_Importer, Json_Fio_Bank_Statement_File_Importer, and Txt_Tatra_Banka_Statement_File_Importer.

Bank_Statement_File_Importer::get_importer_name ( )

Get importer name.

Returns
string
Bank_Statement_File_Importer::get_user_id ( )
protected

User ID of caller of this importer.

(user who calls it)

Returns
integer
static Bank_Statement_File_Importer::import ( Bank_account_Model  $bank_account,
  $filename,
  $ext,
  $send_emails = TRUE,
  $send_sms = FALSE 
)
static

Imports a bank statement placed in a file that is given by the filename to bank account that is given by its database model.

Throws error exceptions with translated error description if any error occures.

Parameters
Bank_account_Model$bank_accountBank account ot which the statement is imported
string$filenameFull path to imported file
string$extFile extension
boolean$send_emailsSend notification of affected members by e-mail
boolean$send_smsSend notification of affected members by sms
Returns
Bank_statement_Model Stored statement
Exceptions
InvalidArgumentExceptionOn invalid file or bank account entity
ExceptionOn any error during parsing or storing of statement
Bank_Statement_File_Importer::notify_affected_members ( )
protected

Informs affected members by email or SMS according to setting variables inform_affected_member_by_email and inform_affected_member_by_sms.

Returns
boolean TRUE if all affected members were notified, FALSE otherwise
Bank_Statement_File_Importer::parse_file_data ( )
abstractprotected

Parses a file data into a semantic interpretation of its content.

This interpretation must be defined by implementing class.

An error in the format may be add into error stack (addError) that is later displayed to user if this function returns FALSE.

Returns
boolean TRUE if file data were succesfully parsed, FALSE otherwise

Reimplemented in Csv_Fio_Bank_Statement_File_Importer, Json_Fio_Bank_Statement_File_Importer, and Txt_Tatra_Banka_Statement_File_Importer.

Bank_Statement_File_Importer::set_file_data (   $fd)
protected

Sets bank statement file data (content of a file)

Parameters
string$fd
Bank_Statement_File_Importer::store ( $stats = array())
abstractprotected

Stores data that are obtain via parse_file_data method (stored internally.

  • so it is in hand of the implemented file importer).

All transfers are stored in the database and grouped using statement entity. This statement entity is than returned.

This method should also set affected members in order to notify them.

An error in the format may be add into error stack (addError) that is later displayed to user if this function returns FALSE.

Parameters
array$statsStatistics about imported statement
Returns
Bank_statement_Model Bank statement that was stored or NULL if bank statement was not stored
Exceptions
Duplicity_ExceptionOn transfers that were already imported

Reimplemented in Fio_Bank_Statement_File_Importer, and Tatra_Banka_Statement_File_Importer.


The documentation for this class was generated from the following file: