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

JournalEntryRepository.php 1.1KB

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