Files
eamco_office_api/app/reports/views.py
2026-01-28 21:55:10 -05:00

48 lines
1.5 KiB
Python
Executable File

import logging
from flask import jsonify
from sqlalchemy.sql import func
from app.reports import reports
from app import db
from app.classes.customer import Customer_Customer
from app.classes.delivery import Delivery_Delivery
logger = logging.getLogger(__name__)
@reports.route("/oil/total", methods=["GET"])
def oil_total_gallons():
logger.info("GET /reports/oil/total - Calculating total oil delivered")
total_oil = db.session\
.query(func.sum(Delivery_Delivery.gallons_delivered))\
.group_by(Delivery_Delivery.id)\
.all()
return jsonify({"ok": True, "oil": total_oil }), 200
@reports.route("/customers/list", methods=["GET"])
def customer_list():
"""
Retrieve a list of customers with selected fields for printing.
Returns account number, first name, last name, address, town, and phone number.
Ordered by last name from A to Z.
"""
logger.info("GET /reports/customers/list - Fetching customer list for reports")
customers = db.session.query(Customer_Customer).order_by(Customer_Customer.customer_last_name.asc()).all()
customer_data = [
{
"account_number": customer.account_number,
"first_name": customer.customer_first_name,
"last_name": customer.customer_last_name,
"address": customer.customer_address,
"town": customer.customer_town,
"phone_number": customer.customer_phone_number
}
for customer in customers
]
response = jsonify({"ok": True, "customers": customer_data})
return response, 200