瀏覽代碼

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

Development 3.x
3.x
Andrew Wallo 3 月之前
父節點
當前提交
ce6283e886
沒有連結到貢獻者的電子郵件帳戶。

+ 4
- 3
app/Concerns/HasJournalEntryActions.php 查看文件

4
 
4
 
5
 use App\Enums\Accounting\JournalEntryType;
5
 use App\Enums\Accounting\JournalEntryType;
6
 use App\Utilities\Currency\CurrencyAccessor;
6
 use App\Utilities\Currency\CurrencyAccessor;
7
+use App\Utilities\Currency\CurrencyConverter;
7
 use Filament\Tables\Actions\Action;
8
 use Filament\Tables\Actions\Action;
8
 
9
 
9
 trait HasJournalEntryActions
10
 trait HasJournalEntryActions
14
 
15
 
15
     private function formatMoney(int $amount): string
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
             return '0';
185
             return '0';
185
         }
186
         }
186
 
187
 
187
-        $currency = currency(CurrencyAccessor::getDefaultCurrency());
188
+        $currency = currency('USD');
188
         $decimal = $currency->getDecimalMark();
189
         $decimal = $currency->getDecimalMark();
189
 
190
 
190
         if (substr($amount, -1) === $decimal) {
191
         if (substr($amount, -1) === $decimal) {
201
      */
202
      */
202
     protected function convertAmountToCents(string $amount): int
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 查看文件

9
 use App\Models\Accounting\Transaction;
9
 use App\Models\Accounting\Transaction;
10
 use App\Models\Banking\BankAccount;
10
 use App\Models\Banking\BankAccount;
11
 use App\Utilities\Currency\CurrencyAccessor;
11
 use App\Utilities\Currency\CurrencyAccessor;
12
+use App\Utilities\Currency\CurrencyConverter;
12
 use Awcodes\TableRepeater\Header;
13
 use Awcodes\TableRepeater\Header;
13
 use Closure;
14
 use Closure;
14
 use Filament\Forms;
15
 use Filament\Forms;
251
 
252
 
252
                         $hasDebit = false;
253
                         $hasDebit = false;
253
                         $hasCredit = false;
254
                         $hasCredit = false;
255
+                        $totalDebits = 0;
256
+                        $totalCredits = 0;
254
 
257
 
255
                         foreach ($value as $entry) {
258
                         foreach ($value as $entry) {
256
-                            if (! isset($entry['type'])) {
259
+                            if (! isset($entry['type']) || ! isset($entry['amount'])) {
257
                                 continue;
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
                                 $hasDebit = true;
267
                                 $hasDebit = true;
262
-                            } elseif (JournalEntryType::parse($entry['type'])->isCredit()) {
268
+                                $totalDebits += $amount;
269
+                            } elseif ($entryType->isCredit()) {
263
                                 $hasCredit = true;
270
                                 $hasCredit = true;
264
-                            }
265
-
266
-                            if ($hasDebit && $hasCredit) {
267
-                                break;
271
+                                $totalCredits += $amount;
268
                             }
272
                             }
269
                         }
273
                         }
270
 
274
 
275
                         if (! $hasCredit) {
279
                         if (! $hasCredit) {
276
                             $fail('At least one credit entry is required.');
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
                 ->searchable(),
336
                 ->searchable(),
327
             Forms\Components\TextInput::make('amount')
337
             Forms\Components\TextInput::make('amount')
328
                 ->label('Amount')
338
                 ->label('Amount')
329
-                ->live()
339
+                ->live(onBlur: true)
330
                 ->money()
340
                 ->money()
331
                 ->afterStateUpdated(function (Forms\Get $get, Forms\Set $set, ?string $state, ?string $old) {
341
                 ->afterStateUpdated(function (Forms\Get $get, Forms\Set $set, ?string $state, ?string $old) {
332
                     $this->updateJournalEntryAmount(JournalEntryType::parse($get('type')), $state, $old);
342
                     $this->updateJournalEntryAmount(JournalEntryType::parse($get('type')), $state, $old);

+ 1
- 1
app/Providers/Filament/CompanyPanelProvider.php 查看文件

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

+ 209
- 195
composer.lock
文件差異過大導致無法顯示
查看文件


+ 5
- 0
resources/css/filament/company/top-navigation.css 查看文件

18
 :is(.dark .fi-topbar > nav.topbar-scrolled, .dark .fi-sidebar-header.topbar-scrolled) {
18
 :is(.dark .fi-topbar > nav.topbar-scrolled, .dark .fi-sidebar-header.topbar-scrolled) {
19
     @apply bg-gray-900/50 !important;
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…
取消
儲存