Andrew Wallo 4 месяцев назад
Родитель
Сommit
1173ba89c0

+ 3
- 3
app/Filament/Company/Resources/Purchases/BillResource.php Просмотреть файл

@@ -624,7 +624,7 @@ class BillResource extends Resource
624 624
                                 ->label('Notes'),
625 625
                         ])
626 626
                         ->before(function (Collection $records, Tables\Actions\BulkAction $action, array $data) {
627
-                            $totalPaymentAmount = CurrencyConverter::convertToCents($data['amount']);
627
+                            $totalPaymentAmount = $data['amount'] ?? 0;
628 628
                             $totalAmountDue = $records->sum(fn (Bill $bill) => $bill->getRawOriginal('amount_due'));
629 629
 
630 630
                             if ($totalPaymentAmount > $totalAmountDue) {
@@ -641,7 +641,7 @@ class BillResource extends Resource
641 641
                             }
642 642
                         })
643 643
                         ->action(function (Collection $records, Tables\Actions\BulkAction $action, array $data) {
644
-                            $totalPaymentAmount = CurrencyConverter::convertToCents($data['amount']);
644
+                            $totalPaymentAmount = $data['amount'] ?? 0;
645 645
                             $remainingAmount = $totalPaymentAmount;
646 646
 
647 647
                             $records->each(function (Bill $record) use (&$remainingAmount, $data) {
@@ -652,7 +652,7 @@ class BillResource extends Resource
652 652
                                 }
653 653
 
654 654
                                 $paymentAmount = min($amountDue, $remainingAmount);
655
-                                $data['amount'] = CurrencyConverter::convertCentsToFormatSimple($paymentAmount);
655
+                                $data['amount'] = $paymentAmount;
656 656
 
657 657
                                 $record->recordPayment($data);
658 658
                                 $remainingAmount -= $paymentAmount;

+ 3
- 3
app/Filament/Company/Resources/Sales/InvoiceResource.php Просмотреть файл

@@ -737,7 +737,7 @@ class InvoiceResource extends Resource
737 737
                                 ->label('Notes'),
738 738
                         ])
739 739
                         ->before(function (DocumentCollection $records, Tables\Actions\BulkAction $action, array $data) {
740
-                            $totalPaymentAmount = CurrencyConverter::convertToCents($data['amount']);
740
+                            $totalPaymentAmount = $data['amount'] ?? 0;
741 741
                             $totalAmountDue = $records->sumMoneyInCents('amount_due');
742 742
 
743 743
                             if ($totalPaymentAmount > $totalAmountDue) {
@@ -754,7 +754,7 @@ class InvoiceResource extends Resource
754 754
                             }
755 755
                         })
756 756
                         ->action(function (DocumentCollection $records, Tables\Actions\BulkAction $action, array $data) {
757
-                            $totalPaymentAmount = CurrencyConverter::convertToCents($data['amount']);
757
+                            $totalPaymentAmount = $data['amount'] ?? 0;
758 758
 
759 759
                             $remainingAmount = $totalPaymentAmount;
760 760
 
@@ -767,7 +767,7 @@ class InvoiceResource extends Resource
767 767
 
768 768
                                 $paymentAmount = min($amountDue, $remainingAmount);
769 769
 
770
-                                $data['amount'] = CurrencyConverter::convertCentsToFormatSimple($paymentAmount);
770
+                                $data['amount'] = $paymentAmount;
771 771
 
772 772
                                 $record->recordPayment($data);
773 773
 

+ 3
- 6
app/Models/Accounting/Bill.php Просмотреть файл

@@ -228,7 +228,7 @@ class Bill extends Document
228 228
         $requiresConversion = $billCurrency !== $bankAccountCurrency;
229 229
 
230 230
         // Store the original payment amount in bill currency before any conversion
231
-        $amountInBillCurrencyCents = CurrencyConverter::convertToCents($data['amount'], $billCurrency);
231
+        $amountInBillCurrencyCents = $data['amount'];
232 232
 
233 233
         if ($requiresConversion) {
234 234
             $amountInBankCurrencyCents = CurrencyConverter::convertBalance(
@@ -236,12 +236,9 @@ class Bill extends Document
236 236
                 $billCurrency,
237 237
                 $bankAccountCurrency
238 238
             );
239
-            $formattedAmountForBankCurrency = CurrencyConverter::convertCentsToFormatSimple(
240
-                $amountInBankCurrencyCents,
241
-                $bankAccountCurrency
242
-            );
239
+            $formattedAmountForBankCurrency = $amountInBankCurrencyCents;
243 240
         } else {
244
-            $formattedAmountForBankCurrency = $data['amount']; // Already in simple format
241
+            $formattedAmountForBankCurrency = $amountInBillCurrencyCents;
245 242
         }
246 243
 
247 244
         // Create transaction with converted amount

+ 5
- 5
app/Models/Accounting/Estimate.php Просмотреть файл

@@ -471,11 +471,11 @@ class Estimate extends Document
471 471
             'currency_code' => $this->currency_code,
472 472
             'discount_method' => $this->discount_method,
473 473
             'discount_computation' => $this->discount_computation,
474
-            'discount_rate' => $this->discount_rate,
475
-            'subtotal' => $this->subtotal,
476
-            'tax_total' => $this->tax_total,
477
-            'discount_total' => $this->discount_total,
478
-            'total' => $this->total,
474
+            'discount_rate' => $this->getRawOriginal('discount_rate'),
475
+            'subtotal' => $this->getRawOriginal('subtotal'),
476
+            'tax_total' => $this->getRawOriginal('tax_total'),
477
+            'discount_total' => $this->getRawOriginal('discount_total'),
478
+            'total' => $this->getRawOriginal('total'),
479 479
             'terms' => $this->terms,
480 480
             'footer' => $this->footer,
481 481
             'created_by' => auth()->id(),

+ 5
- 5
app/Models/Accounting/RecurringInvoice.php Просмотреть файл

@@ -643,11 +643,11 @@ class RecurringInvoice extends Document
643 643
             'currency_code' => $this->currency_code,
644 644
             'discount_method' => $this->discount_method,
645 645
             'discount_computation' => $this->discount_computation,
646
-            'discount_rate' => $this->discount_rate,
647
-            'subtotal' => $this->subtotal,
648
-            'tax_total' => $this->tax_total,
649
-            'discount_total' => $this->discount_total,
650
-            'total' => $this->total,
646
+            'discount_rate' => $this->getRawOriginal('discount_rate'),
647
+            'subtotal' => $this->getRawOriginal('subtotal'),
648
+            'tax_total' => $this->getRawOriginal('tax_total'),
649
+            'discount_total' => $this->getRawOriginal('discount_total'),
650
+            'total' => $this->getRawOriginal('total'),
651 651
             'terms' => $this->terms,
652 652
             'footer' => $this->footer,
653 653
             'created_by' => auth()->id(),

+ 4
- 4
app/Services/TransactionService.php Просмотреть файл

@@ -250,7 +250,7 @@ class TransactionService
250 250
         });
251 251
     }
