mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 03:04:05 +00:00
127 - Calculating Tickets Sold
This commit is contained in:
@@ -99,4 +99,9 @@ class Concert extends Model
|
||||
{
|
||||
return $this->tickets()->available()->count();
|
||||
}
|
||||
|
||||
public function ticketsSold()
|
||||
{
|
||||
return $this->tickets()->sold()->count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ class Ticket extends Model
|
||||
return $query->whereNull('order_id')->whereNull('reserved_at');
|
||||
}
|
||||
|
||||
public function scopeSold($query)
|
||||
{
|
||||
return $query->whereNotNull('order_id');
|
||||
}
|
||||
|
||||
public function reserve()
|
||||
{
|
||||
$this->update(['reserved_at' => Carbon::now()]);
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<div class="card-section p-md-r-2 text-center text-md-left">
|
||||
<h3 class="text-base wt-normal m-xs-b-1">Total Tickets Remaining</h3>
|
||||
<div class="text-jumbo wt-bold">
|
||||
243
|
||||
{{ $concert->ticketsRemaining() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -41,7 +41,7 @@
|
||||
<div class="card-section p-md-x-2 text-center text-md-left">
|
||||
<h3 class="text-base wt-normal m-xs-b-1">Total Tickets Sold</h3>
|
||||
<div class="text-jumbo wt-bold">
|
||||
357
|
||||
{{ $concert->ticketsSold() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -78,10 +78,21 @@ class ConcertTest extends TestCase
|
||||
function tickets_remaining_does_not_include_tickets_associated_with_an_order()
|
||||
{
|
||||
$concert = factory(Concert::class)->create();
|
||||
$concert->tickets()->saveMany(factory(Ticket::class, 30)->create(['order_id' => 1]));
|
||||
$concert->tickets()->saveMany(factory(Ticket::class, 20)->create(['order_id' => null]));
|
||||
$concert->tickets()->saveMany(factory(Ticket::class, 3)->create(['order_id' => 1]));
|
||||
$concert->tickets()->saveMany(factory(Ticket::class, 2)->create(['order_id' => null]));
|
||||
|
||||
$this->assertEquals(20, $concert->ticketsRemaining());
|
||||
$this->assertEquals(2, $concert->ticketsRemaining());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
function tickets_sold_only_includes_tickets_associated_with_an_order()
|
||||
{
|
||||
$concert = factory(Concert::class)->create();
|
||||
$concert->tickets()->saveMany(factory(Ticket::class, 3)->create(['order_id' => 1]));
|
||||
$concert->tickets()->saveMany(factory(Ticket::class, 2)->create(['order_id' => null]));
|
||||
|
||||
$this->assertEquals(3, $concert->ticketsSold());
|
||||
}
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
||||
Reference in New Issue
Block a user