Browse Source

Merge pull request #189 from andrewdwallo/development-3.x

Development 3.x
3.x
Andrew Wallo 3 months ago
parent
commit
ce6283e886
No account linked to committer's email address

+ 4
- 3
app/Concerns/HasJournalEntryActions.php View File

@@ -4,6 +4,7 @@ namespace App\Concerns;
4 4
 
5 5
 use App\Enums\Accounting\JournalEntryType;
6 6
 use App\Utilities\Currency\CurrencyAccessor;
7
+use App\Utilities\Currency\CurrencyConverter;
7 8
 use Filament\Tables\Actions\Action;
8 9
 
9 10
 trait HasJournalEntryActions
@@ -14,7 +15,7 @@ trait HasJournalEntryActions
14 15
 
15 16
     private function formatMoney(int $amount): string
16 17
     {
17
-        return money($amount, CurrencyAccessor::getDefaultCurrency())->format();
18
+        return CurrencyConverter::formatCentsToMoney($amount, CurrencyAccessor::getDefaultCurrency());
18 19
     }
19 20
 
20 21
     /**
@@ -184,7 +185,7 @@ trait HasJournalEntryActions
184 185
             return '0';
185 186
         }
186 187
 
187
-        $currency = currency(CurrencyAccessor::getDefaultCurrency());
188
+        $currency = currency('USD');
188 189
         $decimal = $currency->getDecimalMark();
189 190
 
190 191
         if (substr($amount, -1) === $decimal) {
@@ -201,6 +202,6 @@ trait HasJournalEntryActions
201 202
      */
202 203
     protected function convertAmountToCents(string $amount): int
203 204
     {
204
-        return money($amount, CurrencyAccessor::getDefaultCurrency(), true)->getAmount();
205
+        return CurrencyConverter::convertToCents($amount, 'USD');
205 206
     }
206 207
 }

+ 18
- 8
app/Concerns/HasTransactionAction.php View File

@@ -9,6 +9,7 @@ use App\Models\Accounting\JournalEntry;
9 9
 use App\Models\Accounting\Transaction;
10 10
 use App\Models\Banking\BankAccount;
11 11
 use App\Utilities\Currency\CurrencyAccessor;
12
+use App\Utilities\Currency\CurrencyConverter;
12 13
 use Awcodes\TableRepeater\Header;
13 14
 use Closure;
14 15
 use Filament\Forms;
@@ -251,20 +252,23 @@ trait HasTransactionAction
251 252
 
252 253
                         $hasDebit = false;
253 254
                         $hasCredit = false;
255
+                        $totalDebits = 0;
256
+                        $totalCredits = 0;
254 257
 
255 258
                         foreach ($value as $entry) {
256
-                            if (! isset($entry['type'])) {
259
+                            if (! isset($entry['type']) || ! isset($entry['amount'])) {
257 260
                                 continue;
258 261
                             }
259 262
 
260
-                            if (JournalEntryType::parse($entry['type'])->isDebit()) {
263
+                            $entryType = JournalEntryType::parse($entry['type']);
264
+                            $amount = CurrencyConverter::convertToCents($entry['amount'], 'USD');
265
+
266
+                            if ($entryType->isDebit()) {
261 267
                                 $hasDebit = true;
262
-                            } elseif (JournalEntryType::parse($entry['type'])->isCredit()) {
268
+                                $totalDebits += $amount;
269
+                            } elseif ($entryType->isCredit()) {
263 270
                                 $hasCredit = true;
264
-                            }
265
-
266
-                            if ($hasDebit && $hasCredit) {
267
-                                break;
271
+                                $totalCredits += $amount;
268 272
                             }
269 273
                         }
270 274
 
@@ -275,6 +279,12 @@ trait HasTransactionAction
275 279
                         if (! $hasCredit) {
276 280
                             $fail('At least one credit entry is required.');
277 281
                         }
282
+
283
+                        if ($totalDebits !== $totalCredits) {
284
+                            $debitFormatted = CurrencyConverter::formatCentsToMoney($totalDebits, CurrencyAccessor::getDefaultCurrency());
285
+                            $creditFormatted = CurrencyConverter::formatCentsToMoney($totalCredits, CurrencyAccessor::getDefaultCurrency());
286
+                            $fail("Total debits ({$debitFormatted}) must equal total credits ({$creditFormatted}).");
287
+                        }
278 288
                     };
279 289
                 },
280 290
             ])
@@ -326,7 +336,7 @@ trait HasTransactionAction
326 336
                 ->searchable(),
327 337
             Forms\Components\TextInput::make('amount')
328 338
                 ->label('Amount')
329
-                ->live()
339
+                ->live(onBlur: true)
330 340
                 ->money()
331 341
                 ->afterStateUpdated(function (Forms\Get $get, Forms\Set $set, ?string $state, ?string $old) {
332 342
                     $this->updateJournalEntryAmount(JournalEntryType::parse($get('type')), $state, $old);

+ 1
- 1
app/Providers/Filament/CompanyPanelProvider.php View File

@@ -174,7 +174,7 @@ class CompanyPanelProvider extends PanelProvider
174 174
             })
175 175
             ->globalSearch(false)
176 176
             ->sidebarCollapsibleOnDesktop()
177
-            ->databaseNotifications()
177
+            ->databaseNotifications(isLazy: false)
178 178
             ->viteTheme('resources/css/filament/company/theme.css')
179 179
             ->brandLogo(static fn () => view('components.icons.logo'))
180 180
             ->tenant(Company::class)

+ 209
- 195
composer.lock
File diff suppressed because it is too large
View File


+ 5
- 0
resources/css/filament/company/top-navigation.css View File

@@ -18,3 +18,8 @@
18 18
 :is(.dark .fi-topbar > nav.topbar-scrolled, .dark .fi-sidebar-header.topbar-scrolled) {
19 19
     @apply bg-gray-900/50 !important;
20 20
 }
21
+
22
+/* Notification badge transparency */
23
+.fi-topbar .fi-icon-btn-badge-ctn {
24
+    @apply bg-transparent !important;
25
+}

Loading…
Cancel
Save