public function delete($id) { try { TicketTypeModel::find($id)->delete(); $alert['msg'] = 'Ticket Type has been deleted successfully'; $alert['type'] = 'success'; } catch (\Exception $ex) { $alert['msg'] = 'This Ticket Type has been already used'; $alert['type'] = 'danger'; } return Redirect::route('company.ticket-type')->with('alert', $alert); }
protected function saveModel($event, $tickettype = false) { eerror_log(json_encode($event)); $new_tickettype = false; if (Input::get('id')) { $tickettype = TicketType::find(Input::get('id')); eerror_log("a tickettype id was posted"); } if (!$tickettype) { $tickettype = new TicketType(); $new_tickettype = true; } $tickettype->events_id = $event->id; $tickettype->name = Input::get('name'); $tickettype->num_available = Input::get('num_available'); $tickettype->price = str_replace(',', '.', Input::get('price')); $tickettype->order = Input::get('order'); if (!$new_tickettype) { $tickettype->update(); } else { $tickettype->save(); } return $tickettype; }
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); }
/** * table data rules * * @return array */ public function rules() { return array(array('status', 'in', 'range' => CHtml::listData(TicketStatus::model()->findAll(), 'id', 'id')), array('type', 'in', 'range' => CHtml::listData(TicketType::model()->findAll(), 'id', 'id')), array('category', 'in', 'range' => CHtml::listData(TicketCategory::model()->findAll(), 'id', 'id')), array('priority', 'in', 'range' => CHtml::listData(TicketPriority::model()->findAll(), 'id', 'id')), array('version', 'in', 'range' => CHtml::listData(TicketVersion::model()->findAll(), 'id', 'id')), array('fixedin', 'in', 'range' => CHtml::listData(TicketVersion::model()->findAll(), 'id', 'id')), array('assignedtoid', 'safe'), array('keywords', 'safe'), array('title', 'required'), array('title', 'length', 'min' => 3, 'max' => 100)); }
?> </p> <p id="ticket-priority" class='inline-input'> <?php echo CHtml::activeLabel($search, 'priority'); ?> <?php echo CHtml::activeListBox($search, 'priority', CHtml::listData(TicketPriority::model()->findAll(), 'id', 'title'), array('multiple' => 'multiple')); ?> </p> <p id="ticket-type" class='inline-input'> <?php echo CHtml::activeLabel($search, 'type'); ?> <?php echo CHtml::activeListBox($search, 'type', CHtml::listData(TicketType::model()->findAll(), 'id', 'title'), array('multiple' => 'multiple')); ?> </p> <p id="ticket-category" class='inline-input'> <?php echo CHtml::activeLabel($search, 'category'); ?> <?php echo CHtml::activeListBox($search, 'category', CHtml::listData(TicketCategory::model()->findAll(), 'id', 'title'), array('multiple' => 'multiple')); ?> </p> <p id="ticket-version" class='inline-input'> <?php echo CHtml::activeLabel($search, 'version'); ?> <?php
/** * View single ticket * * @param int $id * @param string $alias */ public function actionViewTicket($id, $alias) { if ($id && ($ticket = Tickets::model()->with(array('reporter', 'assigned', 'status', 'type', 'category', 'ticketpriority', 'version', 'fixed', 'ticketmilestone', 'comments', 'comments.commentreporter', 'comments.changes', 'lastcomment'))->byCommentDate()->findByPk($id))) { // Initiate the ticket comment model $comment = new TicketComments(); $props = new TicketProps(); $ticketChanges = array(); $commentPassed = false; $propsPassed = false; $propertiesPassed = false; // Make sure if we submit the form that we enter a comment if (isset($_POST['TicketComments'])) { $comment->setAttributes($_POST['TicketComments']); $comment->ticketid = $ticket->id; if ($comment->validate()) { $commentPassed = true; } } // Make suer we submitted the form if (isset($_POST['TicketProps'])) { $props->setAttributes($_POST['TicketProps']); if ($props->validate()) { $propsPassed = true; // did we change the title if ($props->title != $ticket->title) { $ticketChanges[] = Yii::t('tickets', '<strong>Title</strong> Changed from <em>{old}</em> To <em>{new}</em>', array('{old}' => $ticket->title, '{new}' => $props->title)); } // did we change the keywords if ($props->keywords != $ticket->keywords) { $ticketChanges[] = Yii::t('tickets', '<strong>Keywords</strong> Changed from <em>{old}</em> To <em>{new}</em>', array('{old}' => $ticket->keywords, '{new}' => $props->keywords)); } // did we change the assigned to if ($props->assignedtoid && $props->assignedtoid != $ticket->assignedtoid) { // Load the users $oldUser = Users::model()->findByPk($ticket->assignedtoid); $newUser = Users::model()->find('username=:username', array(':username' => $props->assignedtoid)); $ticketChanges[] = Yii::t('tickets', '<strong>Assigned</strong> Changed from <em>{old}</em> To <em>{new}</em>', array('{old}' => $oldUser ? $oldUser->getLink() : "''", '{new}' => $newUser ? $newUser->getLink() : "''")); } // Did we change the status if ($props->status && $props->status != $ticket->ticketstatus) { $oldStatus = TicketStatus::model()->findByPk($ticket->ticketstatus); $newStatus = TicketStatus::model()->findByPk($props->status); $ticketChanges[] = Yii::t('tickets', '<strong>Status</strong> Changed from <em>{old}</em> To <em>{new}</em>', array('{old}' => $oldStatus ? $oldStatus->getLink() : "''", '{new}' => $newStatus ? $newStatus->getLink() : "''")); $ticket->ticketstatus = $props->status; } // Did we change the type if ($props->type && $props->type != $ticket->tickettype) { $oldType = TicketType::model()->findByPk($ticket->tickettype); $newType = TicketType::model()->findByPk($props->type); $ticketChanges[] = Yii::t('tickets', '<strong>Type</strong> Changed from <em>{old}</em> To <em>{new}</em>', array('{old}' => $oldType ? $oldType->getLink() : "''", '{new}' => $newType ? $newType->getLink() : "''")); $ticket->tickettype = $props->type; } // Did we change the category if ($props->category && $props->category != $ticket->ticketcategory) { $oldCategory = TicketCategory::model()->findByPk($ticket->ticketcategory); $newCategory = TicketCategory::model()->findByPk($props->category); $ticketChanges[] = Yii::t('tickets', '<strong>Category</strong> Changed from <em>{old}</em> To <em>{new}</em>', array('{old}' => $oldCategory ? $oldCategory->getLink() : "''", '{new}' => $newCategory ? $newCategory->getLink() : "''")); $ticket->ticketcategory = $props->category; } // Did we change the version if ($props->version && $props->version != $ticket->ticketversion) { $oldVersion = TicketVersion::model()->findByPk($ticket->ticketversion); $newVersion = TicketVersion::model()->findByPk($props->version); $ticketChanges[] = Yii::t('tickets', '<strong>Version</strong> Changed from <em>{old}</em> To <em>{new}</em>', array('{old}' => $oldVersion ? $oldVersion->getVersionLink() : "''", '{new}' => $newVersion ? $newVersion->getVersionLink() : "''")); $ticket->ticketversion = $props->version; } // Did we change the fixedin if ($props->fixedin && $props->fixedin != $ticket->fixedin) { $oldFixed = TicketVersion::model()->findByPk($ticket->fixedin); $newFixed = TicketVersion::model()->findByPk($props->fixedin); $ticketChanges[] = Yii::t('tickets', '<strong>Fixed In Version</strong> Changed from <em>{old}</em> To <em>{new}</em>', array('{old}' => $oldFixed ? $oldFixed->getFixedinLink() : "''", '{new}' => $newFixed ? $newFixed->getFixedinLink() : "''")); $ticket->fixedin = $props->fixedin; } // Did we change the priority if ($props->priority && $props->priority != $ticket->priority) { $oldPriority = TicketPriority::model()->findByPk($ticket->priority); $newPriority = TicketPriority::model()->findByPk($props->priority); $ticketChanges[] = Yii::t('tickets', '<strong>Priority</strong> Changed from <em>{old}</em> To <em>{new}</em>', array('{old}' => $oldPriority ? $oldPriority->getLink() : "''", '{new}' => $newPriority ? $newPriority->getLink() : "''")); $ticket->priority = $props->priority; } // Assign props data to ticket $ticket->title = $props->title; $ticket->keywords = $props->keywords; // Reset the ticket assigned to if ($props->assignedtoid) { $ticket->assignedtoid = $props->assignedtoid; } else { $ticket->assignedtoid = (int) $ticket->assignedtoid; } // Make sure we have some changes or at least entered comment if (!$comment->content && !count($ticketChanges)) { $commentPassed = false; Functions::setFlash(Yii::t('tickets', 'You must enter a comment or make some changes to the ticket.')); } // validate ticket if ($ticket->validate()) { $propertiesPassed = true; } } } // Only if all flags were ok then save and update if (isset($_POST['submit']) && $commentPassed && $propsPassed && $propertiesPassed) { // Save both and redirect $comment->save(); // Did we change something? if (count($ticketChanges)) { foreach ($ticketChanges as $change) { $changes = new TicketChanges(); $changes->ticketid = $ticket->id; $changes->commentid = $comment->id; $changes->content = $change; $changes->save(); } } // Save ticket $ticket->lastcommentid = $comment->id; $ticket->update(); // Set flash Functions::setFlash(Yii::t('tickets', 'Tickets: Ticket Updated')); $this->redirect($ticket->getLink('', array(), true)); } // Reset the ticket assigned to if ($props->assignedtoid) { if (is_int($props->assignedtoid)) { $username = Users::model()->findByPk($props->assignedtoid); } else { $username = Users::model()->find('username=:username', array(':username' => $props->assignedtoid)); } $props->assignedtoid = $username ? $username->username : ''; } else { $props->assignedtoid = ''; } // Assign keywords if (!$props->keywords && $ticket->keywords) { $props->keywords = $ticket->keywords; } // Assign Title if (!$props->title && $ticket->title) { $props->title = $ticket->title; } // Show the view screen $this->pageTitle[] = Yii::t('tickets', 'Viewing Ticket - {title}', array('{title}' => CHtml::encode($ticket->title))); $this->render('showticket', array('props' => $props, 'ticket' => $ticket, 'comment' => $comment)); } else { $this->redirect(array('/tickets')); } }
/** * @param int $userID * @param int $eventID * @param string $ticketID * @param int $timestamp * @param int $externalTime * @param string $externalRef * @param string $status * @param TicketType $ticketType * @param int $price * @param int $amount Default 1 */ public function logTicketPurchase($userID, $eventID, $ticketID, $timestamp, $externalTime, $externalRef, $status, TicketType $ticketType, $price, $amount = 1) { // Integers $userID = intval($userID); $eventID = intval($eventID); $timestamp = intval($timestamp); $externalTime = intval($externalTime); $amount = intval($amount); // Strings, misc. $externalRef = db_escape($externalRef); $status = db_escape($status); $price = db_escape($price); $ticketID = db_escape($ticketID); $query = sprintf("INSERT INTO `%s` (`ticketType`, `eventID`, `userID`, `ticketID`, `timestamp`, `externalTime`, `externalRef`, `price`, `amount`, `status`)\nVALUES (%d, %d, %d, '%s', %d, %d, '%s', '%s', %d, '%s');", db_prefix() . "_ticketLogs", $ticketType->getTicketTypeID(), $eventID, $userID, $ticketID, $timestamp, $externalTime, $externalRef, $price, $amount, $status); db_query($query); }
/** * Adds a tickettype to user and checks if user has ordered the maximum allowed then calls addTicketType(). * * @see addTicketType * @param TicketType $ticketType The ticket type to add. * @param int $amount Amount to add. * @param User|null $creator If an moderator has added this ticket, send the mods User object. * @return bool False if amount is reached, true on success. */ public function validateAddTicketType(TicketType $ticketType, $amount = 1, $creator = null) { global $sessioninfo, $sql_prefix, $maxTicketsPrUser; // Validate that user has not ordered too much. $hasAmount = 0; $canAmount = isset($maxTicketsPrUser) && is_numeric($maxTicketsPrUser) ? intval($maxTicketsPrUser) : 1; $tickets = $this->getTickets(); if (count($tickets) > 0) { foreach ($tickets as $value) { if ($value->getTicketTypeID() == $ticketType->getTicketTypeID()) { $hasAmount++; } } } if ($hasAmount >= $canAmount) { return false; } // Call Addtickettype too do the rest $insertIDs = $this->addTicketType($ticketType, $amount, $crator); return $insertIDs; }
?> </p> <p id="ticket-priority" class='inline-input'> <?php echo CHtml::activeLabel($moderation, 'priority'); ?> <?php echo CHtml::activeDropDownList($moderation, 'priority', CHtml::listData(TicketPriority::model()->findAll(), 'id', 'title'), array('prompt' => Yii::t('tickets', '-- Select Priority --'))); ?> </p> <p id="ticket-type" class='inline-input'> <?php echo CHtml::activeLabel($moderation, 'type'); ?> <?php echo CHtml::activeDropDownList($moderation, 'type', CHtml::listData(TicketType::model()->findAll(), 'id', 'title'), array('prompt' => Yii::t('tickets', '-- Select Type --'))); ?> </p> <p id="ticket-category" class='inline-input'> <?php echo CHtml::activeLabel($moderation, 'category'); ?> <?php echo CHtml::activeDropDownList($moderation, 'category', CHtml::listData(TicketCategory::model()->findAll(), 'id', 'title'), array('prompt' => Yii::t('tickets', '-- Select Category --'))); ?> </p> <p id="ticket-version" class='inline-input'> <?php echo CHtml::activeLabel($moderation, 'version'); ?> <?php
/** * table data rules * * @return array */ public function rules() { return array(array('title, content', 'required'), array('title', 'length', 'min' => 3, 'max' => 100), array('keywords', 'length', 'max' => 100), array('content', 'length', 'min' => 3), array('projectid', 'in', 'range' => array_keys(Projects::model()->getUserProjects(true)), 'allowEmpty' => false, 'on' => 'ticketupdate'), array('ticketstatus', 'in', 'range' => CHtml::listData(TicketStatus::model()->findAll(), 'id', 'id')), array('tickettype', 'in', 'range' => CHtml::listData(TicketType::model()->findAll(), 'id', 'id')), array('ticketcategory', 'in', 'range' => CHtml::listData(TicketCategory::model()->findAll(), 'id', 'id')), array('priority', 'in', 'range' => CHtml::listData(TicketPriority::model()->findAll(), 'id', 'id')), array('ticketversion', 'in', 'range' => CHtml::listData(TicketVersion::model()->findAll(), 'id', 'id')), array('fixedin', 'in', 'range' => CHtml::listData(TicketVersion::model()->findAll(), 'id', 'id')), array('assignedtoid', 'checkAssignedTo')); }
/** * table data rules * * @return array */ public function rules() { return array(array('status', 'in', 'range' => CHtml::listData(TicketStatus::model()->findAll(), 'id', 'id')), array('type', 'in', 'range' => CHtml::listData(TicketType::model()->findAll(), 'id', 'id')), array('category', 'in', 'range' => CHtml::listData(TicketCategory::model()->findAll(), 'id', 'id')), array('priority', 'in', 'range' => CHtml::listData(TicketPriority::model()->findAll(), 'id', 'id')), array('version', 'in', 'range' => CHtml::listData(TicketVersion::model()->findAll(), 'id', 'id')), array('fixedin', 'in', 'range' => CHtml::listData(TicketVersion::model()->findAll(), 'id', 'id')), array('assignedtoid', 'checkAssignedTo')); }
echo $priority->getLink(CHtml::encode($priority->title) . ' <small>(' . Yii::app()->format->number($priority->ticketsCount) . ')</small>'); ?> </li> <?php } ?> </ul> </li> <li class="widget-container"> <h3><?php echo Yii::t('global', 'Types'); ?> </h3> <ul> <?php foreach (TicketType::model()->with(array('ticketsCount'))->findAll() as $type) { ?> <li> <?php echo $type->getRssLink(CHtml::image(Yii::app()->themeManager->baseUrl . '/images/atom.gif', 'ATOM'), array('class' => 'atom'), 'atom'); ?> <?php echo $type->getRssLink(CHtml::image(Yii::app()->themeManager->baseUrl . '/images/rss.gif', 'RSS'), array('class' => 'rss')); ?> <?php echo $type->getLink(CHtml::encode($type->title) . ' <small>(' . Yii::app()->format->number($type->ticketsCount) . ')</small>'); ?> </li> <?php } ?>
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); }