/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info("searching for event candidates...");
     // get all relevant events
     $all_events = Events::where('ticketsystem_enabled', 1)->where('ticketsystem_autoremind', 1)->whereNotNull('ticketsystem_autoremind_user_id')->whereNotNull('ticketsystem_recording_startdate')->get();
     error_log('All Events ' . json_encode($all_events));
     $curr_year = date("Y", strtotime('now'));
     $curr_week = date("W", strtotime('now'));
     // iterate to get at the event ticket types without sales
     foreach ($all_events as $key => $curr_event) {
         $this->info("event with ticketsystem enabled found...");
         // event ticket types
         $ticket_types = $curr_event->ticket_types()->get();
         $event_has_incomplete_sales = false;
         foreach ($ticket_types as $key => $tt) {
             // No point sending multiple notifications for same event and different ticket types
             if ($event_has_incomplete_sales) {
                 break;
             }
             $this->info("searching event ticket types...");
             for ($days_added = 0;; $days_added += 7) {
                 $cmp_ts = strtotime($curr_event->ticketsystem_recording_startdate . " +" . $days_added . " days");
                 if ($cmp_ts > strtotime('now')) {
                     break;
                 }
                 // get the week and year
                 $cmp_year = date("Y", $cmp_ts);
                 $cmp_week = date("W", $cmp_ts);
                 // get the ones without sales entries at some week between ticketsystem startdate and now
                 $tt_weekly_sales = TicketSold::where('event_ticket_types_id', $tt->id)->where('week', $cmp_week)->where('year', $cmp_year)->first();
                 if (!$tt_weekly_sales) {
                     $this->comment("notifying promoter...");
                     // get the user to be notified
                     $promoter = User::find($curr_event->ticketsystem_autoremind_user_id);
                     // create autologin entry
                     $confirmation_code = str_random(30);
                     $autologin_entry = TicketSalesAutologin::create(['users_id' => $promoter->id, 'events_id' => $curr_event->id, 'token' => $confirmation_code]);
                     if ($autologin_entry) {
                         // send notification
                         Mail::send('emails.promoters.incomplete_sales', array('promoter' => $promoter, 'curr_event' => $curr_event, 'autologin' => $autologin_entry), function ($message) use($promoter) {
                             $message->to($promoter->email, $promoter->username)->subject("Alda: Incomplete ticket sales");
                         });
                     }
                     $event_has_incomplete_sales = true;
                     break;
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public function postTicketSales($ev)
 {
     $all_input = Input::all();
     eerror_log('>>>> TSAI ' . count($all_input['sales_data']) . ' --- ' . json_encode($all_input['sales_data']));
     foreach ($all_input['sales_data'] as $key => $sales_ttype_data) {
         if (!isset($sales_ttype_data['sold']) || !is_numeric($sales_ttype_data['sold'])) {
             eerror_log('>> invalid sold ' . json_encode($sales_ttype_data['sold']));
             continue;
         }
         // get the ticket type to dicount sold tickets
         $curr_ticket_type = TicketType::find((int) $sales_ttype_data['ttype_id']);
         if (!$curr_ticket_type) {
             eerror_log('>>>> could not find ticket type');
             return Response::make('could not find ticket type', 500);
         }
         // discount
         $curr_ticket_type->num_available -= (int) $sales_ttype_data['sold'];
         $curr_ticket_type->update();
         $sale_date = new DateTime();
         $sale_date->setISODate((int) $sales_ttype_data['year'], (int) $sales_ttype_data['week']);
         $sales_date_ts = $sale_date->format('Y-m-d');
         eerror_log('>>> Sales ' . $sales_date_ts . ' - ' . $sales_ttype_data['week']);
         $ttype_sales_entry = TicketSold::firstOrCreate(['week' => $sales_ttype_data['week'], 'year' => $sales_ttype_data['year'], 'sale_date' => $sales_date_ts, 'event_ticket_types_id' => $sales_ttype_data['ttype_id']]);
         $ttype_sales_entry->num_sold = (int) $sales_ttype_data['sold'];
         $ttype_sales_entry->update();
         eerror_log('saved ticket entry ' . json_encode($ttype_sales_entry));
     }
     return Response::make('OK', 200);
 }