public function index()
 {
     $param['ticketTypes'] = TicketTypeModel::where('company_id', Session::get('company_id'))->paginate(10);
     $param['pageNo'] = 6;
     if ($alert = Session::get('alert')) {
         $param['alert'] = $alert;
     }
     return View::make('company.ticket-type.index')->with($param);
 }
 public function index()
 {
     $param['pageNo'] = 1;
     $agent = AgentModel::find(Session::get('agent_id'));
     $param['is_active'] = $agent->is_active;
     $param['ticketTypes'] = TicketTypeModel::where('company_id', $agent->store->company->id)->get();
     if (Session::has('process_id')) {
         $process = ProcessModel::find(Session::get('process_id'));
         $param['currentQueueNo'] = $process->queue_no;
         $param['lastQueueNo'] = $process->agent->store->status->last_queue_no;
     }
     // Get Store ID
     $storeId = $agent->store_id;
     $status = StatusModel::where('store_id', $storeId)->first();
     $agents = AgentModel::where('store_id', $storeId)->where('is_active', TRUE);
     $param['amountOfQueue'] = $status->last_queue_no - $status->current_queue_no;
     $tickets = ProcessModel::where('agent_id', $agent->id)->whereRaw('DATE(created_at) = DATE(NOW())')->where('end_time', '!=', '');
     $param['ticketsManaged'] = $tickets->count();
     $processTickets = $tickets->get();
     $activeTime = 0;
     foreach ($processTickets as $item) {
         $activeTime += strtotime($item->end_time) - strtotime($item->start_time);
     }
     $param['activeTime'] = $activeTime;
     $param['averageYourTicketTime'] = $tickets->count() == 0 ? 0 : round($activeTime / $tickets->count());
     $agentIds = [];
     $agentIds[] = 0;
     $agents = AgentModel::where('store_id', $storeId)->get();
     foreach ($agents as $agent) {
         $agentIds[] = $agent->id;
     }
     $tickets = ProcessModel::whereIn('agent_id', $agentIds)->whereRaw('DATE(created_at) = DATE(NOW())')->where('end_time', '!=', '');
     $processTickets = $tickets->get();
     $activeTime = 0;
     foreach ($processTickets as $item) {
         $activeTime += strtotime($item->end_time) - strtotime($item->start_time);
     }
     $param['averageTicketTime'] = $tickets->count() == 0 ? 0 : round($activeTime / $tickets->count());
     $prefix = DB::getTablePrefix();
     $sqlType = "SELECT id, name\n                  FROM " . $prefix . "ticket_type\n                 WHERE company_id = " . $agent->store->company->id . "\n                 UNION ALL\n                SELECT 0 as id, 'Skip' as name";
     $sql = "\n                SELECT COUNT(*) AS cnt, IFNULL(ticket_type, 0) AS type\n                  FROM " . $prefix . "process t1, " . $prefix . "agent t2, " . $prefix . "store t3\n                 WHERE t1.agent_id = t2.id\n                   AND t2.store_id = t3.id\n                   AND t1.end_time != ''\n                   AND t3.company_id = " . $agent->store->company->id . "\n                 GROUP BY ticket_type";
     $sql = "SELECT t1.name, IFNULL(t2.cnt, 0) AS cnt\n                  FROM ({$sqlType}) t1\n                  LEFT JOIN ({$sql}) t2\n                    ON t1.id = t2.type\n                 ORDER BY IFNULL(t2.cnt, 0) DESC";
     $param['mostTickets'] = DB::select($sql);
     return View::make('agent.process.index')->with($param);
 }
