mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-13 16:00:13 +00:00
use journal repository instead of direct calls.
This commit is contained in:
@@ -63,66 +63,6 @@ trait TransactionJournalTrait
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function amount(): string
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($this->id);
|
||||
$cache->addProperty('transaction-journal');
|
||||
$cache->addProperty('amount');
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// saves on queries:
|
||||
$amount = $this->transactions()->where('amount', '>', 0)->get()->sum('amount');
|
||||
|
||||
if ($this->isWithdrawal()) {
|
||||
$amount = $amount * -1;
|
||||
}
|
||||
$amount = strval($amount);
|
||||
$cache->store($amount);
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function amountPositive(): string
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($this->id);
|
||||
$cache->addProperty('transaction-journal');
|
||||
$cache->addProperty('amount-positive');
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
// saves on queries:
|
||||
$amount = $this->transactions()->where('amount', '>', 0)->get()->sum('amount');
|
||||
|
||||
$amount = strval($amount);
|
||||
$cache->store($amount);
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function budgetId(): int
|
||||
{
|
||||
$budget = $this->budgets()->first();
|
||||
if (null !== $budget) {
|
||||
return $budget->id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
@@ -133,51 +73,6 @@ trait TransactionJournalTrait
|
||||
*/
|
||||
abstract public function categories(): BelongsToMany;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function categoryAsString(): string
|
||||
{
|
||||
$category = $this->categories()->first();
|
||||
if (null !== $category) {
|
||||
return $category->name;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dateField
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function dateAsString(string $dateField = ''): string
|
||||
{
|
||||
if ('' === $dateField) {
|
||||
return $this->date->format('Y-m-d');
|
||||
}
|
||||
if (null !== $this->$dateField && $this->$dateField instanceof Carbon) {
|
||||
// make field NULL
|
||||
$carbon = clone $this->$dateField;
|
||||
$this->$dateField = null;
|
||||
$this->save();
|
||||
|
||||
// create meta entry
|
||||
$this->setMeta($dateField, $carbon);
|
||||
|
||||
// return that one instead.
|
||||
return $carbon->format('Y-m-d');
|
||||
}
|
||||
$metaField = $this->getMeta($dateField);
|
||||
if (null !== $metaField) {
|
||||
$carbon = new Carbon($metaField);
|
||||
|
||||
return $carbon->format('Y-m-d');
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
|
Reference in New Issue
Block a user