Andrew Wallo 5 months ago
parent
commit
7c7fd088a2

+ 11
- 9
database/factories/Accounting/BillFactory.php View File

162
                     'posted_at' => $postedAt,
162
                     'posted_at' => $postedAt,
163
                     'amount' => CurrencyConverter::convertCentsToFormatSimple($amount, $bill->currency_code),
163
                     'amount' => CurrencyConverter::convertCentsToFormatSimple($amount, $bill->currency_code),
164
                     'payment_method' => $this->faker->randomElement(PaymentMethod::class),
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
                     'notes' => $this->faker->sentence,
166
                     'notes' => $this->faker->sentence,
167
                 ];
167
                 ];
168
 
168
 
224
             return;
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
         $bill->update([
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 View File

8
 use App\Models\Common\Client;
8
 use App\Models\Common\Client;
9
 use App\Models\Company;
9
 use App\Models\Company;
10
 use App\Models\Setting\DocumentDefault;
10
 use App\Models\Setting\DocumentDefault;
11
+use App\Utilities\Currency\CurrencyConverter;
11
 use Illuminate\Database\Eloquent\Factories\Factory;
12
 use Illuminate\Database\Eloquent\Factories\Factory;
12
 use Illuminate\Support\Carbon;
13
 use Illuminate\Support\Carbon;
13
 
14
 
204
             return;
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
         $estimate->update([
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 View File

180
                     'posted_at' => $postedAt,
180
                     'posted_at' => $postedAt,
181
                     'amount' => CurrencyConverter::convertCentsToFormatSimple($amount, $invoice->currency_code),
181
                     'amount' => CurrencyConverter::convertCentsToFormatSimple($amount, $invoice->currency_code),
182
                     'payment_method' => $this->faker->randomElement(PaymentMethod::class),
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
                     'notes' => $this->faker->sentence,
184
                     'notes' => $this->faker->sentence,
185
                 ];
185
                 ];
186
 
186
 
249
             return;
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
         $invoice->update([
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 View File

14
 use App\Models\Accounting\RecurringInvoice;
14
 use App\Models\Accounting\RecurringInvoice;
15
 use App\Models\Common\Client;
15
 use App\Models\Common\Client;
16
 use App\Models\Company;
16
 use App\Models\Company;
17
+use App\Utilities\Currency\CurrencyConverter;
17
 use Illuminate\Database\Eloquent\Factories\Factory;
18
 use Illuminate\Database\Eloquent\Factories\Factory;
18
 use Illuminate\Support\Carbon;
19
 use Illuminate\Support\Carbon;
19
 
20
 
298
             return;
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
         $recurringInvoice->update([
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 View File

51
     {
51
     {
52
         Offering::factory()
52
         Offering::factory()
53
             ->for($this->testCompany)
53
             ->for($this->testCompany)
54
-            ->sellable()
55
             ->withSalesAdjustments()
54
             ->withSalesAdjustments()
56
-            ->purchasable()
57
             ->withPurchaseAdjustments()
55
             ->withPurchaseAdjustments()
58
             ->create();
56
             ->create();
59
 
57
 

Loading…
Cancel
Save