mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
New stuff for categories and transactions.
This commit is contained in:
@@ -3,7 +3,7 @@ declare(strict_types = 1);
|
||||
namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class CategoryId
|
||||
@@ -18,8 +18,8 @@ class CategoryId extends BasicConverter implements ConverterInterface
|
||||
*/
|
||||
public function convert(): Category
|
||||
{
|
||||
/** @var SingleCategoryRepositoryInterface $repository */
|
||||
$repository = app(SingleCategoryRepositoryInterface::class);
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$value = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
|
||||
$category = $repository->find($value);
|
||||
|
||||
|
@@ -4,7 +4,7 @@ namespace FireflyIII\Helpers\Csv\Converter;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
|
||||
/**
|
||||
* Class CategoryName
|
||||
@@ -19,8 +19,8 @@ class CategoryName extends BasicConverter implements ConverterInterface
|
||||
*/
|
||||
public function convert(): Category
|
||||
{
|
||||
/** @var SingleCategoryRepositoryInterface $repository */
|
||||
$repository = app(SingleCategoryRepositoryInterface::class);
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
|
||||
// is mapped? Then it's easy!
|
||||
if (isset($this->mapped[$this->index][$this->value])) {
|
||||
|
@@ -141,7 +141,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the array as returned by SingleCategoryRepositoryInterface::spentPerDay and SingleCategoryRepositoryInterface::earnedByDay
|
||||
* Take the array as returned by CategoryRepositoryInterface::spentPerDay and CategoryRepositoryInterface::earnedByDay
|
||||
* and sum up everything in the array in the given range.
|
||||
*
|
||||
* @param Carbon $start
|
||||
|
@@ -39,4 +39,13 @@ interface BudgetReportHelperInterface
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBudgetsWithExpenses(Carbon $start, Carbon $end, Collection $accounts): Collection;
|
||||
|
||||
/**
|
||||
* @param $start
|
||||
* @param $end
|
||||
* @param $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getCategoriesWithTransactions($start, $end, $accounts): Collection;
|
||||
}
|
||||
|
@@ -103,35 +103,35 @@ class ReportHelper implements ReportHelperInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all transactions and IF we have spent money in them
|
||||
* with either transactions or journals.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getCategoriesWithExpenses(Carbon $start, Carbon $end, Collection $accounts): Collection
|
||||
public function getCategoriesWithTransactions(Carbon $start, Carbon $end, Collection $accounts): Collection
|
||||
{
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$collection = $repository->earnedForAccountsPerMonth($accounts, $start, $end);
|
||||
$second = $repository->spentForAccountsPerMonth($accounts, $start, $end);
|
||||
$collection = $collection->merge($second);
|
||||
$array = [];
|
||||
/** @var Category $category */
|
||||
foreach ($collection as $category) {
|
||||
$id = $category->id;
|
||||
$array[$id] = $category;
|
||||
|
||||
$categories = $repository->getCategories();
|
||||
$return = new Collection;
|
||||
foreach ($categories as $category) {
|
||||
$lastUseDate = $repository->lastUseDate($category, $accounts);
|
||||
if ($lastUseDate >= $start && $lastUseDate <= $end) {
|
||||
$return->push($category);
|
||||
}
|
||||
}
|
||||
$set = new Collection($array);
|
||||
|
||||
$set = $set->sortBy(
|
||||
$return = $return->sortBy(
|
||||
function (Category $category) {
|
||||
return $category->name;
|
||||
}
|
||||
);
|
||||
|
||||
return $set;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,15 +144,15 @@ class ReportHelper implements ReportHelperInterface
|
||||
public function getCategoryReport(Carbon $start, Carbon $end, Collection $accounts): CategoryCollection
|
||||
{
|
||||
$object = new CategoryCollection;
|
||||
|
||||
/**
|
||||
* GET CATEGORIES:
|
||||
*/
|
||||
/** @var \FireflyIII\Repositories\Category\CategoryRepositoryInterface $repository */
|
||||
/** @var CategoryRepositoryInterface $repository */
|
||||
$repository = app(CategoryRepositoryInterface::class);
|
||||
$categories = $repository->getCategories();
|
||||
|
||||
$set = $repository->spentForAccountsPerMonth($accounts, $start, $end);
|
||||
foreach ($set as $category) {
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
|
||||
// CategoryCollection expects the amount in $spent:
|
||||
$category->spent = $spent;
|
||||
$object->addCategory($category);
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ class ReportHelper implements ReportHelperInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the array as returned by SingleCategoryRepositoryInterface::spentPerDay and SingleCategoryRepositoryInterface::earnedByDay
|
||||
* Take the array as returned by CategoryRepositoryInterface::spentPerDay and CategoryRepositoryInterface::earnedByDay
|
||||
* and sum up everything in the array in the given range.
|
||||
*
|
||||
* @param Carbon $start
|
||||
|
Reference in New Issue
Block a user