Andrew Wallo 11 months ago
parent
commit
aef9f95691

+ 11
- 0
app/Enums/Accounting/AccountType.php View File

@@ -129,4 +129,15 @@ enum AccountType: string implements HasLabel
129 129
     {
130 130
         return ! $this->isNominal();
131 131
     }
132
+
133
+    public function isContra(): bool
134
+    {
135
+        return in_array($this, [
136
+            self::ContraAsset,
137
+            self::ContraLiability,
138
+            self::ContraEquity,
139
+            self::ContraRevenue,
140
+            self::ContraExpense,
141
+        ], true);
142
+    }
132 143
 }

+ 9
- 8
app/Services/ReportService.php View File

@@ -63,7 +63,7 @@ class ReportService
63 63
 
64 64
             /** @var Account $account */
65 65
             foreach ($accountsInCategory as $account) {
66
-                $accountBalances = $this->calculateAccountBalances($account, $category);
66
+                $accountBalances = $this->calculateAccountBalances($account);
67 67
 
68 68
                 foreach ($relevantFields as $field) {
69 69
                     $categorySummaryBalances[$field] += $accountBalances[$field];
@@ -98,8 +98,9 @@ class ReportService
98 98
         return new ReportDTO($accountCategories, $formattedReportTotalBalances, $columns);
99 99
     }
100 100
 
101
-    public function calculateAccountBalances(Account $account, AccountCategory $category): array
101
+    public function calculateAccountBalances(Account $account): array
102 102
     {
103
+        $category = $account->category;
103 104
         $balances = [
104 105
             'debit_balance' => $account->total_debit ?? 0,
105 106
             'credit_balance' => $account->total_credit ?? 0,
@@ -130,12 +131,12 @@ class ReportService
130 131
         $expenseTotal = 0;
131 132
 
132 133
         foreach ($revenueAccounts as $account) {
133
-            $revenueBalances = $this->calculateAccountBalances($account, AccountCategory::Revenue);
134
+            $revenueBalances = $this->calculateAccountBalances($account);
134 135
             $revenueTotal += $revenueBalances['net_movement'];
135 136
         }
136 137
 
137 138
         foreach ($expenseAccounts as $account) {
138
-            $expenseBalances = $this->calculateAccountBalances($account, AccountCategory::Expense);
139
+            $expenseBalances = $this->calculateAccountBalances($account);
139 140
             $expenseTotal += $expenseBalances['net_movement'];
140 141
         }
141 142
 
@@ -259,7 +260,7 @@ class ReportService
259 260
 
260 261
             /** @var Account $account */
261 262
             foreach ($accountsInCategory as $account) {
262
-                $accountBalances = $this->calculateAccountBalances($account, $category);
263
+                $accountBalances = $this->calculateAccountBalances($account);
263 264
 
264 265
                 $endingBalance = $accountBalances['ending_balance'] ?? $accountBalances['net_movement'];
265 266
 
@@ -402,7 +403,7 @@ class ReportService
402 403
                 };
403 404
 
404 405
                 if ($category !== null) {
405
-                    $accountBalances = $this->calculateAccountBalances($account, $category);
406
+                    $accountBalances = $this->calculateAccountBalances($account);
406 407
                     $movement = $accountBalances['net_movement'];
407 408
                     $netMovement += $movement;
408 409
                     $group['total'] += $movement;
@@ -517,7 +518,7 @@ class ReportService
517 518
         foreach ([$accounts, $adjustments] as $entries) {
518 519
             foreach ($entries as $entry) {
519 520
                 $accountCategory = $entry->type->getCategory();
520
-                $accountBalances = $this->calculateAccountBalances($entry, $accountCategory);
521
+                $accountBalances = $this->calculateAccountBalances($entry);
521 522
                 $netCashFlow = $accountBalances['net_movement'] ?? 0;
522 523
 
523 524
                 if ($entry->subtype->inverse_cash_flow) {
@@ -608,7 +609,7 @@ class ReportService
608 609
             /** @var Account $account */
609 610
             foreach ($accounts as $account) {
610 611
                 if ($account->type->getCategory() === $category) {
611
-                    $accountBalances = $this->calculateAccountBalances($account, $category);
612
+                    $accountBalances = $this->calculateAccountBalances($account);
612 613
                     $endingBalance = $accountBalances['ending_balance'] ?? $accountBalances['net_movement'];
613 614
 
614 615
                     $categorySummaryBalances['ending_balance'] += $endingBalance;

+ 6
- 6
composer.lock View File

@@ -4585,20 +4585,20 @@
4585 4585
         },
4586 4586
         {
4587 4587
             "name": "nesbot/carbon",
4588
-            "version": "3.8.0",
4588
+            "version": "3.8.1",
4589 4589
             "source": {
4590 4590
                 "type": "git",
4591 4591
                 "url": "https://github.com/briannesbitt/Carbon.git",
4592
-                "reference": "bbd3eef89af8ba66a3aa7952b5439168fbcc529f"
4592
+                "reference": "10ac0aa86b8062219ce21e8189123d611ca3ecd9"
4593 4593
             },
4594 4594
             "dist": {
4595 4595
                 "type": "zip",
4596
-                "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bbd3eef89af8ba66a3aa7952b5439168fbcc529f",
4597
-                "reference": "bbd3eef89af8ba66a3aa7952b5439168fbcc529f",
4596
+                "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/10ac0aa86b8062219ce21e8189123d611ca3ecd9",
4597
+                "reference": "10ac0aa86b8062219ce21e8189123d611ca3ecd9",
4598 4598
                 "shasum": ""
4599 4599
             },
4600 4600
             "require": {
4601
-                "carbonphp/carbon-doctrine-types": "*",
4601
+                "carbonphp/carbon-doctrine-types": "<100.0",
4602 4602
                 "ext-json": "*",
4603 4603
                 "php": "^8.1",
4604 4604
                 "psr/clock": "^1.0",
@@ -4687,7 +4687,7 @@
4687 4687
                     "type": "tidelift"
4688 4688
                 }
4689 4689
             ],
4690
-            "time": "2024-08-19T06:22:39+00:00"
4690
+            "time": "2024-11-03T16:02:24+00:00"
4691 4691
         },
4692 4692
         {
4693 4693
             "name": "nette/schema",

+ 17
- 3
database/factories/Accounting/TransactionFactory.php View File

@@ -49,13 +49,27 @@ class TransactionFactory extends Factory
49 49
             $type = $this->faker->randomElement([TransactionType::Deposit, TransactionType::Withdrawal]);
50 50
 
51 51
             $associatedAccountTypes = match ($type) {
52
-                TransactionType::Deposit => ['asset', 'liability', 'equity', 'revenue'],
53
-                TransactionType::Withdrawal => ['asset', 'liability', 'equity', 'expense'],
52
+                TransactionType::Deposit => [
53
+                    AccountType::CurrentLiability,
54
+                    AccountType::NonCurrentLiability,
55
+                    AccountType::Equity,
56
+                    AccountType::OperatingRevenue,
57
+                    AccountType::NonOperatingRevenue,
58
+                    AccountType::ContraExpense,
59
+                ],
60
+                TransactionType::Withdrawal => [
61
+                    AccountType::OperatingExpense,
62
+                    AccountType::NonOperatingExpense,
63
+                    AccountType::CurrentLiability,
64
+                    AccountType::NonCurrentLiability,
65
+                    AccountType::Equity,
66
+                    AccountType::ContraRevenue,
67
+                ],
54 68
             };
55 69
 
56 70
             $accountIdForBankAccount = $bankAccount->account->id;
57 71
 
58
-            $account = Account::where('category', $this->faker->randomElement($associatedAccountTypes))
72
+            $account = Account::whereIn('type', $associatedAccountTypes)
59 73
                 ->where('company_id', $company->id)
60 74
                 ->whereKeyNot($accountIdForBankAccount)
61 75
                 ->inRandomOrder()

+ 3
- 3
package-lock.json View File

@@ -1026,9 +1026,9 @@
1026 1026
             }
1027 1027
         },
1028 1028
         "node_modules/caniuse-lite": {
1029
-            "version": "1.0.30001676",
1030
-            "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001676.tgz",
1031
-            "integrity": "sha512-Qz6zwGCiPghQXGJvgQAem79esjitvJ+CxSbSQkW9H/UX5hg8XM88d4lp2W+MEQ81j+Hip58Il+jGVdazk1z9cw==",
1029
+            "version": "1.0.30001677",
1030
+            "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001677.tgz",
1031
+            "integrity": "sha512-fmfjsOlJUpMWu+mAAtZZZHz7UEwsUxIIvu1TJfO1HqFQvB/B+ii0xr9B5HpbZY/mC4XZ8SvjHJqtAY6pDPQEog==",
1032 1032
             "dev": true,
1033 1033
             "funding": [
1034 1034
                 {

Loading…
Cancel
Save