Andrew Wallo 2 maanden geleden
bovenliggende
commit
37dfe453a6

+ 0
- 3
app/DTO/ReportDTO.php Bestand weergeven

@@ -7,9 +7,6 @@ use Illuminate\Support\Carbon;
7 7
 class ReportDTO
8 8
 {
9 9
     public function __construct(
10
-        /**
11
-         * @var AccountCategoryDTO[]
12
-         */
13 10
         public array $categories,
14 11
         public ?AccountBalanceDTO $overallTotal = null,
15 12
         public ?AgingBucketDTO $agingSummary = null,

+ 3
- 3
app/Scopes/CurrentCompanyScope.php Bestand weergeven

@@ -16,12 +16,12 @@ class CurrentCompanyScope implements Scope
16 16
      */
17 17
     public function apply(Builder $builder, Model $model): void
18 18
     {
19
-        if (app()->runningInConsole()) {
19
+        $companyId = session('current_company_id');
20
+
21
+        if (! $companyId && app()->runningInConsole()) {
20 22
             return;
21 23
         }
22 24
 
23
-        $companyId = session('current_company_id');
24
-
25 25
         if (! $companyId && ($user = Auth::user()) && ($companyId = $user->current_company_id)) {
26 26
             session(['current_company_id' => $companyId]);
27 27
         }

+ 7
- 8
app/Services/ReportService.php Bestand weergeven

@@ -38,9 +38,12 @@ class ReportService
38 38
     ) {}
39 39
 
40 40
     /**
41
-     * @param  class-string<BalanceFormattable>|null  $dtoClass
41
+     * @template T of BalanceFormattable
42
+     *
43
+     * @param  class-string<T>|null  $dtoClass
44
+     * @return T
42 45
      */
43
-    public function formatBalances(array $balances, ?string $dtoClass = null, bool $formatZeros = true): BalanceFormattable | array
46
+    public function formatBalances(array $balances, ?string $dtoClass = null, bool $formatZeros = true)
44 47
     {
45 48
         $dtoClass ??= AccountBalanceDTO::class;
46 49
 
@@ -52,10 +55,6 @@ class ReportService
52 55
             return CurrencyConverter::formatCentsToMoney($balance);
53 56
         }, $balances);
54 57
 
55
-        if (! $dtoClass) {
56
-            return $formattedBalances;
57
-        }
58
-
59 58
         return $dtoClass::fromArray($formattedBalances);
60 59
     }
61 60
 
@@ -355,7 +354,7 @@ class ReportService
355 354
         return new ReportDTO(categories: $accountCategories, overallTotal: $formattedReportTotalBalances, fields: $columns, reportType: $trialBalanceType);
356 355
     }
357 356
 
358
-    public function getRetainedEarningsBalances(string $startDate, string $endDate): BalanceFormattable | array
357
+    public function getRetainedEarningsBalances(string $startDate, string $endDate): AccountBalanceDTO
359 358
     {
360 359
         $retainedEarningsAmount = $this->calculateRetainedEarnings($startDate, $endDate)->getAmount();
361 360
 
@@ -498,7 +497,7 @@ class ReportService
498 497
         );
499 498
     }
500 499
 
