ticket.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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(__("Lead 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 g-3">
  97. <div class="col-md-6 col-lg">
  98. <div class="mb-3">
  99. <label class="form-label" for="assignee"><?=htmlspecialchars(__("Assignee"))?></label>
  100. <select class="form-select" 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-md-6 col-lg">
  109. <div class="mb-3">
  110. <label class="form-label" for="priority"><?=htmlspecialchars(__("Priority"))?></label>
  111. <select class="form-select" name="priority" id="priority">
  112. <?php
  113. HtmlHelper::renderOptions(TicketPriorities::options(), $ticket->priority);
  114. ?>
  115. </select>
  116. </div>
  117. </div>
  118. <div class="col-md-6 col-lg">
  119. <div class="mb-3">
  120. <label class="form-label" for="sale-number"><?=htmlspecialchars(__("Lead No."))?></label>
  121. <input class="form-control" type="number" name="sale_number" id="sale-number" value="<?=$sale ? $sale->getNumber() : ""?>" placeholder="<?=htmlspecialchars(__("Type number"))?>" />
  122. </div>
  123. </div>
  124. <div class="col-md-6 col-lg">
  125. <div class="mb-3">
  126. <label class="form-label" for="aru-document-number"><?=htmlspecialchars(__("ARU No."))?></label>
  127. <input class="form-control" type="number" name="aru_document_number" id="aru-document-number" value="<?= $aru->number ?? "" ?>" placeholder="<?=htmlspecialchars(__("Type number"))?>" />
  128. </div>
  129. </div>
  130. </div>
  131. <button type="submit" class="btn btn-primary" name="ticket_submit" value="1">
  132. <i class="fa fa-fw fa-save"></i>
  133. <?=htmlspecialchars(__("Update Ticket"))?>
  134. </button>
  135. <?php
  136. if(!$aru) {
  137. ?>
  138. <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?>">
  139. <i class="fa fa-fw fa-plus"></i>
  140. <?=htmlspecialchars(__("Create ARU"))?>
  141. </button>
  142. <?php
  143. }
  144. else {
  145. ?>
  146. <a class="btn btn-primary" href="<?=htmlspecialchars($aru->getUrl())?>">
  147. <i class="fa fa-fw fa-magnifying-glass"></i>
  148. <?=htmlspecialchars(__("View ARU"))?>
  149. </a>
  150. <?php
  151. }
  152. ?>
  153. </form>
  154. </div>
  155. </div>
  156. <div class="card mb-3">
  157. <div class="card-body">
  158. <h5><?=htmlspecialchars(__("Add Comment"))?></h5>
  159. <form method="post" enctype="multipart/form-data">
  160. <div class="row">
  161. <div class="col-lg">
  162. <div class="mb-3">
  163. <label class="form-label" for="content"><?=htmlspecialchars(__("Comment"))?></label>
  164. <textarea class="form-control" name="content" id="content" rows="4" placeholder="<?=htmlspecialchars(__("Type comment"))?>" required></textarea>
  165. </div>
  166. <div class="mb-3">
  167. <div class="form-check form-switch">
  168. <input class="form-check-input" name="internal" id="internal" type="checkbox" value="1" />
  169. <label class="form-check-label" for="internal">
  170. <?=htmlspecialchars(__("Internal Comment"))?>
  171. </label>
  172. </div>
  173. </div>
  174. </div>
  175. <div class="col-lg">
  176. <div class="mb-3">
  177. <label class="form-label" for="status"><?=htmlspecialchars(__("Status"))?></label>
  178. <select name="status" id="status" class="form-select">
  179. <option value=""><?=htmlspecialchars(__("Select Status"))?></option>
  180. <?php
  181. HtmlHelper::renderOptions(TicketStatuses::options());
  182. ?>
  183. </select>
  184. </div>
  185. <div class="mb-3">
  186. <label class="form-label" for="attachments"><?=htmlspecialchars(__("Attachments"))?></label>
  187. <input class="form-control" type="file" id="attachments" name="attachments[]" multiple />
  188. </div>
  189. </div>
  190. </div>
  191. <button type="submit" class="btn btn-success" name="comment_submit" value="1">
  192. <i class="fa fa-fw fa-plus"></i>
  193. <?=htmlspecialchars(__("Add Comment"))?>
  194. </button>
  195. </form>
  196. </div>
  197. </div>
  198. <h3>
  199. <?=htmlspecialchars(__("All Comments"))?>
  200. </h3>
  201. <?php
  202. if(empty($comments)) {
  203. ?>
  204. <div class="alert alert-info">
  205. <i class="fa fa-fw fa-info-circle"></i>
  206. <?=htmlspecialchars(__("No comments have been added to this ticket."))?>
  207. </div>
  208. <?php
  209. }
  210. else {
  211. foreach(array_reverse($comments) as $comment) {
  212. View::include("components/comment_card", ["comment" => $comment]);
  213. }
  214. }