ExpenseService.php 986B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Database\Eloquent\Collection as EloquentCollection;
  4. use Illuminate\Support\Collection as SupportCollection;
  5. class ExpenseService extends CurrencyFormatService
  6. {
  7. public function totalPrice(EloquentCollection $collections)
  8. {
  9. return $collections->sum(fn($collection) => $collection->getRawOriginal('amount'));
  10. }
  11. public function totalPriceAsString(EloquentCollection $collection)
  12. {
  13. return (new CurrencyFormatService)->setRupiahFormat($this->totalPrice($collection), true);
  14. }
  15. public function totalPerMonth(EloquentCollection $collections)
  16. {
  17. return $collections->transform(fn($collection) => $collection->count());
  18. }
  19. public function statisticData(SupportCollection $collections, int $take = -1)
  20. {
  21. $collections = $collections->take($take);
  22. $collections->transform(fn($collections) => $this->totalPerMonth($collections));
  23. return $collections;
  24. }
  25. }