Added price for service
This commit is contained in:
@@ -120,42 +120,42 @@ def teardown_appcontext(error):
|
|||||||
|
|
||||||
|
|
||||||
@app.errorhandler(500)
|
@app.errorhandler(500)
|
||||||
def internal_error500():
|
def internal_error500(error):
|
||||||
return jsonify({"error": "Internal Error 500"}), 500
|
return jsonify({"error": "Internal Error 500"}), 500
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(502)
|
@app.errorhandler(502)
|
||||||
def internal_error502():
|
def internal_error502(error):
|
||||||
return jsonify({"error": "Internal Error 502"}), 502
|
return jsonify({"error": "Internal Error 502"}), 502
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def internal_error404():
|
def internal_error404(error):
|
||||||
return jsonify({"error": "Internal Error 400"}), 400
|
return jsonify({"error": "Internal Error 400"}), 400
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(401)
|
@app.errorhandler(401)
|
||||||
def internal_error404():
|
def internal_error401(error):
|
||||||
return jsonify({"error": "Internal Error 401"}), 401
|
return jsonify({"error": "Internal Error 401"}), 401
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(400)
|
@app.errorhandler(400)
|
||||||
def internal_error400():
|
def internal_error400(error):
|
||||||
return jsonify({"error": "Internal Error 400"}), 400
|
return jsonify({"error": "Internal Error 400"}), 400
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(413)
|
@app.errorhandler(413)
|
||||||
def to_large_file():
|
def to_large_file(error):
|
||||||
return jsonify({"error": "File is too large. Use a smaller image/file."}), 413
|
return jsonify({"error": "File is too large. Use a smaller image/file."}), 413
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(403)
|
@app.errorhandler(403)
|
||||||
def internal_error403():
|
def internal_error403(error):
|
||||||
return jsonify({"error": "Internal Error 403"}), 403
|
return jsonify({"error": "Internal Error 403"}), 403
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(405)
|
@app.errorhandler(405)
|
||||||
def internal_error():
|
def internal_error(error):
|
||||||
return jsonify({"error": "Internal Error 405"}), 405
|
return jsonify({"error": "Internal Error 405"}), 405
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class Service_Service(db.Model):
|
|||||||
scheduled_date = db.Column(db.DATETIME())
|
scheduled_date = db.Column(db.DATETIME())
|
||||||
description = db.Column(db.TEXT())
|
description = db.Column(db.TEXT())
|
||||||
|
|
||||||
|
service_cost = db.Column(db.Numeric(10, 2), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
class Service_Service_schema(ma.SQLAlchemyAutoSchema):
|
class Service_Service_schema(ma.SQLAlchemyAutoSchema):
|
||||||
|
|||||||
@@ -25,14 +25,12 @@ def get_pricing_tiers():
|
|||||||
gallon_tiers = [100, 125, 150, 175, 200, 220]
|
gallon_tiers = [100, 125, 150, 175, 200, 220]
|
||||||
|
|
||||||
# Calculate the total price for each gallon amount by multiplication
|
# Calculate the total price for each gallon amount by multiplication
|
||||||
# e.g., { 100: (2.92 * 100), 125: (2.92 * 125), ... }
|
|
||||||
pricing_totals = {
|
pricing_totals = {
|
||||||
gallons: price_per_gallon * gallons
|
gallons: price_per_gallon * gallons
|
||||||
for gallons in gallon_tiers
|
for gallons in gallon_tiers
|
||||||
}
|
}
|
||||||
|
|
||||||
# Return the dictionary of totals
|
# Return the dictionary of totals
|
||||||
# e.g., { "100": "292.00", "125": "365.00", ... }
|
|
||||||
return jsonify(pricing_totals)
|
return jsonify(pricing_totals)
|
||||||
|
|
||||||
@info.route("/price/oil", methods=["GET"])
|
@info.route("/price/oil", methods=["GET"])
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from app.classes.service import (Service_Service,
|
|||||||
|
|
||||||
@service.route("/all", methods=["GET"])
|
@service.route("/all", methods=["GET"])
|
||||||
def get_all_service_calls():
|
def get_all_service_calls():
|
||||||
|
try:
|
||||||
all_services = Service_Service.query.all()
|
all_services = Service_Service.query.all()
|
||||||
color_map = {
|
color_map = {
|
||||||
0: {"backgroundColor": "blue", "textColor": "white"}, 1: {"backgroundColor": "red", "textColor": "white"},
|
0: {"backgroundColor": "blue", "textColor": "white"}, 1: {"backgroundColor": "red", "textColor": "white"},
|
||||||
@@ -17,24 +18,39 @@ def get_all_service_calls():
|
|||||||
4: {"backgroundColor": "black", "textColor": "white"}
|
4: {"backgroundColor": "black", "textColor": "white"}
|
||||||
}
|
}
|
||||||
service_type_map = {0: 'Tune-up', 1: 'No Heat', 2: 'Fix', 3: 'Tank Install', 4: 'Other'}
|
service_type_map = {0: 'Tune-up', 1: 'No Heat', 2: 'Fix', 3: 'Tank Install', 4: 'Other'}
|
||||||
|
|
||||||
calendar_events = []
|
calendar_events = []
|
||||||
for service_record in all_services:
|
for service_record in all_services:
|
||||||
service_type_text = service_type_map.get(service_record.type_service_call, 'Service')
|
service_type_text = service_type_map.get(service_record.type_service_call, 'Service')
|
||||||
event_title = f"{service_type_text}: {service_record.customer_name}"
|
event_title = f"{service_type_text}: {service_record.customer_name}"
|
||||||
event_colors = color_map.get(service_record.type_service_call, {"backgroundColor": "gray", "textColor": "white"})
|
event_colors = color_map.get(service_record.type_service_call, {"backgroundColor": "gray", "textColor": "white"})
|
||||||
|
|
||||||
|
# Use the schema to safely get the date string
|
||||||
serialized_record = Service_Service_schema().dump(service_record)
|
serialized_record = Service_Service_schema().dump(service_record)
|
||||||
|
start_date = serialized_record.get('scheduled_date')
|
||||||
|
|
||||||
event_data = {
|
event_data = {
|
||||||
"id": service_record.id, "title": event_title, "start": serialized_record.get('scheduled_date'),
|
"id": service_record.id,
|
||||||
"end": None, "customer_id": service_record.customer_id,
|
"title": event_title,
|
||||||
|
"start": start_date,
|
||||||
|
"end": None,
|
||||||
"extendedProps": {
|
"extendedProps": {
|
||||||
|
"customer_id": service_record.customer_id,
|
||||||
"description": service_record.description,
|
"description": service_record.description,
|
||||||
"type_service_call": service_record.type_service_call,
|
"type_service_call": service_record.type_service_call,
|
||||||
|
"service_cost": str(service_record.service_cost) if service_record.service_cost is not None else None
|
||||||
},
|
},
|
||||||
"backgroundColor": event_colors.get("backgroundColor"), "textColor": event_colors.get("textColor"),
|
"backgroundColor": event_colors.get("backgroundColor"),
|
||||||
|
"textColor": event_colors.get("textColor"),
|
||||||
"borderColor": event_colors.get("backgroundColor")
|
"borderColor": event_colors.get("backgroundColor")
|
||||||
}
|
}
|
||||||
calendar_events.append(event_data)
|
calendar_events.append(event_data)
|
||||||
|
|
||||||
return jsonify(calendar_events), 200
|
return jsonify(calendar_events), 200
|
||||||
|
except Exception as e:
|
||||||
|
# Add error logging to see what's happening
|
||||||
|
print(f"An error occurred in /service/all: {e}")
|
||||||
|
return jsonify(error=str(e)), 500
|
||||||
|
|
||||||
|
|
||||||
# --- THIS IS THE FIX ---
|
# --- THIS IS THE FIX ---
|
||||||
@@ -60,6 +76,26 @@ def get_upcoming_service_calls():
|
|||||||
return jsonify(result), 200
|
return jsonify(result), 200
|
||||||
|
|
||||||
|
|
||||||
|
@service.route("/past", methods=["GET"])
|
||||||
|
def get_past_service_calls():
|
||||||
|
"""
|
||||||
|
Fetches a list of all future service calls from today onwards.
|
||||||
|
"""
|
||||||
|
now = datetime.now()
|
||||||
|
upcoming_services = (
|
||||||
|
Service_Service.query
|
||||||
|
.filter(Service_Service.scheduled_date <= now)
|
||||||
|
.order_by(Service_Service.scheduled_date.asc())
|
||||||
|
.limit(100)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
|
||||||
|
service_schema = Service_Service_schema(many=True)
|
||||||
|
result = service_schema.dump(upcoming_services)
|
||||||
|
|
||||||
|
return jsonify(result), 200
|
||||||
|
|
||||||
|
|
||||||
@service.route("/upcoming/count", methods=["GET"])
|
@service.route("/upcoming/count", methods=["GET"])
|
||||||
def get_upcoming_service_calls_count():
|
def get_upcoming_service_calls_count():
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
@@ -90,7 +126,7 @@ def create_service_call():
|
|||||||
customer_address=get_customer.customer_address, customer_town=get_customer.customer_town,
|
customer_address=get_customer.customer_address, customer_town=get_customer.customer_town,
|
||||||
customer_state=get_customer.customer_state, customer_zip=get_customer.customer_zip,
|
customer_state=get_customer.customer_state, customer_zip=get_customer.customer_zip,
|
||||||
type_service_call=data.get('type_service_call'), when_ordered=datetime.utcnow(),
|
type_service_call=data.get('type_service_call'), when_ordered=datetime.utcnow(),
|
||||||
scheduled_date=scheduled_datetime_obj, description=data.get('description'),
|
scheduled_date=scheduled_datetime_obj, description=data.get('description'), service_cost=None,
|
||||||
)
|
)
|
||||||
db.session.add(new_service_call)
|
db.session.add(new_service_call)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
@@ -106,6 +142,8 @@ def update_service_call(id):
|
|||||||
service_record.scheduled_date = datetime.fromisoformat(scheduled_datetime_str)
|
service_record.scheduled_date = datetime.fromisoformat(scheduled_datetime_str)
|
||||||
service_record.type_service_call = data.get('type_service_call', service_record.type_service_call)
|
service_record.type_service_call = data.get('type_service_call', service_record.type_service_call)
|
||||||
service_record.description = data.get('description', service_record.description)
|
service_record.description = data.get('description', service_record.description)
|
||||||
|
service_record.service_cost = data.get('service_cost', service_record.service_cost)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
service_schema = Service_Service_schema(many=False)
|
service_schema = Service_Service_schema(many=False)
|
||||||
|
|||||||
Reference in New Issue
Block a user