Andrew Wallo 4 місяці тому
джерело
коміт
950346147f

+ 5
- 3
app/Filament/Company/Resources/Purchases/BillResource.php Переглянути файл

261
                                                 return;
261
                                                 return;
262
                                             }
262
                                             }
263
 
263
 
264
-                                            $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, CurrencyAccessor::getDefaultCurrency());
264
+                                            $unitPrice = CurrencyConverter::convertCentsToFormatSimple($offeringRecord->price, 'USD');
265
 
265
 
266
                                             $set('description', $offeringRecord->description);
266
                                             $set('description', $offeringRecord->description);
267
                                             $set('unit_price', $unitPrice);
267
                                             $set('unit_price', $unitPrice);
284
                                 Forms\Components\TextInput::make('unit_price')
284
                                 Forms\Components\TextInput::make('unit_price')
285
                                     ->label('Price')
285
                                     ->label('Price')
286
                                     ->hiddenLabel()
286
                                     ->hiddenLabel()
287
-                                    ->numeric()
287
+                                    ->money(useAffix: false)
288
                                     ->live()
288
                                     ->live()
289
                                     ->maxValue(9999999999.99)
289
                                     ->maxValue(9999999999.99)
290
                                     ->default(0),
290
                                     ->default(0),
327
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])
327
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])
328
                                     ->content(function (Forms\Get $get) {
328
                                     ->content(function (Forms\Get $get) {
329
                                         $quantity = max((float) ($get('quantity') ?? 0), 0);
329
                                         $quantity = max((float) ($get('quantity') ?? 0), 0);
330
-                                        $unitPrice = max((float) ($get('unit_price') ?? 0), 0);
330
+                                        $unitPrice = CurrencyConverter::isValidAmount($get('unit_price'), 'USD')
331
+                                            ? CurrencyConverter::convertToFloat($get('unit_price'), 'USD')
332
+                                            : 0;
331
                                         $purchaseTaxes = $get('purchaseTaxes') ?? [];
333
                                         $purchaseTaxes = $get('purchaseTaxes') ?? [];
332
                                         $purchaseDiscounts = $get('purchaseDiscounts') ?? [];
334
                                         $purchaseDiscounts = $get('purchaseDiscounts') ?? [];
333
                                         $currencyCode = $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency();
335
                                         $currencyCode = $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency();

+ 5
- 3
app/Filament/Company/Resources/Sales/InvoiceResource.php Переглянути файл

272
                                                 return;
272
                                                 return;
273
                                             }
273
                                             }
274
 
274
 
275
-                                            $unitPrice = CurrencyConverter::convertCentsToFloat($offeringRecord->price, CurrencyAccessor::getDefaultCurrency());
275
+                                            $unitPrice = CurrencyConverter::convertCentsToFormatSimple($offeringRecord->price, 'USD');
276
 
276
 
277
                                             $set('description', $offeringRecord->description);
277
                                             $set('description', $offeringRecord->description);
278
                                             $set('unit_price', $unitPrice);
278
                                             $set('unit_price', $unitPrice);
294
                                     ->default(1),
294
                                     ->default(1),
295
                                 Forms\Components\TextInput::make('unit_price')
295
                                 Forms\Components\TextInput::make('unit_price')
296
                                     ->hiddenLabel()
296
                                     ->hiddenLabel()
297
-                                    ->numeric()
297
+                                    ->money(useAffix: false)
298
                                     ->live()
298
                                     ->live()
299
                                     ->maxValue(9999999999.99)
299
                                     ->maxValue(9999999999.99)
300
                                     ->default(0),
300
                                     ->default(0),
337
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])
337
                                     ->extraAttributes(['class' => 'text-left sm:text-right'])
