first commit

This commit is contained in:
2026-01-17 15:21:41 -05:00
commit b93d41c1ae
36 changed files with 3391 additions and 0 deletions

15
models/__init__.py Normal file
View File

@@ -0,0 +1,15 @@
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime
import uuid
def get_uuid():
return str(uuid.uuid4())
Base = declarative_base()
from .customer import Customer_Customer, Customer_Description, Customer_Tank_Inspection, Customer_Stats
from .delivery import Delivery_Delivery
from .pricing import Pricing_Oil_Oil
from .company import Company_Company
from .account import Account_User
from .card import Card, Transaction

62
models/account.py Normal file
View File

@@ -0,0 +1,62 @@
from sqlalchemy import Column, Integer, String, TIMESTAMP, TEXT, VARCHAR
from datetime import datetime, timezone
from . import Base
class Account_User(Base):
__tablename__ = 'portal_user'
__table_args__ = {"schema": "public"}
id = Column(Integer, autoincrement=True, primary_key=True, unique=True)
username = Column(String(50))
account_number = Column(String(32))
house_number = Column(String(32))
email = Column(VARCHAR(350))
password_hash = Column(TEXT)
member_since = Column(TIMESTAMP(timezone=True), default=lambda: datetime.now(timezone.utc))
last_seen = Column(TIMESTAMP(timezone=True), default=lambda: datetime.now(timezone.utc))
password_reset_token = Column(TEXT, nullable=True)
password_reset_expires = Column(TIMESTAMP(timezone=True), nullable=True)
admin = Column(Integer)
admin_role = Column(Integer)
confirmed = Column(Integer)
active = Column(Integer, default=1)
user_id = Column(Integer, nullable=True) # References Customer_Customer.id
def __init__(self,
username,
account_number,
house_number,
password_hash,
member_since,
email,
last_seen,
admin,
admin_role,
confirmed,
active=1,
user_id=None,
):
self.username = username
self.account_number = account_number
self.house_number = house_number
self.password_hash = password_hash
self.member_since = member_since
self.email = email
self.last_seen = last_seen
self.admin = admin
self.admin_role = admin_role
self.confirmed = confirmed
self.active = active
self.user_id = user_id
def is_authenticated(self):
return True
def is_active(self):
return True
def is_anonymous(self):
return False
def get_id(self):
return str(self.id)

46
models/card.py Normal file
View File

@@ -0,0 +1,46 @@
from sqlalchemy import Column, Integer, String, TIMESTAMP, TEXT, VARCHAR, Numeric, DateTime, Boolean
from datetime import datetime, timezone
from . import Base
class Card(Base):
__tablename__ = "card_card"
id = Column(Integer, primary_key=True, index=True)
date_added = Column(DateTime, default=datetime.utcnow)
user_id = Column(Integer, nullable=False)
# This stores the payment profile ID for this specific card from Authorize.Net's CIM.
auth_net_payment_profile_id = Column(String, nullable=True)
# Columns to store non-sensitive card info for display purposes
card_number = Column(String(50), nullable=True)
last_four_digits = Column(Integer, nullable=False)
name_on_card = Column(String(500), nullable=True)
expiration_month = Column(String(20), nullable=False)
expiration_year = Column(String(20), nullable=False)
type_of_card = Column(String(50), nullable=True)
security_number = Column(String(10), nullable=True)
accepted_or_declined = Column(Integer, nullable=True)
main_card = Column(Boolean, nullable=True)
zip_code = Column(String(20), nullable=True)
class Transaction(Base):
__tablename__ = "transactions"
id = Column(Integer, primary_key=True, index=True)
# Recommended change: Use Numeric for precision
preauthorize_amount = Column(Numeric(10, 2), nullable=True)
charge_amount = Column(Numeric(10, 2), nullable=True)
customer_id = Column(Integer)
transaction_type = Column(Integer)# 0 = charge, 1 = auth, 2 = capture
status = Column(Integer)
auth_net_transaction_id = Column(String, unique=True, index=True, nullable=True)
service_id = Column(Integer, nullable=True)
delivery_id = Column(Integer, nullable=True)
auto_id = Column(Integer, nullable=True)
card_id = Column(Integer, nullable=True)
payment_gateway = Column(Integer, default=1)
rejection_reason = Column(String, nullable=True)
created_at = Column(DateTime, default=datetime.utcnow)

14
models/company.py Normal file
View File

@@ -0,0 +1,14 @@
from sqlalchemy import Column, Integer, String, Boolean, DECIMAL, TIMESTAMP, DATE, TEXT, VARCHAR
from . import Base
class Company_Company(Base):
__tablename__ = 'company_company'
__table_args__ = {"schema": "public"}
id = Column(Integer, primary_key=True, autoincrement=True, unique=False)
company_dba_name = Column(VARCHAR(250))
company_llc_name = Column(VARCHAR(250))
company_town = Column(VARCHAR(140))
company_state = Column(Integer)
company_zip = Column(VARCHAR(25))

65
models/customer.py Normal file
View File

