You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InvoiceCollection.php 812B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Collections\Accounting;
  3. use App\Models\Accounting\Invoice;
  4. use App\Utilities\Currency\CurrencyAccessor;
  5. use App\Utilities\Currency\CurrencyConverter;
  6. use Illuminate\Database\Eloquent\Collection;
  7. class InvoiceCollection extends Collection
  8. {
  9. public function sumMoneyInCents(string $column): int
  10. {
  11. return $this->reduce(static function ($carry, Invoice $invoice) use ($column) {
  12. return $carry + $invoice->getRawOriginal($column);
  13. }, 0);
  14. }
  15. public function sumMoneyFormattedSimple(string $column, ?string $currency = null): string
  16. {
  17. $currency ??= CurrencyAccessor::getDefaultCurrency();
  18. $totalCents = $this->sumMoneyInCents($column);
  19. return CurrencyConverter::convertCentsToFormatSimple($totalCents, $currency);
  20. }
  21. }