Procházet zdrojové kódy

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

Development 3.x
3.x
Andrew Wallo před 4 měsíci
rodič
revize
5ae85fddb5
Žádný účet není propojen s e-mailovou adresou tvůrce revize

+ 2
- 3
app/Filament/Company/Resources/Purchases/BillResource/Pages/ViewBill.php Zobrazit soubor

@@ -58,10 +58,10 @@ class ViewBill extends ViewRecord
58 58
                             ->link(),
59 59
                         TextEntry::make('total')
60 60
                             ->label('Total')
61
-                            ->currency(fn (Bill $record) => $record->currency_code),
61
+                            ->currency(static fn (Bill $record) => $record->currency_code),
62 62
                         TextEntry::make('amount_due')
63 63
                             ->label('Amount due')
64
-                            ->currency(fn (Bill $record) => $record->currency_code),
64
+                            ->currency(static fn (Bill $record) => $record->currency_code),
65 65
                         TextEntry::make('date')
66 66
                             ->label('Date')
67 67
                             ->date(),
@@ -70,7 +70,6 @@ class ViewBill extends ViewRecord
70 70
                             ->asRelativeDay(),
71 71
                         TextEntry::make('paid_at')
72 72
                             ->label('Paid at')
73
-                            ->placeholder('Not Paid')
74 73
                             ->date(),
75 74
                     ]),
76 75
             ]);

+ 0
- 3
app/Filament/Company/Resources/Sales/EstimateResource/Pages/ViewEstimate.php Zobrazit soubor

@@ -99,15 +99,12 @@ class ViewEstimate extends ViewRecord
99 99
                                     ->asRelativeDay(),
100 100
                                 TextEntry::make('approved_at')
101 101
                                     ->label('Approved at')
102
-                                    ->placeholder('Not Approved')
103 102
                                     ->date(),
104 103
                                 TextEntry::make('last_sent_at')
105 104
                                     ->label('Last sent')
106
-                                    ->placeholder('Never')
107 105
                                     ->date(),
108 106
                                 TextEntry::make('accepted_at')
109 107
                                     ->label('Accepted at')
110
-                                    ->placeholder('Not Accepted')
111 108
                                     ->date(),
112 109
                             ])->columnSpan(1),
113 110
                         DocumentPreview::make()

+ 0
- 3
app/Filament/Company/Resources/Sales/InvoiceResource/Pages/ViewInvoice.php Zobrazit soubor

@@ -99,15 +99,12 @@ class ViewInvoice extends ViewRecord
99 99
                                     ->asRelativeDay(),
100 100
                                 TextEntry::make('approved_at')
101 101
                                     ->label('Approved at')
102
-                                    ->placeholder('Not Approved')
103 102
                                     ->date(),
104 103
                                 TextEntry::make('last_sent_at')
105 104
                                     ->label('Last sent')
106
-                                    ->placeholder('Never')
107 105
                                     ->date(),
108 106
                                 TextEntry::make('paid_at')
109 107
                                     ->label('Paid at')
110
-                                    ->placeholder('Not Paid')
111 108
                                     ->date(),
112 109
                             ])->columnSpan(1),
113 110
                         DocumentPreview::make()

+ 5
- 8
app/Filament/Company/Resources/Sales/RecurringInvoiceResource/Pages/ViewRecurringInvoice.php Zobrazit soubor

@@ -110,13 +110,14 @@ class ViewRecurringInvoice extends ViewRecord
110 110
                                     ->weight(FontWeight::SemiBold)
111 111
                                     ->url(static fn (RecurringInvoice $record) => $record->client_id ? ClientResource::getUrl('view', ['record' => $record->client_id]) : null)
112 112
                                     ->link(),
113
+                                TextEntry::make('total')
114
+                                    ->label('Total')
115
+                                    ->currency(static fn (RecurringInvoice $record) => $record->currency_code),
113 116
                                 TextEntry::make('last_date')
114 117
                                     ->label('Last invoice')
