|
|
@@ -0,0 +1,169 @@
|
|
|
+<?php /** @noinspection PhpUnhandledExceptionInspection */
|
|
|
+
|
|
|
+namespace App;
|
|
|
+
|
|
|
+$core = Core::getInstance();
|
|
|
+
|
|
|
+$user = $core->getUser();
|
|
|
+$user->requireAdmin();
|
|
|
+
|
|
|
+$core->addBreadcrumb("/search", __("Search"));
|
|
|
+
|
|
|
+$request = Request::fromRequest();
|
|
|
+
|
|
|
+$term = $request->string("term");
|
|
|
+
|
|
|
+$results = [];
|
|
|
+
|
|
|
+if($term) {
|
|
|
+ if(mb_strlen($term) < 3) {
|
|
|
+ Session::addAlert("danger", __("Search term must be 3 or more characters long."));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ // Search sale and document numbers
|
|
|
+ if(is_numeric($term)) {
|
|
|
+ $documents = Document::query([
|
|
|
+ "number" => $term,
|
|
|
+ "dts_deleted" => null
|
|
|
+ ]);
|
|
|
+ foreach($documents as $document) {
|
|
|
+ $results[] = [
|
|
|
+ "type" => $document->getDisplayType(),
|
|
|
+ "match_reason" => __("%s number match.", $document->getDisplayType()),
|
|
|
+ "name" => $document->getTitle(),
|
|
|
+ "url" => $document->getUrl()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $sale = Sale::getByNumber($term);
|
|
|
+ if($sale) {
|
|
|
+ $results[] = [
|
|
|
+ "type" => __("Sale"),
|
|
|
+ "match_reason" => __("Sale number match."),
|
|
|
+ "name" => $sale->getTitle(),
|
|
|
+ "url" => $sale->getUrl()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Document items - match serial number
|
|
|
+ $items = DocumentItem::queryFuzzy([
|
|
|
+ "serial_number" => $term,
|
|
|
+ "dts_deleted" => null
|
|
|
+ ]);
|
|
|
+ foreach($items as $item) {
|
|
|
+ $document = $item->getDocument();
|
|
|
+ $results[] = [
|
|
|
+ "type" => __("%s Item", $document->getDisplayType()),
|
|
|
+ "match_reason" => __("%s item serial number match.", $document->getDisplayType()),
|
|
|
+ "name" => $document->getTitle(),
|
|
|
+ "url" => $document->getUrl()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Document items - match description
|
|
|
+ $items = DocumentItem::queryFuzzy([
|
|
|
+ "description" => $term,
|
|
|
+ "dts_deleted" => null
|
|
|
+ ]);
|
|
|
+ foreach($items as $item) {
|
|
|
+ $document = $item->getDocument();
|
|
|
+ $results[] = [
|
|
|
+ "type" => __("%s Item", $document->getDisplayType()),
|
|
|
+ "match_reason" => __("%s item description match.", $document->getDisplayType()),
|
|
|
+ "name" => $document->getTitle(),
|
|
|
+ "url" => $document->getUrl()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Sale notes
|
|
|
+ $notes = SaleNote::queryFuzzy([
|
|
|
+ "content" => $term,
|
|
|
+ "dts_deleted" => null
|
|
|
+ ]);
|
|
|
+ foreach($notes as $note) {
|
|
|
+ $results[] = [
|
|
|
+ "type" => __("Sale Item"),
|
|
|
+ "match_reason" => __("Sale note match."),
|
|
|
+ "name" => $note->getSale()->getTitle(),
|
|
|
+ "url" => $note->getSale()->getUrl()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Ticket comments
|
|
|
+ $comments = TicketComment::queryFuzzy([
|
|
|
+ "content" => $term,
|
|
|
+ "dts_deleted" => null
|
|
|
+ ]);
|
|
|
+ foreach($comments as $comment) {
|
|
|
+ $results[] = [
|
|
|
+ "type" => __("Ticket / Comment"),
|
|
|
+ "match_reason" => __("Ticket or ticket comment match."),
|
|
|
+ "name" => $comment->getTicket()->getTitle(),
|
|
|
+ "url" => $comment->getTicket()->getUrl() . "#ticket-comment-" . $comment->id
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Customers
|
|
|
+ $customers = Customer::queryFuzzy([
|
|
|
+ "name" => $term,
|
|
|
+ "dts_deleted" => null
|
|
|
+ ]);
|
|
|
+ foreach($customers as $customer) {
|
|
|
+ $results[] = [
|
|
|
+ "type" => __("Customer"),
|
|
|
+ "match_reason" => __("Customer name match."),
|
|
|
+ "name" => $customer->name,
|
|
|
+ "url" => $customer->getUrl()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Locations
|
|
|
+ $locations = Location::queryFuzzy([
|
|
|
+ "name" => $term,
|
|
|
+ "dts_deleted" => null
|
|
|
+ ]);
|
|
|
+ foreach($locations as $location) {
|
|
|
+ $results[] = [
|
|
|
+ "type" => __("Location"),
|
|
|
+ "match_reason" => __("Location name match."),
|
|
|
+ "name" => $location->getDisplayName(),
|
|
|
+ "url" => $location->getUrl()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Products
|
|
|
+ $products = Product::queryFuzzy([
|
|
|
+ "name" => $term,
|
|
|
+ "dts_deleted" => null
|
|
|
+ ]);
|
|
|
+ foreach($products as $product) {
|
|
|
+ $results[] = [
|
|
|
+ "type" => __("Product"),
|
|
|
+ "match_reason" => __("Product name match."),
|
|
|
+ "name" => $product->name,
|
|
|
+ "url" => $product->getUrl()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // Suppliers
|
|
|
+ $suppliers = Supplier::queryFuzzy([
|
|
|
+ "name" => $term,
|
|
|
+ "dts_deleted" => null
|
|
|
+ ]);
|
|
|
+ foreach($suppliers as $supplier) {
|
|
|
+ $results[] = [
|
|
|
+ "type" => __("Supplier"),
|
|
|
+ "match_reason" => __("Supplier name match."),
|
|
|
+ "name" => $supplier->name,
|
|
|
+ "url" => $supplier->getUrl()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+View::include("header");
|
|
|
+View::include("search", compact("term", "results"));
|
|
|
+View::include("footer");
|