Skip to content

Commit

Permalink
making it work (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Mar 15, 2018
1 parent 1682a75 commit 53eec09
Showing 1 changed file with 16 additions and 26 deletions.
42 changes: 16 additions & 26 deletions extension/CRM/Banking/PluginImpl/Importer/Fixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ function __construct($config_name) {
*/
protected $tx_raw_lines = NULL;

/**
* line number currently processed
*/
protected $line_nr = 0;



/**
Expand Down Expand Up @@ -148,6 +153,7 @@ function import_file( $file_path, $params )
// TODO: error handling

// all good -> start creating stament
$this->line_nr = 0;
$this->data = array();
foreach ($config->defaults as $key => $value) {
$this->data[$key] = $value;
Expand All @@ -157,6 +163,8 @@ function import_file( $file_path, $params )
$line = NULL;

while ( ($line = fgets($this->file_handle)) !== FALSE ) {
$this->line_nr += 1;

// check encoding if necessary
if (isset($config->encoding)) {
$line = mb_convert_encoding($line, mb_internal_encoding(), $config->encoding);
Expand Down Expand Up @@ -232,7 +240,7 @@ protected function apply_rule($rule, &$line, &$params) {
break;

case 'apply_rules':
if (preg_match($rule->regex, $line)) {
if (empty($rule->regex) || preg_match($rule->regex, $line)) {
$this->apply_rules($rule->rules, $line, $params);
}
break;
Expand All @@ -243,6 +251,10 @@ protected function apply_rule($rule, &$line, &$params) {
$this->storeValue($rule->to, $new_value);
break;

case 'line_nr':
$this->storeValue($rule->to, $this->line_nr);
break;

case 'date':
$value = $this->getValue($rule->from);
$datetime = DateTime::createFromFormat($rule->format, $value);
Expand All @@ -266,7 +278,6 @@ protected function apply_rule($rule, &$line, &$params) {
default:
// TODO error handling
break;

}
}

Expand Down Expand Up @@ -325,34 +336,13 @@ protected function closeTransaction(&$line, &$params) {
// TODO: progress
$progress = 0.0;

// // look up the bank accounts??? => use analyser instead!
// foreach ($btx as $key => $value) {
// // check for NBAN_?? or IBAN endings
// if (preg_match('/^_.*NBAN_..$/', $key) || preg_match('/^_.*IBAN$/', $key)) {
// // this is a *BAN entry -> look it up
// if (!isset($this->account_cache[$value])) {
// $result = civicrm_api('BankingAccountReference', 'getsingle', array('version' => 3, 'reference' => $value));
// if (!empty($result['is_error'])) {
// $this->account_cache[$value] = NULL;
// } else {
// $this->account_cache[$value] = $result['ba_id'];
// }
// }

// if ($this->account_cache[$value] != NULL) {
// if (substr($key, 0, 7)=="_party_") {
// $btx['party_ba_id'] = $this->account_cache[$value];
// } elseif (substr($key, 0, 1)=="_") {
// $btx['ba_id'] = $this->account_cache[$value];
// }
// }
// }
// }
// look up the bank accounts
$this->lookupBankAccounts($btx);

// do some post processing
if (!isset($config->bank_reference)) {
// set SHA1 hash as unique reference
$btx['bank_reference'] = sha1($btx['data_raw']);
$btx['bank_reference'] = sha1(json_encode($btx));
} else {
// we have a template
$bank_reference = $config->bank_reference;
Expand Down

0 comments on commit 53eec09

Please sign in to comment.