Cierra la mesa, calculando el total y, si se lo indica,
imprime el ticket fiscal.
@param type $mesa_id
@param type $imprimir_ticket
@return type
491754
public function cerrarMesa ( $mesa_id, $imprimir_ticket = true) {
        
        $this->Mesa->id = $mesa_id;     
        
        if( !$this->Mesa->cerrar_mesa() ) {
            if( !$this->request->is('ajax') ){
                $this->setFlash('Error al cerrar la mesa', 'flash_error');
            }
        }
        if( !$this->request->is('ajax') ){
            $this->redirect( $this->referer() );
        }         
    }
1034321
public function open(Ticket $ticket)
    {
        $this->authorize('publicStatus', $ticket);
        $ticket->update([
            'open' => true,
        ]);

        return redirect()->route('laralum_public::tickets.index')->with('success', __('laralum_tickets::general.reopened', ['id' => $ticket->id]));
    }
441168
private function getTicket()
	{
		$name = $this->_config['ticketName'];
		$checks = $this->_config['ticketChecks'];

		switch($checks){
			case 'all':
				$ticket = $_SESSION[$name];
				if(!isset($ticket))
					$ticket = $_COOKIE[$name];
				break;
			case 'cookie':
				$ticket = $_COOKIE[$name];
				break;
			case 'session':
				$ticket = $_SESSION[$name];
				break;
		}

		return $ticket;
	}
524410
public function destroy($id)
    {
        $ticket = $this->tickets->findOrFail($id);
        $subject = $ticket->subject;
        $ticket->delete();

        session()->flash('status', trans('ticketit::lang.the-ticket-has-been-deleted', ['name' => $subject]));

        return redirect()->route(Setting::grab('main_route').'.index');
    }
1144085
public function deleteAction(Request $request, $ticketId)
    {
        $userManager = $this->getUserManager();
        $user        = $userManager->getCurrentUser();

        if (!\is_object($user) || !$userManager->hasRole($user, TicketRole::ADMIN)) {
            throw new \Symfony\Component\HttpKernel\Exception\HttpException(403);
        }

        $form = $this->createDeleteForm($ticketId);

        if ($request->isMethod('DELETE')) {
            $form->submit($request->request->get($form->getName()));

            if ($form->isValid()) {
                $ticketManager = $this->get('hackzilla_ticket.ticket_manager');
                $ticket        = $ticketManager->getTicketById($ticketId);

                if (!$ticket) {
                    throw $this->createNotFoundException($this->get('translator')->trans('ERROR_FIND_TICKET_ENTITY', [], 'HackzillaTicketBundle'));
                }

                $ticketManager->deleteTicket($ticket);
                $this->dispatchTicketEvent(TicketEvents::TICKET_DELETE, $ticket);
            }
        }

        return $this->redirect($this->generateUrl('hackzilla_ticket'));
    }
843597
public function validate($validator)
    {
        // Throw an error when there are no tickets selected
        if (empty($this->value)) {
            $validator->validationError($this->name, _t(
                'TicketsField.VALIDATION_EMPTY',
                'Select at least one ticket'
            ), 'validation');

            return false;
        }

        // Get the availability
        $available = $this->getForm()->event->getAvailability();
        // get the sum of selected tickets
        $ticketCount = array_sum(array_map(function ($item) {
            return $item['Amount'];
        }, $this->value));

        // If the sum of tickets is 0 trow the same error as empty
        if ($ticketCount === 0) {
            $validator->validationError($this->name, _t(
                'TicketsField.VALIDATION_EMPTY',
                'Select at least one ticket'
            ), 'validation');

            return false;
        }

        // Throw an error when there are more tickets selected than available
        if ($ticketCount > $available) {
            $validator->validationError($this->name, _t(
                'TicketsField.VALIDATION_TO_MUCH',
                'There are {ticketCount} tickets left',
                null,
                array(
                    'ticketCount' => $available
                )
            ), 'validation');

            return false;
        }

        return false;
    }
566764
public function ticket($forceRefresh = false)
    {
        $key = self::GROUP_TICKET_CACHE_PREFIX.$this->getAccessToken()->getFingerprint();
        $ticket = $this->getCache()->fetch($key);

        if (!$forceRefresh && !empty($ticket)) {
            return $ticket;
        }

        $result = $this->parseJSON('get', [self::API_GROUP_TICKET, ['type' => 'contact']]);

        $this->getCache()->save($key, $result, $result['expires_in'] - 500);

        return $result;
    }
