Bladeren bron

Merge pull request #122 from andrewdwallo/fix/document-amounts

fix #121
3.x
Andrew Wallo 6 maanden geleden
bovenliggende
commit
c69b7830f7
No account linked to committer's email address

+ 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'),

+ 13
- 9
app/Filament/Company/Resources/Sales/EstimateResource.php Bestand weergeven

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

+ 13
- 9
app/Filament/Company/Resources/Sales/InvoiceResource.php Bestand weergeven

@@ -167,15 +167,19 @@ class InvoiceResource extends Resource
167 167
                                         $offeringId = $state;
168 168
                                         $offeringRecord = Offering::with(['salesTaxes', 'salesDiscounts'])->find($offeringId);
169 169
 
170
-                                        if ($offeringRecord) {
171
-                                            $set('description', $offeringRecord->description);
172
-                                            $set('unit_price', $offeringRecord->price);
173
-                                            $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
174
-
175
-                                            $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
176
-                                            if ($discountMethod->isPerLineItem()) {
177
-                                                $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
178
-                                            }
170
+                                        if (! $offeringRecord) {
171
+                                            return;
172
+                                        }
173
+
174
+                                        $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
175
+
176
+                                        $set('description', $offeringRecord->description);
177
+                                        $set('unit_price', $unitPrice);
178
+                                        $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
179
+
180
+                                        $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
181
+                                        if ($discountMethod->isPerLineItem()) {
182
+                                            $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
179 183
                                         }
180 184
                                     }),
181 185
                                 Forms\Components\TextInput::make('description'),

+ 12
- 8
app/Filament/Company/Resources/Sales/RecurringInvoiceResource.php Bestand weergeven

@@ -137,15 +137,19 @@ class RecurringInvoiceResource extends Resource
137 137
                                         $offeringId = $state;
138 138
                                         $offeringRecord = Offering::with(['salesTaxes', 'salesDiscounts'])->find($offeringId);
139 139
 
140
-                                        if ($offeringRecord) {
141
-                                            $set('description', $offeringRecord->description);
142
-                                            $set('unit_price', $offeringRecord->price);
143
-                                            $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
140
+                                        if (! $offeringRecord) {
141
+                                            return;
142
+                                        }
143
+
144
+                                        $unitPrice = CurrencyConverter::convertToFloat($offeringRecord->price, $get('../../currency_code') ?? CurrencyAccessor::getDefaultCurrency());
144 145
 
145
-                                            $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
146
-                                            if ($discountMethod->isPerLineItem()) {
147
-                                                $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
148
-                                            }
146
+                                        $set('description', $offeringRecord->description);
147
+                                        $set('unit_price', $unitPrice);
148
+                                        $set('salesTaxes', $offeringRecord->salesTaxes->pluck('id')->toArray());
149
+
150
+                                        $discountMethod = DocumentDiscountMethod::parse($get('../../discount_method'));
151
+                                        if ($discountMethod->isPerLineItem()) {
152
+                                            $set('salesDiscounts', $offeringRecord->salesDiscounts->pluck('id')->toArray());
149 153
                                         }
150 154
                                     }),
151 155
                                 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