ソースを参照

Facilitate local customisations to the backend

pull/1/head
Chris Smith 13年前
コミット
6870e7db32
1個のファイルの変更61行の追加53行の削除
  1. 61
    53
      data.php

+ 61
- 53
data.php ファイルの表示

@@ -66,81 +66,89 @@
66 66
   '(Ignored)' => array('Internal Transfer'),
67 67
  );
68 68
 
69
- // Formats part (one field) of a transaction
70
- function parseStatementPart($key, $value) {
71
-  if ($key == 'Date') {
72
-   $format = 'd/m/' . (strlen($value) == 8 ? 'y' : 'Y');
73
-   return DateTime::createFromFormat($format, $value)->setTime(0, 0, 0);
74
-  } else if ($key == 'Amount') {
75
-   return (double) $value;
76
-  }
69
+ @include('data.local.php');
70
+
71
+ if (!function_exists('parseStatementPart')) {
72
+  // Formats part (one field) of a transaction
73
+  function parseStatementPart($key, $value) {
74
+   if ($key == 'Date') {
75
+    $format = 'd/m/' . (strlen($value) == 8 ? 'y' : 'Y');
76
+    return DateTime::createFromFormat($format, $value)->setTime(0, 0, 0);
77
+   } else if ($key == 'Amount') {
78
+    return (double) $value;
79
+   }
77 80
 
78
-  return $value;
81
+   return $value;
82
+  }
79 83
  }
80 84
 
81
- // Formats an entire transaction from a statement
82
- function parseStatementLine($line) {
83
-  global $categories, $genericTypes, $types, $rules;
85
+ if (!function_exists('parseStatementLine')) {
86
+  // Formats an entire transaction from a statement
87
+  function parseStatementLine($line) {
88
+   global $categories, $genericTypes, $types, $rules;
84 89
 
85
-  if (preg_match('/^(.*?)\s*\((.*? @ RATE .*?)\)$/', $line['Description'], $m)) {
86
-   $line['Description'] = $m[1];
87
-   $line['Exchange'] = $m[2];
88
-  }
90
+   if (preg_match('/^(.*?)\s*\((.*? @ RATE .*?)\)$/', $line['Description'], $m)) {
91
+    $line['Description'] = $m[1];
92
+    $line['Exchange'] = $m[2];
93
+   }
89 94
 
90
-  foreach ($types as $prefix => $type) {
91
-   if (strpos($line['Description'], $prefix) === 0) {
92
-    $line['Type'] = $type;
95
+   foreach ($types as $prefix => $type) {
96
+    if (strpos($line['Description'], $prefix) === 0) {
97
+     $line['Type'] = $type;
93 98
 
94
-    if (array_search($type, $genericTypes) === false) {
95
-     $line['Description'] = substr($line['Description'], strlen($prefix));
96
-    } else {
97
-     $line['RawDescription'] = $line['Description'];
98
-     $line['Description'] = $type;
99
-    }
99
+     if (array_search($type, $genericTypes) === false) {
100
+      $line['Description'] = substr($line['Description'], strlen($prefix));
101
+     } else {
102
+      $line['RawDescription'] = $line['Description'];
103
+      $line['Description'] = $type;
104
+     }
100 105
 
101
-    break;
106
+     break;
107
+    }
102 108
    }
103
-  }
104 109
 
105
-  foreach ($rules as $regex => $replacement) {
106
-   if (preg_match('(' . $regex . ')', $line['Description'])) {
107
-    $line['RawDescription'] = $line['Description'];
108
-    $line['Description'] = $replacement;
110
+   foreach ($rules as $regex => $replacement) {
111
+    if (preg_match('(' . $regex . ')', $line['Description'])) {
112
+     $line['RawDescription'] = $line['Description'];
113
+     $line['Description'] = $replacement;
114
+    }
109 115
    }
110
-  }
111 116
 
112
-  foreach ($categories as $cat => $entries) {
113
-   foreach ($entries as $regex) {
114
-    if (preg_match('(' . $regex . ')', $line['Description'])) {
115
-     $line['Category'] = $cat;
116
-     break;
117
+   foreach ($categories as $cat => $entries) {
118
+    foreach ($entries as $regex) {
119
+     if (preg_match('(' . $regex . ')', $line['Description'])) {
120
+      $line['Category'] = $cat;
121
+      break;
122
+     }
117 123
     }
118 124
    }
119
-  }
120 125
 
121
-  return $line;
126
+   return $line;
127
+  }
122 128
  }
123 129
 
124
- // Loads statements from the specified directory
125
- function loadStatements($dir = 'Statements') {
126
-  $results = array();
130
+ if (!function_exists('loadStatements')) {
131
+  // Loads statements from the specified directory
132
+  function loadStatements($dir = 'Statements') {
133
+   $results = array();
127 134
 
128
-  foreach (glob($dir . '/*.csv') as $statement) {
129
-   $fh = fopen($statement, 'r');
130
-   $data = array();
135
+   foreach (glob($dir . '/*.csv') as $statement) {
136
+    $fh = fopen($statement, 'r');
137
+    $data = array();
131 138
 
132
-   $headers = array_map('trim', fgetcsv($fh));
139
+    $headers = array_map('trim', fgetcsv($fh));
133 140
 
134
-   while (!feof($fh)) {
135
-    $line = parseStatementLine(array_combine($headers, array_map('parseStatementPart', $headers, array_map('trim', fgetcsv($fh)))));
136
-    $data[] = $line;
141
+    while (!feof($fh)) {
142
+     $line = parseStatementLine(array_combine($headers, array_map('parseStatementPart', $headers, array_map('trim', fgetcsv($fh)))));
143
+     $data[] = $line;
144
+    }
145
+    fclose($fh);
146
+
147
+    $results[basename($statement)] = $data;
137 148
    }
138
-   fclose($fh);
139 149
 
140
-   $results[basename($statement)] = $data;
150
+   return $results;
141 151
   }
142
-
143
-  return $results;
144 152
  }
145 153
 
146 154
  $entries = array_reduce(loadStatements(), 'array_merge', array());

読み込み中…
キャンセル
保存