Browse Source

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

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

+ 2
- 3
app/Filament/Company/Resources/Purchases/BillResource/Pages/ViewBill.php View File

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

+ 0
- 3
app/Filament/Company/Resources/Sales/EstimateResource/Pages/ViewEstimate.php View File

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

+ 0
- 3
app/Filament/Company/Resources/Sales/InvoiceResource/Pages/ViewInvoice.php View File

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

+ 5
- 8
app/Filament/Company/Resources/Sales/RecurringInvoiceResource/Pages/ViewRecurringInvoice.php View File

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

+ 1
- 1
app/Jobs/ProcessTransactionImport.php View File

60
         if (count($newTransactions) > 0) {
60
         if (count($newTransactions) > 0) {
61
             $currentBalance = $transactionsResponse->accounts[0]->balances->current;
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
             $transactionService->storeTransactions($this->company, $this->bankAccount, $newTransactions);
64
             $transactionService->storeTransactions($this->company, $this->bankAccount, $newTransactions);
65
 
65
 
66
             $this->connectedBankAccount->update([
66
             $this->connectedBankAccount->update([

+ 9
- 2
app/Listeners/CreateConnectedAccount.php View File

6
 use App\Models\Banking\Institution;
6
 use App\Models\Banking\Institution;
7
 use App\Models\Company;
7
 use App\Models\Company;
8
 use App\Services\PlaidService;
8
 use App\Services\PlaidService;
9
+use App\Utilities\Currency\CurrencyConverter;
9
 use Illuminate\Support\Facades\DB;
10
 use Illuminate\Support\Facades\DB;
10
 
11
 
11
 class CreateConnectedAccount
12
 class CreateConnectedAccount
59
     {
60
     {
60
         $identifierHash = md5($company->id . $institution->external_institution_id . $plaidAccount->name . $plaidAccount->mask);
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
         $company->connectedBankAccounts()->updateOrCreate([
69
         $company->connectedBankAccounts()->updateOrCreate([
63
             'identifier' => $identifierHash,
70
             'identifier' => $identifierHash,
64
         ], [
71
         ], [
66
             'external_account_id' => $plaidAccount->account_id,
73
             'external_account_id' => $plaidAccount->account_id,
67
             'access_token' => $accessToken,
74
             'access_token' => $accessToken,
68
             'item_id' => $authResponse->item->item_id,
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
             'name' => $plaidAccount->name,
78
             'name' => $plaidAccount->name,
72
             'mask' => $plaidAccount->mask,
79
             'mask' => $plaidAccount->mask,
73
             'type' => $plaidAccount->type,
80
             'type' => $plaidAccount->type,

+ 5
- 3
app/Livewire/Company/Service/ConnectedAccount/ListInstitutions.php View File

79
                     )),
79
                     )),
80
                 Placeholder::make('info')
80
                 Placeholder::make('info')
81
                     ->hiddenLabel()
81
                     ->hiddenLabel()
82
-                    ->visible(static fn (ConnectedBankAccount $connectedBankAccount) => $connectedBankAccount->bank_account_id === null)
82
+                    ->visible(static fn (ConnectedBankAccount $connectedBankAccount) => ! $connectedBankAccount->bank_account_id)
83
                     ->content(static fn (ConnectedBankAccount $connectedBankAccount) => 'If ' . $connectedBankAccount->name . ' already has transactions for an existing account, select the account to import transactions into.'),
83
                     ->content(static fn (ConnectedBankAccount $connectedBankAccount) => 'If ' . $connectedBankAccount->name . ' already has transactions for an existing account, select the account to import transactions into.'),
84
                 Select::make('bank_account_id')
84
                 Select::make('bank_account_id')
85
                     ->label('Select account')
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
                     ->options(fn (ConnectedBankAccount $connectedBankAccount) => $this->getBankAccountOptions($connectedBankAccount))
87
                     ->options(fn (ConnectedBankAccount $connectedBankAccount) => $this->getBankAccountOptions($connectedBankAccount))
88
                     ->required(),
88
                     ->required(),
89
                 DatePicker::make('start_date')
89
                 DatePicker::make('start_date')
90
                     ->label('Start date')
90
                     ->label('Start date')
91
                     ->required()
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
             ->action(function (array $data, ConnectedBankAccount $connectedBankAccount) {
96
             ->action(function (array $data, ConnectedBankAccount $connectedBankAccount) {
95
                 $selectedBankAccountId = $data['bank_account_id'] ?? $connectedBankAccount->bank_account_id;
97
                 $selectedBankAccountId = $data['bank_account_id'] ?? $connectedBankAccount->bank_account_id;

+ 5
- 0
app/Providers/Filament/CompanyPanelProvider.php View File

50
 use Filament\Http\Middleware\Authenticate;
50
 use Filament\Http\Middleware\Authenticate;
51
 use Filament\Http\Middleware\DisableBladeIconComponents;
51
 use Filament\Http\Middleware\DisableBladeIconComponents;
52
 use Filament\Http\Middleware\DispatchServingFilamentEvent;
52
 use Filament\Http\Middleware\DispatchServingFilamentEvent;
53
+use Filament\Infolists\Components\TextEntry;
53
 use Filament\Navigation\NavigationBuilder;
54
 use Filament\Navigation\NavigationBuilder;
54
 use Filament\Navigation\NavigationGroup;
55
 use Filament\Navigation\NavigationGroup;
55
 use Filament\Pages;
56
 use Filament\Pages;
289
         Tables\Columns\TextColumn::configureUsing(function (Tables\Columns\TextColumn $column): void {
290
         Tables\Columns\TextColumn::configureUsing(function (Tables\Columns\TextColumn $column): void {
290
             $column->placeholder('–');
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 View File

15
 {
15
 {
16
     public const API_VERSION = '2020-09-14';
16
     public const API_VERSION = '2020-09-14';
17
 
17
 
18
+    public const TRANSACTION_DAYS_REQUESTED = 730;
19
+
18
     protected ?string $clientId;
20
     protected ?string $clientId;
19
 
21
 
20
     protected ?string $clientSecret;
22
     protected ?string $clientSecret;
204
 
206
 
205
         if ($products) {
207
         if ($products) {
206
             $data['products'] = $products;
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
         if (! empty($this->webhookUrl)) {
217
         if (! empty($this->webhookUrl)) {

+ 13
- 6
app/Services/TransactionService.php View File

18
 
18
 
19
 class TransactionService
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
             $accountSign = $account->category === AccountCategory::Asset ? 1 : -1;
25
             $accountSign = $account->category === AccountCategory::Asset ? 1 : -1;
25
 
26
 
26
             $sumOfTransactions = collect($transactions)->reduce(static function ($carry, $transaction) {
27
             $sumOfTransactions = collect($transactions)->reduce(static function ($carry, $transaction) {
31
 
32
 
32
             $startingBalance = bcsub($adjustedBalance, $sumOfTransactions, 2);
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
         }
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
         $transactionType = $startingBalance >= 0 ? TransactionType::Deposit : TransactionType::Withdrawal;
48
         $transactionType = $startingBalance >= 0 ? TransactionType::Deposit : TransactionType::Withdrawal;
48
         $accountName = $startingBalance >= 0 ? "Owner's Investment" : "Owner's Drawings";
49
         $accountName = $startingBalance >= 0 ? "Owner's Investment" : "Owner's Drawings";
53
 
54
 
54
         $postedAt = Carbon::parse($startDate)->subDay()->toDateTimeString();
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
         Transaction::create([
60
         Transaction::create([
57
             'company_id' => $company->id,
61
             'company_id' => $company->id,
58
             'account_id' => $chartAccount->id,
62
             'account_id' => $chartAccount->id,
59
             'bank_account_id' => $bankAccount->id,
63
             'bank_account_id' => $bankAccount->id,
60
             'type' => $transactionType,
64
             'type' => $transactionType,
61
-            'amount' => abs($startingBalance),
65
+            'amount' => $amountInCents,
62
             'payment_channel' => 'other',
66
             'payment_channel' => 'other',
63
             'posted_at' => $postedAt,
67
             'posted_at' => $postedAt,
64
             'description' => 'Starting Balance',
68
             'description' => 'Starting Balance',
75
         $postedAt = $transaction->datetime ?? Carbon::parse($transaction->date)->toDateTimeString();
79
         $postedAt = $transaction->datetime ?? Carbon::parse($transaction->date)->toDateTimeString();
76
         $description = $transaction->name;
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
         Transaction::create([
85
         Transaction::create([
79
             'company_id' => $company->id,
86
             'company_id' => $company->id,
80
             'account_id' => $chartAccount->id,
87
             'account_id' => $chartAccount->id,
81
             'bank_account_id' => $bankAccount->id,
88
             'bank_account_id' => $bankAccount->id,
82
             'plaid_transaction_id' => $transaction->transaction_id,
89
             'plaid_transaction_id' => $transaction->transaction_id,
83
             'type' => $transactionType,
90
             'type' => $transactionType,
84
-            'amount' => abs($transaction->amount),
91
+            'amount' => $amountInCents,
85
             'payment_channel' => $paymentChannel,
92
             'payment_channel' => $paymentChannel,
86
             'posted_at' => $postedAt,
93
             'posted_at' => $postedAt,
87
             'description' => $description,
94
             'description' => $description,

Loading…
Cancel
Save