Files
eamco_office_api/app/reports/views.py
2025-07-28 12:05:14 -04:00

48 lines
1.5 KiB
Python
Executable File

from flask import request, jsonify
from flask_login import current_user
from sqlalchemy.sql import func
from datetime import date, timedelta
from app.reports import reports
from app import db
from datetime import datetime
from app.classes.auth import Auth_User
from app.classes.customer import Customer_Customer
from app.classes.employee import Employee_Employee
from app.classes.delivery import Delivery_Delivery
@reports.route("/oil/total", methods=["GET"])
def oil_total_gallons():
total_oil = db.session\
.query(func.sum(Delivery_Delivery.gallons_delivered))\
.group_by(Delivery_Delivery.id)\
.all()
return jsonify({"ok": True }), 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.
"""
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