mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-30 20:54:04 -06:00
Small fixes.
This commit is contained in:
parent
1dc6d8de40
commit
f8936210cf
@ -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();
|
||||
}
|
||||
|
73
app/Helpers/Csv/Specifix.php
Normal file
73
app/Helpers/Csv/Specifix.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Helpers\Csv;
|
||||
|
||||
/**
|
||||
* Class Specifix
|
||||
*
|
||||
* @package FireflyIII\Helpers\Csv
|
||||
*/
|
||||
class Specifix
|
||||
{
|
||||
/** @var array */
|
||||
protected $data;
|
||||
|
||||
/** @var array */
|
||||
protected $row;
|
||||
|
||||
|
||||
/**
|
||||
* Implement bank and locale related fixes.
|
||||
*/
|
||||
public function fix()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user