Andrew Wallo 5 个月前
父节点
当前提交
7c7fd088a2

+ 11
- 9
database/factories/Accounting/BillFactory.php 查看文件

@@ -162,7 +162,7 @@ class BillFactory extends Factory
162 162
                     'posted_at' => $postedAt,
163 163
                     'amount' => CurrencyConverter::convertCentsToFormatSimple($amount, $bill->currency_code),
164 164
                     'payment_method' => $this->faker->randomElement(PaymentMethod::class),
165
-                    'bank_account_id' => BankAccount::inRandomOrder()->value('id'),
165
+                    'bank_account_id' => BankAccount::where('company_id', $bill->company_id)->inRandomOrder()->value('id'),
166 166
                     'notes' => $this->faker->sentence,
167 167
                 ];
168 168
 
@@ -224,16 +224,18 @@ class BillFactory extends Factory
224 224
             return;
225 225
         }
226 226
 
227
-        $subtotal = $bill->lineItems()->sum('subtotal') / 100;
228
-        $taxTotal = $bill->lineItems()->sum('tax_total') / 100;
229
-        $discountTotal = $bill->lineItems()->sum('discount_total') / 100;
230
-        $grandTotal = $subtotal + $taxTotal - $discountTotal;
227
+        $subtotalCents = $bill->lineItems()->sum('subtotal');
228
+        $taxTotalCents = $bill->lineItems()->sum('tax_total');
229
+        $discountTotalCents = $bill->lineItems()->sum('discount_total');
230
+
231
+        $grandTotalCents = $subtotalCents + $taxTotalCents - $discountTotalCents;
232
+        $currencyCode = $bill->currency_code;
231 233
 
232 234
         $bill->update([
233
-            'subtotal' => $subtotal,
234
-            'tax_total' => $taxTotal,
235
-            'discount_total' => $discountTotal,
236
-            'total' => $grandTotal,
235
+            'subtotal' => CurrencyConverter::convertCentsToFormatSimple($subtotalCents, $currencyCode),
236
+            'tax_total' => CurrencyConverter::convertCentsToFormatSimple($taxTotalCents, $currencyCode),
237
+            'discount_total' => CurrencyConverter::convertCentsToFormatSimple($discountTotalCents, $currencyCode),
238
+            'total' => CurrencyConverter::convertCentsToFormatSimple($grandTotalCents, $currencyCode),
237 239
         ]);
238 240
     }
239 241
 }

+ 11
- 8
database/factories/Accounting/EstimateFactory.php 查看文件

@@ -8,6 +8,7 @@ use App\Models\Accounting\Estimate;
8 8
 use App\Models\Common\Client;
9 9
 use App\Models\Company;
10 10
 use App\Models\Setting\DocumentDefault;
11
+use App\Utilities\Currency\CurrencyConverter;
11 12
 use Illuminate\Database\Eloquent\Factories\Factory;
12 13
 use Illuminate\Support\Carbon;
13 14
 
@@ -204,16 +205,18 @@ class EstimateFactory extends Factory
204 205
             return;
205 206
         }
206 207
 
207
-        $subtotal = $estimate->lineItems()->sum('subtotal') / 100;
208
-        $taxTotal = $estimate->lineItems()->sum('tax_total') / 100;
209
-        $discountTotal = $estimate->lineItems()->sum('discount_total') / 100;
210
-        $grandTotal = $subtotal + $taxTotal - $discountTotal;
208
+        $subtotalCents = $estimate->lineItems()->sum('subtotal');
209
+        $taxTotalCents = $estimate->lineItems()->sum('tax_total');
210
+        $discountTotalCents = $estimate->lineItems()->sum('discount_total');
211
+
212
+        $grandTotalCents = $subtotalCents + $taxTotalCents - $discountTotalCents;
213
+        $currencyCode = $estimate->currency_code;
211 214
 
212 215
         $estimate->update([
213
-            'subtotal' => $subtotal,
214
-            'tax_total' => $taxTotal,
215
-            'discount_total' => $discountTotal,
216
-            'total' => $grandTotal,
216
+            'subtotal' => CurrencyConverter::convertCentsToFormatSimple($subtotalCents, $currencyCode),
217
+            'tax_total' => CurrencyConverter::convertCentsToFormatSimple($taxTotalCents, $currencyCode),
218
+            'discount_total' => CurrencyConverter::convertCentsToFormatSimple($discountTotalCents, $currencyCode),
219
+            'total' => CurrencyConverter::convertCentsToFormatSimple($grandTotalCents, $currencyCode),
217 220
         ]);
218 221
     }
219 222
 }

+ 11
- 9
database/factories/Accounting/InvoiceFactory.php 查看文件

@@ -180,7 +180,7 @@ class InvoiceFactory extends Factory
180 180
                     'posted_at' => $postedAt,
