From f8936210cfa111fd8138f74f2742a6f311eab25a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 5 Jul 2015 07:18:48 +0200 Subject: [PATCH] Small fixes. --- app/Helpers/Csv/Importer.php | 29 ++++++++++---- app/Helpers/Csv/Specifix.php | 73 ++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 app/Helpers/Csv/Specifix.php diff --git a/app/Helpers/Csv/Importer.php b/app/Helpers/Csv/Importer.php index 4d8ac5c1b4..94e6b75e5a 100644 --- a/app/Helpers/Csv/Importer.php +++ b/app/Helpers/Csv/Importer.php @@ -16,6 +16,8 @@ use FireflyIII\Models\TransactionType; use Illuminate\Support\MessageBag; use Log; +set_time_limit(0); + /** * Class Importer * @@ -106,7 +108,7 @@ class Importer // } } - $data = $this->postProcess($data); + $data = $this->postProcess($data, $row); $result = $this->validateData($data); if ($result === true) { $result = $this->createTransactionJournal($data); @@ -142,11 +144,14 @@ class Importer } /** + * Row denotes the original data. + * * @param array $data + * @param array $row * * @return array */ - protected function postProcess(array $data) + protected function postProcess(array $data, array $row) { bcscale(2); $data['description'] = trim($data['description']); @@ -159,6 +164,16 @@ class Importer $accountType = AccountType::where('type', 'Revenue account')->first(); } + // do bank specific fixes: + + $specifix = new Specifix(); + $specifix->setData($data); + $specifix->setRow($row); + $specifix->fix($data, $row); + + // get data back: + $data = $specifix->getData(); + $data['opposing-account-object'] = Account::firstOrCreateEncrypted( [ 'user_id' => Auth::user()->id, @@ -208,7 +223,7 @@ class Importer } else { $transactionType = TransactionType::where('type', 'Deposit')->first(); } - $errors = new MessageBag; + $errors = new MessageBag; $journal = TransactionJournal::create( [ 'user_id' => Auth::user()->id, @@ -220,7 +235,7 @@ class Importer 'date' => $date, ] ); - $errors = $journal->getErrors()->merge($errors); + $errors = $journal->getErrors()->merge($errors); if ($journal->getErrors()->count() == 0) { // create both transactions: $transaction = Transaction::create( @@ -230,7 +245,7 @@ class Importer 'amount' => $data['amount'] ] ); - $errors = $transaction->getErrors()->merge($errors); + $errors = $transaction->getErrors()->merge($errors); $transaction = Transaction::create( [ @@ -239,9 +254,9 @@ class Importer 'amount' => bcmul($data['amount'], -1) ] ); - $errors = $transaction->getErrors()->merge($errors); + $errors = $transaction->getErrors()->merge($errors); } - if($errors->count() == 0) { + if ($errors->count() == 0) { $journal->completed = 1; $journal->save(); } diff --git a/app/Helpers/Csv/Specifix.php b/app/Helpers/Csv/Specifix.php new file mode 100644 index 0000000000..0e530d4a5d --- /dev/null +++ b/app/Helpers/Csv/Specifix.php @@ -0,0 +1,73 @@ +rabobankFixEmptyOpposing(); + + } + + /** + * Fixes Rabobank specific thing. + */ + protected function rabobankFixEmptyOpposing() + { + if (strlen($this->data['opposing-account']) == 0) { + $this->data['opposing-account'] = $this->row[10]; + } + $this->data['description'] = trim(str_replace($this->row[10], '', $this->data['description'])); + } + + + /** + * @return array + */ + public function getData() + { + return $this->data; + } + + /** + * @param array $data + */ + public function setData($data) + { + $this->data = $data; + } + + /** + * @return array + */ + public function getRow() + { + return $this->row; + } + + /** + * @param array $row + */ + public function setRow($row) + { + $this->row = $row; + } + + +} \ No newline at end of file