Updated forms and search
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from sqlalchemy import Column, Integer, String, Float, DateTime
|
||||
from sqlalchemy import Column, Integer, String, Numeric, DateTime
|
||||
from app import db
|
||||
import datetime
|
||||
|
||||
@@ -7,8 +7,8 @@ class Transaction(db.Model):
|
||||
__tablename__ = "transactions"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
preauthorize_amount = Column(Float, nullable=True) # Amount preauthorized (for auth transactions)
|
||||
charge_amount = Column(Float, nullable=True) # Final charge amount (for charge/capture transactions)
|
||||
preauthorize_amount = Column(Numeric(10, 2), nullable=True) # Amount preauthorized (for auth transactions)
|
||||
charge_amount = Column(Numeric(10, 2), nullable=True) # Final charge amount (for charge/capture transactions)
|
||||
transaction_type = Column(Integer) # 0 = charge, 1 = auth, 3 = capture
|
||||
status = Column(Integer) # 0 = approved, 1 = declined
|
||||
auth_net_transaction_id = Column(String, unique=True, index=True, nullable=True)
|
||||
|
||||
@@ -365,7 +365,7 @@ def get_deliveries_finalized(page):
|
||||
deliveries = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(Delivery_Delivery.delivery_status == 10)
|
||||
.order_by(Delivery_Delivery.when_ordered.desc())
|
||||
.order_by(Delivery_Delivery.id.desc())
|
||||
.limit(per_page_amount).offset(offset_limit))
|
||||
|
||||
customer_schema = Delivery_Delivery_schema(many=True)
|
||||
|
||||
@@ -104,16 +104,6 @@ def office_finalize_delivery(delivery_id):
|
||||
.query(Stats_Employee_Oil)
|
||||
.filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
.first())
|
||||
|
||||
|
||||
|
||||
customer_filled = request.json["customer_filled"]
|
||||
if customer_filled is True:
|
||||
customer_filled = 1
|
||||
else:
|
||||
customer_filled = 0
|
||||
|
||||
|
||||
|
||||
if request.json["cash_recieved"]:
|
||||
cash_amount = request.json["cash_recieved"]
|
||||
@@ -121,7 +111,6 @@ def office_finalize_delivery(delivery_id):
|
||||
cash_amount = None
|
||||
|
||||
|
||||
|
||||
gallons_delivered = request.json["gallons_delivered"]
|
||||
check_number = request.json["check_number"]
|
||||
fill_location = request.json["fill_location"]
|
||||
@@ -171,5 +160,3 @@ def office_finalize_delivery(delivery_id):
|
||||
'id': get_delivery.id,
|
||||
},
|
||||
}), 200
|
||||
|
||||
|
||||
|
||||
@@ -11,13 +11,56 @@ from sqlalchemy import or_, and_
|
||||
def search_customers():
|
||||
"""
|
||||
Searches for customers based on a keyword.
|
||||
The new logic searches across multiple fields (name, address, town, phone, etc.)
|
||||
for each word provided in the search query.
|
||||
Supports special prefixes: @ for last name, ! for address, # for phone, $ for account.
|
||||
Otherwise searches across multiple fields for each word provided in the search query.
|
||||
"""
|
||||
keyword = request.args.get('q')
|
||||
if not keyword or len(keyword) < 2:
|
||||
return jsonify([])
|
||||
|
||||
# Check for special search prefixes
|
||||
search_type = None
|
||||
if keyword[0] in '!@#$':
|
||||
search_type = keyword[0]
|
||||
keyword = keyword[1:] # remove the prefix for the search term
|
||||
|
||||
if search_type:
|
||||
search_pattern = f"%{keyword}%"
|
||||
if search_type == '@':
|
||||
customer_list = (db.session
|
||||
.query(Customer_Customer)
|
||||
.filter(Customer_Customer.customer_last_name.ilike(search_pattern))
|
||||
.order_by(Customer_Customer.customer_last_name.asc())
|
||||
.limit(20)
|
||||
.all())
|
||||
elif search_type == '!':
|
||||
customer_list = (db.session
|
||||
.query(Customer_Customer)
|
||||
.filter(Customer_Customer.customer_address.ilike(search_pattern))
|
||||
.order_by(Customer_Customer.customer_last_name.asc())
|
||||
.limit(20)
|
||||
.all())
|
||||
elif search_type == '#':
|
||||
customer_list = (db.session
|
||||
.query(Customer_Customer)
|
||||
.filter(Customer_Customer.customer_phone_number.ilike(search_pattern))
|
||||
.order_by(Customer_Customer.customer_last_name.asc())
|
||||
.limit(20)
|
||||
.all())
|
||||
elif search_type == '$':
|
||||
customer_list = (db.session
|
||||
.query(Customer_Customer)
|
||||
.filter(Customer_Customer.account_number.ilike(search_pattern))
|
||||
.order_by(Customer_Customer.account_number.asc())
|
||||
.limit(20)
|
||||
.all())
|
||||
else:
|
||||
# fallback, though shouldn't happen
|
||||
return jsonify([])
|
||||
|
||||
customer_schema = Customer_Customer_schema(many=True)
|
||||
return jsonify(customer_schema.dump(customer_list))
|
||||
|
||||
# --- NEW SEARCH LOGIC ---
|
||||
|
||||
# 1. Split the incoming search query into individual words.
|
||||
@@ -65,4 +108,4 @@ def search_delivery():
|
||||
delivery_schema = Delivery_Delivery_schema(many=False)
|
||||
return jsonify(delivery_schema.dump(delivery_ticket))
|
||||
else:
|
||||
return jsonify({})
|
||||
return jsonify({})
|
||||
|
||||
Reference in New Issue
Block a user