mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-15 19:09:50 +00:00
Various code reshuffelling.
This commit is contained in:
@@ -24,6 +24,7 @@ namespace FireflyIII\Repositories\Category;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\CategoryFactory;
|
||||
use FireflyIII\Models\Attachment;
|
||||
@@ -61,6 +62,22 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all categories.
|
||||
*/
|
||||
public function destroyAll(): void
|
||||
{
|
||||
$categories = $this->getCategories();
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
DB::table('category_transaction')->where('category_id', $category->id)->delete();
|
||||
DB::table('category_transaction_journal')->where('category_id', $category->id)->delete();
|
||||
RecurrenceTransactionMeta::where('name', 'category_id')->where('value', $category->id)->delete();
|
||||
RuleAction::where('action_type', 'set_category')->where('action_value', $category->name)->delete();
|
||||
$category->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category.
|
||||
*
|
||||
@@ -150,6 +167,27 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $firstJournalDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAttachments(Category $category): Collection
|
||||
{
|
||||
$set = $category->attachments()->get();
|
||||
|
||||
/** @var Storage $disk */
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) {
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes = $notes ? $notes->text : '';
|
||||
|
||||
return $attachment;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all categories with ID's.
|
||||
*
|
||||
@@ -172,6 +210,19 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $this->user->categories()->with(['attachments'])->orderBy('name', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getNoteText(Category $category): ?string
|
||||
{
|
||||
$dbNote = $category->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $dbNote->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
@@ -201,6 +252,14 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $lastJournalDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*/
|
||||
public function removeNotes(Category $category): void
|
||||
{
|
||||
$category->notes()->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
@@ -254,16 +313,6 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*/
|
||||
public function removeNotes(Category $category): void
|
||||
{
|
||||
$category->notes()->delete();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param array $data
|
||||
@@ -279,6 +328,20 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $service->update($category, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function updateNotes(Category $category, string $notes): void
|
||||
{
|
||||
$dbNote = $category->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note;
|
||||
$dbNote->noteable()->associate($category);
|
||||
}
|
||||
$dbNote->text = trim($notes);
|
||||
$dbNote->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
@@ -345,7 +408,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getLastTransactionDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
@@ -365,68 +428,4 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all categories.
|
||||
*/
|
||||
public function destroyAll(): void
|
||||
{
|
||||
$categories = $this->getCategories();
|
||||
/** @var Category $category */
|
||||
foreach ($categories as $category) {
|
||||
DB::table('category_transaction')->where('category_id', $category->id)->delete();
|
||||
DB::table('category_transaction_journal')->where('category_id', $category->id)->delete();
|
||||
RecurrenceTransactionMeta::where('name', 'category_id')->where('value', $category->id)->delete();
|
||||
RuleAction::where('action_type', 'set_category')->where('action_value', $category->name)->delete();
|
||||
$category->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getAttachments(Category $category): Collection
|
||||
{
|
||||
$set = $category->attachments()->get();
|
||||
|
||||
/** @var Storage $disk */
|
||||
$disk = Storage::disk('upload');
|
||||
|
||||
return $set->each(
|
||||
static function (Attachment $attachment) use ($disk) {
|
||||
$notes = $attachment->notes()->first();
|
||||
$attachment->file_exists = $disk->exists($attachment->fileName());
|
||||
$attachment->notes = $notes ? $notes->text : '';
|
||||
|
||||
return $attachment;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function updateNotes(Category $category, string $notes): void
|
||||
{
|
||||
$dbNote = $category->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
$dbNote = new Note;
|
||||
$dbNote->noteable()->associate($category);
|
||||
}
|
||||
$dbNote->text = trim($notes);
|
||||
$dbNote->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getNoteText(Category $category): ?string
|
||||
{
|
||||
$dbNote = $category->notes()->first();
|
||||
if (null === $dbNote) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $dbNote->text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,38 +34,6 @@ use Illuminate\Support\Collection;
|
||||
interface CategoryRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Remove notes.
|
||||
*
|
||||
* @param Category $category
|
||||
*/
|
||||
public function removeNotes(Category $category): void;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param string $notes
|
||||
*/
|
||||
public function updateNotes(Category $category, string $notes): void;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNoteText(Category $category): ?string;
|
||||
|
||||
/**
|
||||
* Delete all categories.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAttachments(Category $category): Collection;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
@@ -73,6 +41,11 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function destroy(Category $category): bool;
|
||||
|
||||
/**
|
||||
* Delete all categories.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* Find a category.
|
||||
*
|
||||
@@ -106,6 +79,13 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function firstUseDate(Category $category): ?Carbon;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAttachments(Category $category): Collection;
|
||||
|
||||
/**
|
||||
* Get all categories with ID's.
|
||||
*
|
||||
@@ -122,6 +102,13 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function getCategories(): Collection;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNoteText(Category $category): ?string;
|
||||
|
||||
/**
|
||||
* Return most recent transaction(journal) date or null when never used before.
|
||||
*
|
||||
@@ -132,9 +119,16 @@ interface CategoryRepositoryInterface
|
||||
*/
|
||||
public function lastUseDate(Category $category, Collection $accounts): ?Carbon;
|
||||
|
||||
/**
|
||||
* Remove notes.
|
||||
*
|
||||
* @param Category $category
|
||||
*/
|
||||
public function removeNotes(Category $category): void;
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param int $limit
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -147,8 +141,9 @@ interface CategoryRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @return Category
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function store(array $data): Category;
|
||||
|
||||
@@ -159,4 +154,10 @@ interface CategoryRepositoryInterface
|
||||
* @return Category
|
||||
*/
|
||||
public function update(Category $category, array $data): Category;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param string $notes
|
||||
*/
|
||||
public function updateNotes(Category $category, string $notes): void;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -110,7 +109,7 @@ class OperationsRepository implements OperationsRepositoryInterface
|
||||
'source_account_id' => $journal['source_account_id'],
|
||||
'budget_name' => $journal['budget_name'],
|
||||
'source_account_name' => $journal['source_account_name'],
|
||||
'destination_account_id' => $journal['destination_account_id'],
|
||||
'destination_account_id' => $journal['destination_account_id'],
|
||||
'destination_account_name' => $journal['destination_account_name'],
|
||||
'description' => $journal['description'],
|
||||
'transaction_group_id' => $journal['transaction_group_id'],
|
||||
|
||||
Reference in New Issue
Block a user