New converters for #180 (Category and some other stuff)

This commit is contained in:
James Cole
2016-04-01 13:23:12 +02:00
parent 429ef80fb9
commit 5e78cc02bd
10 changed files with 78 additions and 18 deletions

View File

@@ -29,7 +29,7 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
return $account;
}
if (strlen($this->value) > 0) {
// find or create new account:
$set = $repository->getAccounts(['Default account', 'Asset account']);

View File

@@ -2,7 +2,6 @@
declare(strict_types = 1);
namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;

View File

@@ -2,7 +2,6 @@
declare(strict_types = 1);
namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;

View File

@@ -2,8 +2,8 @@
declare(strict_types = 1);
namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
/**
* Class CategoryId
@@ -18,11 +18,14 @@ class CategoryId extends BasicConverter implements ConverterInterface
*/
public function convert()
{
/** @var SingleCategoryRepositoryInterface $repository */
$repository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');
// is mapped? Then it's easy!
if (isset($this->mapped[$this->index][$this->value])) {
$category = Auth::user()->categories()->find($this->mapped[$this->index][$this->value]);
$category = $repository->find($this->mapped[$this->index][$this->value]);
} else {
$category = Auth::user()->categories()->find($this->value);
$category = $repository->find($this->value);
}
return $category;

View File

@@ -4,6 +4,7 @@ namespace FireflyIII\Helpers\Csv\Converter;
use Auth;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
/**
* Class CategoryName
@@ -18,16 +19,20 @@ class CategoryName extends BasicConverter implements ConverterInterface
*/
public function convert()
{
/** @var SingleCategoryRepositoryInterface $repository */
$repository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');
// is mapped? Then it's easy!
if (isset($this->mapped[$this->index][$this->value])) {
$category = Auth::user()->categories()->find($this->mapped[$this->index][$this->value]);
$category = $repository->find($this->mapped[$this->index][$this->value]);
} else {
$category = Category::firstOrCreateEncrypted( // See issue #180
[
'name' => $this->value,
'user_id' => Auth::user()->id,
]
);
$data = [
'name' => $this->value,
'user' => Auth::user()->id,
];
$category = $repository->store($data);
}
return $category;

View File

@@ -257,6 +257,7 @@ class ReportHelper implements ReportHelperInterface
if ($set->count() === 0) {
return $collection;
}
/** @var Tag $entry */
foreach ($set as $entry) {
// less than zero? multiply to be above zero.
$amount = $entry->amount;