181 181
                     'amount' => CurrencyConverter::convertCentsToFormatSimple($amount, $invoice->currency_code),
182 182
                     'payment_method' => $this->faker->randomElement(PaymentMethod::class),
183
-                    'bank_account_id' => BankAccount::inRandomOrder()->value('id'),
183
+                    'bank_account_id' => BankAccount::where('company_id', $invoice->company_id)->inRandomOrder()->value('id'),
184 184
                     'notes' => $this->faker->sentence,
185 185
                 ];
186 186
 
@@ -249,16 +249,18 @@ class InvoiceFactory extends Factory
249 249
             return;
250 250
         }
251 251
 
252
-        $subtotal = $invoice->lineItems()->sum('subtotal') / 100;
253
-        $taxTotal = $invoice->lineItems()->sum('tax_total') / 100;
254
-        $discountTotal = $invoice->lineItems()->sum('discount_total') / 100;
255
-        $grandTotal = $subtotal + $taxTotal - $discountTotal;
252
+        $subtotalCents = $invoice->lineItems()->sum('subtotal');
253
+        $taxTotalCents = $invoice->lineItems()->sum('tax_total');
254
+        $discountTotalCents = $invoice->lineItems()->sum('discount_total');
255
+
256
+        $grandTotalCents = $subtotalCents + $taxTotalCents - $discountTotalCents;
257
+        $currencyCode = $invoice->currency_code;
256 258
 
257 259
         $invoice->update([
258
-            'subtotal' => $subtotal,
259
-            'tax_total' => $taxTotal,
260
-            'discount_total' => $discountTotal,
261
-            'total' => $grandTotal,
260
+            'subtotal' => CurrencyConverter::convertCentsToFormatSimple($subtotalCents, $currencyCode),
261
+            'tax_total' => CurrencyConverter::convertCentsToFormatSimple($taxTotalCents, $currencyCode),
262
+            'discount_total' => CurrencyConverter::convertCentsToFormatSimple($discountTotalCents, $currencyCode),
263
+            'total' => CurrencyConverter::convertCentsToFormatSimple($grandTotalCents, $currencyCode),
262 264
         ]);
263 265
     }
264 266
 }

+ 11
- 8
database/factories/Accounting/RecurringInvoiceFactory.php 查看文件

@@ -14,6 +14,7 @@ use App\Models\Accounting\DocumentLineItem;
14 14
 use App\Models\Accounting\RecurringInvoice;
15 15
 use App\Models\Common\Client;
16 16
 use App\Models\Company;
17
+use App\Utilities\Currency\CurrencyConverter;
17 18
 use Illuminate\Database\Eloquent\Factories\Factory;
18 19
 use Illuminate\Support\Carbon;
19 20
 
@@ -298,16 +299,18 @@ class RecurringInvoiceFactory extends Factory
298 299
             return;
299 300
         }
300 301
 
301
-        $subtotal = $recurringInvoice->lineItems()->sum('subtotal') / 100;
302
-        $taxTotal = $recurringInvoice->lineItems()->sum('tax_total') / 100;
303
-        $discountTotal = $recurringInvoice->lineItems()->sum('discount_total') / 100;
304
-        $grandTotal = $subtotal + $taxTotal - $discountTotal;
302
+        $subtotalCents = $recurringInvoice->lineItems()->sum('subtotal');
303
+        $taxTotalCents = $recurringInvoice->lineItems()->sum('tax_total');
304
+        $discountTotalCents = $recurringInvoice->lineItems()->sum('discount_total');
305
+
306
+        $grandTotalCents = $subtotalCents + $taxTotalCents - $discountTotalCents;
307
+        $currencyCode = $recurringInvoice->currency_code;
305 308
 
306 309
         $recurringInvoice->update([
307
-            'subtotal' => $subtotal,
308
-            'tax_total' => $taxTotal,
309
-            'discount_total' => $discountTotal,
310
-            'total' => $grandTotal,
310
+            'subtotal' => CurrencyConverter::convertCentsToFormatSimple($subtotalCents, $currencyCode),
311
+            'tax_total' => CurrencyConverter::convertCentsToFormatSimple($taxTotalCents, $currencyCode),
312
+            'discount_total' => CurrencyConverter::convertCentsToFormatSimple($discountTotalCents, $currencyCode),
313
+            'total' => CurrencyConverter::convertCentsToFormatSimple($grandTotalCents, $currencyCode),
311 314
         ]);
312 315
     }
313 316
 }

+ 0
- 2
tests/TestCase.php 查看文件

@@ -51,9 +51,7 @@ abstract class TestCase extends BaseTestCase
51 51
     {
52 52
         Offering::factory()
53 53
             ->for($this->testCompany)
54
-            ->sellable()
55 54
             ->withSalesAdjustments()
56
-            ->purchasable()
57 55
             ->withPurchaseAdjustments()
58 56
             ->create();
59 57
 

正在加载...
取消
保存