123456789101112131415161718192021222324252627282930313233343536
  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. if ($collection->count()) {
  14. return $this->setRupiahFormat($this->totalPrice($collection), true);
  15. } else {
  16. return $this->setRupiahFormat(0, true);
  17. }
  18. }
  19. public function totalPerMonth(EloquentCollection $collections)
  20. {
  21. return $collections->transform(fn($collection) => $collection->count());
  22. }
  23. public function statisticData(SupportCollection $collections, int $take = -1)
  24. {
  25. $collections = $collections->take($take);
  26. $collections->transform(fn($collections) => $this->totalPerMonth($collections));
  27. return $collections;
  28. }
  29. }