diff --git a/app/Commands/SendAttendeeTicketCommand.php b/app/Commands/SendAttendeeTicketCommand.php index f57b3d70..75c3b596 100644 --- a/app/Commands/SendAttendeeTicketCommand.php +++ b/app/Commands/SendAttendeeTicketCommand.php @@ -65,7 +65,7 @@ class SendAttendeeTicketCommand extends Command implements ShouldQueue, SelfHand 'image' => base64_encode(file_get_contents(public_path($this->attendee->event->organiser->full_logo_path))), ]; - $pdf_file_name = $this->ticketOrder->order_reference.'-'.$this->attendee->id; + $pdf_file_name = $this->ticketOrder->order_reference.'-1'; $pdf_file_path = public_path(config('attendize.event_pdf_tickets_path')).'/'.$pdf_file_name; $pdf_file = $pdf_file_path.'.pdf'; diff --git a/app/Http/Controllers/EventAttendeesController.php b/app/Http/Controllers/EventAttendeesController.php index 7ea32f35..6c0694e8 100644 --- a/app/Http/Controllers/EventAttendeesController.php +++ b/app/Http/Controllers/EventAttendeesController.php @@ -47,7 +47,6 @@ class EventAttendeesController extends MyBaseController $query->where('orders.order_reference', 'like', $searchQuery . '%') ->orWhere('attendees.first_name', 'like', $searchQuery . '%') ->orWhere('attendees.email', 'like', $searchQuery . '%') - ->orWhere('attendees.reference', 'like', $searchQuery . '%') ->orWhere('attendees.last_name', 'like', $searchQuery . '%'); }) ->orderBy(($sort_by == 'order_reference' ? 'orders.' : 'attendees.') . $sort_by, $sort_order) @@ -188,7 +187,7 @@ class EventAttendeesController extends MyBaseController $attendee->order_id = $order->id; $attendee->ticket_id = $ticket_id; $attendee->account_id = Auth::user()->account_id; - $attendee->reference = $order->order_reference . '-1'; + $attendee->reference_index = 1; $attendee->save(); if ($email_attendee == '1') { @@ -344,7 +343,7 @@ class EventAttendeesController extends MyBaseController $attendee->order_id = $order->id; $attendee->ticket_id = $ticket_id; $attendee->account_id = Auth::user()->account_id; - $attendee->reference = $order->order_reference . '-1'; + $attendee->reference_index = 1; $attendee->save(); if ($email_attendee == '1') { @@ -542,7 +541,6 @@ class EventAttendeesController extends MyBaseController 'attendees.first_name', 'attendees.last_name', 'attendees.email', - 'attendees.reference', 'orders.order_reference', 'tickets.title', 'orders.created_at', @@ -555,7 +553,6 @@ class EventAttendeesController extends MyBaseController 'First Name', 'Last Name', 'Email', - 'Ticket Reference', 'Order Reference', 'Ticket Type', 'Purchase Date', diff --git a/app/Http/Controllers/EventCheckInController.php b/app/Http/Controllers/EventCheckInController.php index 7e655c39..fa5b9218 100644 --- a/app/Http/Controllers/EventCheckInController.php +++ b/app/Http/Controllers/EventCheckInController.php @@ -54,13 +54,14 @@ class EventCheckInController extends MyBaseController $attendees = Attendee::scope()->withoutCancelled() ->join('tickets', 'tickets.id', '=', 'attendees.ticket_id') + ->join('orders', 'orders.id', '=', 'attendees.order_id') ->where(function ($query) use ($event_id) { $query->where('attendees.event_id', '=', $event_id); })->where(function ($query) use ($searchQuery) { $query->orWhere('attendees.first_name', 'like', $searchQuery . '%') - ->orWhere(DB::raw("CONCAT_WS(' ', first_name, last_name)"), 'like', $searchQuery . '%') + ->orWhere(DB::raw("CONCAT_WS(' ', attendees.first_name, attendees.last_name)"), 'like', $searchQuery . '%') //->orWhere('attendees.email', 'like', $searchQuery . '%') - ->orWhere('attendees.reference', 'like', $searchQuery . '%') + ->orWhere('orders.order_reference', 'like', $searchQuery . '%') ->orWhere('attendees.last_name', 'like', $searchQuery . '%'); }) ->select([ @@ -68,10 +69,11 @@ class EventCheckInController extends MyBaseController 'attendees.first_name', 'attendees.last_name', 'attendees.email', - 'attendees.reference', 'attendees.arrival_time', + 'attendees.reference_index', 'attendees.has_arrived', 'tickets.title as ticket', + 'orders.order_reference' ]) ->orderBy('attendees.first_name', 'ASC') ->get(); diff --git a/app/Http/Controllers/EventCheckoutController.php b/app/Http/Controllers/EventCheckoutController.php index 8adc6681..ed95eddc 100644 --- a/app/Http/Controllers/EventCheckoutController.php +++ b/app/Http/Controllers/EventCheckoutController.php @@ -551,7 +551,7 @@ class EventCheckoutController extends Controller $attendee->order_id = $order->id; $attendee->ticket_id = $attendee_details['ticket']['id']; $attendee->account_id = $event->account->id; - $attendee->reference = $order->order_reference . '-' . ($attendee_increment); + $attendee->reference = $attendee_increment; $attendee->save(); diff --git a/app/Models/Attendee.php b/app/Models/Attendee.php index 51c4fd0c..189a2bc6 100644 --- a/app/Models/Attendee.php +++ b/app/Models/Attendee.php @@ -99,10 +99,15 @@ class Attendee extends MyBaseModel return $query->where('attendees.is_cancelled', '=', 0); } -// -// public function getReferenceAttribute() { -// return $this->order->order_reference -// } + + /** + * Get the attendee reference + * + * @return string + */ + public function getReferenceAttribute() { + return $this->order->order_reference . '-' . $this->reference_index; + } /** * Get the full name of the attendee. @@ -114,6 +119,8 @@ class Attendee extends MyBaseModel return $this->first_name.' '.$this->last_name; } + + /** * The attributes that should be mutated to dates. * diff --git a/database/migrations/2016_05_25_145857_attendee_ref_fix.php b/database/migrations/2016_05_25_145857_attendee_ref_fix.php new file mode 100644 index 00000000..78c3a55f --- /dev/null +++ b/database/migrations/2016_05_25_145857_attendee_ref_fix.php @@ -0,0 +1,61 @@ +integer('reference_index'); + }); + + $attendees = Attendee::all(); + + foreach($attendees as $attendee) { + $attendee->reference_index = explode('-', $attendee->reference)[1]; + $attendee->save(); + } + + Schema::table('attendees', function (Blueprint $table) { + $table->dropColumn('reference'); + }); + + + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('attendees', function (Blueprint $table) { + $table->string('reference'); + $table->dropColumn('reference_index'); + }); + + $orders = Order::all(); + foreach ($orders as $order) { + + $attendee_count = 0; + + foreach($order->attendees as $attendee) { + $attendee->reference = $order->order_reference. '-' . ++$attendee_count; + $attendee->save(); + } + + } + + } +} diff --git a/resources/views/ManageEvent/Attendees.blade.php b/resources/views/ManageEvent/Attendees.blade.php index e6596a7f..4c5888bb 100644 --- a/resources/views/ManageEvent/Attendees.blade.php +++ b/resources/views/ManageEvent/Attendees.blade.php @@ -108,7 +108,7 @@ Attendees