Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

TrialBalanceReportTest.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. use App\Facades\Accounting;
  3. use App\Facades\Reporting;
  4. use App\Factories\ReportDateFactory;
  5. use App\Filament\Company\Pages\Reports\TrialBalance;
  6. use App\Models\Accounting\Transaction;
  7. use function Pest\Livewire\livewire;
  8. it('correctly builds a standard trial balance report', function () {
  9. $testCompany = $this->testCompany;
  10. $reportDates = ReportDateFactory::create($testCompany);
  11. $defaultDateRange = $reportDates->defaultDateRange;
  12. $defaultStartDate = $reportDates->defaultStartDate->toImmutable();
  13. $defaultEndDate = $reportDates->defaultEndDate->toImmutable();
  14. $defaultReportType = 'standard';
  15. $depositAmount = 1000;
  16. $withdrawalAmount = 1000;
  17. $depositCount = 10;
  18. $withdrawalCount = 10;
  19. Transaction::factory()
  20. ->forDefaultBankAccount()
  21. ->forUncategorizedRevenue()
  22. ->asDeposit($depositAmount)
  23. ->count($depositCount)
  24. ->state([
  25. 'posted_at' => $defaultStartDate->subWeek(),
  26. ])
  27. ->create();
  28. Transaction::factory()
  29. ->forDefaultBankAccount()
  30. ->forUncategorizedExpense()
  31. ->asWithdrawal($withdrawalAmount)
  32. ->count($withdrawalCount)
  33. ->state([
  34. 'posted_at' => now()->subWeek(),
  35. ])
  36. ->create();
  37. $defaultBankAccountAccount = $testCompany->default->bankAccount->account;
  38. $earliestTransactionDate = $reportDates->refresh()->earliestTransactionDate;
  39. $expectedBalances = Accounting::getBalances(
  40. $defaultBankAccountAccount,
  41. $earliestTransactionDate->toDateString(),
  42. $defaultEndDate->toDateString(),
  43. );
  44. $calculatedTrialBalances = Reporting::calculateTrialBalances($defaultBankAccountAccount->category, $expectedBalances['ending_balance']);
  45. $formattedExpectedBalances = Reporting::formatBalances($calculatedTrialBalances);
  46. livewire(TrialBalance::class)
  47. ->assertFormSet([
  48. 'deferredFilters.reportType' => $defaultReportType,
  49. 'deferredFilters.dateRange' => $defaultDateRange,
  50. 'deferredFilters.asOfDate' => $defaultEndDate->toDateTimeString(),
  51. ])
  52. ->assertSet('filters', [
  53. 'reportType' => $defaultReportType,
  54. 'dateRange' => $defaultDateRange,
  55. 'asOfDate' => $defaultEndDate->toDateString(),
  56. ])
  57. ->call('applyFilters')
  58. ->assertDontSeeText('Retained Earnings')
  59. ->assertSeeTextInOrder([
  60. $defaultBankAccountAccount->code,
  61. $defaultBankAccountAccount->name,
  62. $formattedExpectedBalances->debitBalance,
  63. $formattedExpectedBalances->creditBalance,
  64. ])
  65. ->assertReportTableData();
  66. });
  67. it('correctly builds a post-closing trial balance report', function () {
  68. $testCompany = $this->testCompany;
  69. $reportDates = ReportDateFactory::create($testCompany);
  70. $defaultDateRange = $reportDates->defaultDateRange;
  71. $defaultStartDate = $reportDates->defaultStartDate->toImmutable();
  72. $defaultEndDate = $reportDates->defaultEndDate->toImmutable();
  73. $defaultReportType = 'postClosing';
  74. $depositAmount = 2000;
  75. $withdrawalAmount = 1000;
  76. $depositCount = 5;
  77. $withdrawalCount = 5;
  78. Transaction::factory()
  79. ->forDefaultBankAccount()
  80. ->forUncategorizedRevenue()
  81. ->asDeposit($depositAmount)
  82. ->count($depositCount)
  83. ->state([
  84. 'posted_at' => $defaultStartDate->subWeek(),
  85. ])
  86. ->create();
  87. Transaction::factory()
  88. ->forDefaultBankAccount()
  89. ->forUncategorizedExpense()
  90. ->asWithdrawal($withdrawalAmount)
  91. ->count($withdrawalCount)
  92. ->state([
  93. 'posted_at' => now()->subWeek(),
  94. ])
  95. ->create();
  96. $defaultBankAccountAccount = $testCompany->default->bankAccount->account;
  97. $earliestTransactionDate = $reportDates->refresh()->earliestTransactionDate;
  98. $expectedBalances = Accounting::getBalances(
  99. $defaultBankAccountAccount,
  100. $earliestTransactionDate->toDateString(),
  101. $defaultEndDate->toDateString(),
  102. );
  103. $calculatedTrialBalances = Reporting::calculateTrialBalances($defaultBankAccountAccount->category, $expectedBalances['ending_balance']);
  104. $formattedExpectedBalances = Reporting::formatBalances($calculatedTrialBalances);
  105. $formattedRetainedEarningsBalances = Reporting::getRetainedEarningsBalances($earliestTransactionDate->toDateTimeString(), $defaultEndDate->toDateTimeString());
  106. // Use Livewire to assert the report's filters and displayed data
  107. livewire(TrialBalance::class)
  108. ->set('deferredFilters.reportType', $defaultReportType)
  109. ->assertFormSet([
  110. 'deferredFilters.reportType' => $defaultReportType,
  111. 'deferredFilters.dateRange' => $defaultDateRange,
  112. 'deferredFilters.asOfDate' => $defaultEndDate->toDateTimeString(),
  113. ])
  114. ->call('applyFilters')
  115. ->assertSet('filters', [
  116. 'reportType' => $defaultReportType,
  117. 'dateRange' => $defaultDateRange,
  118. 'asOfDate' => $defaultEndDate->toDateString(),
  119. ])
  120. ->assertSeeTextInOrder([
  121. $defaultBankAccountAccount->code,
  122. $defaultBankAccountAccount->name,
  123. $formattedExpectedBalances->debitBalance,
  124. $formattedExpectedBalances->creditBalance,
  125. ])
  126. ->assertSeeText('Retained Earnings')
  127. ->assertSeeTextInOrder([
  128. 'RE',
  129. 'Retained Earnings',
  130. $formattedRetainedEarningsBalances->debitBalance,
  131. $formattedRetainedEarningsBalances->creditBalance,
  132. ])
  133. ->assertSeeTextInOrder([
  134. 'Total Revenue',
  135. '$0.00',
  136. '$0.00',
  137. ])
  138. ->assertSeeTextInOrder([
  139. 'Total Expenses',
  140. '$0.00',
  141. '$0.00',
  142. ])
  143. ->assertReportTableData();
  144. });