| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php /** @noinspection PhpUnhandledExceptionInspection */
- namespace App;
- use App\Enums\DocumentTypes;
- use App\Enums\TicketPriorities;
- use Exception;
- use RuntimeException;
- /**
- * @var int $id
- */
- $core = Core::getInstance();
- $core->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(__("Sale No. and ARU No. cannot be simultaneously provided."));
- }
- if($sale_number) {
- $sale = Sale::getByNumber($sale_number);
- if(!$sale) {
- throw new RuntimeException(__("Sale 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");
|