Procházet zdrojové kódy

Add "Created By" filter to document pages

Alan Lam před 1 rokem
rodič
revize
b6677a9e2b

+ 6 - 1
controllers/documents.php

@@ -117,6 +117,11 @@ if($location_id) {
 	$nvp["location_id"] = $location_id;
 }
 
+$user_id = $request->int("user_id");
+if($user_id) {
+	$nvp["user_id"] = $user_id;
+}
+
 $status = $request->int("status");
 if($status !== null && $status_field) {
 	$nvp[$status_field] = $status;
@@ -155,6 +160,6 @@ $core->addScript("/js/new-document-modal.js");
 $core->addScript("/js/documents.js");
 
 View::include("header");
-View::include("documents", compact("title", "type_string", "type", "documents", "pagination", "type_name", "supplier_id", "customer_id", "location_id", "status", "number", "custom_filter"));
+View::include("documents", compact("title", "type_string", "type", "documents", "pagination", "type_name", "supplier_id", "customer_id", "location_id", "user_id", "status", "number", "custom_filter"));
 View::include("modals/new_document");
 View::include("footer");

+ 14 - 1
engine/User.php

@@ -2,6 +2,7 @@
 
 namespace App;
 
+use App\Interfaces\OptionInterface;
 use Carbon\CarbonImmutable;
 use DateTimeInterface;
 use Exception;
@@ -24,7 +25,7 @@ use RuntimeException;
  * @property string $dts_deleted
  */
 
-class User extends Model {
+class User extends Model implements OptionInterface {
 
 	protected static $table = "user";
 	protected static $idField = "id";
@@ -64,6 +65,11 @@ class User extends Model {
 		foreach(self::getAll() as $user) {
 			$options[$user->id] = $user->getDisplayName();
 		}
+
+		uasort($options, static function(string $a, string $b) {
+			return strnatcasecmp($a, $b);
+		});
+
 		return $options;
 	}
 
@@ -178,4 +184,11 @@ class User extends Model {
 		return "Europe/London";
 	}
 
+	public function getOptionValue(): string {
+		return $this->getIdString();
+	}
+
+	public function getOptionLabel(): string {
+		return $this->getDisplayName();
+	}
 }

+ 24 - 0
views/components/user_id_field.php

@@ -0,0 +1,24 @@
+<?php /** @noinspection PhpUnhandledExceptionInspection */
+
+/**
+ * @var int $user_id
+ * @var string $label
+ */
+
+use App\Helpers\HtmlHelper;
+use App\User;
+
+$label ??= __("User");
+
+?>
+
+<div class="mb-3">
+	<label class="form-label" for="user-id"><?=htmlspecialchars($label)?></label>
+
+	<select class="form-control" name="user_id" id="user-id">
+		<option value=""><?=htmlspecialchars(__("Select User"))?></option>
+		<?php
+		HtmlHelper::renderOptions(User::getOptions(), $user_id);
+		?>
+	</select>
+</div>

+ 9 - 0
views/documents.php

@@ -16,6 +16,7 @@ use App\Helpers\HtmlHelper;
  * @var int $supplier_id
  * @var int $customer_id
  * @var int $location_id
+ * @var int $user_id
  * @var int $status
  * @var int $number
  * @var int $custom_filter
@@ -96,6 +97,14 @@ $show_batch_actions = $is_sale_order && $documents;
 				View::include("components/location_id_field", compact("location_id"));
 				?>
 			</div>
+			<div class="col-sm-4">
+				<?php
+				View::include("components/user_id_field", [
+					"user_id" => $user_id,
+					"label" => __("Created By"),
+				]);
+				?>
+			</div>
 			<?php
 			if($status_options) {
 				?>