| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?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");
|