Ver código fonte

Add ability to set sale or ARU number when updating a ticket

Alan Lam 3 anos atrás
pai
commit
8fe6550c52
2 arquivos alterados com 52 adições e 3 exclusões
  1. 37 0
      controllers/ticket.php
  2. 15 3
      views/ticket.php

+ 37 - 0
controllers/ticket.php

@@ -2,7 +2,9 @@
 
 namespace App;
 
+use App\Enums\DocumentTypes;
 use App\Enums\TicketPriorities;
+use Exception;
 use RuntimeException;
 
 /**
@@ -45,6 +47,41 @@ if($ticket_submit) {
 		$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();
 

+ 15 - 3
views/ticket.php

@@ -104,8 +104,8 @@ $render_data_row = static function(string $title, string $html): void {
 		<h5><?=htmlspecialchars(__("Update Ticket"))?></h5>
 
 		<form method="post">
-			<div class="row">
-				<div class="col-sm">
+			<div class="row g-3">
+				<div class="col-md-6 col-lg">
 					<div class="mb-2">
 						<label class="form-label" for="assignee"><?=htmlspecialchars(__("Assignee"))?></label>
 						<select class="form-control" name="assignee" id="assignee">
@@ -116,7 +116,7 @@ $render_data_row = static function(string $title, string $html): void {
 						</select>
 					</div>
 				</div>
-				<div class="col-sm">
+				<div class="col-md-6 col-lg">
 					<div class="mb-2">
 						<label class="form-label" for="priority"><?=htmlspecialchars(__("Priority"))?></label>
 						<select class="form-control" name="priority" id="priority">
@@ -126,6 +126,18 @@ $render_data_row = static function(string $title, string $html): void {
 						</select>
 					</div>
 				</div>
+				<div class="col-md-6 col-lg">
+					<div class="mb-2">
+						<label class="form-label" for="sale-number"><?=htmlspecialchars(__("Sale No."))?></label>
+						<input class="form-control" type="number" name="sale_number" id="sale-number" value="<?=$sale ? $sale->getNumber() : ""?>" placeholder="<?=htmlspecialchars(__("Type number"))?>" />
+					</div>
+				</div>
+				<div class="col-md-6 col-lg">
+					<div class="mb-2">
+						<label class="form-label" for="aru-document-number"><?=htmlspecialchars(__("ARU No."))?></label>
+						<input class="form-control" type="number" name="aru_document_number" id="aru-document-number" value="<?= $aru->number ?? "" ?>" placeholder="<?=htmlspecialchars(__("Type number"))?>" />
+					</div>
+				</div>
 			</div>
 			<button type="submit" class="btn btn-primary" name="ticket_submit" value="1">
 				<i class="fa fa-fw fa-save"></i>