252 252
 
253
-    private function getConvertedTransactionAmount(Transaction $transaction): string
253
+    private function getConvertedTransactionAmount(Transaction $transaction): int
254 254
     {
255 255
         $defaultCurrency = CurrencyAccessor::getDefaultCurrency();
256 256
         $bankAccountCurrency = $transaction->bankAccount->account->currency_code;
@@ -259,7 +259,7 @@ class TransactionService
259 259
             return $this->convertToDefaultCurrency($transaction->amount, $bankAccountCurrency, $defaultCurrency);
260 260
         }
261 261
 
262
-        return $transaction->amount;
262
+        return CurrencyConverter::prepareForAccessor($transaction->amount, $defaultCurrency);
263 263
     }
264 264
 
265 265
     private function convertToDefaultCurrency(string $amount, string $fromCurrency, string $toCurrency): string
@@ -268,7 +268,7 @@ class TransactionService
268 268
 
269 269
         $convertedAmountInCents = CurrencyConverter::convertBalance($amountInCents, $fromCurrency, $toCurrency);
270 270
 
271
-        return CurrencyConverter::prepareForMutator($convertedAmountInCents, $toCurrency);
271
+        return $convertedAmountInCents;
272 272
     }
273 273
 
274 274
     private function hasRelevantChanges(Transaction $transaction): bool
@@ -276,7 +276,7 @@ class TransactionService
276 276
         return $transaction->wasChanged(['amount', 'account_id', 'bank_account_id', 'type']);
277 277
     }
278 278
 
