Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions pos/src/lib/customer-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,33 @@ export async function addCustomer(
}
}

function getscramblePattern(text: string) {
return `%${text.split("").join("%")}%`;
}

export async function searchCustomers(search: string, limit = 5) {
if (!search.trim()) return [];

const pattern = getscramblePattern(search);

try {
const res = await call.get('frappe.utils.global_search.search', {
text: search,
doctype: DOCTYPES.CUSTOMER,
const res = await db.getDocList(DOCTYPES.CUSTOMER, {
fields: ["name", "customer_name", "mobile_number"],
orFilters: [
["customer_name", "like", pattern],
["mobile_number", "like", pattern],
["name", "like", pattern],
],
limit,
limit_start: 0,
});
return res.message || [];

return res.map((doc: any) => ({
...doc,
content: `Customer Name : ${doc.customer_name ?? ""} | Mobile Number : ${doc.mobile_number ?? ""}`,
}));
} catch (error) {
console.error('Customer search error:', error);
console.error("Customer search error:", error);
throw error;
}
}
}
Loading