Revize 20904a5d
Přidáno uživatelem Ondřej Fibich před asi 9 roky(ů)
application/libraries/Bank_Statement_File_Importer.php | ||
---|---|---|
throw new Exception(__('Cannot prepare for statement download'));
|
||
}
|
||
|
||
// make download
|
||
$file_data = $this->do_download($bank_account, $settings, $url);
|
||
// make download
|
||
$file_data = $this->do_download($bank_account, $settings, $url);
|
||
|
||
if ($file_data === FALSE)
|
||
{
|
||
throw new Exception(__('Import download has failed caused by: %s',
|
||
implode('<br>', $driver->get_errors())));
|
||
}
|
||
if ($file_data === FALSE)
|
||
{
|
||
throw new Exception(__('Import download has failed caused by: %s',
|
||
implode('<br>', $driver->get_errors())));
|
||
}
|
||
|
||
// import
|
||
return self::import_loaded($bank_account, $file_data, $type,
|
||
$send_emails, $send_sms);
|
||
$send_emails, $send_sms);
|
||
}
|
||
|
||
/**
|
||
... | ... | |
*/
|
||
public static function import(Bank_account_Model $bank_account,
|
||
$filename, $ext, $send_emails = TRUE, $send_sms = FALSE)
|
||
{
|
||
$fd = @file_get_contents($filename);
|
||
{
|
||
$fd = @file_get_contents($filename);
|
||
|
||
if ($fd == FALSE)
|
||
{
|
||
... | ... | |
throw new InvalidArgumentException($m);
|
||
}
|
||
|
||
return self::import_loaded($bank_account, $fd, $filename, $ext,
|
||
$send_emails, $send_sms);
|
||
}
|
||
return self::import_loaded($bank_account, $fd, $filename, $ext,
|
||
$send_emails, $send_sms);
|
||
}
|
||
|
||
/**
|
||
* Imports a bank statement from given loaded file data to bank account
|
||
* that is given by its database model. Throws error exceptions with
|
||
* translated error description if any error occures.
|
||
* that is given by its database model. Throws error exceptions with
|
||
* translated error description if any error occures.
|
||
*
|
||
* @param Bank_account_Model $bank_account Bank account ot which the statement
|
||
* is imported
|
||
... | ... | |
$driver->inform_affected_member_by_sms = $send_sms;
|
||
|
||
/* set file data */
|
||
if (empty($file_data))
|
||
{
|
||
throw new Exception(__('Invalid file data'));
|
||
}
|
||
if (empty($file_data))
|
||
{
|
||
throw new Exception(__('Invalid file data'));
|
||
}
|
||
|
||
$driver->set_file_data($file_data);
|
||
|
||
... | ... | |
$header_data = $driver->get_header_data();
|
||
|
||
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);
|
||
}
|
||
}
|
||
{
|
||
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())
|
||
... | ... | |
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* 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.
|
||
*
|
||
/**
|
||
* 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.
|
||
*
|
||
* @param Bank_account_Model $bank_account
|
||
* @param Bank_Account_Settings $settings
|
||
* @param string $url Prepare download URL
|
||
* @return string Content of downloaded file or FALSE on error
|
||
*/
|
||
protected function do_download(Bank_account_Model $bank_account,
|
||
Bank_Account_Settings $settings, $url)
|
||
{
|
||
$fd = @file_get_contents($filename);
|
||
* @param string $url Prepare download URL
|
||
* @return string Content of downloaded file or FALSE on error
|
||
*/
|
||
protected function do_download(Bank_account_Model $bank_account,
|
||
Bank_Account_Settings $settings, $url)
|
||
{
|
||
$fd = @file_get_contents($filename);
|
||
|
||
if ($fd == FALSE)
|
||
{
|
||
... | ... | |
$m = __('Cannot download statement from ') . ' "' . $url . '": '
|
||
. (isset($e['message']) ? $e['message'] : '');
|
||
$this->add_error($m);
|
||
return FALSE;
|
||
return FALSE;
|
||
}
|
||
|
||
return $fd;
|
||
}
|
||
|
||
return $fd;
|
||
}
|
||
|
||
/**
|
||
* Checks whether the file content that is stored into a fileData property
|
||
... | ... | |
*
|
||
* 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.
|
||
*
|
||
* If bank statement file not providing any header information NULL can
|
||
* be returned to skip assert for bank account match.
|
||
*
|
||
* @return Header_Data|boolean|null
|
||
*/
|
Také k dispozici: Unified diff
WS polishing (tabs not expanded).