mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clean up repository.
This commit is contained in:
parent
bfa7ee90f4
commit
ac8ff4e565
@ -36,9 +36,9 @@ class ChartJsPiggyBankChartGenerator implements PiggyBankChartGeneratorInterface
|
||||
],
|
||||
];
|
||||
$sum = '0';
|
||||
foreach ($set as $entry) {
|
||||
$date = new Carbon($entry->date);
|
||||
$sum = bcadd($sum, $entry->sum);
|
||||
foreach ($set as $key => $value) {
|
||||
$date = new Carbon($key);
|
||||
$sum = bcadd($sum, $value);
|
||||
$data['labels'][] = $date->formatLocalized($format);
|
||||
$data['datasets'][0]['data'][] = round($sum, 2);
|
||||
}
|
||||
|
@ -5,8 +5,10 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Support\Collection;
|
||||
use Response;
|
||||
|
||||
|
||||
@ -49,8 +51,20 @@ class PiggyBankController extends Controller
|
||||
return Response::json($cache->get());
|
||||
}
|
||||
|
||||
$set = $repository->getEventSummarySet($piggyBank);
|
||||
$data = $this->generator->history($set);
|
||||
$set = $repository->getEvents($piggyBank);
|
||||
$set = $set->reverse();
|
||||
$collection = [];
|
||||
/** @var PiggyBankEvent $entry */
|
||||
foreach ($set as $entry) {
|
||||
$date = $entry->date->format('Y-m-d');
|
||||
$amount = $entry->amount;
|
||||
if (isset($collection[$date])) {
|
||||
$amount = bcadd($amount, $collection[$date]);
|
||||
}
|
||||
$collection[$date] = $amount;
|
||||
}
|
||||
|
||||
$data = $this->generator->history(new Collection($collection));
|
||||
$cache->store($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
@ -22,7 +22,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* BillRepository constructor.
|
||||
* PiggyBankRepository constructor.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
@ -48,6 +48,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(PiggyBank $piggyBank): bool
|
||||
{
|
||||
@ -56,18 +57,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getEventSummarySet(PiggyBank $piggyBank): Collection
|
||||
{
|
||||
$var = DB::table('piggy_bank_events')->where('piggy_bank_id', $piggyBank->id)->groupBy('date')->get(['date', DB::raw('SUM(`amount`) AS `sum`')]);
|
||||
|
||||
return new Collection($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
|
@ -16,6 +16,8 @@ interface PiggyBankRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a new event.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param string $amount
|
||||
*
|
||||
@ -24,6 +26,8 @@ interface PiggyBankRepositoryInterface
|
||||
public function createEvent(PiggyBank $piggyBank, string $amount): PiggyBankEvent;
|
||||
|
||||
/**
|
||||
* Destroy piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return bool
|
||||
@ -31,13 +35,8 @@ interface PiggyBankRepositoryInterface
|
||||
public function destroy(PiggyBank $piggyBank): bool;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
* Get all events.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getEventSummarySet(PiggyBank $piggyBank) : Collection;
|
||||
|
||||
/**
|
||||
* @param PiggyBank $piggyBank
|
||||
*
|
||||
* @return Collection
|
||||
@ -45,11 +44,15 @@ interface PiggyBankRepositoryInterface
|
||||
public function getEvents(PiggyBank $piggyBank) : Collection;
|
||||
|
||||
/**
|
||||
* Highest order of all piggy banks.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxOrder(): int;
|
||||
|
||||
/**
|
||||
* Return all piggy banks.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPiggyBanks() : Collection;
|
||||
@ -62,8 +65,7 @@ interface PiggyBankRepositoryInterface
|
||||
public function reset(): bool;
|
||||
|
||||
/**
|
||||
*
|
||||
* set id of piggy bank.
|
||||
* Set specific piggy bank to specific order.
|
||||
*
|
||||
* @param int $piggyBankId
|
||||
* @param int $order
|
||||
@ -74,6 +76,8 @@ interface PiggyBankRepositoryInterface
|
||||
|
||||
|
||||
/**
|
||||
* Store new piggy bank.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return PiggyBank
|
||||
@ -81,6 +85,8 @@ interface PiggyBankRepositoryInterface
|
||||
public function store(array $data): PiggyBank;
|
||||
|
||||
/**
|
||||
* Update existing piggy bank.
|
||||
*
|
||||
* @param PiggyBank $piggyBank
|
||||
* @param array $data
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user