您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JournalEntryRepository.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Repositories\Accounting;
  3. use App\Models\Accounting\Account;
  4. use Illuminate\Database\Eloquent\Builder;
  5. class JournalEntryRepository
  6. {
  7. public function sumAmounts(Account $account, string $type, ?string $startDate = null, ?string $endDate = null): int
  8. {
  9. $query = $account->journalEntries()->where('type', $type);
  10. if ($startDate && $endDate) {
  11. $query->whereHas('transaction', static function (Builder $query) use ($startDate, $endDate) {
  12. $query->whereBetween('posted_at', [$startDate, $endDate]);
  13. });
  14. } elseif ($startDate) {
  15. $query->whereHas('transaction', static function (Builder $query) use ($startDate) {
  16. $query->where('posted_at', '<=', $startDate);
  17. });
  18. }
  19. return $query->sum('amount');
  20. }
  21. public function sumDebitAmounts(Account $account, string $startDate, ?string $endDate = null): int
  22. {
  23. return $this->sumAmounts($account, 'debit', $startDate, $endDate);
  24. }
  25. public function sumCreditAmounts(Account $account, string $startDate, ?string $endDate = null): int
  26. {
  27. return $this->sumAmounts($account, 'credit', $startDate, $endDate);
  28. }
  29. }