示例#3
0
 public function getTickets($curr_event)
 {
     $curr_year = (int) date('Y', strtotime('now'));
     $curr_week = (int) date('W', strtotime('now'));
     $event_ticketsystem_startdate = $curr_event->ticketsystem_recording_startdate;
     $event_ts_startyear = (int) date('Y', strtotime($event_ticketsystem_startdate));
     $event_ts_startweek = (int) date('W', strtotime($event_ticketsystem_startdate));
     $ticket_types = TicketType::where('events_id', $curr_event->id)->orderBy('order')->get();
     $ticket_aggregate = [];
     $yearly_tickettype_aggregate = [];
     $global_aggregate = (object) ['num_sold' => 0, 'amt' => 0, 'points' => null, 'cum_points' => null];
     $global_aggregate->points = [];
     $global_aggregate->cum_points = [];
     // yearly aggregates
     foreach ($ticket_types as $key => $tt) {
         $tmp_yearly_tickettype = (object) ['id' => $tt->id, 'name' => $tt->name, 'num_sold' => 0, 'amt' => 0, 'points' => null, 'sales_points' => null];
         $tmp_yearly_tickettype->points = [];
         $tmp_yearly_tickettype->sales_points = [];
         $yearly_tickettype_aggregate[] = $tmp_yearly_tickettype;
     }
     // years
     for ($y = $event_ts_startyear; $y <= $curr_year; $y++) {
         // last week for current year
         $last_week_dt = new DateTime('December 28th, ' . $y);
         $last_week = $y === $curr_year ? $curr_week : (int) $last_week_dt->format('W');
         $start_week = $y === $event_ts_startyear ? $event_ts_startweek : 1;
         // weeks
         for ($w = $start_week; $w <= $last_week; $w++) {
             // tmp storage for all ticket types for a given week
             $tmp_ticket_aggregate = (object) ['week_ndx' => $w, 'year' => $y, 'ticket_details' => null, 'weekly_totals' => null];
             $tmp_ticket_aggregate->ticket_details = [];
             // tmp weekly cumulative counter vars for all ticket types
             $weekly_total_sold = 0;
             $weekly_total_revenue = 0;
             // for each ticket type
             $tmp_global_point = 0;
             foreach ($ticket_types as $key => $ticket_type) {
                 $curr_tickets_sold = TicketSold::where('event_ticket_types_id', $ticket_type->id)->where('week', $w)->where('year', $y)->first();
                 // find the yearly ticket_type ndx
                 $yearly_tt_ndx = -1;
                 foreach ($yearly_tickettype_aggregate as $key => $yearly_tickettype_value) {
                     if ($yearly_tickettype_value->id === $ticket_type->id) {
                         $yearly_tt_ndx = $key;
                         break;
                     }
                 }
                 if ($curr_tickets_sold) {
                     eerror_log('Event ' . $curr_event->id . ' has ticketssold for ' . $w . '-' . $y . ' ' . json_encode($curr_tickets_sold));
                     // update weekly accumulators
                     $curr_ticket_price = (double) $ticket_type->price;
                     $weekly_total_sold += (int) $curr_tickets_sold->num_sold;
                     $weekly_total_revenue += (int) $curr_tickets_sold->num_sold * $curr_ticket_price;
                     // update yearly accumulators
                     if ($yearly_tt_ndx !== -1) {
                         $revenue = (double) $curr_tickets_sold->num_sold * $curr_ticket_price;
                         $yearly_tickettype_aggregate[$yearly_tt_ndx]->num_sold += (int) $curr_tickets_sold->num_sold;
                         $yearly_tickettype_aggregate[$yearly_tt_ndx]->amt += $revenue;
                         $yearly_tickettype_aggregate[$yearly_tt_ndx]->points[] = (int) $curr_tickets_sold->num_sold;
                         $yearly_tickettype_aggregate[$yearly_tt_ndx]->sales_points[] = $revenue;
                         $tmp_global_point += $revenue;
                     }
                 } else {
                     if ($yearly_tt_ndx !== -1) {
                         // set to 0 if no tt sale exists
                         $yearly_tickettype_aggregate[$yearly_tt_ndx]->points[] = 0;
                         $yearly_tickettype_aggregate[$yearly_tt_ndx]->sales_points[] = 0;
                     }
                 }
                 // save resuts for current ticket type
                 $tmp_ticket_aggregate->ticket_details[] = ['ticket_type' => $ticket_type, 'tickets_sold' => $curr_tickets_sold, 'input_visible' => !$curr_tickets_sold ? true : false];
             }
             // save weekly accumulators
             $tmp_ticket_aggregate->weekly_totals = ['num_sold' => $weekly_total_sold, 'amt' => $weekly_total_revenue];
             $ticket_aggregate[] = $tmp_ticket_aggregate;
             $global_aggregate->points[] = $tmp_global_point;
             $num_points = count($global_aggregate->points);
             if ($num_points === 0) {
                 $global_aggregate->cum_points[] = $tmp_global_point;
             } else {
                 if ($num_points > 0) {
                     $prev_val = end($global_aggregate->cum_points);
                     $global_aggregate->cum_points[] = $prev_val + $tmp_global_point;
                 }
             }
         }
     }
     return [$ticket_types, $ticket_aggregate, $yearly_tickettype_aggregate, $global_aggregate];
 }