66use App \Models \Revenue ;
77use App \Models \User ;
88use App \Models \VatNotice ;
9+ use Database \Seeders \CostTypeSeeder ;
10+ use Illuminate \Foundation \Testing \RefreshDatabase ;
911use Illuminate \Support \Number ;
1012use Tests \TestCase ;
1113
1214class VatNoticeTest extends TestCase
1315{
16+ use RefreshDatabase;
17+
18+ protected function setUp (): void
19+ {
20+ parent ::setUp ();
21+ $ this ->seed (CostTypeSeeder::class);
22+ }
23+
1424 public function test_vat_notice_page_is_loaded (): void
1525 {
1626 $ user = User::factory ()->create ();
1727
1828 $ vatNoticePage = $ this ->actingAs ($ user )
19- ->get ('/vat-notice ' );
29+ ->get ('/vat-notice/ ' );
2030
2131 $ vatNoticePage ->assertSeeInOrder ([
2232 'Zu meldende steuerpflichtige Umsätze ' ,
@@ -30,18 +40,29 @@ public function test_vat_notice_page_is_loaded(): void
3040 public function test_vat_notice_page_calcs_total_tax (): void
3141 {
3242 $ user = User::factory ()->createOne ();
33- $ rev1 = Revenue::factory ()->create ();
34- $ rev2 = Revenue::factory ()->create ();
43+ $ rev1 = Revenue::factory ()->create ([ ' net ' => 5200 ] );
44+ $ rev2 = Revenue::factory ()->create ([ ' net ' => 3200 ] );
3545 $ exp1 = Expense::factory ()->create ();
3646 $ exp2 = Expense::factory ()->create ();
47+ $ vatNotice1 = VatNotice::factory ()->create ();
48+ $ vatNotice2 = VatNotice::factory ()->create ();
49+
3750 $ totalReceivedTax = $ rev1 ->tax + $ rev2 ->tax ;
51+ $ remainingRevenueTax = $ totalReceivedTax - $ vatNotice1 ->vat_received - $ vatNotice2 ->vat_received ;
52+
53+ $ remainingNetRevenueRounded = round ($ remainingRevenueTax * 100 / 19 , 0 ); // Elster only let you use non decimal numbers for the net revenue
54+ $ remainingRevenueTaxRounded = $ remainingNetRevenueRounded * 19 / 100 ;
55+
3856 $ totalPaidTax = $ exp1 ->tax + $ exp2 ->tax ;
57+ $ paidTaxToReport = $ totalPaidTax - $ vatNotice1 ->vat_paid - $ vatNotice2 ->vat_paid ;
3958
4059 $ vatNoticePage = $ this ->actingAs ($ user )
41- ->get ('/vat-notice ' );
60+ ->get ('/vat-notice/ ' );
4261
43- $ vatNoticePage ->assertSee (Number::currency ($ totalReceivedTax , in: 'EUR ' , locale: 'de ' ));
62+ $ vatNoticePage ->assertSee (Number::currency ($ remainingNetRevenueRounded , in: 'EUR ' , locale: 'de ' ));
63+ $ vatNoticePage ->assertSee (Number::currency ($ remainingRevenueTaxRounded , in: 'EUR ' , locale: 'de ' ));
4464 $ vatNoticePage ->assertSee (Number::currency ($ totalPaidTax , in: 'EUR ' , locale: 'de ' ));
65+ $ vatNoticePage ->assertSee (Number::currency ($ paidTaxToReport , in: 'EUR ' , locale: 'de ' ));
4566 $ vatNoticePage ->assertStatus (200 );
4667
4768 $ rev1 ->delete ();
@@ -92,6 +113,7 @@ public function test_vat_notice_page_shows_notices(): void
92113 $ vatNoticePage ->assertSee (Number::currency ($ vatNotice ->vat_paid , in: 'EUR ' , locale: 'de ' ));
93114 $ vatNoticePage ->assertStatus (200 );
94115
116+ $ user ->delete ();
95117 $ vatNotice ->delete ();
96118 }
97119
@@ -105,6 +127,7 @@ public function test_create_vat_notice_page_is_loaded(): void
105127 $ vatNoticePage ->assertSeeInOrder ([
106128 'Meldedatum ' ,
107129 ]);
130+ $ user ->delete ();
108131 $ vatNoticePage ->assertStatus (200 );
109132 }
110133
0 commit comments