Andrew Wallo 6 maanden geleden
bovenliggende
commit
08b18c66c9

+ 13
- 9
app/Filament/Company/Resources/Purchases/BillResource.php Bestand weergeven

@@ -148,15 +148,19 @@ class BillResource extends Resource
148 148
                                         $offeringId = $state;
149 149
                                         $offeringRecord = Offering::with(['purchaseTaxes', 'purchaseDiscounts'])->find($offeringId);
150 150
 
151
-                                        if ($offeringRecord) {
152
-                                            $set('description', $offeringRecord->description);
153
-                                            $set('unit_price', $offeringRecord->price);
154
-                                            $set('purchaseTaxes', $offeringRecord->purchaseTaxes->pluck('id')->toArray());
155
-
156
-                                            $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
157
-                                            if ($discountMethod->isPerLineItem()) {
158
-                                                $set('purchaseDiscounts', $offeringRecord->purchaseDiscounts->pluck('id')->toArray());
159
-                                            }
151
+                                        if (! $offeringRecord) {
152
+                                            return;
153
+                                        }
154
+
155
+                                        $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
156
+
157
+                                        $set('description', $offeringRecord->description);
158
+                                        $set('unit_price', $unitPrice);
159
+                                        $set('purchaseTaxes', $offeringRecord->purchaseTaxes->pluck('id')->toArray());
160
+
161
+                                        $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
162
+                                        if ($discountMethod->isPerLineItem()) {
163
+                                            $set('purchaseDiscounts', $offeringRecord->purchaseDiscounts->pluck('id')->toArray());
160 164
                                         }
161 165
                                     }),
162 166
                                 Forms\Components\TextInput::make('description'),

+ 7
- 0
app/Utilities/Currency/CurrencyConverter.php Bestand weergeven

@@ -88,6 +88,13 @@ class CurrencyConverter
88 88
         return money($amount, $currency)->getValue();
89 89
     }
90 90
 
91
+    public static function convertToFloat(string | float $amount, ?string $currency = null): float
92
+    {
93
+        $currency ??= CurrencyAccessor::getDefaultCurrency();
94
+
95
+        return money($amount, $currency, true)->getValue();
96
+    }
97
+
91 98
     public static function isValidAmount(?string $amount, ?string $currency = null): bool
92 99
     {
93 100
         $currency ??= CurrencyAccessor::getDefaultCurrency();

Laden…
Annuleren
Opslaan