ticket.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php /** @noinspection PhpUnhandledExceptionInspection */
  2. namespace App;
  3. use App\Enums\DocumentTypes;
  4. use App\Enums\TicketPriorities;
  5. use App\Enums\TicketStatuses;
  6. use App\Helpers\HtmlHelper;
  7. /**
  8. * @var Ticket $ticket
  9. */
  10. $core = Core::getInstance();
  11. $user = $core->getUser();
  12. $comments = $ticket->getComments();
  13. $ticket_details = array_shift($comments);
  14. $attachments = $ticket_details->getAttachments();
  15. $creator = $ticket->getCreator();
  16. $sale = $ticket->getSale();
  17. $aru = $ticket->getAruDocument();
  18. $render_data_row = static function(string $title, string $html): void {
  19. ?>
  20. <div class="row my-1">
  21. <div class="col-6 col-md-3">
  22. <strong><?=htmlspecialchars($title)?></strong>
  23. </div>
  24. <div class="col-6 col-md">
  25. <?=$html?>
  26. </div>
  27. </div>
  28. <?php
  29. };
  30. ?>
  31. <div class="card mb-3">
  32. <div class="card-header">
  33. <?=htmlspecialchars(__("Ticket #%d", $ticket->id))?>
  34. <span class="float-end badge bg-primary">
  35. <?=htmlspecialchars($ticket->getDisplayStatus())?>
  36. </span>
  37. </div>
  38. <div class="card-body">
  39. <h5>
  40. <?=htmlspecialchars($ticket->subject)?>
  41. </h5>
  42. <div>
  43. <i class="fa fa-fw fa-user-circle"></i>
  44. <?=htmlspecialchars($creator->getDisplayName())?> (<?=htmlspecialchars($creator->email)?>)
  45. </div>
  46. <div>
  47. <i class="fa fa-fw fa-map-marker"></i>
  48. <?=htmlspecialchars($ticket->getLocation()->name)?>
  49. </div>
  50. </div>
  51. <div class="card-body border-top">
  52. <h5><?=htmlspecialchars(__("Details"))?></h5>
  53. <?=$ticket_details->getHtml()?>
  54. </div>
  55. <?php
  56. if($attachments) {
  57. ?>
  58. <div class="card-body border-top">
  59. <h5><?=htmlspecialchars(__("Attachments"))?></h5>
  60. <?php
  61. foreach($attachments as $attachment) {
  62. $attachment->renderButton();
  63. }
  64. ?>
  65. </div>
  66. <?php
  67. }
  68. ?>
  69. <div class="card-body border-top">
  70. <h5><?=htmlspecialchars(__("Other Details"))?></h5>
  71. <div class="row">
  72. <div class="col-xl">
  73. <?php
  74. $render_data_row(__("Assigned:"), htmlspecialchars($ticket->getDisplayAssignedTo()));
  75. $render_data_row(__("Priority:"), $ticket->getPriorityBadgeHtml());
  76. $render_data_row(__("Contact Name:"), htmlspecialchars($ticket->contact_name));
  77. ?>
  78. </div>
  79. <div class="col-xl">
  80. <?php
  81. if($sale) {
  82. $render_data_row(__("Sale No."), sprintf('<a href="%s">%s</a>', htmlspecialchars($sale->getUrl()), $sale->getNumber()));
  83. }
  84. if($aru) {
  85. $render_data_row(__("ARU No."), sprintf('<a href="%s">%s</a>', htmlspecialchars($aru->getUrl()), $aru->number));
  86. }
  87. $render_data_row(__("Updated:"), $user->formatDateTime($ticket->getDateTimeUpdated()));
  88. $render_data_row(__("Created:"), $user->formatDateTime($ticket->getDateTimeCreated()));
  89. ?>
  90. </div>
  91. </div>
  92. </div>
  93. <div class="card-body border-top">
  94. <h5><?=htmlspecialchars(__("Update Ticket"))?></h5>
  95. <form method="post">
  96. <div class="row">
  97. <div class="col-sm">
  98. <div class="mb-2">
  99. <label class="form-label" for="assignee"><?=htmlspecialchars(__("Assignee"))?></label>
  100. <select class="form-control" name="assignee" id="assignee">
  101. <option value=""><?=htmlspecialchars(__("Unassigned"))?></option>
  102. <?php
  103. HtmlHelper::renderOptions(User::getStaffOptions(), $ticket->assigned_user_id);
  104. ?>
  105. </select>
  106. </div>
  107. </div>
  108. <div class="col-sm">
  109. <div class="mb-2">
  110. <label class="form-label" for="priority"><?=htmlspecialchars(__("Priority"))?></label>
  111. <select class="form-control" name="priority" id="priority">
  112. <?php
  113. HtmlHelper::renderOptions(TicketPriorities::options(), $ticket->priority);
  114. ?>
  115. </select>
  116. </div>
  117. </div>
  118. </div>
  119. <button type="submit" class="btn btn-primary" name="ticket_submit" value="1">
  120. <i class="fa fa-fw fa-save"></i>
  121. <?=htmlspecialchars(__("Update Ticket"))?>
  122. </button>
  123. <?php
  124. if(!$aru) {
  125. ?>
  126. <button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#new-document-modal" data-type="<?=DocumentTypes::ADVANCE_REPLACEMENT_UNIT?>" data-location-id="<?=$ticket->location_id?>" data-ticket-id="<?=$ticket->id?>">
  127. <i class="fa fa-fw fa-plus"></i>
  128. <?=htmlspecialchars(__("Create ARU"))?>
  129. </button>
  130. <?php
  131. }
  132. else {
  133. ?>
  134. <a class="btn btn-primary" href="<?=htmlspecialchars($aru->getUrl())?>">
  135. <i class="fa fa-fw fa-magnifying-glass"></i>
  136. <?=htmlspecialchars(__("View ARU"))?>
  137. </a>
  138. <?php
  139. }
  140. ?>
  141. </form>
  142. </div>
  143. </div>
  144. <div class="card mb-3">
  145. <div class="card-body">
  146. <h5><?=htmlspecialchars(__("Add Comment"))?></h5>
  147. <form method="post" enctype="multipart/form-data">
  148. <div class="row">
  149. <div class="col-lg">
  150. <div class="mb-2">
  151. <label class="form-label" for="content"><?=htmlspecialchars(__("Comment"))?></label>
  152. <textarea class="form-control" name="content" id="content" rows="4" placeholder="<?=htmlspecialchars(__("Type comment"))?>" required></textarea>
  153. </div>
  154. <div class="mb-2">
  155. <div class="form-check form-switch">
  156. <input class="form-check-input" name="internal" id="internal" type="checkbox" value="1" />
  157. <label class="form-check-label" for="internal">
  158. <?=htmlspecialchars(__("Internal Comment"))?>
  159. </label>
  160. </div>
  161. </div>
  162. </div>
  163. <div class="col-lg">
  164. <div class="mb-2">
  165. <label class="form-label" for="status"><?=htmlspecialchars(__("Status"))?></label>
  166. <select name="status" id="status" class="form-control">
  167. <option value=""><?=htmlspecialchars(__("Select Status"))?></option>
  168. <?php
  169. HtmlHelper::renderOptions(TicketStatuses::options());
  170. ?>
  171. </select>
  172. </div>
  173. <div class="mb-2">
  174. <label class="form-label" for="attachments"><?=htmlspecialchars(__("Attachments"))?></label>
  175. <input class="form-control" type="file" id="attachments" name="attachments[]" multiple />
  176. </div>
  177. </div>
  178. </div>
  179. <button type="submit" class="btn btn-success" name="comment_submit" value="1">
  180. <i class="fa fa-fw fa-plus"></i>
  181. <?=htmlspecialchars(__("Add Comment"))?>
  182. </button>
  183. </form>
  184. </div>
  185. </div>
  186. <h3>
  187. <?=htmlspecialchars(__("All Comments"))?>
  188. </h3>
  189. <?php
  190. if(empty($comments)) {
  191. ?>
  192. <div class="alert alert-info">
  193. <i class="fa fa-fw fa-info-circle"></i>
  194. <?=htmlspecialchars(__("No comments have been added to this ticket."))?>
  195. </div>
  196. <?php
  197. }
  198. else {
  199. foreach(array_reverse($comments) as $comment) {
  200. View::include("components/comment_card", ["comment" => $comment]);
  201. }
  202. }