338
                                     ->content(function (Forms\Get $get) {
338
                                     ->content(function (Forms\Get $get) {
339
                                         $quantity = max((float) ($get('quantity') ?? 0), 0);
339
                                         $quantity = max((float) ($get('quantity') ?? 0), 0);
340
-                                        $unitPrice = max((float) ($get('unit_price') ?? 0), 0);
340
+                                        $unitPrice = CurrencyConverter::isValidAmount($get('unit_price'), 'USD')
341
+                                            ? CurrencyConverter::convertToFloat($get('unit_price'), 'USD')
342
+                                            : 0;
341
                                         $salesTaxes = $get('salesTaxes') ?? [];
343
                                         $salesTaxes = $get('salesTaxes') ?? [];
342
                                         $salesDiscounts = $get('salesDiscounts') ?? [];
344
                                         $salesDiscounts = $get('salesDiscounts') ?? [];
343
                                         $currencyCode = $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency();
345
                                         $currencyCode = $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency();

+ 0
- 8
app/Models/Accounting/DocumentLineItem.php Переглянути файл

41
         'updated_by',
41
         'updated_by',
42
     ];
42
     ];
43
 
43
 
44
-    protected $casts = [
45
-        'unit_price' => DocumentMoneyCast::class,
46
-        'subtotal' => DocumentMoneyCast::class,
47
-        'tax_total' => DocumentMoneyCast::class,
48
-        'discount_total' => DocumentMoneyCast::class,
49
-        'total' => DocumentMoneyCast::class,
50
-    ];
51
-
52
     public function documentable(): MorphTo
44
     public function documentable(): MorphTo
53
     {
45
     {
54
         return $this->morphTo();
46
         return $this->morphTo();

+ 2
- 2
app/Models/Accounting/Invoice.php Переглянути файл

393
 
393
 
394
         foreach ($this->lineItems as $index => $lineItem) {
394
         foreach ($this->lineItems as $index => $lineItem) {
395
             $lineItemDescription = "{$baseDescription} › {$lineItem->offering->name}";
395
             $lineItemDescription = "{$baseDescription} › {$lineItem->offering->name}";
396
-            $lineItemSubtotalInInvoiceCurrency = $lineItem->getRawOriginal('subtotal');
396
+            $lineItemSubtotalInInvoiceCurrency = $lineItem->subtotal;
397
 
397
 
398
             $journalEntryData[] = [
398
             $journalEntryData[] = [
399
                 'type' => JournalEntryType::Credit,
399
                 'type' => JournalEntryType::Credit,
415
 
415
 
416
             // Handle per-document discount allocation
416
             // Handle per-document discount allocation
417
             if ($this->discount_method->isPerDocument() && $totalLineItemSubtotalInInvoiceCurrency > 0) {
417
             if ($this->discount_method->isPerDocument() && $totalLineItemSubtotalInInvoiceCurrency > 0) {
418
-                $lineItemSubtotalInInvoiceCurrency = (int) $lineItem->getRawOriginal('subtotal');
418
+                $lineItemSubtotalInInvoiceCurrency = $lineItem->subtotal;
419
 
419
 
420
                 if ($index === $this->lineItems->count() - 1) {
420
                 if ($index === $this->lineItems->count() - 1) {
421
                     $lineItemDiscountInInvoiceCurrency = $remainingDiscountInInvoiceCurrency;
421
                     $lineItemDiscountInInvoiceCurrency = $remainingDiscountInInvoiceCurrency;

+ 11
- 7
app/View/Models/DocumentTotalViewModel.php Переглянути файл

72
     private function calculateLineSubtotalInCents(array $item, string $currencyCode): int
72
     private function calculateLineSubtotalInCents(array $item, string $currencyCode): int
73
     {
73
     {
74
         $quantity = max((float) ($item['quantity'] ?? 0), 0);
74
         $quantity = max((float) ($item['quantity'] ?? 0), 0);
75
-        $unitPrice = max((float) ($item['unit_price'] ?? 0), 0);
75
+        $unitPrice = CurrencyConverter::isValidAmount($item['unit_price'], 'USD')
76
+            ? CurrencyConverter::convertToFloat($item['unit_price'], 'USD')
77
+            : 0;
76
 
78
 
77
         $subtotal = $quantity * $unitPrice;
79
         $subtotal = $quantity * $unitPrice;
78
 
80
 
79
-        return CurrencyConverter::convertToCents($subtotal, $currencyCode);
81
+        return CurrencyConverter::convertToCents($subtotal, 'USD');
80
     }
82
     }
81
 
83
 
82
     private function calculateAdjustmentsTotalInCents($lineItems, string $key, string $currencyCode): int
84
     private function calculateAdjustmentsTotalInCents($lineItems, string $key, string $currencyCode): int
83
     {
85
     {
84
-        return $lineItems->reduce(function ($carry, $item) use ($key, $currencyCode) {
86
+        return $lineItems->reduce(function ($carry, $item) use ($key) {
85
             $quantity = max((float) ($item['quantity'] ?? 0), 0);
87
             $quantity = max((float) ($item['quantity'] ?? 0), 0);
86
-            $unitPrice = max((float) ($item['unit_price'] ?? 0), 0);
88
+            $unitPrice = CurrencyConverter::isValidAmount($item['unit_price'], 'USD')
89
+                ? CurrencyConverter::convertToFloat($item['unit_price'], 'USD')
90
+                : 0;
91
+
87
             $adjustmentIds = $item[$key] ?? [];
92
             $adjustmentIds = $item[$key] ?? [];
88
             $lineTotal = $quantity * $unitPrice;
93
             $lineTotal = $quantity * $unitPrice;
89
 
94
 
90
-            $lineTotalInCents = CurrencyConverter::convertToCents($lineTotal, $currencyCode);
95
+            $lineTotalInCents = CurrencyConverter::convertToCents($lineTotal, 'USD');
91
 
96
 
92
             $adjustmentTotal = Adjustment::whereIn('id', $adjustmentIds)
97
             $adjustmentTotal = Adjustment::whereIn('id', $adjustmentIds)
93
                 ->get()
98
                 ->get()
152
 
157
 
153
     private function calculateAmountDueInCents(int $grandTotalInCents, string $currencyCode): int
158
     private function calculateAmountDueInCents(int $grandTotalInCents, string $currencyCode): int
154
     {
159
     {
155
-        $amountPaid = $this->data['amount_paid'] ?? '0.00';
156
-        $amountPaidInCents = CurrencyConverter::convertToCents($amountPaid, $currencyCode);
160
+        $amountPaidInCents = $this->data['amount_paid'] ?? 0;
157
 
161
 
158
         return $grandTotalInCents - $amountPaidInCents;
162
         return $grandTotalInCents - $amountPaidInCents;
159
     }
163
     }

+ 32
- 32
composer.lock Переглянути файл

497
         },
497
         },
498
         {
498
         {
499
             "name": "aws/aws-sdk-php",
499
             "name": "aws/aws-sdk-php",
500
-            "version": "3.343.18",
500
+            "version": "3.343.19",
501
             "source": {
501
             "source": {
502
                 "type": "git",
502
                 "type": "git",
503
                 "url": "https://github.com/aws/aws-sdk-php.git",
503
                 "url": "https://github.com/aws/aws-sdk-php.git",
504
-                "reference": "ae98d503173740cce23b30d2ba2737c49b0d9876"
504
+                "reference": "00b44b1a9d570bc945d223b20886c1ac13b54641"
505
             },
505
             },
506
             "dist": {
506
             "dist": {
507
                 "type": "zip",
507
                 "type": "zip",
508
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/ae98d503173740cce23b30d2ba2737c49b0d9876",
509
-                "reference": "ae98d503173740cce23b30d2ba2737c49b0d9876",
508
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/00b44b1a9d570bc945d223b20886c1ac13b54641",
509
+                "reference": "00b44b1a9d570bc945d223b20886c1ac13b54641",
510
                 "shasum": ""
510
                 "shasum": ""
511
             },
511
             },
512
             "require": {
512
             "require": {
588
             "support": {
588
             "support": {
589
                 "forum": "https://github.com/aws/aws-sdk-php/discussions",
589
                 "forum": "https://github.com/aws/aws-sdk-php/discussions",
590
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
590
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
591
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.343.18"
591
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.343.19"
592
             },
592
             },
593
-            "time": "2025-05-23T18:08:18+00:00"
593
+            "time": "2025-05-27T18:10:12+00:00"
594
         },
594
         },
595
         {
595
         {
596
             "name": "aws/aws-sdk-php-laravel",
596
             "name": "aws/aws-sdk-php-laravel",
1799
         },
1799
         },
1800
         {
1800
         {
1801
             "name": "filament/actions",
1801
             "name": "filament/actions",
1802
-            "version": "v3.3.16",
1802
+            "version": "v3.3.17",
1803
             "source": {
1803
             "source": {
1804
                 "type": "git",
1804
                 "type": "git",
1805
                 "url": "https://github.com/filamentphp/actions.git",
1805
                 "url": "https://github.com/filamentphp/actions.git",
1852
         },
1852
         },
1853
         {
1853
         {
1854
             "name": "filament/filament",
1854
             "name": "filament/filament",
1855
-            "version": "v3.3.16",
1855
+            "version": "v3.3.17",
1856
             "source": {
1856
             "source": {
1857
                 "type": "git",
1857
                 "type": "git",
1858
                 "url": "https://github.com/filamentphp/panels.git",
1858
                 "url": "https://github.com/filamentphp/panels.git",
1859
-                "reference": "ed0a0109e6b2663247fcd73076c95c918bc5b412"
1859
+                "reference": "94ee92244d2a64666fb8c1ea50cb7315ebceb63b"
1860
             },
1860
             },
1861
             "dist": {
1861
             "dist": {
1862
                 "type": "zip",
1862
                 "type": "zip",
1863
-                "url": "https://api.github.com/repos/filamentphp/panels/zipball/ed0a0109e6b2663247fcd73076c95c918bc5b412",
1864
-                "reference": "ed0a0109e6b2663247fcd73076c95c918bc5b412",
1863
+                "url": "https://api.github.com/repos/filamentphp/panels/zipball/94ee92244d2a64666fb8c1ea50cb7315ebceb63b",
1864
+                "reference": "94ee92244d2a64666fb8c1ea50cb7315ebceb63b",
1865
                 "shasum": ""
1865
                 "shasum": ""
1866
             },
1866
             },
1867
             "require": {
1867
             "require": {
1913
                 "issues": "https://github.com/filamentphp/filament/issues",
1913
                 "issues": "https://github.com/filamentphp/filament/issues",
1914
                 "source": "https://github.com/filamentphp/filament"
1914
                 "source": "https://github.com/filamentphp/filament"
1915
             },
1915
             },
1916
-            "time": "2025-05-21T08:45:13+00:00"
1916
+            "time": "2025-05-27T18:46:23+00:00"
1917
         },
1917
         },
1918
         {
1918
         {
1919
             "name": "filament/forms",
1919
             "name": "filament/forms",
1920
-            "version": "v3.3.16",
1920
+            "version": "v3.3.17",
1921
             "source": {
1921
             "source": {
1922
                 "type": "git",
1922
                 "type": "git",
1923
                 "url": "https://github.com/filamentphp/forms.git",
1923
                 "url": "https://github.com/filamentphp/forms.git",
1924
-                "reference": "eeb18e482b1addc5fe88d57f59d6b91cb71957ff"
1924
+                "reference": "5cef64051fcb23cbbc6152baaac5da1c44ec9a63"
1925
             },
1925
             },
1926
             "dist": {
1926
             "dist": {
1927
                 "type": "zip",
1927
                 "type": "zip",
1928
-                "url": "https://api.github.com/repos/filamentphp/forms/zipball/eeb18e482b1addc5fe88d57f59d6b91cb71957ff",
1929
-                "reference": "eeb18e482b1addc5fe88d57f59d6b91cb71957ff",
1928
+                "url": "https://api.github.com/repos/filamentphp/forms/zipball/5cef64051fcb23cbbc6152baaac5da1c44ec9a63",
1929
+                "reference": "5cef64051fcb23cbbc6152baaac5da1c44ec9a63",
1930
                 "shasum": ""
1930
                 "shasum": ""
1931
             },
1931
             },
1932
             "require": {
1932
             "require": {
1969
                 "issues": "https://github.com/filamentphp/filament/issues",
1969
                 "issues": "https://github.com/filamentphp/filament/issues",
1970
                 "source": "https://github.com/filamentphp/filament"
1970
                 "source": "https://github.com/filamentphp/filament"
1971
             },
1971
             },
1972
-            "time": "2025-05-21T08:45:29+00:00"
1972
+            "time": "2025-05-27T18:46:33+00:00"
1973
         },
1973
         },
1974
         {
1974
         {
1975
             "name": "filament/infolists",
1975
             "name": "filament/infolists",
1976
-            "version": "v3.3.16",
1976
+            "version": "v3.3.17",
1977
             "source": {
1977
             "source": {
1978
                 "type": "git",
1978
                 "type": "git",
1979
                 "url": "https://github.com/filamentphp/infolists.git",
1979
                 "url": "https://github.com/filamentphp/infolists.git",
2024
         },
2024
         },
2025
         {
2025
         {
2026
             "name": "filament/notifications",
2026
             "name": "filament/notifications",
2027
-            "version": "v3.3.16",
2027
+            "version": "v3.3.17",
2028
             "source": {
2028
             "source": {
2029
                 "type": "git",
2029
                 "type": "git",
2030
                 "url": "https://github.com/filamentphp/notifications.git",
2030
                 "url": "https://github.com/filamentphp/notifications.git",
2076
         },
2076
         },
2077
         {
2077
         {
2078
             "name": "filament/support",
2078
             "name": "filament/support",
2079
-            "version": "v3.3.16",
2079
+            "version": "v3.3.17",
2080
             "source": {
2080
             "source": {
2081
                 "type": "git",
2081
                 "type": "git",
2082
                 "url": "https://github.com/filamentphp/support.git",
2082
                 "url": "https://github.com/filamentphp/support.git",
2135
         },
2135
         },
2136
         {
2136
         {
2137
             "name": "filament/tables",
2137
             "name": "filament/tables",
2138
-            "version": "v3.3.16",
2138
+            "version": "v3.3.17",
2139
             "source": {
2139
             "source": {
2140
                 "type": "git",
2140
                 "type": "git",
2141
                 "url": "https://github.com/filamentphp/tables.git",
2141
                 "url": "https://github.com/filamentphp/tables.git",
2187
         },
2187
         },
2188
         {
2188
         {
2189
             "name": "filament/widgets",
2189
             "name": "filament/widgets",
2190
-            "version": "v3.3.16",
2190
+            "version": "v3.3.17",
2191
             "source": {
2191
             "source": {
2192
                 "type": "git",
2192
                 "type": "git",
2193
                 "url": "https://github.com/filamentphp/widgets.git",
2193
                 "url": "https://github.com/filamentphp/widgets.git",
3516
         },
3516
         },
3517
         {
3517
         {
3518
             "name": "laravel/socialite",
3518
             "name": "laravel/socialite",
3519
-            "version": "v5.20.0",
3519
+            "version": "v5.21.0",
3520
             "source": {
3520
             "source": {
3521
                 "type": "git",
3521
                 "type": "git",
3522
                 "url": "https://github.com/laravel/socialite.git",
3522
                 "url": "https://github.com/laravel/socialite.git",
3523
-                "reference": "30972c12a41f71abeb418bc9ff157da8d9231519"
3523
+                "reference": "d83639499ad14985c9a6a9713b70073300ce998d"
3524
             },
3524
             },
3525
             "dist": {
3525
             "dist": {
3526
                 "type": "zip",
3526
                 "type": "zip",
3527
-                "url": "https://api.github.com/repos/laravel/socialite/zipball/30972c12a41f71abeb418bc9ff157da8d9231519",
3528
-                "reference": "30972c12a41f71abeb418bc9ff157da8d9231519",
3527
+                "url": "https://api.github.com/repos/laravel/socialite/zipball/d83639499ad14985c9a6a9713b70073300ce998d",
3528
+                "reference": "d83639499ad14985c9a6a9713b70073300ce998d",
3529
                 "shasum": ""
3529
                 "shasum": ""
3530
             },
3530
             },
3531
             "require": {
3531
             "require": {
3584
                 "issues": "https://github.com/laravel/socialite/issues",
3584
                 "issues": "https://github.com/laravel/socialite/issues",
3585
                 "source": "https://github.com/laravel/socialite"
3585
                 "source": "https://github.com/laravel/socialite"
3586
             },
3586
             },
3587
-            "time": "2025-04-21T14:21:34+00:00"
3587
+            "time": "2025-05-19T12:56:37+00:00"
3588
         },
3588
         },
3589
         {
3589
         {
3590
             "name": "laravel/tinker",
3590
             "name": "laravel/tinker",
9861
         },
9861
         },
9862
         {
9862
         {
9863
             "name": "laravel/sail",
9863
             "name": "laravel/sail",
9864
-            "version": "v1.43.0",
9864
+            "version": "v1.43.1",
9865
             "source": {
9865
             "source": {
9866
                 "type": "git",
9866
                 "type": "git",
9867
                 "url": "https://github.com/laravel/sail.git",
9867
                 "url": "https://github.com/laravel/sail.git",
9868
-                "reference": "71a509b14b2621ce58574274a74290f933c687f7"
9868
+                "reference": "3e7d899232a8c5e3ea4fc6dee7525ad583887e72"
9869
             },
9869
             },
9870
             "dist": {
9870
             "dist": {
9871
                 "type": "zip",
9871
                 "type": "zip",
9872
-                "url": "https://api.github.com/repos/laravel/sail/zipball/71a509b14b2621ce58574274a74290f933c687f7",
9873
-                "reference": "71a509b14b2621ce58574274a74290f933c687f7",
9872
+                "url": "https://api.github.com/repos/laravel/sail/zipball/3e7d899232a8c5e3ea4fc6dee7525ad583887e72",
9873
+                "reference": "3e7d899232a8c5e3ea4fc6dee7525ad583887e72",
9874
                 "shasum": ""
9874
                 "shasum": ""
9875
             },
9875
             },
9876
             "require": {
9876
             "require": {
9920
                 "issues": "https://github.com/laravel/sail/issues",
9920
                 "issues": "https://github.com/laravel/sail/issues",
9921
                 "source": "https://github.com/laravel/sail"
9921
                 "source": "https://github.com/laravel/sail"
9922
             },
9922
             },
9923
-            "time": "2025-05-13T13:34:34+00:00"
9923
+            "time": "2025-05-19T13:19:21+00:00"
9924
         },
9924
         },
9925
         {
9925
         {
9926
             "name": "mockery/mockery",
9926
             "name": "mockery/mockery",

Завантаження…
Відмінити
Зберегти