115
-                                    ->date()
116
-                                    ->placeholder('Not Created'),
118
+                                    ->date(),
117 119
                                 TextEntry::make('next_date')
118 120
                                     ->label('Next invoice')
119
-                                    ->placeholder('Not Scheduled')
120 121
                                     ->date(),
121 122
                                 TextEntry::make('schedule')
122 123
                                     ->label('Schedule')
@@ -141,15 +142,11 @@ class ViewRecurringInvoice extends ViewRecord
141 142
                                     ->visible(fn (RecurringInvoice $record) => $record->end_type?->isOn()),
142 143
                                 TextEntry::make('approved_at')
143 144
                                     ->label('Approved at')
144
-                                    ->placeholder('Not Approved')
145 145
                                     ->date(),
146 146
                                 TextEntry::make('ended_at')
147 147
                                     ->label('Ended at')
148 148
                                     ->date()
149
-                                    ->visible(fn (RecurringInvoice $record) => $record->ended_at),
150
-                                TextEntry::make('total')
151
-                                    ->label('Invoice amount')
152
-                                    ->currency(static fn (RecurringInvoice $record) => $record->currency_code),
149
+                                    ->visible(static fn (RecurringInvoice $record) => $record->ended_at),
153 150
                             ])->columnSpan(1),
154 151
                         DocumentPreview::make()
155 152
                             ->type(DocumentType::RecurringInvoice),

+ 1
- 1
app/Jobs/ProcessTransactionImport.php Zobrazit soubor

