Massively complex but working never the less.

This commit is contained in:
James Cole
2015-07-05 16:39:25 +02:00
parent 601f9f86bb
commit 12ee5da872
6 changed files with 191 additions and 53 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Account;
/**
* Class OpposingAccountIban
*
* @package FireflyIII\Helpers\Csv\Converter
*/
class OpposingAccountIban extends BasicConverter implements ConverterInterface
{
/**
* If mapped, return account. Otherwise, only return the name itself.
*
* @return Account|string
*/
public function convert()
{
if (isset($this->mapped[$this->index][$this->value])) {
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
return $account;
} else {
$set = Auth::user()->accounts()->get();
/** @var Account $account */
foreach ($set as $account) {
if ($account->iban == $this->value) {
return $account;
}
}
return $this->value;
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Account;
/**
* Class OpposingName
*
* @package FireflyIII\Helpers\Csv\Converter
*/
class OpposingAccountId extends BasicConverter implements ConverterInterface
{
/**
* @return Account
*/
public function convert()
{
if (isset($this->mapped[$this->index][$this->value])) {
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
} else {
$account = Auth::user()->accounts()->find($this->value);
}
return $account;
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Account;
/**
* Class OpposingName
*
* @package FireflyIII\Helpers\Csv\Converter
*/
class OpposingAccountName extends BasicConverter implements ConverterInterface
{
/**
* If mapped, return account. Otherwise, only return the name itself.
*
* @return Account|string
*/
public function convert()
{
if (isset($this->mapped[$this->index][$this->value])) {
$account = Auth::user()->accounts()->find($this->mapped[$this->index][$this->value]);
return $account;
} else {
return $this->value;
}
}
}

View File

@@ -1,24 +0,0 @@
<?php
namespace FireflyIII\Helpers\Csv\Converter;
/**
* Class OpposingName
*
* @package FireflyIII\Helpers\Csv\Converter
*/
class OpposingName extends BasicConverter implements ConverterInterface
{
/**
* This method cannot search yet for the correct account (Expense account, Revenue account or Asset account) because simply put,
* Firefly doesn't know yet if this account needs to be an Expense account or a Revenue account. This depends
* on the amount which is in the current row and that's a big unknown.
*
* @return mixed
*/
public function convert()
{
return $this->value;
}
}