added checks emergency fixed bugs
This commit is contained in:
@@ -13,10 +13,10 @@ class Auto_Temp(db.Model):
|
||||
autoincrement=True,
|
||||
unique=False)
|
||||
todays_date = db.Column(db.TIMESTAMP(), default=datetime.utcnow())
|
||||
temp = db.Column(db.DECIMAL(50, 2))
|
||||
temp_max = db.Column(db.DECIMAL(50, 2))
|
||||
temp_min = db.Column(db.DECIMAL(50, 2))
|
||||
temp_avg = db.Column(db.DECIMAL(50, 2))
|
||||
temp = db.Column(db.DECIMAL(6, 2))
|
||||
temp_max = db.Column(db.DECIMAL(6, 2))
|
||||
temp_min = db.Column(db.DECIMAL(6, 2))
|
||||
temp_avg = db.Column(db.DECIMAL(6, 2))
|
||||
degree_day = db.Column(db.INTEGER())
|
||||
|
||||
class Auto_Temp_schema(ma.SQLAlchemyAutoSchema):
|
||||
|
||||
@@ -23,6 +23,7 @@ class Card_Card(db.Model):
|
||||
security_number = db.Column(db.INTEGER())
|
||||
accepted_or_declined = db.Column(db.INTEGER())
|
||||
main_card = db.Column(db.BOOLEAN())
|
||||
zip_code = db.Column(db.VARCHAR(20))
|
||||
|
||||
class Card_Card_schema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
|
||||
@@ -24,7 +24,7 @@ class Delivery_Delivery(db.Model):
|
||||
# if customer asked for a fill
|
||||
customer_asked_for_fill = db.Column(db.INTEGER)
|
||||
# integer value if delivered, waiting, cancelled etc
|
||||
gallons_delivered =db.Column(db.DECIMAL(50, 2))
|
||||
gallons_delivered =db.Column(db.DECIMAL(6, 2))
|
||||
# if customer has a full tank
|
||||
customer_filled = db.Column(db.INTEGER)
|
||||
# integer value if delivered, waiting, cancelled etc
|
||||
@@ -36,9 +36,9 @@ class Delivery_Delivery(db.Model):
|
||||
# issue = 5
|
||||
# finalized = 10
|
||||
delivery_status = db.Column(db.INTEGER)
|
||||
emergency = db.Column(db.INTEGER)
|
||||
|
||||
# when the call to order took place
|
||||
when_ordered = db.Column(db.DATE(), default=datetime.utcnow())
|
||||
when_ordered = db.Column(db.DATE(), default=None)
|
||||
# when the delivery date happened
|
||||
when_delivered = db.Column(db.DATE(), default=None)
|
||||
# when the delivery is expected ie what day
|
||||
@@ -48,14 +48,18 @@ class Delivery_Delivery(db.Model):
|
||||
automatic_id = db.Column(db.INTEGER)
|
||||
# OIL info and id from table
|
||||
oil_id = db.Column(db.INTEGER)
|
||||
supplier_price = db.Column(db.DECIMAL(50, 2))
|
||||
customer_price = db.Column(db.DECIMAL(50, 2))
|
||||
supplier_price = db.Column(db.DECIMAL(6, 2))
|
||||
customer_price = db.Column(db.DECIMAL(6, 2))
|
||||
# weather
|
||||
customer_temperature = db.Column(db.DECIMAL(50, 2))
|
||||
customer_temperature = db.Column(db.DECIMAL(6, 2))
|
||||
# services
|
||||
dispatcher_notes = db.Column(db.TEXT())
|
||||
|
||||
|
||||
prime = db.Column(db.INTEGER)
|
||||
same_day = db.Column(db.INTEGER)
|
||||
emergency = db.Column(db.INTEGER)
|
||||
|
||||
# cash = 0
|
||||
# credit = 1
|
||||
# credit/cash = 2
|
||||
@@ -63,15 +67,15 @@ class Delivery_Delivery(db.Model):
|
||||
# other = 4
|
||||
payment_type = db.Column(db.INTEGER)
|
||||
payment_card_id = db.Column(db.INTEGER)
|
||||
cash_recieved = db.Column(db.DECIMAL(50, 2))
|
||||
cash_recieved = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
driver_employee_id = db.Column(db.INTEGER)
|
||||
driver_first_name = db.Column(db.VARCHAR(140))
|
||||
driver_last_name = db.Column(db.VARCHAR(140))
|
||||
|
||||
pre_charge_amount = db.Column(db.DECIMAL(50, 2))
|
||||
total_price = db.Column(db.DECIMAL(50, 2))
|
||||
final_price = db.Column(db.DECIMAL(50, 2))
|
||||
pre_charge_amount = db.Column(db.DECIMAL(6, 2))
|
||||
total_price = db.Column(db.DECIMAL(6, 2))
|
||||
final_price = db.Column(db.DECIMAL(6, 2))
|
||||
check_number = db.Column(db.VARCHAR(20))
|
||||
|
||||
class Delivery_Delivery_schema(ma.SQLAlchemyAutoSchema):
|
||||
|
||||
@@ -64,7 +64,7 @@ class Employee_Vacation(db.Model):
|
||||
employee_id = db.Column(db.INTEGER)
|
||||
employee_name = db.Column(db.VARCHAR(140))
|
||||
employee_total_days_off = db.Column(db.INTEGER)
|
||||
employee_days_off_multiplier = db.Column(db.DECIMAL(50, 2))
|
||||
employee_days_off_multiplier = db.Column(db.DECIMAL(6, 2))
|
||||
employee_days_off_per_year = db.Column(db.INTEGER)
|
||||
|
||||
|
||||
|
||||
@@ -14,18 +14,18 @@ class Money_delivery(db.Model):
|
||||
|
||||
delivery_id = db.Column(db.INTEGER)
|
||||
time_added = db.Column(db.TIMESTAMP(), default=datetime.utcnow())
|
||||
gallons_delivered = db.Column(db.DECIMAL(50, 2))
|
||||
supplier_price = db.Column(db.DECIMAL(50, 2))
|
||||
customer_price = db.Column(db.DECIMAL(50, 2))
|
||||
gallons_delivered = db.Column(db.DECIMAL(6, 2))
|
||||
supplier_price = db.Column(db.DECIMAL(6, 2))
|
||||
customer_price = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
total_amount_oil = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount_prime = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount_same_day = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount_fee = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount = db.Column(db.DECIMAL(50, 2))
|
||||
total_profit_oil = db.Column(db.DECIMAL(50, 2))
|
||||
taxes_paid = db.Column(db.DECIMAL(50, 2))
|
||||
total_profit = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount_oil = db.Column(db.DECIMAL(6, 2))
|
||||
total_amount_prime = db.Column(db.DECIMAL(6, 2))
|
||||
total_amount_same_day = db.Column(db.DECIMAL(6, 2))
|
||||
total_amount_fee = db.Column(db.DECIMAL(6, 2))
|
||||
total_amount = db.Column(db.DECIMAL(6, 2))
|
||||
total_profit_oil = db.Column(db.DECIMAL(6, 2))
|
||||
taxes_paid = db.Column(db.DECIMAL(6, 2))
|
||||
total_profit = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
|
||||
class Money_delivery_schema(ma.SQLAlchemyAutoSchema):
|
||||
@@ -44,5 +44,5 @@ class Pricing_Taxes(db.Model):
|
||||
autoincrement=True,
|
||||
unique=False)
|
||||
state_id = db.Column(db.Integer)
|
||||
taxes_oil = db.Column(db.DECIMAL(50, 2))
|
||||
taxes_other = db.Column(db.DECIMAL(50, 2))
|
||||
taxes_oil = db.Column(db.DECIMAL(6, 2))
|
||||
taxes_other = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
@@ -12,17 +12,17 @@ class Stats_Customer(db.Model):
|
||||
primary_key=True,
|
||||
autoincrement=True,
|
||||
unique=False)
|
||||
|
||||
customer_id = db.Column(db.INTEGER)
|
||||
total_calls = db.Column(db.INTEGER)
|
||||
service_calls_total = db.Column(db.INTEGER)
|
||||
service_calls_total_spent = db.Column(db.DECIMAL(50, 2))
|
||||
service_calls_total_profit = db.Column(db.DECIMAL(50, 2))
|
||||
service_calls_total_spent = db.Column(db.DECIMAL(6, 2))
|
||||
service_calls_total_profit = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
|
||||
oil_deliveries = db.Column(db.INTEGER)
|
||||
oil_total_gallons = db.Column(db.INTEGER)
|
||||
oil_total_spent = db.Column(db.DECIMAL(50, 2))
|
||||
oil_total_profit = db.Column(db.DECIMAL(50, 2))
|
||||
oil_total_gallons = db.Column(db.DECIMAL(6, 2))
|
||||
oil_total_spent = db.Column(db.DECIMAL(6, 2))
|
||||
oil_total_profit = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
class Stats_Customer_schema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
|
||||
@@ -15,11 +15,11 @@ class Delivery_Payment(db.Model):
|
||||
|
||||
delivery_id = db.Column(db.INTEGER)
|
||||
time_added = db.Column(db.TIMESTAMP(), default=datetime.utcnow())
|
||||
total_amount_oil = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount_emergency = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount_prime = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount_fee = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount = db.Column(db.DECIMAL(50, 2))
|
||||
total_amount_oil = db.Column(db.DECIMAL(6, 2))
|
||||
total_amount_emergency = db.Column(db.DECIMAL(6, 2))
|
||||
total_amount_prime = db.Column(db.DECIMAL(6, 2))
|
||||
total_amount_fee = db.Column(db.DECIMAL(6, 2))
|
||||
total_amount = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
class Delivery_Payment_schema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
|
||||
@@ -12,5 +12,5 @@ class Pricing_Taxes(db.Model):
|
||||
autoincrement=True,
|
||||
unique=False)
|
||||
state_id = db.Column(db.Integer)
|
||||
taxes_oil = db.Column(db.DECIMAL(50, 2))
|
||||
taxes_other = db.Column(db.DECIMAL(50, 2))
|
||||
taxes_oil = db.Column(db.DECIMAL(6, 2))
|
||||
taxes_other = db.Column(db.DECIMAL(6, 2))
|
||||
|
||||
@@ -11,9 +11,16 @@ from app.classes.customer import \
|
||||
Customer_Description_schema
|
||||
from app.classes.admin import Admin_Company
|
||||
from app.classes.auto import Auto_Delivery
|
||||
from app.classes.stats_customer import Stats_Customer
|
||||
import string
|
||||
import random
|
||||
|
||||
|
||||
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
|
||||
return ''.join(random.choice(chars) for _ in range(size))
|
||||
|
||||
|
||||
|
||||
@customer.route("/all", methods=["GET"])
|
||||
@login_required
|
||||
def all_customers_around():
|
||||
@@ -51,7 +58,6 @@ def all_customers(page):
|
||||
@customer.route("/<int:customer_id>", methods=["GET"])
|
||||
def get_a_customer(customer_id):
|
||||
"""
|
||||
Checks auth token to ensure user is authenticated
|
||||
"""
|
||||
get_customer = (db.session
|
||||
.query(Customer_Customer)
|
||||
@@ -60,8 +66,37 @@ def get_a_customer(customer_id):
|
||||
customer_schema = Customer_Customer_schema(many=False)
|
||||
return jsonify(customer_schema.dump(get_customer))
|
||||
|
||||
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
|
||||
return ''.join(random.choice(chars) for _ in range(size))
|
||||
|
||||
@customer.route("/description/<int:customer_id>", methods=["GET"])
|
||||
def get_a_customer_description(customer_id):
|
||||
"""
|
||||
|
||||
"""
|
||||
get_customer_description = (db.session
|
||||
.query(Customer_Description)
|
||||
.filter(Customer_Description.customer_id == customer_id)
|
||||
.first())
|
||||
if get_customer_description is None:
|
||||
get_customer = (db.session
|
||||
.query(Customer_Customer)
|
||||
.filter(Customer_Customer.id == customer_id)
|
||||
.first())
|
||||
|
||||
new_description = Customer_Description(
|
||||
customer_id = customer_id,
|
||||
account_number = get_customer.account_number,
|
||||
company_id = get_customer.company_id,
|
||||
fill_location = None,
|
||||
description = None,
|
||||
)
|
||||
db.session.add(new_description)
|
||||
db.session.commit()
|
||||
get_customer_description = (db.session
|
||||
.query(Customer_Description)
|
||||
.filter(Customer_Description.customer_id == customer_id)
|
||||
.first())
|
||||
customer_schema = Customer_Description_schema(many=False)
|
||||
return jsonify(customer_schema.dump(get_customer_description))
|
||||
|
||||
@customer.route("/create", methods=["POST"])
|
||||
@login_required
|
||||
@@ -115,7 +150,20 @@ def create_customer():
|
||||
)
|
||||
db.session.add(new_customer)
|
||||
db.session.flush()
|
||||
|
||||
|
||||
create_stats_customer = Stats_Customer(
|
||||
customer_id = new_customer.id,
|
||||
total_calls = 1,
|
||||
service_calls_total = 0,
|
||||
service_calls_total_spent = 0,
|
||||
service_calls_total_profit = 0,
|
||||
oil_deliveries = 0,
|
||||
oil_total_gallons = 0,
|
||||
oil_total_spent = 0,
|
||||
oil_total_profit = 0,
|
||||
)
|
||||
db.session.add(create_stats_customer)
|
||||
|
||||
new_description = Customer_Description(
|
||||
customer_id = new_customer.id,
|
||||
account_number = made_account_number,
|
||||
@@ -125,7 +173,6 @@ def create_customer():
|
||||
)
|
||||
db.session.add(new_description)
|
||||
|
||||
|
||||
new_auto = Auto_Delivery(
|
||||
customer_id = new_customer.id,
|
||||
account_number = made_account_number,
|
||||
|
||||
@@ -33,6 +33,7 @@ def get_a_delivery(delivery_id):
|
||||
'delivery_gallons_ordered': get_delivery.gallons_ordered,
|
||||
'delivery_dispatcher_notes': get_delivery.dispatcher_notes,
|
||||
'delivery_prime': get_delivery.prime,
|
||||
'delivery_emergency': get_delivery.emergency,
|
||||
'delivery_same_day': get_delivery.same_day,
|
||||
'when_ordered': get_delivery.when_ordered,
|
||||
'customer_price': get_delivery.customer_price,
|
||||
@@ -505,6 +506,7 @@ def create_a_delivery(user_id):
|
||||
dispatcher_notes_taken = request.json["dispatcher_notes_taken"]
|
||||
prime_info = request.json["prime"]
|
||||
same_day_info = request.json["same_day"]
|
||||
emergency_info = request.json["emergency"]
|
||||
delivery_driver_id = request.json["driver_employee_id"]
|
||||
|
||||
|
||||
@@ -570,6 +572,11 @@ def create_a_delivery(user_id):
|
||||
else:
|
||||
customer_fill_up = 0
|
||||
|
||||
if emergency_info is True:
|
||||
emergency_asked = 1
|
||||
else:
|
||||
emergency_asked = 0
|
||||
|
||||
if prime_info is True:
|
||||
prime_asked = 1
|
||||
else:
|
||||
@@ -585,17 +592,25 @@ def create_a_delivery(user_id):
|
||||
now = datetime.utcnow()
|
||||
|
||||
# Pricing
|
||||
|
||||
if customer_fill_up == 1:
|
||||
# Fill
|
||||
precharge_amount = (250 * get_today_price.price_for_customer)
|
||||
else:
|
||||
# Gallons
|
||||
precharge_amount = int(gallons_ordered) * get_today_price.price_for_customer
|
||||
|
||||
|
||||
# if prime/emergency/sameday
|
||||
if same_day_asked == 1 and prime_asked == 0:
|
||||
total_precharge_amount = precharge_amount + get_today_price.price_same_day
|
||||
|
||||
elif prime_asked == 1 and same_day_asked == 0:
|
||||
total_precharge_amount = precharge_amount + get_today_price.price_prime
|
||||
|
||||
elif emergency_asked == 1:
|
||||
total_precharge_amount = precharge_amount + get_today_price.price_emergency
|
||||
|
||||
else:
|
||||
total_precharge_amount = precharge_amount + get_today_price.price_prime + get_today_price.price_same_day
|
||||
|
||||
@@ -624,6 +639,7 @@ def create_a_delivery(user_id):
|
||||
dispatcher_notes=dispatcher_notes_taken,
|
||||
prime=prime_asked,
|
||||
same_day=same_day_asked,
|
||||
emergency=emergency_asked,
|
||||
payment_type=delivery_payment_method,
|
||||
payment_card_id=card_id_from_customer,
|
||||
pre_charge_amount=total_precharge_amount,
|
||||
@@ -798,25 +814,30 @@ def calculate_total(delivery_id):
|
||||
|
||||
get_price_query = (db.session
|
||||
.query(Pricing_Oil_Oil)
|
||||
.order_by(Pricing_Oil_Oil.date.asc())
|
||||
.order_by(Pricing_Oil_Oil.date.desc())
|
||||
.first())
|
||||
|
||||
|
||||
if get_delivery.prime == 1:
|
||||
priceprime = get_price_query.price_prime
|
||||
else:
|
||||
priceprime = 0
|
||||
|
||||
|
||||
if get_delivery.emergency == 1:
|
||||
priceemergency = get_price_query.price_emergency
|
||||
else:
|
||||
priceemergency = 0
|
||||
|
||||
if get_delivery.same_day == 1:
|
||||
pricesameday = get_price_query.price_same_day
|
||||
else:
|
||||
pricesameday = 0
|
||||
|
||||
total = float(get_delivery.total_price) + float(priceprime) + float(pricesameday)
|
||||
total = float(get_delivery.total_price) + float(priceprime) + float(pricesameday) + float(priceemergency)
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'priceprime': priceprime,
|
||||
'pricesameday': pricesameday,
|
||||
'priceemergency': priceemergency,
|
||||
'total_amount':total,
|
||||
}), 200
|
||||
@@ -3,13 +3,13 @@ from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from app.delivery_data import delivery_data
|
||||
from app import db
|
||||
from app.classes.customer import Customer_Customer
|
||||
from app.classes.customer import Customer_Customer, Customer_Description
|
||||
from app.classes.delivery import Delivery_Delivery
|
||||
from app.classes.employee import Employee_Employee
|
||||
from app.classes.cards import Card_Card
|
||||
from app.classes.stats_employee import Stats_Employee_Oil
|
||||
from app.classes.auto import Auto_Delivery
|
||||
|
||||
from app.classes.stats_customer import Stats_Customer
|
||||
|
||||
@delivery_data.route("/finalize/<int:delivery_id>", methods=["PUT"])
|
||||
def office_finalize_delivery(delivery_id):
|
||||
@@ -20,7 +20,7 @@ def office_finalize_delivery(delivery_id):
|
||||
"""
|
||||
Finalizes a delivery from office
|
||||
"""
|
||||
|
||||
now = datetime.utcnow()
|
||||
get_delivery = db.session \
|
||||
.query(Delivery_Delivery) \
|
||||
.filter(Delivery_Delivery.id == delivery_id) \
|
||||
@@ -31,6 +31,24 @@ def office_finalize_delivery(delivery_id):
|
||||
.filter(Customer_Customer.id == get_delivery.customer_id) \
|
||||
.first()
|
||||
|
||||
get_customer_description = db.session \
|
||||
.query(Customer_Description) \
|
||||
.filter(Customer_Description.customer_id == get_delivery.customer_id) \
|
||||
.first()
|
||||
if get_customer_description is None:
|
||||
new_customer_desc = Customer_Description(
|
||||
customer_id = get_customer.id,
|
||||
account_number =get_customer.account_number,
|
||||
company_id = get_customer.company_id,
|
||||
fill_location = None,
|
||||
description = None,
|
||||
)
|
||||
db.session.add(new_customer_desc)
|
||||
db.session.commit()
|
||||
get_customer_description = db.session \
|
||||
.query(Customer_Description) \
|
||||
.filter(Customer_Description.customer_id == get_delivery.customer_id) \
|
||||
.first()
|
||||
delivery_driver_id = request.json["driver_employee_id"]
|
||||
if delivery_driver_id is None:
|
||||
delivery_driver_id = 2
|
||||
@@ -42,12 +60,36 @@ def office_finalize_delivery(delivery_id):
|
||||
.filter(Employee_Employee.id == delivery_driver_id)
|
||||
.first())
|
||||
|
||||
get_stats = (db.session
|
||||
get_stats_employee = (db.session
|
||||
.query(Stats_Employee_Oil)
|
||||
.filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
.first())
|
||||
|
||||
if get_stats is None:
|
||||
get_stats_customer = (db.session
|
||||
.query(Stats_Customer)
|
||||
.filter(Stats_Customer.customer_id == get_customer.id)
|
||||
.first())
|
||||
if get_stats_customer is None:
|
||||
create_stats_customer = Stats_Customer(
|
||||
customer_id = get_customer.id,
|
||||
total_calls = 1,
|
||||
service_calls_total = 0,
|
||||
service_calls_total_spent = 0,
|
||||
service_calls_total_profit = 0,
|
||||
oil_deliveries = 1,
|
||||
oil_total_gallons = 0,
|
||||
oil_total_spent = 0,
|
||||
oil_total_profit = 0,
|
||||
|
||||
)
|
||||
db.session.add(create_stats_customer)
|
||||
db.session.flush()
|
||||
get_stats_customer = (db.session
|
||||
.query(Stats_Customer)
|
||||
.filter(Stats_Customer.customer_id == get_customer.id)
|
||||
.first())
|
||||
|
||||
if get_stats_employee is None:
|
||||
create_stats = Stats_Employee_Oil(
|
||||
employee_id = get_delivery.driver_employee_id,
|
||||
total_deliveries = 0,
|
||||
@@ -58,8 +100,7 @@ def office_finalize_delivery(delivery_id):
|
||||
db.session.add(create_stats)
|
||||
db.session.flush()
|
||||
|
||||
|
||||
get_stats = (db.session
|
||||
get_stats_employee = (db.session
|
||||
.query(Stats_Employee_Oil)
|
||||
.filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
.first())
|
||||
@@ -83,9 +124,9 @@ def office_finalize_delivery(delivery_id):
|
||||
prime_info = request.json["prime"]
|
||||
if prime_info is True:
|
||||
prime_info = 1
|
||||
current_primes = get_stats.total_primes
|
||||
current_primes = get_stats_employee.total_primes
|
||||
newprimes = current_primes + 1
|
||||
get_stats.total_primes = newprimes
|
||||
get_stats_employee.total_primes = newprimes
|
||||
else:
|
||||
prime_info = 0
|
||||
|
||||
@@ -142,11 +183,17 @@ def office_finalize_delivery(delivery_id):
|
||||
else:
|
||||
emergency_info = 0
|
||||
|
||||
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
|
||||
get_delivery.driver_employee_id = get_driver.id
|
||||
|
||||
|
||||
# update delivery
|
||||
get_delivery.when_delivered = now
|
||||
get_delivery.gallons_delivered = gallons_delivered
|
||||
get_delivery.prime = prime_info
|
||||
get_delivery.emergency = emergency_info
|
||||
@@ -157,15 +204,32 @@ def office_finalize_delivery(delivery_id):
|
||||
get_delivery.check_number = check_number
|
||||
get_delivery.delivery_status = 10
|
||||
|
||||
# update stats
|
||||
current_deliveres = get_stats.total_deliveries + 1
|
||||
get_stats.total_deliveries = current_deliveres
|
||||
# update stats employee
|
||||
current_deliveres = get_stats_employee.total_deliveries + 1
|
||||
get_stats_employee.total_deliveries = current_deliveres
|
||||
|
||||
current_gallons_delivered = Decimal(get_stats.total_gallons_delivered) + Decimal(gallons_delivered)
|
||||
get_stats.total_gallons_delivered = current_gallons_delivered
|
||||
current_gallons_delivered = Decimal(get_stats_employee.total_gallons_delivered) + Decimal(gallons_delivered)
|
||||
get_stats_employee.total_gallons_delivered = current_gallons_delivered
|
||||
|
||||
# update stats customer
|
||||
current_deliveres = int(get_stats_customer.oil_deliveries) + 1
|
||||
get_stats_customer.oil_deliveries = current_deliveres
|
||||
|
||||
new_gallons = Decimal(get_stats_customer.oil_total_gallons) + Decimal(gallons_delivered)
|
||||
get_stats_customer.oil_total_gallons = new_gallons
|
||||
|
||||
new_calls = int(get_stats_customer.total_calls) + 1
|
||||
get_stats_customer.total_calls = new_calls
|
||||
|
||||
|
||||
# update fill location
|
||||
get_customer_description.fill_location = fill_location
|
||||
|
||||
db.session.add(get_customer_description)
|
||||
db.session.add(get_stats_customer)
|
||||
db.session.add(get_stats_employee)
|
||||
db.session.add(get_delivery)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from app.payment import payment
|
||||
from app import db
|
||||
from app.classes.customer import Customer_Customer
|
||||
from app.classes.cards import Card_Card, Card_Card_schema
|
||||
from flask_login import current_user
|
||||
|
||||
|
||||
|
||||
def set_card_main(user_id, card_id):
|
||||
@@ -111,6 +111,7 @@ def create_user_card(user_id):
|
||||
type_of_card = request.json["type_of_card"]
|
||||
security_number = request.json["security_number"]
|
||||
main_card = request.json["main_card"]
|
||||
zip_code = request.json["main_card"]
|
||||
|
||||
card_number = request.json["card_number"]
|
||||
last_four = card_number[-4]
|
||||
@@ -126,10 +127,15 @@ def create_user_card(user_id):
|
||||
security_number=security_number,
|
||||
accepted_or_declined=None,
|
||||
main_card=main_card,
|
||||
zip_code=zip_code
|
||||
)
|
||||
db.session.add(create_new_card)
|
||||
db.session.flush()
|
||||
if main_card is True:
|
||||
set_card_main(user_id=get_customer.id, card_id=create_new_card.id)
|
||||
try:
|
||||
set_card_main(user_id=get_customer.id, card_id=create_new_card.id)
|
||||
except:
|
||||
pass
|
||||
db.session.add(create_new_card)
|
||||
db.session.commit()
|
||||
|
||||
@@ -186,6 +192,7 @@ def update_user_card(card_id):
|
||||
security_number = request.json["security_number"]
|
||||
card_number = request.json["card_number"]
|
||||
main_card = request.json["main_card"]
|
||||
zip_code = request.json["zip_code"]
|
||||
|
||||
get_card.user_id = get_customer.id
|
||||
get_card.card_number = card_number
|
||||
@@ -195,6 +202,7 @@ def update_user_card(card_id):
|
||||
get_card.type_of_card = type_of_card
|
||||
get_card.security_number = security_number
|
||||
get_card.main_card = main_card
|
||||
get_card.zip_code = zip_code
|
||||
|
||||
if main_card is True:
|
||||
set_card_main(user_id=get_customer.id, card_id=get_card.id)
|
||||
|
||||
@@ -5,7 +5,7 @@ from app.stats import stats
|
||||
from app import db
|
||||
from app.classes.delivery import Delivery_Delivery
|
||||
from app.classes.stats_company import Stats_Company, Stats_Company_schema
|
||||
|
||||
from app.classes.stats_customer import Stats_Customer, Stats_Customer_schema
|
||||
|
||||
@stats.route("/calls/add", methods=["PUT"])
|
||||
def total_calls_post():
|
||||
@@ -101,3 +101,52 @@ def total_deliveries_today_finished():
|
||||
'data': total_stops,
|
||||
}), 200
|
||||
|
||||
|
||||
@stats.route("/user/<int:user_id>", methods=["GET"])
|
||||
def get_user_stats(user_id):
|
||||
"""
|
||||
gets stats of user
|
||||
"""
|
||||
get_user = db.session \
|
||||
.query(Stats_Customer) \
|
||||
.filter(Stats_Customer.customer_id == user_id) \
|
||||
.first()
|
||||
if get_user is None:
|
||||
new_stats = Stats_Customer(
|
||||
customer_id = user_id,
|
||||
total_calls = 1,
|
||||
service_calls_total = 0,
|
||||
service_calls_total_spent = 0,
|
||||
service_calls_total_profit = 0,
|
||||
oil_deliveries = 0,
|
||||
oil_total_gallons = 0,
|
||||
oil_total_spent = 0,
|
||||
oil_total_profit = 0,
|
||||
)
|
||||
db.session.add(new_stats)
|
||||
db.session.commit()
|
||||
get_user = db.session \
|
||||
.query(Stats_Customer) \
|
||||
.filter(Stats_Customer.customer_id == user_id) \
|
||||
.first()
|
||||
user_schema = Stats_Customer_schema(many=False)
|
||||
return jsonify(user_schema.dump(get_user))
|
||||
|
||||
|
||||
@stats.route("/user/lastdelivery/<int:user_id>", methods=["GET"])
|
||||
def get_user_last_delivery(user_id):
|
||||
"""
|
||||
gets users last delivery. used on profile page
|
||||
"""
|
||||
get_delivery= db.session \
|
||||
.query(Delivery_Delivery) \
|
||||
.filter(Delivery_Delivery.customer_id == user_id) \
|
||||
.order_by(Delivery_Delivery.id.desc())\
|
||||
.first()
|
||||
if get_delivery:
|
||||
date_delivered = get_delivery.when_delivered
|
||||
else:
|
||||
date_delivered = "no deliveries on record"
|
||||
return jsonify({"ok": True,
|
||||
'date': date_delivered,
|
||||
}), 200
|
||||
Reference in New Issue
Block a user