493319
public function post($ticketId, $text, $interimNotice = false)
	{
		$data = new TicketMessageAddTransfer();
		$data->id_ticket = (int)$ticketId;
		$data->text = $text;
		$data->interim_notice = $interimNotice;

		$endpoint = new Post($this->getTransport());
		$endpoint->setTransfer($data);

		$resultRequest = $endpoint->performRequest();

		return Response::extractId($resultRequest, '/ticket-messages/%d/');
	}
1239081
public function run()
    {
        Model::unguard();

        $faker = \Faker\Factory::create();

        // create agents
        $agents_counter = 1;

        for ($a = 1; $a <= $this->agents_qty; $a++) {
            $agent_info = new \App\User();
            $agent_info->name = $faker->name;
            $agent_info->email = 'agent'.$agents_counter.$this->email_domain;
            $agent_info->ticketit_agent = 1;
            $agent_info->password = Hash::make($this->default_agent_password);
            $agent_info->save();
            $agents[$agent_info->id] = $agent_info;
            $agents_counter++;
        }

        // create tickets statuses
        foreach ($this->statuses as $name => $color) {
            $status = \Kordy\Ticketit\Models\Status::create([
                'name'  => $name,
                'color' => $color,
            ]);
        }

        $counter = 0;
        // create tickets statuses
        foreach ($this->categories as $name => $color) {
            $category = \Kordy\Ticketit\Models\Category::create([
                'name'  => $name,
                'color' => $color,
            ]);
            $agent = array_rand($agents, $this->agents_per_category);
            $category->agents()->attach($agent);
            $counter++;
        }

        // create tickets statuses
        foreach ($this->priorities as $name => $color) {
            $priority = \Kordy\Ticketit\Models\Priority::create([
                'name'  => $name,
                'color' => $color,
            ]);
        }
        $categories_qty = \Kordy\Ticketit\Models\Category::count();
        $priorities_qty = \Kordy\Ticketit\Models\Priority::count();
        $statuses_qty = \Kordy\Ticketit\Models\Status::count();

        // create users
        $users_counter = 1;

        for ($u = 1; $u <= $this->users_qty; $u++) {
            $user_info = new \App\User();
            $user_info->name = $faker->name;
            $user_info->email = 'user'.$users_counter.$this->email_domain;
            $user_info->ticketit_agent = 0;
            $user_info->password = Hash::make($this->default_user_password);
            $user_info->save();
            $users_counter++;

            $tickets_qty = rand($this->tickets_per_user_min, $this->tickets_per_user_max);

            for ($t = 1; $t <= $tickets_qty; $t++) {
                $rand_category = rand(1, $categories_qty);
                $priority_id = rand(1, $priorities_qty);
                do {
                    $rand_status = rand(1, $statuses_qty);
                } while ($rand_status == $this->default_closed_status_id);

                $category = \Kordy\Ticketit\Models\Category::find($rand_category);

                if (version_compare(app()->version(), '5.2.0', '>=')) {
                    $agents = $category->agents()->pluck('name', 'id')->toArray();
                } else { // if Laravel 5.1
                    $agents = $category->agents()->lists('name', 'id')->toArray();
                }

                $agent_id = array_rand($agents);
                $random_create = rand(1, $this->tickets_date_period);

                $random_complete = rand($this->tickets_min_close_period,
                                        $this->tickets_max_close_period);

                $ticket = new \Kordy\Ticketit\Models\Ticket();
                $ticket->subject = $faker->text(50);
                $ticket->content = $faker->paragraphs(3, true);
                $ticket->html = nl2br($ticket->content);
                $ticket->status_id = $rand_status;
                $ticket->priority_id = $priority_id;
                $ticket->user_id = $user_info->id;
                $ticket->agent_id = $agent_id;
                $ticket->category_id = $rand_category;
                $ticket->created_at = \Carbon\Carbon::now()->subDays($random_create);
                $ticket->updated_at = \Carbon\Carbon::now()->subDays($random_create);

                $completed_at = new Carbon($ticket->created_at);

                if (!$completed_at->addDays($random_complete)->gt(\Carbon\Carbon::now())) {
                    $ticket->completed_at = $completed_at;
                    $ticket->updated_at = $completed_at;
                    $ticket->status_id = $this->default_closed_status_id;
                }
                $ticket->save();

                $comments_qty = rand($this->comments_per_ticket_min,
                                    $this->comments_per_ticket_max);

                for ($c = 1; $c <= $comments_qty; $c++) {
                    if (is_null($ticket->completed_at)) {
                        $random_comment_date = $faker->dateTimeBetween(
                        '-'.$random_create.' days', 'now');
                    } else {
                        $random_comment_date = $faker->dateTimeBetween(
                        '-'.$random_create.' days', '-'.($random_create - $random_complete).' days');
                    }

                    $comment = new \Kordy\Ticketit\Models\Comment();
                    $comment->ticket_id = $ticket->id;
                    $comment->content = $faker->paragraphs(3, true);
                    $comment->html = nl2br($comment->content);

                    if ($c % 2 == 0) {
                        $comment->user_id = $ticket->user_id;
                    } else {
                        $comment->user_id = $ticket->agent_id;
                    }
                    $comment->created_at = $random_comment_date;
                    $comment->updated_at = $random_comment_date;
                    $comment->save();
                }
                $last_comment = $ticket->Comments->sortByDesc('created_at')->first();
                $ticket->updated_at = $last_comment['created_at'];
                $ticket->save();
            }
        }
    }