501
-    private function calculateTotalCashFlows(array $sections, string $startDate): BalanceFormattable | array
500
+    private function calculateTotalCashFlows(array $sections, string $startDate): AccountBalanceDTO
502 501
     {
503 502
         $totalInflow = 0;
504 503
         $totalOutflow = 0;

+ 6
- 6
tests/Feature/Reports/AccountBalancesReportTest.php Bestand weergeven

@@ -54,8 +54,8 @@ it('correctly builds an account balances report for the current fiscal year', fu
54 54
     livewire(AccountBalances::class)
55 55
         ->assertFormSet([
56 56
             'deferredFilters.dateRange' => $defaultDateRange,
57
-            'deferredFilters.startDate' => $defaultStartDate->toDateTimeString(),
58
-            'deferredFilters.endDate' => $defaultEndDate->toDateTimeString(),
57
+            'deferredFilters.startDate' => $defaultStartDate->toDateString(),
58
+            'deferredFilters.endDate' => $defaultEndDate->toDateString(),
59 59
         ])
60 60
         ->assertSet('filters', [
61 61
             'dateRange' => $defaultDateRange,
@@ -120,8 +120,8 @@ it('correctly builds an account balances report for the previous fiscal year', f
120 120
     livewire(AccountBalances::class)
121 121
         ->assertFormSet([
122 122
             'deferredFilters.dateRange' => $defaultDateRange,
123
-            'deferredFilters.startDate' => $defaultStartDate->toDateTimeString(),
124
-            'deferredFilters.endDate' => $defaultEndDate->toDateTimeString(),
123
+            'deferredFilters.startDate' => $defaultStartDate->toDateString(),
124
+            'deferredFilters.endDate' => $defaultEndDate->toDateString(),
125 125
         ])
126 126
         ->assertSet('filters', [
127 127
             'dateRange' => $defaultDateRange,
@@ -129,8 +129,8 @@ it('correctly builds an account balances report for the previous fiscal year', f
129 129
             'endDate' => $defaultEndDate->toDateString(),
130 130
         ])
131 131
         ->set('deferredFilters', [
132
-            'startDate' => $defaultStartDate->subYear()->startOfYear()->toDateTimeString(),
133
-            'endDate' => $defaultEndDate->subYear()->endOfYear()->toDateTimeString(),
132
+            'startDate' => $defaultStartDate->subYear()->startOfYear()->toDateString(),
133
+            'endDate' => $defaultEndDate->subYear()->endOfYear()->toDateString(),
134 134
         ])
135 135
         ->call('applyFilters')
136 136
         ->assertSeeTextInOrder([

+ 3
- 3
tests/Feature/Reports/TrialBalanceReportTest.php Bestand weergeven

@@ -60,7 +60,7 @@ it('correctly builds a standard trial balance report', function () {
60 60
         ->assertFormSet([
61 61
             'deferredFilters.reportType' => $defaultReportType,
62 62
             'deferredFilters.dateRange' => $defaultDateRange,
63
-            'deferredFilters.asOfDate' => $defaultEndDate->toDateTimeString(),
63
+            'deferredFilters.asOfDate' => $defaultEndDate->toDateString(),
64 64
         ])
65 65
         ->assertSet('filters', [
66 66
             'reportType' => $defaultReportType,
@@ -125,7 +125,7 @@ it('correctly builds a post-closing trial balance report', function () {
125 125
 
126 126
     $formattedExpectedBalances = Reporting::formatBalances($calculatedTrialBalances);
127 127
 
128
-    $formattedRetainedEarningsBalances = Reporting::getRetainedEarningsBalances($earliestTransactionDate->toDateTimeString(), $defaultEndDate->toDateTimeString());
128
+    $formattedRetainedEarningsBalances = Reporting::getRetainedEarningsBalances($earliestTransactionDate->toDateString(), $defaultEndDate->toDateString());
129 129
 
130 130
     // Use Livewire to assert the report's filters and displayed data
131 131
     livewire(TrialBalance::class)
@@ -133,7 +133,7 @@ it('correctly builds a post-closing trial balance report', function () {
133 133
         ->assertFormSet([
134 134
             'deferredFilters.reportType' => $defaultReportType,
135 135
             'deferredFilters.dateRange' => $defaultDateRange,
136
-            'deferredFilters.asOfDate' => $defaultEndDate->toDateTimeString(),
136
+            'deferredFilters.asOfDate' => $defaultEndDate->toDateString(),
137 137
         ])
138 138
         ->call('applyFilters')
139 139
         ->assertSet('filters', [

Laden…
Annuleren
Opslaan