Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

InvoiceCollection.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  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. public function sumMoneyFormatted(string $column, ?string $currency = null): string
  22. {
  23. $currency ??= CurrencyAccessor::getDefaultCurrency();
  24. $totalCents = $this->sumMoneyInCents($column);
  25. return CurrencyConverter::formatCentsToMoney($totalCents, $currency);
  26. }
  27. }