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';
|
$sum = '0';
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $key => $value) {
|
||||||
$date = new Carbon($entry->date);
|
$date = new Carbon($key);
|
||||||
$sum = bcadd($sum, $entry->sum);
|
$sum = bcadd($sum, $value);
|
||||||
$data['labels'][] = $date->formatLocalized($format);
|
$data['labels'][] = $date->formatLocalized($format);
|
||||||
$data['datasets'][0]['data'][] = round($sum, 2);
|
$data['datasets'][0]['data'][] = round($sum, 2);
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,10 @@ namespace FireflyIII\Http\Controllers\Chart;
|
|||||||
|
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
|
use FireflyIII\Models\PiggyBankEvent;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
use FireflyIII\Support\CacheProperties;
|
use FireflyIII\Support\CacheProperties;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Response;
|
use Response;
|
||||||
|
|
||||||
|
|
||||||
@ -49,8 +51,20 @@ class PiggyBankController extends Controller
|
|||||||
return Response::json($cache->get());
|
return Response::json($cache->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
$set = $repository->getEventSummarySet($piggyBank);
|
$set = $repository->getEvents($piggyBank);
|
||||||
$data = $this->generator->history($set);
|
$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);
|
$cache->store($data);
|
||||||
|
|
||||||
return Response::json($data);
|
return Response::json($data);
|
||||||
|
@ -22,7 +22,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BillRepository constructor.
|
* PiggyBankRepository constructor.
|
||||||
*
|
*
|
||||||
* @param User $user
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
@ -48,6 +48,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
* @param PiggyBank $piggyBank
|
* @param PiggyBank $piggyBank
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function destroy(PiggyBank $piggyBank): bool
|
public function destroy(PiggyBank $piggyBank): bool
|
||||||
{
|
{
|
||||||
@ -56,18 +57,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
return true;
|
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
|
* @param PiggyBank $piggyBank
|
||||||
*
|
*
|
||||||
|
@ -16,6 +16,8 @@ interface PiggyBankRepositoryInterface
|
|||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Create a new event.
|
||||||
|
*
|
||||||
* @param PiggyBank $piggyBank
|
* @param PiggyBank $piggyBank
|
||||||
* @param string $amount
|
* @param string $amount
|
||||||
*
|
*
|
||||||
@ -24,6 +26,8 @@ interface PiggyBankRepositoryInterface
|
|||||||
public function createEvent(PiggyBank $piggyBank, string $amount): PiggyBankEvent;
|
public function createEvent(PiggyBank $piggyBank, string $amount): PiggyBankEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Destroy piggy bank.
|
||||||
|
*
|
||||||
* @param PiggyBank $piggyBank
|
* @param PiggyBank $piggyBank
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
@ -31,13 +35,8 @@ interface PiggyBankRepositoryInterface
|
|||||||
public function destroy(PiggyBank $piggyBank): bool;
|
public function destroy(PiggyBank $piggyBank): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param PiggyBank $piggyBank
|
* Get all events.
|
||||||
*
|
*
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getEventSummarySet(PiggyBank $piggyBank) : Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param PiggyBank $piggyBank
|
* @param PiggyBank $piggyBank
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
@ -45,11 +44,15 @@ interface PiggyBankRepositoryInterface
|
|||||||
public function getEvents(PiggyBank $piggyBank) : Collection;
|
public function getEvents(PiggyBank $piggyBank) : Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Highest order of all piggy banks.
|
||||||
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getMaxOrder(): int;
|
public function getMaxOrder(): int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Return all piggy banks.
|
||||||
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getPiggyBanks() : Collection;
|
public function getPiggyBanks() : Collection;
|
||||||
@ -62,8 +65,7 @@ interface PiggyBankRepositoryInterface
|
|||||||
public function reset(): bool;
|
public function reset(): bool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Set specific piggy bank to specific order.
|
||||||
* set id of piggy bank.
|
|
||||||
*
|
*
|
||||||
* @param int $piggyBankId
|
* @param int $piggyBankId
|
||||||
* @param int $order
|
* @param int $order
|
||||||
@ -74,6 +76,8 @@ interface PiggyBankRepositoryInterface
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Store new piggy bank.
|
||||||
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return PiggyBank
|
* @return PiggyBank
|
||||||
@ -81,6 +85,8 @@ interface PiggyBankRepositoryInterface
|
|||||||
public function store(array $data): PiggyBank;
|
public function store(array $data): PiggyBank;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Update existing piggy bank.
|
||||||
|
*
|
||||||
* @param PiggyBank $piggyBank
|
* @param PiggyBank $piggyBank
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user