Skip to content

Commit

Permalink
#131 work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Mar 14, 2016
1 parent d197c5e commit 88a9010
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
19 changes: 12 additions & 7 deletions configuration_database/importer/fixed/bancario43.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
{
"comment": "11 is the file header",
"type": "apply_rules",
"regex": "^11",
"rules": "rules_header",
"regex": "#^11#",
"rules": "rules_header"
},
{
"comment": "22 is transaction",
"type": "apply_rules",
"regex": "^22",
"rules": "rules_transaction",
"regex": "#^22#",
"rules": "rules_transaction"
},
{
"comment": "33 is the footer",
"type": "apply_rules",
"regex": "^33",
"rules": "rules_footer",
"regex": "#^33#",
"rules": "rules_footer"
}
],
"rules_header": [
Expand All @@ -35,9 +35,14 @@
"type": "extract",
"position": "17-22",
"to": "tx.value_date"
},
{
"type": "extract",
"position": "29-42",
"to": "tx.amount"
}
],
"rules_header": [
"rules_footer": [
{
"type": "transaction:close"
}
Expand Down
18 changes: 12 additions & 6 deletions extension/CRM/Banking/PluginImpl/Importer/Fixed.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function import_stream( $params )
function probe_file( $file_path, $params )
{
// TODO: use sentinel if exists
return true;
}


Expand All @@ -144,8 +145,10 @@ function import_file( $file_path, $params )
// all good -> start creating stament
$this->data = array();
$batch = $this->openTransactionBatch();
$line = NULL;

while ( ($line == fgets($this->file_handle)) !== false) {
while ( ($line = fgets($this->file_handle)) !== false) {
error_log("processing $line");
$this->apply_rules('generic_rules', $line, $params);

}
Expand Down Expand Up @@ -180,13 +183,15 @@ function import_file( $file_path, $params )
protected function apply_rules($rules_name, $line, &$params) {
$config = $this->_plugin_config;

if (empty($config->$rules_name) && is_array($config->$rules_name)) {
error_log("applying rule set $rules_name");

if (empty($config->$rules_name) || !is_array($config->$rules_name)) {
// TODO: error handling
return;
}

foreach ($config->$rules_name as $rule) {
$this->apply_rule($rule, $params);
$this->apply_rule($rule, $line, $params);
}
}

Expand All @@ -196,6 +201,7 @@ protected function apply_rules($rules_name, $line, &$params) {
* executes ONE import rule
*/
protected function apply_rule($rule, $line, &$params) {
error_log("applying rule {$rule->type}");

switch ($rule->type) {
case 'extract':
Expand All @@ -208,13 +214,13 @@ protected function apply_rule($rule, $line, &$params) {
// TODO: error handling
}

$value = substr($line, $pos_from, $length);
$value = substr($line, $pos_from-1, $length);
$this->storeValue($value, $rule->to);
break;

case 'apply_rules':
if (preg_match($rule->regex, $line)) {
$this->apply_rules($rule->rules, $line);
$this->apply_rules($rule->rules, $line, $params);
}
break;

Expand Down Expand Up @@ -258,7 +264,7 @@ protected function storeValue($name, $value) {
$this->tx_data[substr($name, 3)] = $value;
} else {
// TODO: remove prefix? other prefixes?
$this->data[$name] -> $value;
$this->data[$name] = $value;
}
}

Expand Down

0 comments on commit 88a9010

Please sign in to comment.