79 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| from flask import request, jsonify
 | |
| from flask_login import current_user
 | |
| from sqlalchemy.sql import func
 | |
| from datetime import date, timedelta
 | |
| from app.search import search
 | |
| from app import db
 | |
| from datetime import datetime
 | |
| 
 | |
| from app.classes.auth import Auth_User
 | |
| from app.classes.customer import Customer_Customer, Customer_Customer_schema
 | |
| from app.classes.service import Service_Call, Service_Call_schema
 | |
| from app.classes.employee import Employee_Employee
 | |
| from app.classes.service import Service_Call_Notes_Dispatcher, Service_Call_Notes_Technician
 | |
| from app.classes.delivery import Delivery_Delivery, Delivery_Delivery_schema
 | |
| 
 | |
| 
 | |
| @search.route("/customer", methods=["GET"])
 | |
| def search_customers():
 | |
|     """
 | |
| 
 | |
|     """
 | |
| 
 | |
|     keyword = request.args.get('q')
 | |
|     search = "%{}%".format(keyword)
 | |
|     search_type = (search[1])
 | |
|     search = search.replace("!", "")
 | |
|     search = search.replace("#", "")
 | |
|     search = search.replace("@", "")
 | |
|     # search by last name
 | |
|     if search_type == '@':
 | |
|         search = search[1:]
 | |
|         customer_list = (db.session
 | |
|                          .query(Customer_Customer)
 | |
|                          .filter(Customer_Customer.customer_first_name.ilike(search))
 | |
|                          .all())
 | |
| 
 | |
|     elif search_type == '!':
 | |
| 
 | |
|         search = search[::1]
 | |
|         customer_list = (db.session
 | |
|                          .query(Customer_Customer)
 | |
|                          .filter(Customer_Customer.customer_address.ilike(search))
 | |
|                          .all())
 | |
|     # Phone Number
 | |
|     elif search_type == '#':
 | |
|         search = search[::1]
 | |
|         customer_list = (db.session
 | |
|                          .query(Customer_Customer)
 | |
|                          .filter(Customer_Customer.customer_phone_number.ilike(search))
 | |
|                          .all())
 | |
| 
 | |
|     else:
 | |
|         customer_list = (db.session
 | |
|                          .query(Customer_Customer)
 | |
|                          .filter(Customer_Customer.customer_last_name.ilike(search))
 | |
|                          .all())
 | |
| 
 | |
| 
 | |
|     customer_schema = Customer_Customer_schema(many=True)
 | |
|     return jsonify(customer_schema.dump(customer_list))
 | |
| 
 | |
| 
 | |
| @search.route("/delivery", methods=["GET"])
 | |
| def search_delivery():
 | |
|     """
 | |
|     pagination all customers
 | |
|     """
 | |
|     keyword = request.args.get('q')
 | |
|     search = "%{}%".format(keyword)
 | |
|     search_type = (search[1])
 | |
| 
 | |
|     delivery_ticket = (db.session
 | |
|                      .query(Delivery_Delivery)
 | |
|                      .filter(Delivery_Delivery.id.ilike(search))
 | |
|                      .all())
 | |
| 
 | |
| 
 | |
|     delivery_schema = Delivery_Delivery_schema(many=True)
 | |
|     return jsonify(delivery_schema.dump(delivery_ticket)) |