addBreadcrumb("/tickets", __("Tickets")); $user = $core->getUser(); $ticket = Ticket::get($id); if(!$ticket) { throw new RuntimeException(__("Ticket not found.")); } $core->addBreadcrumb("/tickets/$id", $ticket->subject); $request = Request::fromRequest(); $ticket_submit = $request->int("ticket_submit"); if($ticket_submit) { $assign_to_user_id = $request->int("assignee"); $assign_to_user = null; if($assign_to_user_id) { $assign_to_user = User::requireStaff($assign_to_user_id); } $priority = $request->int("priority"); if(!TicketPriorities::validate($priority)) { throw new RuntimeException(__("Invalid priority.")); } if($assign_to_user) { if((int) $ticket->assigned_user_id !== (int) $assign_to_user->id) { $ticket->assign($assign_to_user); } } else { $ticket->unassign(); } try { $sale_number = $request->int("sale_number"); $aru_document_number = $request->int("aru_document_number"); if($sale_number && $aru_document_number) { throw new RuntimeException(__("Lead No. and ARU No. cannot be simultaneously provided.")); } if($sale_number) { $sale = Sale::getByNumber($sale_number); if(!$sale) { throw new RuntimeException(__("Lead No. %d not found.", $sale_number)); } $ticket->sale_id = $sale->id; } else { $ticket->sale_id = null; } if($aru_document_number) { $aru = Document::getByNumber($aru_document_number, DocumentTypes::ADVANCE_REPLACEMENT_UNIT); if(!$aru) { throw new RuntimeException(__("ARU No. %d not found.", $aru_document_number)); } $ticket->aru_document_id = $aru->id; } else { $ticket->aru_document_id = null; } } catch(Exception $e) { Session::addAlert("danger", $e->getMessage()); Http::redirect($ticket->getUrl()); } $ticket->priority = $priority; $ticket->commit(); Session::addAlert("success", __("Ticket updated successfully.")); Http::redirect($ticket->getUrl()); } $comment_submit = $request->int("comment_submit"); if($comment_submit) { $content = $request->string("content"); $internal = (int) $request->int("internal"); $status = $request->int("status"); $attachments = Request::getFileArray("attachments", true); $comment = new TicketComment(); $comment->ticket_id = $ticket->id; $comment->user_id = $user->id; $comment->content = $content; $comment->internal = $internal; $comment->dts_created = Database::dts(); $comment->commit(); $ticket->status = $status; $ticket->commit(); foreach($attachments as $attachment) { $comment->addAttachment($attachment); } Session::addAlert("success", __("Comment added successfully.")); Http::redirect($ticket->getUrl()); } $core->addScript("/js/new-document-modal.js"); View::include("header"); View::include("ticket", compact("ticket")); View::include("modals/new_document"); View::include("footer");