@@ -0,0 +1,65 @@
from sqlalchemy import Column, Integer, String, Boolean, DECIMAL, TIMESTAMP, DATE, TEXT, VARCHAR, JSON
from . import Base
class Customer_Customer(Base):
__tablename__ = 'customer_customer'
__table_args__ = {"schema": "public"}
id = Column(Integer, primary_key=True, autoincrement=True, unique=False)
auth_net_profile_id = Column(String, unique=True, index=True, nullable=True)
account_number = Column(VARCHAR(25))
customer_last_name = Column(VARCHAR(250))
customer_first_name = Column(VARCHAR(250))
customer_town = Column(VARCHAR(140))
customer_state = Column(Integer)
customer_zip = Column(VARCHAR(25))
customer_first_call = Column(TIMESTAMP())
customer_email = Column(VARCHAR(500))
customer_automatic = Column(Integer)
customer_phone_number = Column(VARCHAR(25))
customer_home_type = Column(Integer)
customer_apt = Column(VARCHAR(140))
customer_address = Column(VARCHAR(1000))
company_id = Column(Integer)
customer_latitude = Column(VARCHAR(250))
customer_longitude = Column(VARCHAR(250))
correct_address = Column(Boolean)
class Customer_Description(Base):
__tablename__ = 'customer_description'
__table_args__ = {"schema": "public"}
id = Column(Integer, primary_key=True, autoincrement=True, unique=False)
customer_id = Column(Integer)
account_number = Column(VARCHAR(25))
company_id = Column(Integer)
fill_location = Column(Integer)
description = Column(VARCHAR(2000))
class Customer_Tank_Inspection(Base):
__tablename__ = 'customer_tank'
__table_args__ = {"schema": "public"}
id = Column(Integer, primary_key=True, autoincrement=True, unique=False)
customer_id = Column(Integer)
last_tank_inspection = Column(DATE)
tank_status = Column(Boolean)
outside_or_inside = Column(Boolean)
tank_size = Column(Integer)
tank_images = Column(Integer, default=0) # Number of image sets uploaded (each set = 3 images)
tank_image_upload_dates = Column(JSON, default=list) # List of upload dates for each set
class Customer_Stats(Base):
__tablename__ = 'stats_customer'
__table_args__ = {"schema": "public"}
id = Column(Integer, primary_key=True, autoincrement=True, unique=False)
customer_id = Column(Integer)
total_calls = Column(Integer, default=0)
service_calls_total = Column(Integer, default=0)
service_calls_total_spent = Column(DECIMAL(6, 2), default=0.00)
service_calls_total_profit = Column(DECIMAL(6, 2), default=0.00)
oil_deliveries = Column(Integer, default=0)
oil_total_gallons = Column(DECIMAL(6, 2), default=0.00)
oil_total_spent = Column(DECIMAL(6, 2), default=0.00)
oil_total_profit = Column(DECIMAL(6, 2), default=0.00)

77
models/delivery.py Normal file
View File

@@ -0,0 +1,77 @@
from sqlalchemy import Column, Integer, String, Boolean, DECIMAL, TIMESTAMP, DATE, TEXT, VARCHAR
from . import Base
class Delivery_Delivery(Base):
__tablename__ = 'delivery_delivery'
__table_args__ = {"schema": "public"}
id = Column(Integer, primary_key=True, autoincrement=True, unique=False)
customer_id = Column(Integer)
customer_name = Column(VARCHAR(1000))
customer_address = Column(VARCHAR(1000))
customer_town = Column(VARCHAR(140))
customer_state = Column(VARCHAR(140))
customer_zip = Column(Integer)
# how many gallons ordered
gallons_ordered = Column(Integer)
# if customer asked for a fill
customer_asked_for_fill = Column(Integer)
# integer value if delivered, waiting, cancelled etc
gallons_delivered = Column(DECIMAL(6, 2))
# if customer has a full tank
customer_filled = Column(Integer)
# integer value if delivered, waiting, cancelled etc
# waiting = 0
# cancelled = 1
# out for delivery = 2
# tommorrow = 3
# issue = 5
# finalized = 10
delivery_status = Column(Integer)
# when the call to order took place
when_ordered = Column(DATE(), default=None)
# when the delivery date happened
when_delivered = Column(DATE(), default=None)
# when the delivery is expected ie what day
expected_delivery_date = Column(DATE(), default=None)
# automatic delivery
automatic = Column(Integer)
automatic_id = Column(Integer)
# OIL info and id from table
oil_id = Column(Integer)
supplier_price = Column(DECIMAL(6, 2))
customer_price = Column(DECIMAL(6, 2))
# weather
customer_temperature = Column(DECIMAL(6, 2))
dispatcher_notes = Column(TEXT())
prime = Column(Integer)
same_day = Column(Integer)
emergency = Column(Integer)
# cash = 0
# credit = 1
# credit/cash = 2
# check = 3
# other = 4
payment_type = Column(Integer)
payment_card_id = Column(Integer)
cash_recieved = Column(DECIMAL(6, 2))
driver_employee_id = Column(Integer)
driver_first_name = Column(VARCHAR(140))
driver_last_name = Column(VARCHAR(140))
pre_charge_amount = Column(DECIMAL(6, 2))
total_price = Column(DECIMAL(6, 2))
final_price = Column(DECIMAL(6, 2))
check_number = Column(VARCHAR(20))
promo_id = Column(Integer)
promo_money_discount = Column(DECIMAL(6, 2))

17
models/pricing.py Normal file
View File

@@ -0,0 +1,17 @@
from sqlalchemy import Column, Integer, String, Boolean, DECIMAL, TIMESTAMP, DATE, TEXT, VARCHAR
from datetime import datetime
from . import Base
class Pricing_Oil_Oil(Base):
__tablename__ = 'pricing_oil_oil'
__table_args__ = {"schema": "public"}
id = Column(Integer, primary_key=True, autoincrement=True, unique=False)
price_from_supplier = Column(DECIMAL(6, 2))
price_for_customer = Column(DECIMAL(6, 2))
price_for_employee = Column(DECIMAL(6, 2))
price_same_day = Column(DECIMAL(6, 2))
price_prime = Column(DECIMAL(6, 2))
price_emergency = Column(DECIMAL(6, 2))
date = Column(TIMESTAMP(), default=datetime.utcnow())