@@ -60,7 +60,7 @@ class ProcessTransactionImport implements ShouldQueue
60 60
         if (count($newTransactions) > 0) {
61 61
             $currentBalance = $transactionsResponse->accounts[0]->balances->current;
62 62
 
63
-            $transactionService->createStartingBalanceIfNeeded($this->company, $this->account, $this->bankAccount, $newTransactions, $currentBalance, $startDate);
63
+            $transactionService->createStartingBalanceIfNeeded($this->company, $this->bankAccount, $newTransactions, $currentBalance, $startDate);
64 64
             $transactionService->storeTransactions($this->company, $this->bankAccount, $newTransactions);
65 65
 
66 66
             $this->connectedBankAccount->update([

+ 9
- 2
app/Listeners/CreateConnectedAccount.php Zobrazit soubor

@@ -6,6 +6,7 @@ use App\Events\PlaidSuccess;
6 6
 use App\Models\Banking\Institution;
7 7
 use App\Models\Company;
8 8
 use App\Services\PlaidService;
9
+use App\Utilities\Currency\CurrencyConverter;
9 10
 use Illuminate\Support\Facades\DB;
10 11
 
11 12
 class CreateConnectedAccount
@@ -59,6 +60,12 @@ class CreateConnectedAccount
59 60
     {
60 61
         $identifierHash = md5($company->id . $institution->external_institution_id . $plaidAccount->name . $plaidAccount->mask);
61 62
 
63
+        $currencyCode = $plaidAccount->balances->iso_currency_code ?? 'USD';
64
+
65
+        $currentBalance = $plaidAccount->balances->current ?? 0;
66
+
67
+        $currentBalanceCents = CurrencyConverter::convertToCents($currentBalance, $currencyCode);
68
+
62 69
         $company->connectedBankAccounts()->updateOrCreate([
63 70
             'identifier' => $identifierHash,
64 71
         ], [
@@ -66,8 +73,8 @@ class CreateConnectedAccount
66 73
             'external_account_id' => $plaidAccount->account_id,
67 74
             'access_token' => $accessToken,
68 75
             'item_id' => $authResponse->item->item_id,
69
-            'currency_code' => $plaidAccount->balances->iso_currency_code ?? 'USD',
70
-            'current_balance' => $plaidAccount->balances->current ?? 0,
76
+            'currency_code' => $currencyCode,
77
+            'current_balance' => $currentBalanceCents,
71 78
             'name' => $plaidAccount->name,
72 79
             'mask' => $plaidAccount->mask,
73 80
             'type' => $plaidAccount->type,

+ 5
- 3
app/Livewire/Company/Service/ConnectedAccount/ListInstitutions.php Zobrazit soubor

@@ -79,17 +79,19 @@ class ListInstitutions extends Component implements HasActions, HasForms
79 79
                     )),
80 80
                 Placeholder::make('info')
81 81
                     ->hiddenLabel()
82
-                    ->visible(static fn (ConnectedBankAccount $connectedBankAccount) => $connectedBankAccount->bank_account_id === null)
82
+                    ->visible(static fn (ConnectedBankAccount $connectedBankAccount) => ! $connectedBankAccount->bank_account_id)
83 83
                     ->content(static fn (ConnectedBankAccount $connectedBankAccount) => 'If ' . $connectedBankAccount->name . ' already has transactions for an existing account, select the account to import transactions into.'),
84 84
                 Select::make('bank_account_id')
85 85
                     ->label('Select account')
86
-                    ->visible(static fn (ConnectedBankAccount $connectedBankAccount) => $connectedBankAccount->bank_account_id === null)
86
+                    ->visible(static fn (ConnectedBankAccount $connectedBankAccount) => ! $connectedBankAccount->bank_account_id)
87 87
                     ->options(fn (ConnectedBankAccount $connectedBankAccount) => $this->getBankAccountOptions($connectedBankAccount))
88 88
                     ->required(),
89 89
                 DatePicker::make('start_date')
90 90
                     ->label('Start date')
91 91
                     ->required()
92
-                    ->placeholder('Select a start date for importing transactions.'),
92
+                    ->placeholder('Select a start date for importing transactions.')
93
+                    ->minDate(now()->subDays(PlaidService::TRANSACTION_DAYS_REQUESTED)->toDateString())
94
+                    ->maxDate(now()->toDateString()),
93 95
             ])
94 96
             ->action(function (array $data, ConnectedBankAccount $connectedBankAccount) {
95 97
                 $selectedBankAccountId = $data['bank_account_id'] ?? $connectedBankAccount->bank_account_id;

+ 5
- 0
app/Providers/Filament/CompanyPanelProvider.php Zobrazit soubor

@@ -50,6 +50,7 @@ use Filament\Forms\Components\Select;
50 50
 use Filament\Http\Middleware\Authenticate;
51 51
 use Filament\Http\Middleware\DisableBladeIconComponents;
52 52
 use Filament\Http\Middleware\DispatchServingFilamentEvent;
53
+use Filament\Infolists\Components\TextEntry;
53 54
 use Filament\Navigation\NavigationBuilder;
54 55
 use Filament\Navigation\NavigationGroup;
55 56
 use Filament\Pages;
@@ -289,6 +290,10 @@ class CompanyPanelProvider extends PanelProvider
289 290
         Tables\Columns\TextColumn::configureUsing(function (Tables\Columns\TextColumn $column): void {
290 291
             $column->placeholder('–');
291 292
         });
293
+
294
+        TextEntry::configureUsing(function (TextEntry $component): void {
295
+            $component->placeholder('–');
296
+        });
292 297
     }
293 298
 
294 299
     /**

+ 8
- 0
app/Services/PlaidService.php Zobrazit soubor

@@ -15,6 +15,8 @@ class PlaidService
15 15
 {
16 16
     public const API_VERSION = '2020-09-14';
17 17
 
18
+    public const TRANSACTION_DAYS_REQUESTED = 730;
19
+
18 20
     protected ?string $clientId;
19 21
 
20 22
     protected ?string $clientSecret;
@@ -204,6 +206,12 @@ class PlaidService
204 206
 
205 207
         if ($products) {
206 208
             $data['products'] = $products;
209
+
210
+            if (in_array('transactions', $products, true)) {
211
+                $data['transactions'] = [
212
+                    'days_requested' => self::TRANSACTION_DAYS_REQUESTED,
213
+                ];
214
+            }
207 215
         }
208 216
 
209 217
         if (! empty($this->webhookUrl)) {

+ 13
- 6
app/Services/TransactionService.php Zobrazit soubor

@@ -18,9 +18,10 @@ use Illuminate\Support\Facades\DB;
18 18
 
19 19
 class TransactionService
20 20
 {
21
-    public function createStartingBalanceIfNeeded(Company $company, Account $account, BankAccount $bankAccount, array $transactions, float $currentBalance, string $startDate): void
21
+    public function createStartingBalanceIfNeeded(Company $company, BankAccount $bankAccount, array $transactions, float $currentBalance, string $startDate): void
22 22
     {
23
-        if ($account->transactions()->doesntExist()) {
23
+        if ($bankAccount->transactions()->doesntExist()) {
24
+            $account = $bankAccount->account;
24 25
             $accountSign = $account->category === AccountCategory::Asset ? 1 : -1;
25 26
 
26 27
             $sumOfTransactions = collect($transactions)->reduce(static function ($carry, $transaction) {
@@ -31,7 +32,7 @@ class TransactionService
31 32
 
32 33
             $startingBalance = bcsub($adjustedBalance, $sumOfTransactions, 2);
33 34
 
34
-            $this->createStartingBalanceTransaction($company, $account, $bankAccount, (float) $startingBalance, $startDate);
35
+            $this->createStartingBalanceTransaction($company, $bankAccount, (float) $startingBalance, $startDate);
35 36
         }
36 37
     }
37 38
 
@@ -42,7 +43,7 @@ class TransactionService
42 43
         }
43 44
     }
44 45
 
45
-    public function createStartingBalanceTransaction(Company $company, Account $account, BankAccount $bankAccount, float $startingBalance, string $startDate): void
46
+    public function createStartingBalanceTransaction(Company $company, BankAccount $bankAccount, float $startingBalance, string $startDate): void
46 47
     {
47 48
         $transactionType = $startingBalance >= 0 ? TransactionType::Deposit : TransactionType::Withdrawal;
48 49
         $accountName = $startingBalance >= 0 ? "Owner's Investment" : "Owner's Drawings";
@@ -53,12 +54,15 @@ class TransactionService
53 54
 
54 55
         $postedAt = Carbon::parse($startDate)->subDay()->toDateTimeString();
55 56
 
57
+        $currencyCode = $bankAccount->account->currency_code ?? 'USD';
58
+        $amountInCents = CurrencyConverter::convertToCents(abs($startingBalance), $currencyCode);
59
+
56 60
         Transaction::create([
57 61
             'company_id' => $company->id,
58 62
             'account_id' => $chartAccount->id,
59 63
             'bank_account_id' => $bankAccount->id,
60 64
             'type' => $transactionType,
61
-            'amount' => abs($startingBalance),
65
+            'amount' => $amountInCents,
62 66
             'payment_channel' => 'other',
63 67
             'posted_at' => $postedAt,
64 68
             'description' => 'Starting Balance',
@@ -75,13 +79,16 @@ class TransactionService
75 79
         $postedAt = $transaction->datetime ?? Carbon::parse($transaction->date)->toDateTimeString();
76 80
         $description = $transaction->name;
77 81
 
82
+        $currencyCode = $transaction->iso_currency_code ?? $bankAccount->account->currency_code ?? 'USD';
83
+        $amountInCents = CurrencyConverter::convertToCents(abs($transaction->amount), $currencyCode);
84
+
78 85
         Transaction::create([
79 86
             'company_id' => $company->id,
80 87
             'account_id' => $chartAccount->id,
81 88
             'bank_account_id' => $bankAccount->id,
82 89
             'plaid_transaction_id' => $transaction->transaction_id,
83 90
             'type' => $transactionType,
84
-            'amount' => abs($transaction->amount),
91
+            'amount' => $amountInCents,
85 92
             'payment_channel' => $paymentChannel,
86 93
             'posted_at' => $postedAt,
87 94
             'description' => $description,

Načítá se…
Zrušit
Uložit