From 86ec25a4990ae8a7a2c59ee976f0ee1407046ed5 Mon Sep 17 00:00:00 2001 From: Edwin Eames Date: Wed, 20 Nov 2024 18:01:14 -0500 Subject: [PATCH] added maps --- app/classes/auto.py | 51 +++++++++- app/classes/cards.py | 2 +- app/classes/customer.py | 6 +- app/classes/money.py | 1 + app/customer/views.py | 192 ++++++++++++++++++++--------------- app/delivery_data/views.py | 9 -- app/delivery_status/views.py | 26 ++++- app/employees/views.py | 1 - requirements.txt | 3 +- 9 files changed, 188 insertions(+), 103 deletions(-) diff --git a/app/classes/auto.py b/app/classes/auto.py index 958d43e..97f1592 100755 --- a/app/classes/auto.py +++ b/app/classes/auto.py @@ -2,6 +2,17 @@ from app import db, ma from datetime import datetime +class Auto_Update(db.Model): + __tablename__ = 'auto_update' + + id = db.Column(db.Integer, + primary_key=True, + autoincrement=True, + unique=False) + + last_updated = db.Column(db.DATE()) + + class Auto_Temp(db.Model): __tablename__ = 'auto_temp' @@ -11,7 +22,7 @@ class Auto_Temp(db.Model): primary_key=True, autoincrement=True, unique=False) - todays_date = db.Column(db.TIMESTAMP(), default=datetime.utcnow()) + todays_date = db.Column(db.DATE()) temp = db.Column(db.DECIMAL(6, 2)) temp_max = db.Column(db.DECIMAL(6, 2)) temp_min = db.Column(db.DECIMAL(6, 2)) @@ -39,10 +50,11 @@ class Auto_Delivery(db.Model): customer_address = db.Column(db.VARCHAR(1000)) customer_zip = db.Column(db.VARCHAR(25)) customer_full_name = db.Column(db.VARCHAR(250)) - last_fill = db.Column(db.TIMESTAMP()) - last_updated = db.Column(db.TIMESTAMP()) - estimated_gallons_left = db.Column(db.INTEGER()) - estimated_gallons_left_prev_day = db.Column(db.INTEGER()) + last_fill = db.Column(db.DATE()) + days_since_last_fill = db.Column(db.Integer) + last_updated = db.Column(db.DATE()) + estimated_gallons_left = db.Column(db.DECIMAL(6, 2)) + estimated_gallons_left_prev_day = db.Column(db.DECIMAL(6, 2)) tank_height = db.Column(db.VARCHAR(25)) tank_size = db.Column(db.VARCHAR(25)) house_factor = db.Column(db.DECIMAL(5, 2)) @@ -54,3 +66,32 @@ class Auto_Delivery(db.Model): class Auto_Delivery_schema(ma.SQLAlchemyAutoSchema): class Meta: model = Auto_Delivery + + +class Tickets_Auto_Delivery(db.Model): + __tablename__ = 'auto_tickets' + __table_args__ = {"schema": "public"} + + id = db.Column(db.Integer, + primary_key=True, + autoincrement=True, + unique=False) + customer_id = db.Column(db.INTEGER()) + account_number = db.Column(db.VARCHAR(25)) + + customer_town = db.Column(db.VARCHAR(140)) + customer_state = db.Column(db.Integer) + customer_address = db.Column(db.VARCHAR(1000)) + customer_zip = db.Column(db.VARCHAR(25)) + customer_full_name = db.Column(db.VARCHAR(250)) + + oil_prices_id = db.Column(db.INTEGER()) + + gallons_delivered = db.Column(db.DECIMAL(6, 2)) + price_per_gallon = db.Column(db.DECIMAL(6, 2)) + + total_amount_customer = db.Column(db.DECIMAL(6, 2)) + +class Tickets_Auto_Delivery_schema(ma.SQLAlchemyAutoSchema): + class Meta: + model = Tickets_Auto_Delivery diff --git a/app/classes/cards.py b/app/classes/cards.py index 90db789..21ab6c4 100755 --- a/app/classes/cards.py +++ b/app/classes/cards.py @@ -19,7 +19,7 @@ class Card_Card(db.Model): expiration_month = db.Column(db.INTEGER()) expiration_year = db.Column(db.INTEGER()) type_of_card = db.Column(db.VARCHAR(500)) - security_number = db.Column(db.INTEGER()) + security_number = db.Column(db.VARCHAR(10)) accepted_or_declined = db.Column(db.INTEGER()) main_card = db.Column(db.BOOLEAN()) zip_code = db.Column(db.VARCHAR(20)) diff --git a/app/classes/customer.py b/app/classes/customer.py index f1ecd53..9e63af3 100755 --- a/app/classes/customer.py +++ b/app/classes/customer.py @@ -25,8 +25,10 @@ class Customer_Customer(db.Model): customer_apt = db.Column(db.VARCHAR(140)) customer_address = db.Column(db.VARCHAR(1000)) company_id = db.Column(db.INTEGER) - - + customer_latitude = db.Column(db.VARCHAR(250)) + customer_longitude = db.Column(db.VARCHAR(250)) + correct_address = db.Column(db.BOOLEAN) + class Customer_Customer_schema(ma.SQLAlchemyAutoSchema): class Meta: model = Customer_Customer diff --git a/app/classes/money.py b/app/classes/money.py index 22e613e..2b8c22a 100644 --- a/app/classes/money.py +++ b/app/classes/money.py @@ -25,6 +25,7 @@ class Money_delivery(db.Model): taxes_paid = db.Column(db.DECIMAL(6, 2)) total_profit = db.Column(db.DECIMAL(6, 2)) total_profit_oil = db.Column(db.DECIMAL(6, 2)) + auto = db.Column(db.BOOLEAN) class Money_delivery_schema(ma.SQLAlchemyAutoSchema): class Meta: diff --git a/app/customer/views.py b/app/customer/views.py index 7b0613a..04fd7df 100755 --- a/app/customer/views.py +++ b/app/customer/views.py @@ -1,5 +1,6 @@ from flask import request, jsonify from flask_login import login_required +from geopy.geocoders import Nominatim from app.customer import customer from app import db from datetime import datetime @@ -146,6 +147,8 @@ def create_customer(): .query(Customer_Customer) .order_by(Customer_Customer.id.desc()) .first()) + + new_customer_id = last_customer.id + 1 if len(str(new_customer_id)) == 2: new_customer_id = '000' + str(new_customer_id) @@ -154,10 +157,8 @@ def create_customer(): if len(str(new_customer_id)) == 4: new_customer_id = '0' + str(new_customer_id) - starter_digits = str(get_company.account_prefix) + '-' + str(new_customer_id) - made_account_number = starter_digits @@ -174,11 +175,31 @@ def create_customer(): customer_description_msg = request.json["customer_description"] - int_customer_home_type = int(response_customer_home_type) response_customer_zip = str(response_customer_zip) response_customer_state = int(response_customer_state) + if response_customer_state == 0: + the_state = 'MA' + elif response_customer_state == 1: + the_state = 'RI' + elif response_customer_state == 1: + the_state = 'NH' + else: + the_state = 'MA' + + geolocator = Nominatim(user_agent="auburnoil") + address_string = customer_address + ' ' + response_customer_town + the_state + response_customer_zip + try: + location = geolocator.geocode(address_string) + user_lat =location.latitude + user_long = location.longitude + cor_ad = True + except: + user_lat =location.latitude + user_long = location.longitude + cor_ad = False + new_customer = Customer_Customer( account_number=made_account_number, customer_last_name=response_customer_last_name, @@ -194,6 +215,9 @@ def create_customer(): customer_address=customer_address, customer_apt=customer_apt, company_id=1, + customer_latitude=user_lat, + customer_longitude=user_long, + correct_address=cor_ad ) db.session.add(new_customer) db.session.flush() @@ -229,24 +253,7 @@ def create_customer(): ) db.session.add(new_tank) - new_auto = Auto_Delivery( - customer_id = new_customer.id, - account_number = made_account_number, - customer_full_name = new_customer.customer_last_name + " " + new_customer.customer_first_name, - last_fill = None, - last_updated = None, - estimated_gallons_left = None, - estimated_gallons_left_prev_day = None, - tank_height = None, - tank_size = None, - house_factor = 1, - customer_town = new_customer.customer_town, - customer_state = new_customer.customer_state, - customer_zip = new_customer.customer_zip, - auto_status=0 - ) - - db.session.add(new_auto) + db.session.commit() return jsonify({ @@ -258,62 +265,6 @@ def create_customer(): }, }), 200 -@customer.route("/edit/tank/", methods=["PUT"]) -@login_required -def edit_customer_tank(customer_id): - """ - """ - get_customer = (db.session - .query(Customer_Customer) - .filter(Customer_Customer.id == customer_id) - .first()) - get_customer_description = (db.session - .query(Customer_Description) - .filter(Customer_Description.customer_id == customer_id) - .first()) - get_customer_tank = (db.session - .query(Customer_Tank_Inspection) - .filter(Customer_Tank_Inspection.customer_id == customer_id) - .first()) - - response_tank_status = request.json["tank_status"] - if response_tank_status == 'true': - get_customer_tank.tank_status = True - - elif response_tank_status == 'false': - get_customer_tank.outside_or_inside = False - else: - pass - - - response_outside_or_inside = request.json["outside_or_inside"] - if response_outside_or_inside == 'true': - get_customer_tank.outside_or_inside = True - - elif response_outside_or_inside == 'false': - get_customer_tank.outside_or_inside = False - else: - pass - - response_last_tank_inspection = request.json["last_tank_inspection"] - response_tank_size = request.json["tank_size"] - response_customer_fill_location = request.json["fill_location"] - - - get_customer_tank.last_tank_inspection = response_last_tank_inspection - get_customer_tank.tank_size = response_tank_size - - - get_customer_description.fill_location = response_customer_fill_location - db.session.add(get_customer_description) - - db.session.add(get_customer) - db.session.commit() - - return jsonify({ - "ok": True, - }), 200 - @customer.route("/edit/", methods=["PUT"]) @@ -338,7 +289,7 @@ def edit_customer(customer_id): response_customer_email = request.json["customer_email"] response_customer_home_type = request.json["customer_home_type"] response_customer_address = request.json["customer_address"] - + response_customer_apt = request.json["customer_apt"] response_customer_description = request.json["customer_description"] response_customer_fill_location = request.json["customer_fill_location"] @@ -349,6 +300,27 @@ def edit_customer(customer_id): get_customer_description.fill_location = response_customer_fill_location db.session.add(get_customer_description) + if response_customer_state == 0: + the_state = 'MA' + elif response_customer_state == 1: + the_state = 'RI' + elif response_customer_state == 1: + the_state = 'NH' + else: + the_state = 'MA' + + geolocator = Nominatim(user_agent="auburnoil") + address_string = response_customer_address + ' ' + response_customer_town+ ' ' + the_state + try: + location = geolocator.geocode(address_string, timeout=10) + get_customer.customer_latitude = location.latitude + get_customer.customer_longitude = location.longitude + cor_ad = True + except: + get_customer.customer_latitude = None + get_customer.customer_longitude = None + cor_ad = False + get_customer.customer_address = response_customer_address get_customer.customer_home_type = response_customer_home_type @@ -359,6 +331,9 @@ def edit_customer(customer_id): get_customer.customer_state = response_customer_state get_customer.customer_zip = response_customer_zip get_customer.customer_email = response_customer_email + get_customer.customer_apt = response_customer_apt + get_customer.correct_address = cor_ad + db.session.add(get_customer) db.session.commit() @@ -490,14 +465,15 @@ def customer_automatic_assignment(customer_id): customer_state=get_customer.customer_state, customer_zip=get_customer.customer_zip, customer_address=get_customer.customer_address, - last_fill = datetime.utcnow(), + last_fill = None, last_updated = None, estimated_gallons_left = 0, estimated_gallons_left_prev_day = 0, tank_height = 0, tank_size =275, house_factor = 1, - auto_status=0 + auto_status=1, + days_since_last_fill=0 ) db.session.add(create_auto) @@ -513,3 +489,59 @@ def customer_automatic_assignment(customer_id): 'status': status }), 200 +@customer.route("/edit/tank/", methods=["PUT"]) +@login_required +def edit_customer_tank(customer_id): + """ + """ + get_customer = (db.session + .query(Customer_Customer) + .filter(Customer_Customer.id == customer_id) + .first()) + get_customer_description = (db.session + .query(Customer_Description) + .filter(Customer_Description.customer_id == customer_id) + .first()) + get_customer_tank = (db.session + .query(Customer_Tank_Inspection) + .filter(Customer_Tank_Inspection.customer_id == customer_id) + .first()) + + response_tank_status = request.json["tank_status"] + if response_tank_status == 'true': + get_customer_tank.tank_status = True + + elif response_tank_status == 'false': + get_customer_tank.outside_or_inside = False + else: + pass + + + response_outside_or_inside = request.json["outside_or_inside"] + if response_outside_or_inside == 'true': + get_customer_tank.outside_or_inside = True + + elif response_outside_or_inside == 'false': + get_customer_tank.outside_or_inside = False + else: + pass + + response_last_tank_inspection = request.json["last_tank_inspection"] + response_tank_size = request.json["tank_size"] + response_customer_fill_location = request.json["fill_location"] + + + get_customer_tank.last_tank_inspection = response_last_tank_inspection + get_customer_tank.tank_size = response_tank_size + + + get_customer_description.fill_location = response_customer_fill_location + db.session.add(get_customer_description) + + db.session.add(get_customer) + db.session.commit() + + return jsonify({ + "ok": True, + }), 200 + diff --git a/app/delivery_data/views.py b/app/delivery_data/views.py index 1673459..81e824c 100755 --- a/app/delivery_data/views.py +++ b/app/delivery_data/views.py @@ -122,18 +122,11 @@ def office_finalize_delivery(delivery_id): - - gallons_delivered = request.json["gallons_delivered"] - check_number = request.json["check_number"] - - - fill_location = request.json["fill_location"] - # update driver get_delivery.driver_last_name = get_driver.employee_last_name get_delivery.driver_first_name = get_driver.employee_first_name @@ -161,8 +154,6 @@ def office_finalize_delivery(delivery_id): get_stats_customer.oil_total_gallons = new_gallons - - # update fill location get_customer_description.fill_location = fill_location diff --git a/app/delivery_status/views.py b/app/delivery_status/views.py index b3d65e5..afab129 100755 --- a/app/delivery_status/views.py +++ b/app/delivery_status/views.py @@ -2,12 +2,11 @@ from flask import jsonify from datetime import date, timedelta from app.delivery_status import deliverystatus from app import db -from sqlalchemy import or_ from app.classes.delivery import (Delivery_Delivery, Delivery_Delivery_schema, ) - +from app.classes.auto import Auto_Delivery @deliverystatus.route("/delivered", methods=["GET"]) def delivered_delivery(): @@ -87,11 +86,11 @@ def get_deliveries_driver_tommorrow(user_id): return jsonify(delivery_schema.dump(get_delivery)) + @deliverystatus.route("/count/tommorrow", methods=["GET"]) def get_deliveries_driver_tommorrow_count(): """ """ - tomm = date.today() + timedelta(days=1) get_delivery = (db.session .query(Delivery_Delivery) .filter(Delivery_Delivery.delivery_status == 3) @@ -109,7 +108,6 @@ def get_deliveries_driver_waiting(user_id): """ waiting deliveries scheduled out """ - tomm = date.today() + timedelta(days=1) get_delivery = (db.session .query(Delivery_Delivery) .filter(Delivery_Delivery.driver_employee_id == user_id) @@ -120,6 +118,26 @@ def get_deliveries_driver_waiting(user_id): return jsonify(delivery_schema.dump(get_delivery)) + +@deliverystatus.route("/count/automatic", methods=["GET"]) +def get_deliveries_automatic_count(): + """ + + """ + + autos = (db.session + .query(Auto_Delivery) + .filter(Auto_Delivery.estimated_gallons_left <= 80) + .count()) + + + return jsonify({ + "ok": True, + 'count':autos, + }), 200 + + + @deliverystatus.route("/count/waiting", methods=["GET"]) def get_deliveries_waiting_count(): """ diff --git a/app/employees/views.py b/app/employees/views.py index 28a9f05..8ed3a11 100755 --- a/app/employees/views.py +++ b/app/employees/views.py @@ -11,7 +11,6 @@ from app.classes.stats_employee import Stats_Employee_Oil, Stats_Employee_Office @employees.route("/", methods=["GET"]) @login_required def get_specific_employee(userid): - print(userid) employee = db.session \ .query(Employee_Employee) \ .filter(Employee_Employee.id == userid) \ diff --git a/requirements.txt b/requirements.txt index c6153d3..cefd790 100755 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,5 @@ redis sqlalchemy flask_wtf flask_mail -Werkzeug==2.3.8 \ No newline at end of file +Werkzeug==2.3.8 +geopy \ No newline at end of file