964845
protected function requestJsApiTicket($type = 'jsapi')
    {
        $result = $this->httpGet(static::WECHAT_JS_API_TICKET_URL, [
            'access_token' => $this->getAccessToken(),
            'type' => $type
        ]);
        if (isset($result['ticket'])) {
            $result['expire'] = $result['expires_in'] + (int)YII_BEGIN_TIME;
            return $result;
        }
        return false;
    }
317224
public function showqrcode_url($ticket = '')
    {
        if (!is_string($ticket) || $ticket == '') {
            $this->setError('参数错误');

            return false;
        }

        $url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket;

        return $url;
    }
973268
public function getTickets($accountID, $page = 1)
    {
        $result = $this->httpHelper->get("/accounts/" . intval($accountID) . "/tickets", $page);
        $tickets = [];
        foreach ($result as $datum)
        {
            if ($datum->type !== "public")
            {
                continue;
            }
            $ticket = new Ticket([
                'subject' => $datum->subject,
                'ticket_group_id' => $datum->ticket_group_id,
                'user_id' => $datum->user_id,
                'account_id' => $datum->assignee_id,
                'priority' => $datum->priority,
                'open' => $datum->open,
                'inbound_email_account_id' => $datum->inbound_email_account_id,
                'email_address' => $datum->email_address,
                'ticket_id' => $datum->id,
                'last_reply_incoming' => $datum->last_reply_incoming,
            ]);
            array_push($tickets, $ticket);
        }

        return $tickets;
    }
1257134
public function update(TicketObject $ticket) {
        return new TicketObject($this->client->post('tickets/' . $ticket->guid, array("ticket" => $ticket)));
    }
48891
public function showqrcode($ticket = '')
    {
        Api::setApiUrl('https://mp.weixin.qq.com/');

        $this->apitype = 'cgi-bin';
        $this->module  = 'showqrcode';

        $queryStr = ['ticket' => $ticket];

        $res = $this->_get('', $queryStr);

        return $res;
    }
521323
public function new_jsapi_ticket()
    {
        $url = self::API_DOMAIN . 'cgi-bin/ticket/getticket?access_token=' . $this->get_access_token() . '&type=jsapi';
        $res = HttpCurl::get($url, 'json');
        // 异常处理: 获取时网络错误
        if ($res === false) {
            return Error::code('ERR_GET');
        }
        // 判断是否调用成功
        if ($res->errcode == 0) {
            return (object)array(
                'ticket' => $res->ticket,
                'expires_in' => $res->expires_in + time()
            );
        } else {
            return false;
        }
    }
172540
public function complete($id)
    {
        if ($this->permToClose($id) == 'yes') {
            $ticket = $this->tickets->findOrFail($id);
            $ticket->completed_at = Carbon::now();

            if (Setting::grab('default_close_status_id')) {
                $ticket->status_id = Setting::grab('default_close_status_id');
            }

            $subject = $ticket->subject;
            $ticket->save();

            session()->flash('status', trans('ticketit::lang.the-ticket-has-been-completed', ['name' => $subject]));

            return redirect()->route(Setting::grab('main_route').'.index');
        }

        return redirect()->route(Setting::grab('main_route').'.index')
            ->with('warning', trans('ticketit::lang.you-are-not-permitted-to-do-this'));
    }
909722
public function getTicketSubject4Admin($ticketId)
    {
        $query = $this->createQueryBuilder('p')
            ->select('p')
            ->where('p.id = :subjectTicketId')
            ->setParameter('subjectTicketId', $ticketId)
            ->getQuery();

        return $query->getOneOrNullResult();
    }