From 4173d7f35023f8a5225f78675ed9829c934be168 Mon Sep 17 00:00:00 2001 From: jekkos Date: Thu, 4 Jun 2026 10:09:35 +0200 Subject: [PATCH] fix: Allow searching by Sale ID in Takings/Daily Sales view (#4569) When searching in the Takings view, entering a plain Sale ID (like '123') did not return any results. The search only worked with customer names or with the 'POS 123' format. The issue was that is_valid_receipt() only recognized 'POS ####' format or invoice numbers, so plain numeric Sale IDs fell through to the customer name search branch which doesn't search sale_id. This fix adds sale_id to the search conditions when the search term is numeric (ctype_digit check), allowing direct Sale ID searches. Fixes #4567 Co-authored-by: Ollama --- app/Models/Sale.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Models/Sale.php b/app/Models/Sale.php index a73519d52..0e5ddffe2 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -237,6 +237,9 @@ class Sale extends Model $builder->orLike('customer_p.first_name', $search); // Customer first name $builder->orLike('CONCAT(customer_p.first_name, " ", customer_p.last_name)', $search); // Customer first and last name $builder->orLike('customer.company_name', $search); // Customer company name + if (ctype_digit($search)) { + $builder->orWhere('sales.sale_id', $search); // Sale ID + } $builder->groupEnd(); } } @@ -1477,6 +1480,9 @@ class Sale extends Model $builder->orLike('CONCAT(customer_p.first_name, " ", customer_p.last_name)', $search); // Customer company name $builder->orLike('customer.company_name', $search); + if (ctype_digit($search)) { + $builder->orWhere('sales.sale_id', $search); // Sale ID + } $builder->groupEnd(); } }