279
-    private function updateJournalEntryForTransaction(JournalEntry $journalEntry, Account $account, string $convertedTransactionAmount): void
279
+    private function updateJournalEntryForTransaction(JournalEntry $journalEntry, Account $account, int $convertedTransactionAmount): void
280 280
     {
281 281
         DB::transaction(static function () use ($journalEntry, $account, $convertedTransactionAmount) {
282 282
             $journalEntry->update([

+ 6
- 7
database/factories/Accounting/BillFactory.php Просмотреть файл

@@ -12,7 +12,6 @@ use App\Models\Banking\BankAccount;
12 12
 use App\Models\Common\Vendor;
13 13
 use App\Models\Company;
14 14
 use App\Models\Setting\DocumentDefault;
15
-use App\Utilities\Currency\CurrencyConverter;
16 15
 use App\Utilities\RateCalculator;
17 16
 use Illuminate\Database\Eloquent\Factories\Factory;
18 17
 use Illuminate\Support\Carbon;
@@ -174,7 +173,7 @@ class BillFactory extends Factory
174 173
 
175 174
                 $data = [
176 175
                     'posted_at' => $postedAt,
177
-                    'amount' => CurrencyConverter::convertCentsToFormatSimple($amount, $bill->currency_code),
176
+                    'amount' => $amount,
178 177
                     'payment_method' => $this->faker->randomElement(PaymentMethod::class),
179 178
                     'bank_account_id' => BankAccount::where('company_id', $bill->company_id)->inRandomOrder()->value('id'),
180 179
                     'notes' => $this->faker->sentence,
@@ -250,7 +249,7 @@ class BillFactory extends Factory
250 249
                 $scaledRate = RateCalculator::parseLocalizedRate($bill->discount_rate);
251 250
                 $discountTotalCents = RateCalculator::calculatePercentage($subtotalCents, $scaledRate);
252 251
             } else {
253
-                $discountTotalCents = CurrencyConverter::convertToCents($bill->discount_rate, $bill->currency_code);
252
+                $discountTotalCents = $bill->getRawOriginal('discount_rate');
254 253
             }
255 254
         }
256 255
 
@@ -258,10 +257,10 @@ class BillFactory extends Factory
258 257
         $currencyCode = $bill->currency_code;
259 258
 
260 259
         $bill->update([
261
-            'subtotal' => CurrencyConverter::convertCentsToFormatSimple($subtotalCents, $currencyCode),
262
-            'tax_total' => CurrencyConverter::convertCentsToFormatSimple($taxTotalCents, $currencyCode),
263
-            'discount_total' => CurrencyConverter::convertCentsToFormatSimple($discountTotalCents, $currencyCode),
264
-            'total' => CurrencyConverter::convertCentsToFormatSimple($grandTotalCents, $currencyCode),
260
+            'subtotal' => $subtotalCents,
261
+            'tax_total' => $taxTotalCents,
262
+            'discount_total' => $discountTotalCents,
263
+            'total' => $grandTotalCents,
265 264
         ]);
266 265
     }
267 266
 }

+ 5
- 6
database/factories/Accounting/EstimateFactory.php Просмотреть файл

@@ -10,7 +10,6 @@ use App\Models\Accounting\Estimate;
10 10
 use App\Models\Common\Client;
11 11
 use App\Models\Company;
12 12
 use App\Models\Setting\DocumentDefault;
13
-use App\Utilities\Currency\CurrencyConverter;
14 13
 use App\Utilities\RateCalculator;
15 14
 use Illuminate\Database\Eloquent\Factories\Factory;
16 15
 use Illuminate\Support\Carbon;
@@ -231,7 +230,7 @@ class EstimateFactory extends Factory
231 230
                 $scaledRate = RateCalculator::parseLocalizedRate($estimate->discount_rate);
232 231
                 $discountTotalCents = RateCalculator::calculatePercentage($subtotalCents, $scaledRate);
233 232
             } else {
234
-                $discountTotalCents = CurrencyConverter::convertToCents($estimate->discount_rate, $estimate->currency_code);
233
+                $discountTotalCents = $estimate->getRawOriginal('discount_rate');
235 234
             }
236 235
         }
237 236
 
@@ -239,10 +238,10 @@ class EstimateFactory extends Factory
239 238
         $currencyCode = $estimate->currency_code;
240 239
 
241 240
         $estimate->update([
242
-            'subtotal' => CurrencyConverter::convertCentsToFormatSimple($subtotalCents, $currencyCode),
243
-            'tax_total' => CurrencyConverter::convertCentsToFormatSimple($taxTotalCents, $currencyCode),
244
-            'discount_total' => CurrencyConverter::convertCentsToFormatSimple($discountTotalCents, $currencyCode),
245
-            'total' => CurrencyConverter::convertCentsToFormatSimple($grandTotalCents, $currencyCode),
241
+            'subtotal' => $subtotalCents,
242
+            'tax_total' => $taxTotalCents,
243
+            'discount_total' => $discountTotalCents,
244
+            'total' => $grandTotalCents,
246 245
         ]);
247 246
     }
248 247
 }

+ 6
- 7
database/factories/Accounting/InvoiceFactory.php Просмотреть файл

@@ -12,7 +12,6 @@ use App\Models\Banking\BankAccount;
12 12
 use App\Models\Common\Client;
