Andrew Wallo 6 mesi fa
parent
commit
bfec50db37

+ 2
- 2
app/Filament/Company/Resources/Purchases/BillResource/Pages/CreateBill.php Vedi File

@@ -3,7 +3,7 @@
3 3
 namespace App\Filament\Company\Resources\Purchases\BillResource\Pages;
4 4
 
5 5
 use App\Concerns\ManagesLineItems;
6
-use App\Concerns\RedirectToListPage;
6
+use App\Concerns\RedirectToViewPage;
7 7
 use App\Filament\Company\Resources\Purchases\BillResource;
8 8
 use App\Models\Accounting\Bill;
9 9
 use App\Models\Common\Vendor;
@@ -15,7 +15,7 @@ use Livewire\Attributes\Url;
15 15
 class CreateBill extends CreateRecord
16 16
 {
17 17
     use ManagesLineItems;
18
-    use RedirectToListPage;
18
+    use RedirectToViewPage;
19 19
 
20 20
     protected static string $resource = BillResource::class;
21 21
 

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

@@ -62,10 +62,10 @@ class ViewBill extends ViewRecord
62 62
                             ->url(static fn (Bill $record) => VendorResource::getUrl('edit', ['record' => $record->vendor_id])),
63 63
                         TextEntry::make('total')
64 64
                             ->label('Total')
65
-                            ->money(),
65
+                            ->currency(fn (Bill $record) => $record->currency_code),
66 66
                         TextEntry::make('amount_due')
67 67
                             ->label('Amount due')
68
-                            ->money(),
68
+                            ->currency(fn (Bill $record) => $record->currency_code),
69 69
                         TextEntry::make('date')
70 70
                             ->label('Date')
71 71
                             ->date(),

+ 2
- 2
app/Filament/Company/Resources/Sales/InvoiceResource/Pages/CreateInvoice.php Vedi File

@@ -3,7 +3,7 @@
3 3
 namespace App\Filament\Company\Resources\Sales\InvoiceResource\Pages;
4 4
 
5 5
 use App\Concerns\ManagesLineItems;
6
-use App\Concerns\RedirectToListPage;
6
+use App\Concerns\RedirectToViewPage;
7 7
 use App\Filament\Company\Resources\Sales\InvoiceResource;
8 8
 use App\Models\Accounting\Invoice;
9 9
 use App\Models\Common\Client;
@@ -15,7 +15,7 @@ use Livewire\Attributes\Url;
15 15
 class CreateInvoice extends CreateRecord
16 16
 {
17 17
     use ManagesLineItems;
18
-    use RedirectToListPage;
18
+    use RedirectToViewPage;
19 19
 
20 20
     protected static string $resource = InvoiceResource::class;
21 21
 

+ 8
- 2
app/Models/Accounting/Bill.php Vedi File

@@ -164,7 +164,7 @@ class Bill extends Document
164 164
         return ! in_array($this->status, [
165 165
             BillStatus::Paid,
166 166
             BillStatus::Void,
167
-        ]) && $this->currency_code === CurrencyAccessor::getDefaultCurrency();
167
+        ]);
168 168
     }
169 169
 
170 170
     public function hasPayments(): bool
@@ -227,8 +227,10 @@ class Bill extends Document
227 227
         $billCurrency = $this->currency_code;
228 228
         $requiresConversion = $billCurrency !== $bankAccountCurrency;
229 229
 
230
+        // Store the original payment amount in bill currency before any conversion
231
+        $amountInBillCurrencyCents = CurrencyConverter::convertToCents($data['amount'], $billCurrency);
232
+
230 233
         if ($requiresConversion) {
231
-            $amountInBillCurrencyCents = CurrencyConverter::convertToCents($data['amount'], $billCurrency);
232 234
             $amountInBankCurrencyCents = CurrencyConverter::convertBalance(
233 235
                 $amountInBillCurrencyCents,
234 236
                 $billCurrency,
@@ -254,6 +256,10 @@ class Bill extends Document
254 256
             'account_id' => Account::getAccountsPayableAccount()->id,
255 257
             'description' => $transactionDescription,
256 258
             'notes' => $data['notes'] ?? null,
259
+            'meta' => [
260
+                'original_bill_currency' => $billCurrency,
261
+                'amount_in_bill_currency_cents' => $amountInBillCurrencyCents,
262
+            ],
257 263
         ]);
258 264
     }
259 265
 

+ 2
- 0
app/Models/Accounting/Transaction.php Vedi File

@@ -45,6 +45,7 @@ class Transaction extends Model
45 45
         'posted_at',
46 46
         'created_by',
47 47
         'updated_by',
48
+        'meta',
48 49
     ];
49 50
 
50 51
     protected $casts = [
@@ -54,6 +55,7 @@ class Transaction extends Model
54 55
         'pending' => 'boolean',
55 56
         'reviewed' => 'boolean',
56 57
         'posted_at' => 'date',
58
+        'meta' => 'array',
57 59
     ];
58 60
 
59 61
     public function account(): BelongsTo

+ 10
- 0
app/Observers/TransactionObserver.php Vedi File

@@ -166,6 +166,16 @@ class TransactionObserver
166 166
             ->when($excludedTransaction, fn (Builder $query) => $query->whereKeyNot($excludedTransaction->getKey()))
167 167
             ->get()
168 168
             ->sum(function (Transaction $transaction) use ($billCurrency) {
169
+                // If the transaction has stored the original bill amount in metadata, use that
170
+                if (! empty($transaction->meta) &&
171
+                    isset($transaction->meta['original_bill_currency']) &&
172
+                    $transaction->meta['original_bill_currency'] === $billCurrency &&
173
+                    isset($transaction->meta['amount_in_bill_currency_cents'])) {
174
+
175
+                    return (int) $transaction->meta['amount_in_bill_currency_cents'];
176
+                }
177
+
178
+                // Fall back to conversion if metadata is not available
169 179
                 $bankAccountCurrency = $transaction->bankAccount->account->currency_code;
170 180
                 $amountCents = (int) $transaction->getRawOriginal('amount');
171 181
 

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

@@ -152,7 +152,7 @@ class CompanyPanelProvider extends PanelProvider
152 152
                             ->icon('heroicon-o-clipboard-document-list')
153 153
                             ->extraSidebarAttributes(['class' => 'es-sidebar-group'])
154 154
                             ->items([
155
-                                ...BudgetResource::getNavigationItems(),
155
+                                // ...BudgetResource::getNavigationItems(),
156 156
                                 ...AccountChart::getNavigationItems(),
157 157
                                 ...Transactions::getNavigationItems(),
158 158
                             ]),

+ 1
- 0
database/migrations/2024_01_01_234943_create_transactions_table.php Vedi File

@@ -27,6 +27,7 @@ return new class extends Migration
27 27
             $table->text('notes')->nullable();
28 28
             $table->string('reference')->nullable();
29 29
             $table->bigInteger('amount')->default(0);
30
+            $table->json('meta')->nullable();
30 31
             $table->boolean('pending')->default(false);
31 32
             $table->boolean('reviewed')->default(false);
32 33
             $table->dateTime('posted_at');

Loading…
Annulla
Salva