Andrew Wallo 11 månader sedan
förälder
incheckning
aef9f95691

+ 11
- 0
app/Enums/Accounting/AccountType.php Visa fil

129
     {
129
     {
130
         return ! $this->isNominal();
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 Visa fil

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

+ 6
- 6
composer.lock Visa fil

4585
         },
4585
         },
4586
         {
4586
         {
4587
             "name": "nesbot/carbon",
4587
             "name": "nesbot/carbon",
4588
-            "version": "3.8.0",
4588
+            "version": "3.8.1",
4589
             "source": {
4589
             "source": {
4590
                 "type": "git",
4590
                 "type": "git",
4591
                 "url": "https://github.com/briannesbitt/Carbon.git",
4591
                 "url": "https://github.com/briannesbitt/Carbon.git",
4592
-                "reference": "bbd3eef89af8ba66a3aa7952b5439168fbcc529f"
4592
+                "reference": "10ac0aa86b8062219ce21e8189123d611ca3ecd9"
4593
             },
4593
             },
4594
             "dist": {
4594
             "dist": {
4595
                 "type": "zip",
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
                 "shasum": ""
4598
                 "shasum": ""
4599
             },
4599
             },
4600
             "require": {
4600
             "require": {
4601
-                "carbonphp/carbon-doctrine-types": "*",
4601
+                "carbonphp/carbon-doctrine-types": "<100.0",
4602
                 "ext-json": "*",
4602
                 "ext-json": "*",
4603
                 "php": "^8.1",
4603
                 "php": "^8.1",
4604
                 "psr/clock": "^1.0",
4604
                 "psr/clock": "^1.0",
4687
                     "type": "tidelift"
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
             "name": "nette/schema",
4693
             "name": "nette/schema",

+ 17
- 3
database/factories/Accounting/TransactionFactory.php Visa fil

49
             $type = $this->faker->randomElement([TransactionType::Deposit, TransactionType::Withdrawal]);
49
             $type = $this->faker->randomElement([TransactionType::Deposit, TransactionType::Withdrawal]);
50
 
50
 
51
             $associatedAccountTypes = match ($type) {
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
             $accountIdForBankAccount = $bankAccount->account->id;
70
             $accountIdForBankAccount = $bankAccount->account->id;
57
 
71
 
58
-            $account = Account::where('category', $this->faker->randomElement($associatedAccountTypes))
72
+            $account = Account::whereIn('type', $associatedAccountTypes)
59
                 ->where('company_id', $company->id)
73
                 ->where('company_id', $company->id)
60
                 ->whereKeyNot($accountIdForBankAccount)
74
                 ->whereKeyNot($accountIdForBankAccount)
61
                 ->inRandomOrder()
75
                 ->inRandomOrder()

+ 3
- 3
package-lock.json Visa fil

1026
             }
1026
             }
1027
         },
1027
         },
1028
         "node_modules/caniuse-lite": {
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
             "dev": true,
1032
             "dev": true,
1033
             "funding": [
1033
             "funding": [
1034
                 {
1034
                 {

Laddar…
Avbryt
Spara