13 13
 use App\Models\Company;
14 14
 use App\Models\Setting\DocumentDefault;
15
-use App\Utilities\Currency\CurrencyConverter;
16 15
 use App\Utilities\RateCalculator;
17 16
 use Illuminate\Database\Eloquent\Factories\Factory;
18 17
 use Illuminate\Support\Carbon;
@@ -192,7 +191,7 @@ class InvoiceFactory extends Factory
192 191
 
193 192
                 $data = [
194 193
                     'posted_at' => $postedAt,
195
-                    'amount' => CurrencyConverter::convertCentsToFormatSimple($amount, $invoice->currency_code),
194
+                    'amount' => $amount,
196 195
                     'payment_method' => $this->faker->randomElement(PaymentMethod::class),
197 196
                     'bank_account_id' => BankAccount::where('company_id', $invoice->company_id)->inRandomOrder()->value('id'),
198 197
                     'notes' => $this->faker->sentence,
@@ -275,7 +274,7 @@ class InvoiceFactory extends Factory
275 274
                 $scaledRate = RateCalculator::parseLocalizedRate($invoice->discount_rate);
276 275
                 $discountTotalCents = RateCalculator::calculatePercentage($subtotalCents, $scaledRate);
277 276
             } else {
278
-                $discountTotalCents = CurrencyConverter::convertToCents($invoice->discount_rate, $invoice->currency_code);
277
+                $discountTotalCents = $invoice->getRawOriginal('discount_rate');
279 278
             }
280 279
         }
281 280
 
@@ -283,10 +282,10 @@ class InvoiceFactory extends Factory
283 282
         $currencyCode = $invoice->currency_code;
284 283
 
285 284
         $invoice->update([
286
-            'subtotal' => CurrencyConverter::convertCentsToFormatSimple($subtotalCents, $currencyCode),
287
-            'tax_total' => CurrencyConverter::convertCentsToFormatSimple($taxTotalCents, $currencyCode),
288
-            'discount_total' => CurrencyConverter::convertCentsToFormatSimple($discountTotalCents, $currencyCode),
289
-            'total' => CurrencyConverter::convertCentsToFormatSimple($grandTotalCents, $currencyCode),
285
+            'subtotal' => $subtotalCents,
286
+            'tax_total' => $taxTotalCents,
287
+            'discount_total' => $discountTotalCents,
288
+            'total' => $grandTotalCents,
290 289
         ]);
291 290
     }
292 291
 }

+ 5
- 6
database/factories/Accounting/RecurringInvoiceFactory.php Просмотреть файл

@@ -16,7 +16,6 @@ use App\Models\Accounting\DocumentLineItem;
16 16
 use App\Models\Accounting\RecurringInvoice;
17 17
 use App\Models\Common\Client;
18 18
 use App\Models\Company;
19
-use App\Utilities\Currency\CurrencyConverter;
20 19
 use App\Utilities\RateCalculator;
21 20
 use Illuminate\Database\Eloquent\Factories\Factory;
22 21
 use Illuminate\Support\Carbon;
@@ -325,7 +324,7 @@ class RecurringInvoiceFactory extends Factory
325 324
                 $scaledRate = RateCalculator::parseLocalizedRate($recurringInvoice->discount_rate);
326 325
                 $discountTotalCents = RateCalculator::calculatePercentage($subtotalCents, $scaledRate);
327 326
             } else {
328
-                $discountTotalCents = CurrencyConverter::convertToCents($recurringInvoice->discount_rate, $recurringInvoice->currency_code);
327
+                $discountTotalCents = $recurringInvoice->getRawOriginal('discount_rate');
329 328
             }
330 329
         }
331 330
 
@@ -333,10 +332,10 @@ class RecurringInvoiceFactory extends Factory
333 332
         $currencyCode = $recurringInvoice->currency_code;
334 333
 
335 334
         $recurringInvoice->update([
336
-            'subtotal' => CurrencyConverter::convertCentsToFormatSimple($subtotalCents, $currencyCode),
337
-            'tax_total' => CurrencyConverter::convertCentsToFormatSimple($taxTotalCents, $currencyCode),
338
-            'discount_total' => CurrencyConverter::convertCentsToFormatSimple($discountTotalCents, $currencyCode),
339
-            'total' => CurrencyConverter::convertCentsToFormatSimple($grandTotalCents, $currencyCode),
335
+            'subtotal' => $subtotalCents,
336
+            'tax_total' => $taxTotalCents,
337
+            'discount_total' => $discountTotalCents,
338
+            'total' => $grandTotalCents,
340 339
         ]);
341 340
     }
342 341
 }

Загрузка…
Отмена
Сохранить