Fix: Split subscriptions between members
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
376c1ceb9b
commit
b2f3e4f1fd
|
@ -49,7 +49,6 @@ class Invoice extends Model
|
||||||
*/
|
*/
|
||||||
public static function createForMember(Member $member, Collection $members, int $year, Subscription $subscription = null): self
|
public static function createForMember(Member $member, Collection $members, int $year, Subscription $subscription = null): self
|
||||||
{
|
{
|
||||||
$subscription = $subscription ?: $member->subscription;
|
|
||||||
$invoice = new self([
|
$invoice = new self([
|
||||||
'to' => [
|
'to' => [
|
||||||
'name' => 'Familie ' . $member->lastname,
|
'name' => 'Familie ' . $member->lastname,
|
||||||
|
@ -66,7 +65,8 @@ class Invoice extends Model
|
||||||
|
|
||||||
$positions = collect([]);
|
$positions = collect([]);
|
||||||
foreach ($members as $member) {
|
foreach ($members as $member) {
|
||||||
foreach ($subscription->children as $child) {
|
$memberSubscription = $subscription ?: $member->subscription;
|
||||||
|
foreach ($memberSubscription->children as $child) {
|
||||||
$positions->push([
|
$positions->push([
|
||||||
'description' => str($child->name)->replace('{name}', $member->firstname . ' ' . $member->lastname)->replace('{year}', (string) $year),
|
'description' => str($child->name)->replace('{name}', $member->firstname . ' ' . $member->lastname)->replace('{year}', (string) $year),
|
||||||
'price' => $child->amount,
|
'price' => $child->amount,
|
||||||
|
|
|
@ -90,8 +90,8 @@ class MassStoreActionTest extends TestCase
|
||||||
|
|
||||||
$this->assertDatabaseCount('invoices', 1);
|
$this->assertDatabaseCount('invoices', 1);
|
||||||
$this->assertDatabaseCount('invoice_positions', 2);
|
$this->assertDatabaseCount('invoice_positions', 2);
|
||||||
$this->assertDatabaseHas('invoice_positions', ['description' => 'beitrag Max Muster']);
|
$this->assertDatabaseHas('invoice_positions', ['description' => 'beitrag Max Muster', 'price' => 4466]);
|
||||||
$this->assertDatabaseHas('invoice_positions', ['description' => 'beitrag Jane Muster']);
|
$this->assertDatabaseHas('invoice_positions', ['description' => 'beitrag Jane Muster', 'price' => 4466]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItSeparatesBillKinds(): void
|
public function testItSeparatesBillKinds(): void
|
||||||
|
@ -105,4 +105,21 @@ class MassStoreActionTest extends TestCase
|
||||||
$this->assertDatabaseCount('invoices', 2);
|
$this->assertDatabaseCount('invoices', 2);
|
||||||
$this->assertDatabaseCount('invoice_positions', 2);
|
$this->assertDatabaseCount('invoice_positions', 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testItSeparatesSubscriptions(): void
|
||||||
|
{
|
||||||
|
$member1 = Member::factory()->defaults()->emailBillKind()
|
||||||
|
->for(Subscription::factory()->forFee()->children([new Child('beitrag1 {name}', 4466)]))
|
||||||
|
->create(['firstname' => 'Member1', 'lastname' => 'ln']);
|
||||||
|
$member2 = Member::factory()->defaults()->sameFamilyAs($member1)->emailBillKind()
|
||||||
|
->for(Subscription::factory()->forFee()->children([new Child('beitrag2 {name}', 4467)]))
|
||||||
|
->create(['firstname' => 'Member2']);
|
||||||
|
|
||||||
|
$this->postJson(route('invoice.mass-store'), ['year' => now()->addYear()->year])->assertOk();
|
||||||
|
$invoice = Invoice::first();
|
||||||
|
|
||||||
|
$this->assertDatabaseCount('invoice_positions', 2);
|
||||||
|
$this->assertDatabaseHas('invoice_positions', ['invoice_id' => $invoice->id, 'member_id' => $member1->id, 'description' => 'beitrag1 Member1 ln', 'price' => 4466]);
|
||||||
|
$this->assertDatabaseHas('invoice_positions', ['invoice_id' => $invoice->id, 'member_id' => $member2->id, 'description' => 'beitrag2 Member2 ln', 'price' => 4467]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue