Andrew Wallo 6 months ago
parent
commit
08b18c66c9

+ 13
- 9
app/Filament/Company/Resources/Purchases/BillResource.php View File

148
                                         $offeringId = $state;
148
                                         $offeringId = $state;
149
                                         $offeringRecord = Offering::with(['purchaseTaxes', 'purchaseDiscounts'])->find($offeringId);
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
                                 Forms\Components\TextInput::make('description'),
166
                                 Forms\Components\TextInput::make('description'),

+ 7
- 0
app/Utilities/Currency/CurrencyConverter.php View File

88
         return money($amount, $currency)->getValue();
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
     public static function isValidAmount(?string $amount, ?string $currency = null): bool
98
     public static function isValidAmount(?string $amount, ?string $currency = null): bool
92
     {
99
     {
93
         $currency ??= CurrencyAccessor::getDefaultCurrency();
100
         $currency ??= CurrencyAccessor::getDefaultCurrency();

Loading…
Cancel
Save