Andrew Wallo пре 2 месеци
родитељ
комит
37dfe453a6

+ 0
- 3
app/DTO/ReportDTO.php Прегледај датотеку

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

+ 3
- 3
app/Scopes/CurrentCompanyScope.php Прегледај датотеку

16
      */
16
      */
17
     public function apply(Builder $builder, Model $model): void
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
             return;
22
             return;
21
         }
23
         }
22
 
24
 
23
-        $companyId = session('current_company_id');
24
-
25
         if (! $companyId && ($user = Auth::user()) && ($companyId = $user->current_company_id)) {
25
         if (! $companyId && ($user = Auth::user()) && ($companyId = $user->current_company_id)) {
26
             session(['current_company_id' => $companyId]);
26
             session(['current_company_id' => $companyId]);
27
         }
27
         }

+ 7
- 8
app/Services/ReportService.php Прегледај датотеку

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
         $dtoClass ??= AccountBalanceDTO::class;
48
         $dtoClass ??= AccountBalanceDTO::class;
46
 
49
 
52
             return CurrencyConverter::formatCentsToMoney($balance);
55
             return CurrencyConverter::formatCentsToMoney($balance);
53
         }, $balances);
56
         }, $balances);
54
 
57
 
55
-        if (! $dtoClass) {
56
-            return $formattedBalances;
57
-        }
58
-
59
         return $dtoClass::fromArray($formattedBalances);
58
         return $dtoClass::fromArray($formattedBalances);
60
     }
59
     }
61
 
60
 
355
         return new ReportDTO(categories: $accountCategories, overallTotal: $formattedReportTotalBalances, fields: $columns, reportType: $trialBalanceType);
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
         $retainedEarningsAmount = $this->calculateRetainedEarnings($startDate, $endDate)->getAmount();
359
         $retainedEarningsAmount = $this->calculateRetainedEarnings($startDate, $endDate)->getAmount();
361
 
360
 
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
         $totalInflow = 0;
502
         $totalInflow = 0;
504
         $totalOutflow = 0;
503
         $totalOutflow = 0;

+ 6
- 6
tests/Feature/Reports/AccountBalancesReportTest.php Прегледај датотеку

54
     livewire(AccountBalances::class)
54
     livewire(AccountBalances::class)
55
         ->assertFormSet([
55
         ->assertFormSet([
56
             'deferredFilters.dateRange' => $defaultDateRange,
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
         ->assertSet('filters', [
60
         ->assertSet('filters', [
61
             'dateRange' => $defaultDateRange,
61
             'dateRange' => $defaultDateRange,
120
     livewire(AccountBalances::class)
120
     livewire(AccountBalances::class)
121
         ->assertFormSet([
121
         ->assertFormSet([
122
             'deferredFilters.dateRange' => $defaultDateRange,
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
         ->assertSet('filters', [
126
         ->assertSet('filters', [
127
             'dateRange' => $defaultDateRange,
127
             'dateRange' => $defaultDateRange,
129
             'endDate' => $defaultEndDate->toDateString(),
129
             'endDate' => $defaultEndDate->toDateString(),
130
         ])
130
         ])
131
         ->set('deferredFilters', [
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
         ->call('applyFilters')
135
         ->call('applyFilters')
136
         ->assertSeeTextInOrder([
136
         ->assertSeeTextInOrder([

+ 3
- 3
tests/Feature/Reports/TrialBalanceReportTest.php Прегледај датотеку

60
         ->assertFormSet([
60
         ->assertFormSet([
61
             'deferredFilters.reportType' => $defaultReportType,
61
             'deferredFilters.reportType' => $defaultReportType,
62
             'deferredFilters.dateRange' => $defaultDateRange,
62
             'deferredFilters.dateRange' => $defaultDateRange,
63
-            'deferredFilters.asOfDate' => $defaultEndDate->toDateTimeString(),
63
+            'deferredFilters.asOfDate' => $defaultEndDate->toDateString(),
64
         ])
64
         ])
65
         ->assertSet('filters', [
65
         ->assertSet('filters', [
66
             'reportType' => $defaultReportType,
66
             'reportType' => $defaultReportType,
125
 
125
 
126
     $formattedExpectedBalances = Reporting::formatBalances($calculatedTrialBalances);
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
     // Use Livewire to assert the report's filters and displayed data
130
     // Use Livewire to assert the report's filters and displayed data
131
     livewire(TrialBalance::class)
131
     livewire(TrialBalance::class)
133
         ->assertFormSet([
133
         ->assertFormSet([
134
             'deferredFilters.reportType' => $defaultReportType,
134
             'deferredFilters.reportType' => $defaultReportType,
135
             'deferredFilters.dateRange' => $defaultDateRange,
135
             'deferredFilters.dateRange' => $defaultDateRange,
136
-            'deferredFilters.asOfDate' => $defaultEndDate->toDateTimeString(),
136
+            'deferredFilters.asOfDate' => $defaultEndDate->toDateString(),
137
         ])
137
         ])
138
         ->call('applyFilters')
138
         ->call('applyFilters')
139
         ->assertSet('filters', [
139
         ->assertSet('filters', [

Loading…
Откажи
Сачувај